working on it ...

Filters

Explore Public Snippets

Sort by

Found 28k snippets matching: official

    public by paulsimmons  1060  0  5  0

    WooCommerce Variable Pricing Plugin by FMEAddons

    If you want to convert potential customers to successful business leads, then WooCommerce variable pricing extension is a powerful tool for achieving this goal. This addon provides you an easy interface to offer bulk discounts on various sections on your website. You can give a special offer to your customers such as buy three products and get one
    // Enter here the actual content of the snippet.            

    public by msdn  231521  0  6  0

    _GetTickCount64: Retrieves the number of milliseconds that have elapsed since the system was started.

    Retrieves the number of milliseconds that have elapsed since the system was started. This value is a monotonically increasing value, unlike DateTime.Now. DateTime.Now can appear to move backwards due to system time changes, which can cause bugs in programs that expect to be able to calculate elapsed time by subtractin
    using System;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    
    private static GetTickCount64Delegate sm_GetTickCount64;
    
    /// <summary>
    ///    Retrieves the number of milliseconds that have elapsed since the system was
    ///    started.
    /// </summary>
    /// <remarks>
    /// <para>
    ///    This value is a monotonically increasing value, unlike DateTime.Now.
    ///    DateTime.Now can appear to move backwards due to system time changes, which
    ///    can cause bugs in programs that expect to be able to calculate elapsed time
    ///    by subtracting DateTimes obtained from DateTime.Now.
    /// </para>
    /// <para>
    ///    IMPORTANT: On Vista+, this simply calls the native GetTickCount64. On XP,
    ///    it emulates a 64-bit tick counter. The emulation assumes that the calling
    ///    program will call it <em>more than once every 49 days.</em> If not, the
    ///    results will be unpredictable.
    /// </para>
    /// </remarks>
    /// <returns>
    ///    A 64-bit value that contains the number of milliseconds that have elapsed
    ///    since the system was started.
    /// </returns>
    private static ulong _GetTickCount64()
    {
        // This is not threadsafe. It does not matter.
        if( null == sm_GetTickCount64 )
        {
            _AcquireGetTickCount64Delegate();
        }
    
        return sm_GetTickCount64();
    }

    public by msdn  222223  0  6  0

    Main: This sample uses the ProxyCommand class to create a proxy command that calls an existing cmdlet, but restricts the set of available parameters. The proxy command is then added to an intial session state that is used to crea...

    This sample uses the ProxyCommand class to create a proxy command that calls an existing cmdlet, but restricts the set of available parameters. The proxy command is then added to an intial session state that is used to create a contrained runspace. This means that the user can access the cmdlet through the proxy command. This sample
    /// <summary>
    /// This sample uses the ProxyCommand class to create a proxy command that 
    /// calls an existing cmdlet, but restricts the set of available parameters.  
    /// The proxy command is then added to an intial session state that is used to 
    /// create a contrained runspace. This means that the user can access the cmdlet 
    /// through the proxy command.
    /// </summary>
    /// <remarks>
    /// This sample demonstrates the following:
    /// 1. Creating a CommandMetadata object that describes the metadata of an 
    ///    existing cmdlet.
    /// 2. Modifying the cmdlet metadata to remove a parameter of the cmdlet.
    /// 3. Adding the cmdlet to an initial session state and making it private.
    /// 4. Creating a proxy function that calls the existing cmdlet, but exposes 
    ///    only a restricted set of parameters.   
    /// 6. Adding the proxy function to the initial session state. 
    /// 7. Calling the private cmdlet and the proxy function to demonstrate the 
    ///    constrained runspace.
    /// </remarks>
    private static void Main()
    {
      // Create a default intial session state. The default inital session state
      // includes all the elements that are provided by Windows PowerShell. 
      InitialSessionState iss = InitialSessionState.CreateDefault();
          
      // Add the get-proc cmdlet to the initial session state.
      SessionStateCmdletEntry cmdletEntry = new SessionStateCmdletEntry("get-proc", typeof(GetProcCommand), null);
      iss.Commands.Add(cmdletEntry);
          
      // Make the cmdlet private so that it is not accessable.
      cmdletEntry.Visibility = SessionStateEntryVisibility.Private;
          
      // Set the language mode of the intial session state to NoLanguge to 
      //prevent users from using language features. Only the invocation of 
      // public commands is allowed.
      iss.LanguageMode = PSLanguageMode.NoLanguage;
          
      // Create the proxy command using cmdlet metadata to expose the 
      // get-proc cmdlet.
      CommandMetadata cmdletMetadata = new CommandMetadata(typeof(GetProcCommand));
          
      // Remove one of the parameters from the command metadata.
      cmdletMetadata.Parameters.Remove("Name");
          
      // Generate the body of a proxy function that calls the original cmdlet, 
      // but does not have the removed parameter.
      string bodyOfProxyFunction = ProxyCommand.Create(cmdletMetadata);
          
      // Add the proxy function to the initial session state. The name of the proxy 
      // function can be the same as the name of the cmdlet, but to clearly 
      // demonstrate that the original cmdlet is not available a different name is 
      // used for the proxy function.
      iss.Commands.Add(new SessionStateFunctionEntry("get-procProxy", bodyOfProxyFunction));
          
      // Create the constrained runspace using the intial session state. 
      using (Runspace myRunspace = RunspaceFactory.CreateRunspace(iss))
      {
        myRunspace.Open();
            
        // Call the private cmdlet to demonstrate that it is not available.
        try
        {
          using (PowerShell powershell = PowerShell.Create())
          {
            powershell.Runspace = myRunspace;
            powershell.AddCommand("get-proc").AddParameter("Name", "*explore*");
            powershell.Invoke();
          }
        }
        catch (CommandNotFoundException e)
        {
          System.Console.WriteLine(
                        "Invoking 'get-proc' failed as expected: {0}: {1}", 
                        e.GetType().FullName, 
                        e.Message);
        }
            
        // Call the proxy function to demonstrate that the -Name parameter is 
        // not available.
        try
        {
          using (PowerShell powershell = PowerShell.Create())
          {
            powershell.Runspace = myRunspace;
            powershell.AddCommand("get-procProxy").AddParameter("Name", "idle");
            powershell.Invoke();
          }
        }
        catch (ParameterBindingException e)
        {
          System.Console.WriteLine(
                        "\nInvoking 'get-procProxy -Name idle' failed as expected: {0}: {1}", 
                        e.GetType().FullName, 
                        e.Message);
        }
            
        // Call the proxy function to demonstrate that it calls into the 
        // private cmdlet to retrieve the processes.
        using (PowerShell powershell = PowerShell.Create())
        {
          powershell.Runspace = myRunspace;
          powershell.AddCommand("get-procProxy");
          List<Process> processes = new List<Process>(powershell.Invoke<Process>());
          System.Console.WriteLine(
                        "\nInvoking the get-procProxy function called into the get-proc cmdlet and returned {0} processes", 
                        processes.Count);
        }
            
        // Close the runspace to release resources.
        myRunspace.Close();
      }
          
      System.Console.WriteLine("Hit any key to exit...");
      System.Console.ReadKey();
    }

    public by msdn  215740  1  7  0

    SelectDistinct: "SELECT DISTINCT" over a DataTable

    "SELECT DISTINCT" over a DataTable Input DataTable Fields to select (distinct) Optional filter to be applied to the selection DataTable
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    /// <summary>
    ///"SELECT DISTINCT" over a DataTable 
    /// </summary>
    /// <param name="SourceTable">Input DataTable</param>
    /// <param name="FieldNames">Fields to select (distinct)</param>
    /// <param name="Filter">Optional filter to be applied to the selection</param>
    /// <returns>DataTable</returns>
    /// <example>
    /// <code source="CodeExamples\SelectDistinctExamples.cs"  title="C# Examples"/>
    /// <code source="CodeExamples\DataTableSelectDistinctExamples.vb" language="vbnet" title="VB.NET Examples"/>
    /// </example>
    public static DataTable SelectDistinct(this DataTable SourceTable, String FieldNames, String Filter)
    {
        DataTable dt = new DataTable();
        String[] arrFieldNames = FieldNames.Replace(" ", "").Split(',');
        foreach (String s in arrFieldNames)
        {
            if (SourceTable.Columns.Contains(s))
                dt.Columns.Add(s, SourceTable.Columns[s].DataType);
            else
                throw new Exception(String.Format("The column {0} does not exist.", s));
        }
    
        Object[] LastValues = null;
        foreach (DataRow dr in SourceTable.Select(Filter, FieldNames))
        {
            Object[] NewValues = GetRowFields(dr, arrFieldNames);
            if (LastValues == null || !(ObjectComparison(LastValues, NewValues)))
            {
                LastValues = NewValues;
                dt.Rows.Add(LastValues);
            }
        }
    
        return dt;
    }

    public by msdn  194799  0  6  0

    GetParentName: Retreives the parent name from a storage Uri.

    Retreives the parent name from a storage Uri. The BLOB address. The delimiter. If set to true use path style Uris. The name of the parent. Adds the trailing delimiter as the prefix returned by the storage REST api always contains the delimiter. GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob", "/")) will re
    /// <summary>
    /// Retreives the parent name from a storage Uri.
    /// </summary>
    /// <param name="blobAddress">The BLOB address.</param>
    /// <param name="delimiter">The delimiter.</param>
    /// <param name="usePathStyleUris">If set to <c>true</c> use path style Uris.</param>
    /// <returns>The name of the parent.</returns>
    /// <remarks>
    /// Adds the trailing delimiter as the prefix returned by the storage REST api always contains the delimiter.
    /// </remarks>
    /// <example>
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob", "/")) will return "/mycontainer/myfolder/"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder|myblob", "|") will return "/mycontainer/myfolder|"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myblob", "/") will return "/mycontainer/"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/", "/") will return "/mycontainer/"
    /// </example>
    internal static string GetParentName(Uri blobAddress, string delimiter, bool usePathStyleUris)
    {
        CommonUtils.AssertNotNull("blobAbsoluteUriString", blobAddress);
        CommonUtils.AssertNotNullOrEmpty("delimiter", delimiter);
    
        string containerName;
        Uri containerUri;
        GetContainerNameAndAddress(blobAddress, usePathStyleUris, out containerName, out containerUri);
    
        // Get the blob path as the rest of the Uri
        var blobPathUri = containerUri.MakeRelativeUri(blobAddress);
        var blobPath = blobPathUri.OriginalString;
    
        if (blobPath.EndsWith(delimiter))
        {
            blobPath = blobPath.Substring(0, blobPath.Length - delimiter.Length);
        }
    
        string parentName = null;
    
        if (string.IsNullOrEmpty(blobPath))
        {
            // Case 1 /<ContainerName>[Delimiter]*? => /<ContainerName>
            // Parent of container is container itself
            parentName = containerName + delimiter;
        }
        else
        {
            var parentLength = blobPath.LastIndexOf(delimiter);
    
            if (parentLength <= 0)
            {
                // Case 2 /<Container>/<folder>
                // Parent of a folder is container
                parentName = containerName + delimiter;
            }
            else
            {
                // Case 3 /<Container>/<folder>/[<subfolder>/]*<BlobName>
                // Parent of blob is folder
                parentName = blobPath.Substring(0, parentLength + delimiter.Length);
            }
        }
    
        return parentName;
    }

    public by msdn  192693  0  7  0

    VerifyName: Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name. The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more than 15 characte...

    Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name. The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more than 15 characters. Storage Names are the most restricted in that they can only contain lower case letters and numbers. true if valid
    using System;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name.
    /// The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more
    /// than 15 characters.
    /// Storage Names are the most restricted in that they can only contain lower case letters and numbers.
    /// </summary>
    /// <returns>true if valid</returns>
    static public bool VerifyName(string name)
    {
        if (String.IsNullOrEmpty(name))
            return false;
        return Regex.IsMatch(name, "^[a-z0-9]{3,15}$", RegexOptions.Singleline);
    }

    public by msdn  190502  1  8  0

    IpcGetKey

    // IpcGetKey() - http://msdn.microsoft.com/en-us/library/windows/desktop/hh535263(v=vs.85).aspx
    using System;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Globalization;
    using Microsoft.Win32;
    
    // IpcGetKey() - http://msdn.microsoft.com/en-us/library/windows/desktop/hh535263(v=vs.85).aspx
    public static SafeInformationProtectionKeyHandle IpcGetKey(
                                    byte[] license,
                                    bool suppressUI, 
                                    bool offline,
                                    bool hasUserConsent,
                                    System.Windows.Forms.Form parentForm)
    {
        SafeInformationProtectionKeyHandle keyHandle = null;
        int hr = 0;
    
        SafeIpcPromptContext ipcPromptContext = CreateIpcPromptContext(suppressUI, offline, hasUserConsent, parentForm);
        SafeIpcBuffer ipcBuffer = MarshalIpcBufferToNative(license);
        try
        {
            hr = UnsafeNativeMethods.IpcGetKey(
                        (IpcBuffer)ipcBuffer,
                        0,
                        (IpcPromptContext)ipcPromptContext,
                        IntPtr.Zero,
                        out keyHandle);
            ThrowOnErrorCode(hr);
        }
        finally
        {
            ipcBuffer.Dispose();
            ReleaseIpcPromptContext(ipcPromptContext);
        }
    
        return keyHandle;
    }

    public by msdn  183601  0  6  0

    SelectManagementCertFile: Return a collection of installed X509Certificates from standard X509Certificate dialogue window

    Return a collection of installed X509Certificates from standard X509Certificate dialogue window
    using System;
    using System.IO;
    using System.Security.Cryptography.X509Certificates;
    using System.Security.Cryptography;
    using Microsoft.ComputeCluster.Management.Win32Helpers;
    using System.Collections.Generic;
    
    /// <summary>
    /// Return a collection of installed X509Certificates from standard X509Certificate dialogue window
    /// </summary>
    /// <returns></returns>
    public static X509Certificate2Collection SelectManagementCertFile()
    {
        X509Certificate2Collection certs = X509Certificate2UI.SelectFromCollection(GetValidCertificates(),
                                           "Select a Windows Azure Management Certificate",
                                           "",
                                           X509SelectionFlag.SingleSelection);
        return certs;
    }

    public by msdn  180065  0  8  0

    CreateTextOnlyToast

    // Note: All toast templates available in the Toast Template Catalog (http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) // are treated as a ToastText02 template on Windows Phone. // That template defines a maximum of 2 text elements. The first text element is treated as header text and is always bold. // Images will never be do
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Data.Xml.Dom;
    using Windows.Security.ExchangeActiveSyncProvisioning;
    using Windows.UI.Notifications;
    
    // Note: All toast templates available in the Toast Template Catalog (http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx)
    // are treated as a ToastText02 template on Windows Phone.
    // That template defines a maximum of 2 text elements. The first text element is treated as header text and is always bold.
    // Images will never be downloaded when any of the other templates containing image elements are used, because Windows Phone will
    // not display the image. The app icon (Square 150 x 150) is displayed to the left of the toast text and is also show in the action center.
    public static ToastNotification CreateTextOnlyToast(string toastHeading, string toastBody)
    {
        // Using the ToastText02 toast template.
        ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
    
        // Retrieve the content part of the toast so we can change the text.
        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    
        //Find the text component of the content
        XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    
        // Set the text on the toast. 
        // The first line of text in the ToastText02 template is treated as header text, and will be bold.
        toastTextElements[0].AppendChild(toastXml.CreateTextNode(toastHeading));
        toastTextElements[1].AppendChild(toastXml.CreateTextNode(toastBody));
    
        // Set the duration on the toast
        IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
        ((XmlElement)toastNode).SetAttribute("duration", "long");
    
        // Create the actual toast object using this toast specification.
        ToastNotification toast = new ToastNotification(toastXml); 
    
        return toast;
    }

    public by msdn  171138  2  6  0

    IpcInitialize

    // Configures the dll directory to include msipc.dll path. This function must be called before any other MSIPC function.
    using System;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Globalization;
    using Microsoft.Win32;
    
    // Configures the dll directory to include msipc.dll path. This function must be called before any other MSIPC function.
    public static void IpcInitialize()
    {
        const string MSIPC_CURRENT_VERSION_KEY = "SOFTWARE\\Microsoft\\MSIPC\\CurrentVersion";
        const string INSTALL_LOCATION_VALUE = "InstallLocation";
    
        RegistryKey key = Registry.LocalMachine.OpenSubKey(MSIPC_CURRENT_VERSION_KEY);
        if (null == key)
        {
            throw new Exception(MSIPC_CURRENT_VERSION_KEY + " not found");
        }
    
        string installLocation = (string)key.GetValue(INSTALL_LOCATION_VALUE);
        if (ReferenceEquals(installLocation, null) || 0 == installLocation.Trim().Length)
        {
            throw new Exception(INSTALL_LOCATION_VALUE + " not found");
        }
    
        bool configSuccessful = UnsafeNativeMethods.SetDllDirectory(installLocation);
        if (false == configSuccessful)
        {
            throw new Exception("SetDllDirectory failed with " + Marshal.GetLastWin32Error());
        }
        else
        {
            //Call a quick MSIPC method to load all the MSIPC.dll function pointers
            IpcGetAPIMode();
        }
    }
    • Public Snippets
    • Channels Snippets