working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,854 snippets matching: azure

    public by SpeedOfSpin modified Aug 4, 2016  236323  2  3  0

    Verbose Debugging output on Azure

    c#
    RoleEnvironment.TraceSource.Switch.Level = SourceLevels.Information;                 

    public by Geometry modified Jul 28, 2016  103540  4  5  0

    ResolveToEndPoint

    ResolveToEndPoint
    using System;
    using System.Linq;
    using System.Net;
    using System.Collections.Generic;
    
    public static IPEndPoint ResolveToEndPoint(string value)
    {
    	if (String.IsNullOrEmpty(value))
    		throw new ArgumentNullException("value");
    
    	var parts = value.Split(':');
    	if (parts.Length != 2)
    		throw new ArgumentException("host:port is expected", "value");
    
    	int port;
    	if (!Int32.TryParse(parts[1], out port))
    		throw new ArgumentException("Cannot parse port: " + parts[1], "value");
    
    	return ResolveToEndPoint(parts[0], port);
    }

    public by Geometry modified Jul 28, 2016  50773  0  4  0

    Allows bool to be BindableWithTypeConverter

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    private static bool IsBindableWithTypeConverter(Type parameterType)
    {
        if (parameterType == null)
        {
            return false;
        }
    
        return TypeDescriptor.GetConverter(parameterType).CanConvertFrom(typeof(string));
    }

    public by cghersi modified Sep 7, 2018  188  1  3  0

    Retrieve BLOB From Azure Blob Storage

    Quick method to retrieve a set of BLOBs for Azure Blob Storage, given their names. Unfortunately the Azure REST APIs don't allow, yet, to BULK retrieve the content of several BLOBs in one single call, so we need to loop over each BLOB and retrieve the content one by one
    public static Dictionary<Guid, byte[]> GetBlobs(List<string> names)
    {
      Dictionary<string, byte[]> result = new Dictionary<string, byte[]>();
    
      // retrieve info about the interesting BLOBs:
      IEnumerable<CloudBlob> blobs = s_defaultContainer.ListBlobs().
        OfType<CloudBlob>().Where(c => names.Contains(c.Name));
      
      // loop over the retrieved BLOBs:
      foreach (CloudBlob b in blobs)
      {
      	b.FetchAttributes(); //otherwise we cannot query for Properties...
      	byte[] res = new byte[b.Properties.Length];
      	
      	// download the actual content:
      	b.DownloadToByteArray(res, 0); 
      	
      	result.Add(b.Name, res);
      }
      
      return result;
    }

    public by marksimon232 modified Aug 12, 2014  2730  1  6  4

    Most efficient way to perform a FullText Search on SQL MS Azure

    On Azure SQL Database the FullText Search is not enabled, so what is the best way to do a similar search with acceptable performances? Using LIKE operator is not an option for large databases...
    SQL Azure Database does not currently (August 2014) support Full Text Search. Many requiring this functionality have opted to use Lucene.NET instead. There's a useful overview of Lucene.NET plus code samples below:
    
    Lucene.NET Overview and Code Samples: 
    http://leoncullens.nl/post/2012/11/18/Full-Text-Search-on-Azure-with-LuceneNET.aspx
    
    I was able to create a working demo against one of my own SQL Azure tables in about 10 minutes.
    var indexWriter = new IndexWriter(azureDir, new StandardAnalyzer(Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED);

    public by Geometry modified Jul 28, 2016  45145  0  4  0

    Main: The main entry point for the application.

    The main entry point for the application.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }

    public by SpeedOfSpin modified Feb 25, 2015  2022  3  4  0

    Upload blob to Azure

    var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());
    var blobClient = storageAccount.CreateCloudBlobClient();
    var logContainer = blobClient.GetContainerReference("data");
    if (logContainer.CreateIfNotExists())
    {
        logContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
    }
    CloudBlockBlob logfile = logContainer.GetBlockBlobReference("linkchecklogfiles/results.html");
    logfile.Properties.ContentType = "text/html";
    logfile.UploadFromFile("outputdata.html", FileMode.Open);                     

    public by Geometry modified Jul 28, 2016  42740  0  4  0

    Provides ParseTwitterDateTime

    Provides ParseTwitterDateTime
    using Newtonsoft.Json.Linq;
    using System;
    using System.Globalization;
    using System.IO;
    using System.Net;
    using System.Text;
    using System.Web;
    
    static DateTime ParseTwitterDateTime(string p)
    {
        if (p == null)
            return DateTime.Now;
        p = p.Replace("+0000 ", "");
        DateTimeOffset result;
    
        if (DateTimeOffset.TryParseExact(p, "ddd MMM dd HH:mm:ss yyyy", CultureInfo.GetCultureInfo("en-us").DateTimeFormat, DateTimeStyles.AssumeUniversal, out result))
            return result.DateTime;
        else
            return DateTime.Now;
    }

    public by Geometry modified Jul 28, 2016  39308  0  4  0

    Allows to InitializeGenerators

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Reflection;
    
    [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "These are simple type factories and cannot be split up.")]
    private static Dictionary<Type, Func<long, object>> InitializeGenerators()
    {
        return new Dictionary<Type, Func<long, object>>
        {
            { typeof(Boolean), index => true },
            { typeof(Byte), index => (Byte)64 },
            { typeof(Char), index => (Char)65 },
            { typeof(DateTime), index => DateTime.Now },
            { typeof(DateTimeOffset), index => new DateTimeOffset(DateTime.Now) },
            { typeof(DBNull), index => DBNull.Value },
            { typeof(Decimal), index => (Decimal)index },
            { typeof(Double), index => (Double)(index + 0.1) },
            { typeof(Guid), index => Guid.NewGuid() },
            { typeof(Int16), index => (Int16)(index % Int16.MaxValue) },
            { typeof(Int32), index => (Int32)(index % Int32.MaxValue) },
            { typeof(Int64), index => (Int64)index },
            { typeof(Object), index => new object() },
            { typeof(SByte), index => (SByte)64 },
            { typeof(Single), index => (Single)(index + 0.1) },
            { 
                typeof(String), index =>
                {
                    return String.Format(CultureInfo.CurrentCulture, "sample string {0}", index);
                }
            },
            { 
                typeof(TimeSpan), index =>
                {
                    return TimeSpan.FromTicks(1234567);
                }
            },
            { typeof(UInt16), index => (UInt16)(index % UInt16.MaxValue) },
            { typeof(UInt32), index => (UInt32)(index % UInt32.MaxValue) },
            { typeof(UInt64), index => (UInt64)index },
            { 
                typeof(Uri), index =>
                {
                    return new Uri(String.Format(CultureInfo.CurrentCulture, "http://webapihelppage{0}.com", index));
                }
            },
        };
    }

    public by Geometry modified Jul 28, 2016  22272  0  4  0

    Allows to GenerateRequestModelDescription

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    private static void GenerateRequestModelDescription(HelpPageApiModel apiModel, ModelDescriptionGenerator modelGenerator, HelpPageSampleGenerator sampleGenerator)
    {
        ApiDescription apiDescription = apiModel.ApiDescription;
        foreach (ApiParameterDescription apiParameter in apiDescription.ParameterDescriptions)
        {
            if (apiParameter.Source == ApiParameterSource.FromBody)
            {
                Type parameterType = apiParameter.ParameterDescriptor.ParameterType;
                apiModel.RequestModelDescription = modelGenerator.GetOrCreateModelDescription(parameterType);
                apiModel.RequestDocumentation = apiParameter.Documentation;
            }
            else if (apiParameter.ParameterDescriptor != null &&
                apiParameter.ParameterDescriptor.ParameterType == typeof(HttpRequestMessage))
            {
                Type parameterType = sampleGenerator.ResolveHttpRequestMessageType(apiDescription);
    
                if (parameterType != null)
                {
                    apiModel.RequestModelDescription = modelGenerator.GetOrCreateModelDescription(parameterType);
                }
            }
        }
    }
    • Public Snippets
    • Channels Snippets