Microsoft Security Advisory Notification Issued: April 15, 2015

Security Advisories Updated or Released Today

* Microsoft Security Advisory (2755801)
– Title: Update for Vulnerabilities in Adobe Flash Player in
Internet Explorer
https://technet.microsoft.com/library/security/2755801
– Revision Note: V39.0 (April 15, 2015): Added the 3049508
update to the Current Update section.

Global Azure Bootcamp 2015


Our friends from SoCal Code Camp have another awesome Community Developer Event! >>> Don’t Miss the Hands On Labs!!

Join us in San Diego for the 3rd annual Global Azure Bootcamp! On, Saturday, April 25, 2015 we are out to set some records again with the help of almost 200 locations!

 

Our San Diego event will be held at the Microsoft office in UTC. Michele Leroux Bustamante (Soliance) and Bret Stateham (Microsoft) are your hosts. Get ready for some fun-filled presentations and discussions on the Azure platform, a little real world special sauce.

In addition to this great learning opportunity we will have another set of hands on labs. In 2014 we pooled a huge global compute farm to perform diabetes research. This year everyone can participate in a compute pool for breast cancer research!

Register at : http://azurebootcamp-sd.eventday.com seating is limited and last year we sold out as fast as you read this email!

Thank your customer, tell them how valuable they are to you, but don’t go overboard. Insincerity is easy to spot.

 

 

 

Sincerely,

SoCal Code Camp
Community Developer Events

 

 

Ivan

Blog: http://blogs.msmvps.com/ivansanders/

clip_image001 clip_image002 clip_image003 clip_image004 clip_image005 clip_image006

 

Technorati Tags:

Microsoft Offers Free Care for your PCs

Our PC tune-ups don't cost a thing. Find your store

FacebookTwitter

Instagram

Pinterest

Pinterest

YouTube

 

Text 'MSSTORE' to 29502 for news and offers

 

 

Cheers,

Ivan Sanders
Blog: http://blogs.msmvps.com/ivansanders/

clip_image001[4] clip_image002[4] clip_image003[4] clip_image004[4] clip_image005[4] clip_image006[4]

 

Technorati Tags: ,

Add or Remove Trusted Devices Associated with your Microsoft Account in Windows 10

When you try to view or edit sensitive info related to your Microsoft account—like your credit card details—Microsoft might ask you for a security code first, to make sure that only you can get in to your account. But you can designate a PC as a trusted device. On trusted devices, you don’t need to enter a security code each time you try to access sensitive info.

This tutorial will show you how to add or remove PCs that you sign in to with your Microsoft account as trusted devices.

Read more…

Removal instructions for GoHDV15.04

What is GoHDV15.04?

The Malwarebytes research team has determined that GoHDV15.04 is a browser hijacker. These so-called “hijackers” manipulate your browser(s), for example to change your startpage or searchscopes, so that the affected browser visits their site or one of their choice. This one also displays advertisements.

https://forums.malwarebytes.org/index.php?%2Ftopic%2F167449-removal-instructions-for-gohdv1504%2F

Proyecto Liqueed (4)

Anterior Post
Siguiente Post

Ya quedó claro en los posts anteriores que gran parte del proyecto:

https://github.com/liquid-co-ops/liqueed

ha sido armado siguiendo el flujo de trabajo de TDD (Test-Driven Development).

En el anterior post vimos un ejemplo de lógica de servicio, cómo quedó implementada siguiendo tests. Veamos hoy que hay controladores, módulos JavaScript que exponen métodos como acciones a mapear por Express, que exponen una API (Application Program Interface) hacia afuera. Por ejemplo, controllerspersonapi.js, que comienza declarando:

'use strict';

var service = require('../services/person');

Vean que usa al servicio de personas.

Hay tests correspondientes, en testpersonapi.js, que comienza importando los módulos que va a usar:

'use strict';

var controller = require('../controllers/personapi');

var loaddata = require('../utils/loaddata');
var db = require('../utils/db');
var async = require('simpleasync');

En el anterior posts, discutí que en JavaScript la granularidad que prefiero para correr los tests es el módulo, más que una función. Luego ejecuto los tests en orden, dentro de ese módulo. Acá aparece el primer test, que se ocupa de inicializar el modelo de dominio:

var persons;

exports['clear and load data'] = function (test) {
    var personService = require('../services/person');

    test.async();
    
    async()
    .then(function (data, next) { db.clear(next); })
    .then(function (data, next) { loaddata(next); })
    .then(function (data, next) { personService.getPersons(next); })
    .then(function (data, next) {
        persons = data;
        test.ok(persons);
        test.ok(persons.length);
        test.done();
    })
    .run();
};

Lo nuevo aca a entender, es el uso de simpleasync, en la variable async, un módulo que escribí hace un tiempo para encadenar funciones JavaScript. Cada función recibe: data, el resultado de la anterior función, y next, un callback de JavaScript que admite dos argumentos: err y data. La función que definamos en la cadena, puede tomar data como resultado bueno de la anterior función definida en la cadena, y entregar err en null, y el nuevo data para el siguiente eslabón. O puede entregar err, y data en null, si detecta algún problema. Vemos en el ejemplo de arriba, que personService.getPersons(next) invoca la recuperación de la lista de personas, y se le pasa next, como callback. Entonces, la siguiente función en la cadena recibe data como respuesta, y lo utiliza.

A pesar que parece que está usando una base de datos, lo asumido es usar un modelo en memoria. Tenemos que ver dónde está esa decisión, pero hoy nos basta saber que el modelo inicial está en el directorio principal, en formato JSON en testdata.json. Parte de este archivo:

{
    "projects": [
        {
            "name": "FaceHub",
            "periods": [
                { 
                    "name": "January 2014", 
                    "date": "2014-01-31", 
                    "amount": 100,
                    "assignments": [
                        { "from": "Alice", 
                            "to": "Bob", 
                            "amount": 50, 
                            "note": "Arrive earlier" },
                        { "from": "Alice", 
                            "to": "Charlie", 
                            "amount": 50 , 
                            "note": "Arrive earlier" },
                        { "from": "Bob", 
                            "to": "Alice", 
                            "amount": 60 , 
                            "note": "Arrive earlier" },
                        { "from": "Bob", 
                            "to": "Charlie", 
                            "amount": 40 , 
                            "note": "Arrive earlier" },
                        { "from": "Charlie", 
                            "to": "Alice", 
                            "amount": 35 , 
                            "note": "Arrive earlier" },
                        { "from": "Charlie", 
                            "to": "Bob", 
                            "amount": 65 , 
                            "note": "Arrive earlier" }
                    ]
                },
                { "name": "February 2014", 
                    "date": "2014-02-28", 
                    "amount": 100 }
            ],
            "team": [ "Alice", "Bob", "Charlie" ],
//....

Vemos que personapi.js como módulo, al final termina exportando las acciones que queremos consumir:

module.exports = {
    list: list,
    get: get,
    getProjects: getProjects,
    loginPerson: loginPerson,
    getPendingShareProjects:getPendingShareProjects,
    updatePassword: updatePassword
}

Veremos en próximos posts, el segundo y siguientes tests de la API de persona, y cómo las acciones se rutean con Express.

Nos leemos!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Adobe Release Notes | Flash Player® 17 AIR® 17

April 14, 2015

In today’s scheduled release, we’ve updated Flash Player and AIR with important bug fixes and security updates.

Current Flash Player users that have enrolled in the “Allow Adobe to install updates (recommended)” update mechanism will be automatically updated over the next 24 hours. No additional work is required on your part.

Users that have selected “Notify me to install updates” will receive an update notification dialog within 7 days from today. Please note that Windows users will need to restart their system or log out and in to activate the update notification dialog.

Flash Player can always be downloaded and installed by simply visiting https://get.adobe.com/flashplayer

Customers using Google Chrome or Windows 8.x Internet Explorer will receive the update through the Google and Microsoft update mechanisms.

https://helpx.adobe.com/flash-player/release-note/fp_17_air_17_release_notes.html

Jogostempo.com Browser Hijacker Removal Guide

The Jogostempo.com program from the Adware/ShortcutHijacker family of browser hijackers that is bundled with other free software that you download off of the Internet. Once it is installed it will change your installed browser’s home page and search engine to Jogostempo.com without your permission. This adware will also infect your web browser shortcuts by adding the http://www.jogostempo.com?oem=unknown&uid=SG12412&tm=<timestamp> argument to them so that the Jogostempo.com site is opened every time you launch your browser. The method that they use to infect your shortcuts makes it impossible to fix without specialized tools such as our Shortcut Cleaner.

http://www.bleepingcomputer.com/virus-removal/remove-jogostempo.com-browser-hijacker

Microsoft Security Advisory Notification Issued: April 14, 2015

Security Advisories Updated or Released Today

* Microsoft Security Advisory (3045755)
– Title: Update to Improve PKU2U Authentication
– »technet.microsoft.com/library/se ··· /3045755
– Revision Note: V1.0 (April 14, 2015): Advisory published.

* Microsoft Security Advisory (3009008)
– Title: Vulnerability in SSL 3.0 Could Allow Information
Disclosure
– »technet.microsoft.com/library/se ··· /3009008
– Revision Note: V3.0 (April 14, 2015) Revised advisory to
announce that with the release of security update 3038314
on April 14, 2015 SSL 3.0 is disabled by default in Internet
Explorer 11, and to add instructions for how to undo the
workarounds.

Microsoft Security Bulletin Releases Issued: April 14, 2015

Summary

The following bulletin has undergone a major revision increment.

* MS14-080 – Critical

Bulletin Information:

MS14-080 – Critical

– Title: Cumulative Security Update for Internet Explorer (3008923)
– »technet.microsoft.com/library/se ··· ms14-080
– Reason for Revision: V3.0 (April 14, 2015): To comprehensively
address issues with the 3008923 security update, customers running
Internet Explorer 11 on either Windows 7 or Windows Server 2008 R2
should also install the 3038314 security update released on
April 14, 2015. For more information, see MS15-032 or use the
following Microsoft Download Center links for your specific
configuration:
* Internet Explorer 11 on Windows 7 for 32-bit Systems (3038314)
* Internet Explorer 11 on Windows 7 for x64-based Systems
Service Pack 1 (3038314)
* Internet Explorer 11 on Windows Server 2008 R2 for x64-based
Systems Service Pack 1 (3038314)
– Originally posted: December 9, 2014
– Updated: April 14, 2015
– Bulletin Severity Rating: Critical
– Version: 3.0

Microsoft Security Bulletin(s) for April 14, 2015

Note: There may be latency issues due to replication, if the page does not display keep refreshing

Today Microsoft released the following Security Bulletin(s).

Note: »www.microsoft.com/technet/securi ··· security and »www.microsoft.com/security are authoritative in all matters concerning Microsoft Security Bulletins! ANY e-mail, web board or newsgroup posting (including this one) should be verified by visiting these sites for official information. Microsoft never sends security or other updates as attachments. These updates must be downloaded from the microsoft.com download center or Windows Update. See the individual bulletins for details.

Because some malicious messages attempt to masquerade as official Microsoft security notices, it is recommended that you physically type the URLs into your web browser and not click on the hyperlinks provided.

Bulletin Summary:
»technet.microsoft.com/library/se ··· ms15-apr

Critical (4)

Microsoft Security Bulletin MS15-032
Cumulative Security Update for Internet Explorer (3038314)
»technet.microsoft.com/library/se ··· ms15-032

Microsoft Security Bulletin MS15-033
Vulnerabilities in Microsoft Office Could Allow Remote Code Execution (3048019)
»technet.microsoft.com/library/se ··· ms15-033

Microsoft Security Bulletin MS15-034
Vulnerability in HTTP.sys Could Allow Remote Code Execution (3042553)
»technet.microsoft.com/library/se ··· ms15-034

Microsoft Security Bulletin MS15-035
Vulnerability in Microsoft Graphics Component Could Allow Remote Code Execution (3046306)
»technet.microsoft.com/library/se ··· ms15-035

Important (7)

Microsoft Security Bulletin MS15-036
Vulnerabilities in Microsoft SharePoint Server Could Allow Elevation of Privilege (3052044)
»technet.microsoft.com/library/se ··· ms15-036

Microsoft Security Bulletin MS15-037
Vulnerability in Windows Task Scheduler Could Allow Elevation of Privilege (3046269)
»technet.microsoft.com/library/se ··· ms15-037

Microsoft Security Bulletin MS15-038
Vulnerabilities in Microsoft Windows Could Allow Elevation of Privilege (3049576)
»technet.microsoft.com/library/se ··· ms15-038

Microsoft Security Bulletin MS15-039
Vulnerability in XML Core Services Could Allow Security Feature Bypass (3046482)
»technet.microsoft.com/library/se ··· ms15-039

Microsoft Security Bulletin MS15-040
Vulnerability in Active Directory Federation Services Could Allow Information Disclosure (3045711)
»technet.microsoft.com/library/se ··· ms15-040

Microsoft Security Bulletin MS15-041
Vulnerability in .NET Framework Could Allow Information Disclosure (3048010)
»technet.microsoft.com/library/se ··· ms15-041

Microsoft Security Bulletin MS15-042
Vulnerability in Windows Hyper-V Could Allow Denial of Service (3047234)
»technet.microsoft.com/library/se ··· ms15-042

Please note that Microsoft may release bulletins out side of this schedule if we determine the need to do so.

If you have any questions regarding the patch or its implementation after reading the above listed bulletin you should contact Product Support Services in the United States at 1-866-PCSafety 1-866-727-2338. International customers should contact their local subsidiary.

As always, download the updates only from the vendors website – visit Windows Update and Office Update or Microsoft Update websites. You may also get the updates thru Automatic Updates functionality in Windows system.

Security Tool
Find out if you are missing important Microsoft product updates by using MBSA.

How to Create a Battery Saver Shortcut in Windows 10

Windows 10 introduces a new battery saver feature that conserves your PC’s battery by limiting background activity and adjusting hardware settings. Battery saver will turn on automatically if you like, but you can also turn it on manually.

This tutorial will show you how to create or download a battery saver shortcut that opens directly to Battery saver in Settings in Windows 10.

Read more…

Winpatrol 33.5.2015.3 Released

What’s new in 33.5.2015.3
  • Fixed issue with recurring alerts
  • Fixed issue where registry monitoring did not always alert
  • Enhanced background process to improve speed of detections
  • Enhanced product display and sorting on systems with large numbers of programs
  • Improved registration process
  • Fixed sorting on Delay Time in Delayed Start tab

https://www.winpatrol.com/winpatrol/

SIMDA – Major Botnet shutdown on April 9th

A major BOTNET was shutdown last week as the FBI & Interpol seized 14 command-and-control servers.  Microsoft, Kaspersky, Trend, and other major software vendors participated in helping take down this former threat.   

http://www.techweekeurope.co.uk/security/interpol-simda-botnet-166373

https://securelist.com/blog/69580/simdas-hide-and-seek-grown-up-games/

https://grahamcluley.com/2015/04/simda-check/

Microsoft MMPC -SIMDA Blog post

On 9 April, 2015 Kaspersky Lab was involved in the synchronized Simda botnet takedown operation coordinated by INTERPOL Global Complex for Innovation. In this case the investigation was initially started by Microsoft and expanded to involve a larger circle of participants including TrendMicro, the Cyber Defense Institute, officers from the Dutch National High Tech Crime Unit (NHTCU), the FBI, the Police Grand-Ducale Section Nouvelles Technologies in Luxembourg, and the Russian Ministry of the Interior’s Cybercrime Department “K” supported by the INTERPOL National Central Bureau in Moscow.

As a result of this takedown 14 C&C servers were seized in the Netherlands, USA, Luxembourg, Poland and Russia. Preliminary analysis of some of the sinkholed server logs revealed a list of 190 countries affected by the Simda botnet. Microsoft said it measured about 128,000 new Simda.AT infections each month for the past six months, with a sharp increase in recent weeks, registering 90,000 new infections in the US alone in the first two months of 2015. The countries most affected include the US, the UK, Turkey, Canada and Russia, according to Interpol.

Kaspersky IP CHECK to see if PC was registered as part of BOTNET
https://checkip.kaspersky.com/

SharePoint XSLT Web Part

After my previous post on XSLT processing, what else could follow? Of course, an XSLT web part for SharePoint! Smile

Here I want to solve a couple of problems:

  • Allow the usage of XSLT 2.0;
  • Have a more flexible parameter passing mechanism than <ParameterBindings>;
  • Make the XSLT extension mechanism (parameters, functions) more usable.

Similar to XsltListViewWebPart and the others, this web part will query SharePoint and return the results processed by a XSLT style sheet. I am going to built on top of the classes introduced in the last post. Here is the SPCustomXsltWebPart (please, do give it a better name…):

public enum XsltVersion

{

    Xslt1 = 1,

    Xslt2 = 2

}

 

public class SPCustomXsltWebPart : WebPart, IWebPartTable

{

    private static readonly Regex parametersRegex = new Regex(@"@(w+)b", RegexOptions.IgnoreCase);

 

    [NonSerialized]

    private DataTable table;

    [NonSerialized]

    private IOrderedDictionary parameters;

 

    public SPCustomXsltWebPart()

    {

        this.AddDefaultExtensions = true;

        this.RowLimit = Int32.MaxValue;

        this.Parameters = new ParameterCollection();

        this.XsltVersion = XsltVersion.Xslt1;

    }

 

    [Category("XSLT")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("XSL Version")]

    [WebDescription("The XSLT version")]

    [DefaultValue(XsltVersion.Xslt1)]

    public XsltVersion XsltVersion { get; set; }

 

    [Category("XSLT")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("XSL Link")]

    [WebDescription("The URL of a file containing XSLT")]

    [DefaultValue("")]

    public String XslLink { get; set; }

 

    [Category("XSLT")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("XSL")]

    [WebDescription("The XSLT content")]

    [DefaultValue("")]

    [PersistenceMode(PersistenceMode.InnerProperty)]

    public String Xsl { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Query")]

    [WebDescription("The CAML query")]

    [DefaultValue("")]

    [PersistenceMode(PersistenceMode.InnerProperty)]

    public String Query { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Row Limit")]

    [WebDescription("The row limit")]

    [DefaultValue(Int32.MaxValue)]

    public UInt32 RowLimit { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Lists")]

    [WebDescription("The target lists")]

    [DefaultValue("")]

    public String Lists { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Webs")]

    [WebDescription("The target webs")]

    [DefaultValue("")]

    public String Webs { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("View Fields")]

    [WebDescription("The view fields")]

    [DefaultValue("")]

    public String ViewFields { get; set; }

 

    [Category("Query")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Query Throttle Mode")]

    [WebDescription("The query throttle mode")]

    [DefaultValue(SPQueryThrottleOption.Default)]

    public SPQueryThrottleOption QueryThrottleMode { get; set; }

 

    [Category("General")]

    [Personalizable(PersonalizationScope.Shared)]

    [WebBrowsable(true)]

    [WebDisplayName("Add Default Extensions")]

    [WebDescription("Adds the default extensions")]

    [DefaultValue(true)]

    public Boolean AddDefaultExtensions { get; set; }

 

    [PersistenceModeAttribute(PersistenceMode.InnerProperty)]

    public ParameterCollection Parameters { get; private set; }

 

    public event EventHandler<XsltExtensionEventArgs> XsltExtension;

 

    protected XsltProvider XsltProvider

    {

        get

        {

            return this.XsltVersion == XsltVersion.Xslt1 ? DefaultXsltProvider.Instance : SaxonXsltProvider.Instance;

        }

    }

    protected virtual void OnXsltExtension(XsltExtensionEventArgs e)

    {

        var handler = this.XsltExtension;

 

        if (handler != null)

        {

            handler(this, e);

        }

    }

 

    protected override void CreateChildControls()

    {

        var xml = this.GetXml();

        var html = this.Render(xml);

        var literal = new LiteralControl(html);

 

        this.Controls.Add(literal);

 

        base.CreateChildControls();

    }

 

    private String GetXslt()

    {

        var xslt = String.Empty;

 

        if (String.IsNullOrWhiteSpace(this.Xsl) == false)

        {

            xslt = this.Xsl;

        }

        else if (String.IsNullOrWhiteSpace(this.XslLink) == false)

        {

            var doc = new XmlDocument();

            doc.Load(this.XslLink);

 

            xslt = doc.InnerXml;

        }

 

        return xslt;

    }

 

    private DataTable GetTable()

    {

        if (this.table == null)

        {

            var query = new SPSiteDataQuery();

            query.Query = this.ApplyParameters(this.Query);

            query.QueryThrottleMode = this.QueryThrottleMode;

            query.RowLimit = this.RowLimit;

            query.Lists = this.Lists;

            query.Webs = this.Webs;

            query.ViewFields = this.ViewFields;

 

            this.table = SPContext.Current.Site.RootWeb.GetSiteData(query);

            this.table.TableName = "Row";

 

            foreach (var column in this.table.Columns.OfType<DataColumn>())

            {

                column.ColumnMapping = MappingType.Attribute;

            }

        }

 

        return this.table;

    }

 

    private String ApplyParameters(String value)

    {

        var parameters = this.GetParameters();

 

        value = parametersRegex.Replace(value, x => this.GetFormattedValue(parameters[x.Value.Substring(1)]));

 

        return value;

    }

 

    private String GetFormattedValue(Object value)

    {

        if (value == null)

        {

            return String.Empty;

        }

 

        if (value is Enum)

        {

            return ((Int32)value).ToString();

        }

 

        if (value is DateTime)

        {

            return SPUtility.CreateISO8601DateTimeFromSystemDateTime((DateTime)value);

        }

 

        if (value is IFormattable)

        {

            return (value as IFormattable).ToString(String.Empty, CultureInfo.InvariantCulture);

        }

 

        return value.ToString();

    }

 

    private IOrderedDictionary GetParameters()

    {

        if (this.parameters == null)

        {

            this.parameters = this.Parameters.GetValues(this.Context, this);

        }

 

        return this.parameters;

    }

 

    private String GetXml()

    {

        var sb = new StringBuilder();

        var table = this.GetTable();

 

        using (var writer = new StringWriter(sb))

        {

            table.WriteXml(writer);

        }

 

        sb

            .Replace("<DocumentElement>", "<dsQueryResponse RowLimit='" + this.RowLimit + "'><Rows>")

            .Replace("</DocumentElement>", "</Rows></dsQueryResponse>");

 

        return sb.ToString();

    }

 

    private String ApplyXslt(String xml, String xslt, XsltExtensionEventArgs args)

    {

        return this.XsltProvider.Transform(xml, xslt, args);

    }

 

    private String Render(String xml)

    {

        if (String.IsNullOrWhiteSpace(xml) == true)

        {

            return String.Empty;

        }

 

        var xslt = this.GetXslt();

 

        if (String.IsNullOrWhiteSpace(xslt) == true)

        {

            return String.Empty;

        }

 

        var extensions = new XsltExtensionEventArgs();

 

        this.OnXsltExtension(extensions);

 

        if (this.AddDefaultExtensions == true)

        {

            var defaultExtensions = Activator.CreateInstance(typeof(Microsoft.SharePoint.WebPartPages.DataFormWebPart).Assembly.GetType("Microsoft.SharePoint.WebPartPages.DataFormDdwRuntime"));

            extensions.AddExtension("http://schemas.microsoft.com/WebParts/v2/DataView/runtime", defaultExtensions);

        }

 

        foreach (var ext in extensions.Extensions)

        {

            extensions.AddExtension(ext.Key, ext.Value);

        }

 

        var parameters = this.GetParameters();

 

        foreach (var key in parameters.Keys.OfType<String>())

        {

            extensions.AddParameter(key, String.Empty, parameters[key].ToString());

        }

 

        foreach (var param in extensions.Parameters)

        {

            extensions.AddParameter(param.Name, param.NamespaceUri, param.Parameter.ToString());

        }

 

        return this.ApplyXslt(xml, xslt, extensions);

    }

 

    void IWebPartTable.GetTableData(TableCallback callback)

    {

        callback(this.GetTable().DefaultView);

    }

 

    PropertyDescriptorCollection IWebPartTable.Schema

    {

        get { return TypeDescriptor.GetProperties(this.GetTable().DefaultView); }

    }

}

This class extends the basic WebPart class and adds a couple of properties:

  • XsltVersion: the XSLT version to use, which will result in either my DefaultXsltProvider or the SaxonXsltProvider being used;
  • XslLink: the URL of a file containing XSLT;
  • Xsl: in case you prefer to have the XSLT inline;
  • Query: a CAML query;
  • Webs: the webs to query;
  • Lists: the lists to query;
  • ViewFields: the fields to return;
  • RowLimit: maximum number of rows to return;
  • QueryThrottleMode: the query throttle mode;
  • AddDefaultExtensions: whether to add the default extension functions and parameters;
  • Parameters: a standard collection of ASP.NET parameter controls.

The web part uses SPSiteDataQuery to execute a CAML query. Before the query is executed, any parameters it may have, in the form @ParameterName,  are replaced by actual values evaluated from the Parameters collection. This gives some flexibility to the queries, because, not only ASP.NET includes parameters for all the common sources, it’s very easy to add new ones. The web part knows how to format strings, enumerations, DateTime objects and in general any object implementing IFormattable; if you wish, you can extend it to support other types, but I don’t think it will be necessary.

An example usage:

<web:SPCustomXsltWebPart runat="server" XslLink="~/Style.xslt">

    <Query>

        <Where><Eq><FieldRef Name='Id'/><Value Type='Number'>@Id</Value></Eq></Where>

    </Query>

    <Parameters>

        <asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />

    </Parameters>

</web:SPCustomXsltWebPart>

Notice that one of the Xsl or the XslLink properties must be set, and the same goes for the Query.

Hope you find this useful, and let me know how it works!

     

    How to Check if User is a Local Account or Microsoft Account in Windows 10

    You can sign in to Windows 10 with a local account or a Microsoft account.

    This tutorial will show you how to check if a user account in Windows 10 is either a local account or a Microsoft account.

    Read more…

    How to Create a Windows Update Shortcut in Windows 10

    Windows Update helps keep your PC safer and your software current by automatically downloading and installing important and critical updates for Windows from Microsoft via the Internet.

    This tutorial will show you how to create or download a Windows Update shortcut that opens directly to Windows Update in Settings in Windows 10.

    Read more…

    XSLT Processing in .NET

    God only knows why, but the .NET framework only includes support for XSLT 1.0. This makes it difficult, but not impossible, to use the more recent 2.0 version: a number of external libraries exist that can help us achieve that.

    I wanted to make this easier for us developers, namely:

    1. To have a common interface for abstracting typical functionality – transform some XML with some XSLT;
    2. Be able to inject parameters;
    3. Be able to inject custom extension functions.

    I first set out to define my base API:

    [Serializable]

    public abstract class XsltProvider

    {

        public abstract String Transform(String xml, String xslt, XsltExtensionEventArgs args);

        public abstract Single Version { get; }

    }

     

    [Serializable]

    public sealed class XsltExtensionEventArgs

    {

        public XsltExtensionEventArgs()

        {

            this.Extensions = new Dictionary<String, Object>();

            this.Parameters = new HashSet<XsltParameter>();

        }

     

        public IDictionary<String, Object> Extensions

        {

            get;

            private set;

        }

     

        public ISet<XsltParameter> Parameters

        {

            get;

            private set;

        }

     

        public XsltExtensionEventArgs AddExtension(String @namespace, Object extension)

        {

            this.Extensions[@namespace] = extension;

            return this;

        }

     

        public XsltExtensionEventArgs AddParameter(String name, String namespaceUri, String parameter)

        {

            this.Parameters.Add(new XsltParameter(name, namespaceUri, parameter));

            return this;

        }

    }

    The XsltProvider class only defines a version and a transformation method. This transformation method receives an XML and an XSLT parameters and also an optional collection of extension methods and parameters. There’s a singleton instance to make it easier to use, since this class really has no state.

    An implementation using .NET’s built-in classes, for XSLT 1.0, is trivial:

    [Serializable]

    public sealed class DefaultXsltProvider : XsltProvider

    {

        public static readonly XsltProvider Instance = new DefaultXsltProvider();

     

        public override Single Version

        {

            get { return 1F; }

        }

     

        public override String Transform(String xml, String xslt, XsltExtensionEventArgs args)

        {

            using (var stylesheet = new XmlTextReader(xslt, XmlNodeType.Document, null))

            {

                var arg = new XsltArgumentList();

     

                foreach (var key in args.Extensions.Keys)

                {

                    arg.AddExtensionObject(key, args.Extensions[key]);

                }

     

                foreach (var param in args.Parameters)

                {

                    arg.AddParam(param.Name, param.NamespaceUri, param.Parameter);

                }

     

                var doc = new XmlDocument();

                doc.LoadXml(xml);

     

                var transform = new XslCompiledTransform();

                transform.Load(stylesheet);

     

                var sb = new StringBuilder();

     

                using (var writer = new StringWriter(sb))

                {

                    var results = new XmlTextWriter(writer);

     

                    transform.Transform(doc, arg, results);

     

                    return sb.ToString();

                }

            }

        }

    }

    For XSLT 2.0, we have a number of options. I ended up using Saxon-HE, an open-source and very popular library for .NET and Java. I installed it through NuGet:

    image

    Here is a possible implementation on top of my base class:

    [Serializable]

    public sealed class SaxonXsltProvider : XsltProvider

    {

        public static readonly XsltProvider Instance = new SaxonXsltProvider();

     

        public override Single Version

        {

            get { return 2F; }

        }

     

        public override String Transform(String xml, String xslt, XsltExtensionEventArgs args)

        {

            var processor = new Processor();

     

            foreach (var key in args.Extensions.Keys)

            {

                foreach (var function in this.CreateExtensionFunctions(args.Extensions[key], key))

                {

                    processor.RegisterExtensionFunction(function);

                }

            }

     

            var document = new XmlDocument();

            document.LoadXml(xslt);

     

            var input = processor.NewDocumentBuilder().Build(document);

     

            var xsltCompiler = processor.NewXsltCompiler();

     

            var xsltExecutable = xsltCompiler.Compile(input);

     

            var xsltTransformer = xsltExecutable.Load();

     

            foreach (var parameter in args.Parameters)

            {

                xsltTransformer.SetParameter(new QName(String.Empty, parameter.NamespaceUri, parameter.Name), CustomExtensionFunctionDefinition.GetValue(parameter.Parameter));

            }

     

            using (var transformedXmlStream = new MemoryStream())

            {

                var dataSerializer = processor.NewSerializer(transformedXmlStream);

     

                xsltTransformer.InputXmlResolver = null;

                xsltTransformer.InitialContextNode = processor.NewDocumentBuilder().Build(input);

                xsltTransformer.Run(dataSerializer);

     

                var result = Encoding.Default.GetString(transformedXmlStream.ToArray());

     

                return result;

            }

        }

     

        private IEnumerable<ExtensionFunctionDefinition> CreateExtensionFunctions(Object extension, String namespaceURI)

        {

            foreach (var method in extension.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static).Where(x => x.IsAbstract == false))

            {

                yield return new CustomExtensionFunctionDefinition(method, namespaceURI, extension);

            }

        }

     

        class CustomExtensionFunctionDefinition : ExtensionFunctionDefinition

        {

            private readonly String namespaceURI;

            private readonly MethodInfo method;

            private readonly Object target;

     

            public CustomExtensionFunctionDefinition(MethodInfo method, String namespaceURI, Object target)

            {

                this.method = method;

                this.namespaceURI = namespaceURI;

                this.target = target;

            }

     

            public override XdmSequenceType[] ArgumentTypes

            {

                get

                {

                    return this.method.GetParameters().Select(x => this.GetArgumentType(x)).ToArray();

                }

            }

     

            private XdmSequenceType GetArgumentType(ParameterInfo parameter)

            {

                return new XdmSequenceType(GetValueType(parameter.ParameterType), XdmSequenceType.ONE);

            }

     

            internal static XdmAtomicValue GetValue(Object value)

            {

                if (value is String)

                {

                    return new XdmAtomicValue(value.ToString());

                }

     

                if ((value is Int32) || (value is Int32))

                {

                    return new XdmAtomicValue(Convert.ToInt64(value));

                }

     

                if (value is Boolean)

                {

                    return new XdmAtomicValue((Boolean)value);

                }

     

                if (value is Single)

                {

                    return new XdmAtomicValue((Single)value);

                }

     

                if (value is Double)

                {

                    return new XdmAtomicValue((Double)value);

                }

     

                if (value is Decimal)

                {

                    return new XdmAtomicValue((Decimal)value);

                }

     

                if (value is Uri)

                {

                    return new XdmAtomicValue((Uri)value);

                }

     

                throw new ArgumentException("Invalid value type.", "value");

            }

     

            internal static XdmAtomicType GetValueType(Type type)

            {

                if (type == typeof(Int32) || type == typeof(Int64) || type == typeof(Int16))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_INTEGER);

                }

     

                if (type == typeof(Boolean))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_BOOLEAN);

                }

     

                if (type == typeof(String))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_STRING);

                }

     

                if (type == typeof(Single))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_FLOAT);

                }

     

                if (type == typeof(Double))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_DOUBLE);

                }

     

                if (type == typeof(Decimal))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_DECIMAL);

                }

     

                if (type == typeof(Uri))

                {

                    return XdmAtomicType.BuiltInAtomicType(QName.XS_ANYURI);

                }

     

                throw new ArgumentException("Invalid value type.", "value");

            }

     

            public override QName FunctionName

            {

                get { return new QName(String.Empty, this.namespaceURI, this.method.Name); }

            }

     

            public override ExtensionFunctionCall MakeFunctionCall()

            {

                return new CustomExtensionFunctionCall(this.method, this.target);

            }

     

            public override Int32 MaximumNumberOfArguments

            {

                get { return this.method.GetParameters().Length; }

            }

     

            public override Int32 MinimumNumberOfArguments

            {

                get { return this.method.GetParameters().Count(p => p.HasDefaultValue == false); }

            }

     

            public override XdmSequenceType ResultType(XdmSequenceType[] argumentTypes)

            {

                return new XdmSequenceType(GetValueType(this.method.ReturnType), XdmSequenceType.ONE);

            }

        }

     

        class CustomExtensionFunctionCall : ExtensionFunctionCall

        {

            private readonly MethodInfo method;

            private readonly Object target;

     

            public CustomExtensionFunctionCall(MethodInfo method, Object target)

            {

                this.method = method;

                this.target = target;

            }

     

            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)

            {

                var args = new List<Object>();

     

                foreach (var arg in arguments)

                {

                    var next = arg.MoveNext();

                    var current = arg.Current as XdmAtomicValue;

                    args.Add(current.Value);

                }

     

                var result = this.method.Invoke(this.target, args.ToArray());

     

                var value = CustomExtensionFunctionDefinition.GetValue(result);

                return value.GetEnumerator() as IXdmEnumerator;

            }

        }

    }

    You can see that this required considerable more effort. I use reflection to find all arguments and the return type of the passed extension objects and I convert them to the proper types that Saxon expects.

    A simple usage might be:

    //sample class containing utility functions

    class Utils

    {

        public int Length(string s)

        {

            //just a basic example

            return s.Length;

        }

    }

     

    var provider = SaxonXsltProvider.Instance;

     

    var arg = new XsltExtensionEventArgs()

        .AddExtension("urn:utils", new Utils())

        .AddParameter("MyParam", String.Empty, "My Value");

     

    var xslt = "<?xml version='1.0'?><xsl:transform version='2.0' xmlns:utils='urn:utils' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'>Length: <xsl:value-of select='utils:Length("Some Text")'/> My Parameter: <xsl:value-of select='@MyParam'/></xsl:template></xsl:transform>";

    var xml = "<?xml version='1.0'?><My><SampleContents/></My>";

     

    var result = provider.Transform(xml, xslt, arg);

    Here I register an extension object with a public function taking one parameter and also a global parameter. In the XSLT I output this parameter and also the results of the invocation of a method in the extension object. The namespace of the custom function (Length) must match the one registered in the XsltExtensionEventArgs instance.

    As always, hope you find this useful! Winking smile

    How to Switch to a Microsoft Account from a Local Account in Windows 10

    You can sign in to Windows 10 with a local account or a Microsoft account. However, you can easily switch between using a local account or a Microsoft account to sign in to Windows 10.

    This tutorial will show you how to switch to sign in to Windows 10 with a Microsoft account instead of a local account.

    Read more…

     

    How to Switch to a Local Account from a Microsoft Account in Windows 10

    You can sign in to Windows 10 with a local account or a Microsoft account. However, you can easily switch between using a local account or a Microsoft account to sign in to Windows 10.

    This tutorial will show you how to switch to sign in to Windows 10 with a local account instead of a Microsoft account.

    Read more…

    Recent Comments

    Archives