当前位置: 首页>>代码示例>>C#>>正文


C# Auth.StorageCredentials类代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Auth.StorageCredentials的典型用法代码示例。如果您正苦于以下问题:C# StorageCredentials类的具体用法?C# StorageCredentials怎么用?C# StorageCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StorageCredentials类属于Microsoft.WindowsAzure.Storage.Auth命名空间,在下文中一共展示了StorageCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Tracker

        public Tracker(string accountName, string keyValue)
        {
            _applicationId = IdUtil.ApplicationId();
            _deviceId = IdUtil.DeviceId();
            _anid = IdUtil.GetAnidFromOs();
            _appTitle = IdUtil.ApplicationName();
            _adsRefreshRate = 3;
            _pubCenterAdsId = new List<string>();
            _adsReady = false;

            // Due to Disallowed key in RowKey, /, \, #, ? needs to be removed
            // And excel cannot allow "=" at the beginning
            foreach (var s in _invalidRowKeyChar) {
                _deviceId = _deviceId.Replace(s, string.Empty);
                if (_deviceId.Substring(0, 1) == "=") {
                    _deviceId = "x" + _deviceId;
                }
            }

            GetAdAssemblyVersion();
            RefreshIpInfo();

            _storageCredentials = new StorageCredentials(accountName, keyValue);
            _storageAccount = new CloudStorageAccount(_storageCredentials, false);
            _tableClient = _storageAccount.CreateCloudTableClient();

            EnsureTablesCreated();
        }
开发者ID:NBitionDevelopment,项目名称:WindowsPhonePhotoHuntAnimal,代码行数:28,代码来源:Tracker.cs

示例2: Log

 public async static void Log(
     string storageAccountName, 
     string storageAccountKey, 
     string exceptionsTableName, 
     string exceptionSource, 
     string exceptionDescription, 
     ILogger logger = null)
 {
     DateTime dt = DateTime.UtcNow;
     try
     {
         StorageCredentials storageCredentials = new StorageCredentials(storageAccountName, storageAccountKey);
         CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
         CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
         tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 10);
         CloudTable table_AppExceptions = tableClient.GetTableReference(exceptionsTableName);
         await table_AppExceptions.CreateIfNotExistsAsync();
         ExceptionLog entity = new ExceptionLog((DateTime.MaxValue - dt).ToString());
         entity.DT = dt;
         entity.MachineName = Environment.MachineName;
         entity.Application = Assembly.GetEntryAssembly().GetName().Name;
         entity.Source = exceptionSource;
         entity.Description = exceptionDescription;
         await table_AppExceptions.ExecuteAsync(TableOperation.Insert(entity));
     } 
     catch (System.Exception ex)
     {
         if (logger != null)
         {
             logger.Error(exceptionSource + ":" + exceptionDescription + ": " + ex.ToString());
         }
         Console.WriteLine(dt.ToString() + " " + Environment.MachineName + ":" + Assembly.GetEntryAssembly().GetName().Name + ":" + exceptionSource + ":" + exceptionDescription + ": " + ex.ToString());
     } 
 }
开发者ID:GuardRex,项目名称:GuardRex.AzureTableStorageExceptionLogger,代码行数:34,代码来源:ExceptionLogger.cs

示例3: CloudQueue

        public CloudQueue(StorageUri queueAddress, StorageCredentials credentials)
#endif
        {
            this.ParseQueryAndVerify(queueAddress, credentials);
            this.Metadata = new Dictionary<string, string>();
            this.EncodeMessage = true;
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:7,代码来源:CloudQueue.Common.cs

示例4: InitStorage

 private static void InitStorage()
 {
     var credentials = new StorageCredentials(AppKeys.Storage_Account_Name, AppKeys.PrimaryAccessKey);
     var storageAccount = new CloudStorageAccount(credentials, true);
     var blobClient = storageAccount.CreateCloudBlobClient();
     imagesContainer = blobClient.GetContainerReference("images");
 }
开发者ID:antataiv,项目名称:ASP.Net-Photo-Contest-Web-Application,代码行数:7,代码来源:BaseController.cs

示例5: CreateRequestMessage

        /// <summary>
        /// Creates the web request.
        /// </summary>
        /// <param name="uri">The request Uri.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="builder">The builder.</param>
        /// <returns>A web request for performing the operation.</returns>
        internal static StorageRequestMessage CreateRequestMessage(HttpMethod method, Uri uri, int? timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            if (timeout.HasValue && timeout.Value > 0)
            {
                builder.Add("timeout", timeout.ToString());
            }

#if WINDOWS_RT && !NETCORE
            // Windows Phone does not allow the caller to disable caching, so a random GUID
            // is added to every URI to make it look like a different request.
            builder.Add("randomguid", Guid.NewGuid().ToString("N"));
#endif

            Uri uriRequest = builder.AddToUri(uri);

            StorageRequestMessage msg = new StorageRequestMessage(method, uriRequest, canonicalizer, credentials, credentials.AccountName);
            msg.Content = content;

            return msg;
        }
开发者ID:mirobers,项目名称:azure-storage-net,代码行数:32,代码来源:HttpRequestMessageFactory.cs

示例6: StorageHelper

 public StorageHelper()
 {
     var storageCred = new StorageCredentials(AppSettings.StorageAccountName, AppSettings.StorageAccountKey);
      storageAccount = new CloudStorageAccount(storageCred, true);
     configureCors(storageAccount);
   
 }
开发者ID:cephalin,项目名称:ContosoMoments,代码行数:7,代码来源:StorageHelper.cs

示例7: GetStorageCredentials

        protected StorageCredentials GetStorageCredentials(String resourceGroupName, String storageAccountName)
        {
            StorageCredentials credentials = null;

            if (StorageClient != null && StorageClient.StorageAccounts != null)
            {
                var keys = StorageClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName);

                if (keys != null && keys.StorageAccountKeys != null)
                {
                    var storageAccountKey = string.IsNullOrEmpty(keys.StorageAccountKeys.Key1) ? keys.StorageAccountKeys.Key2 : keys.StorageAccountKeys.Key1;

                    credentials = new StorageCredentials(storageAccountName, storageAccountKey);
                }
            }

            if (credentials == null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new UnauthorizedAccessException(Properties.Resources.AzureVMDscDefaultStorageCredentialsNotFound),
                        "CredentialsNotFound",
                        ErrorCategory.PermissionDenied,
                        null));
            }

            if (string.IsNullOrEmpty(credentials.AccountName))
            {
                ThrowInvalidArgumentError(Properties.Resources.AzureVMDscStorageContextMustIncludeAccountName);
            }

            return credentials;
        }
开发者ID:nemanja88,项目名称:azure-powershell,代码行数:33,代码来源:VirtualMachineDscExtensionBaseCmdlet.cs

示例8: CopyBlobData

        /// <summary>
        /// Initiates the SolCat Azure blob data sync.  
        /// </summary>
        public static void CopyBlobData()
        {
            // Authentication Credentials for Azure Storage:
            var credsSrc
                = new StorageCredentials(
                    ConfigHelper.GetConfigValue("HubContainerName"),
                    ConfigHelper.GetConfigValue("HubContainerKey"));

            var credsDest
                = new StorageCredentials(
                    ConfigHelper.GetConfigValue("NodeContainerKey"),
                    ConfigHelper.GetConfigValue("NodeContainerKey"));

            // Source Container: Hub (Development)
            _srcContainer =
                new CloudBlobContainer(
                    new Uri(ConfigHelper.GetConfigValue("HubContainerUri")),
                    credsSrc);

            // Destination Container: Node (Production)
            _destContainer =
                new CloudBlobContainer(
                    new Uri(ConfigHelper.GetConfigValue("NodeContainerUri")),
                    credsDest);

            // Set permissions on the container:
            var permissions = new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessType.Blob};
            _srcContainer.SetPermissions(permissions);
            _destContainer.SetPermissions(permissions);

            // Call the blob copy master method:
            CopyBlobs(_srcContainer, _destContainer);
        }
开发者ID:nocarrier,项目名称:AzureStorage,代码行数:36,代码来源:BlobManager.cs

示例9: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("Press any key to run sample...");
            Console.ReadKey();

            // Make sure the endpoint matches with the web role's endpoint.
            var tokenServiceEndpoint = ConfigurationManager.AppSettings["serviceEndpointUrl"];

            try
            {
                var blobSas = GetBlobSas(new Uri(tokenServiceEndpoint)).Result;

                // Create storage credentials object based on SAS
                var credentials = new StorageCredentials(blobSas.Credentials);

                // Using the returned SAS credentials and BLOB Uri create a block blob instance to upload
                var blob = new CloudBlockBlob(blobSas.BlobUri, credentials);

                using (var stream = GetFileToUpload(10))
                {
                    blob.UploadFromStream(stream);
                }

                Console.WriteLine("Blob uplodad successful: {0}", blobSas.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
            Console.WriteLine();
            Console.WriteLine("Done. Press any key to exit...");
            Console.ReadKey();
        }
开发者ID:mspnp,项目名称:cloud-design-patterns,代码行数:34,代码来源:Program.cs

示例10: UploadFile

        public virtual Uri UploadFile(
            string storageName,
            Uri blobEndpointUri,
            string storageKey,
            string filePath,
            BlobRequestOptions blobRequestOptions)
        {
            StorageCredentials credentials = new StorageCredentials(storageName, storageKey);
            CloudBlobClient client = new CloudBlobClient(blobEndpointUri, credentials);
            string blobName = string.Format(
                CultureInfo.InvariantCulture,
                "{0}_{1}",
                DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture),
                Path.GetFileName(filePath));

            CloudBlobContainer container = client.GetContainerReference(ContainerName);
            container.CreateIfNotExists();
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            BlobRequestOptions uploadRequestOption = blobRequestOptions ?? new BlobRequestOptions();

            if (!uploadRequestOption.ServerTimeout.HasValue)
            {
                uploadRequestOption.ServerTimeout = TimeSpan.FromMinutes(300);
            }

            using (FileStream readStream = File.OpenRead(filePath))
            {
                blob.UploadFromStream(readStream, AccessCondition.GenerateEmptyCondition(), uploadRequestOption);
            }

            return new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}", client.BaseUri, ContainerName, client.DefaultDelimiter, blobName));
        }
开发者ID:FrankSiegemund,项目名称:azure-powershell,代码行数:33,代码来源:CloudBlobUtility.cs

示例11: button3_Click

        private async void button3_Click(object sender, EventArgs e)
        {
            string AccountSid = "ACd489d0930dc658a3384b1b52a28cbced";
            string AuthToken = "b4f632beb8bbf85f696693d0df69dba3";
            FaceServiceClient faceClient = new FaceServiceClient("0e58dbc56e5445ac8fcdfa9ffbf5ef60");
            if (!cam.IsRunning)
            {
                System.Threading.Thread.Sleep(1000);
            }
            bit.Save(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg");
            Thread.Sleep(1000);
            StorageCredentials storageCredentials = new StorageCredentials("faceimage", "DYrgou0cTTp6J7KDdMVVxR3BDtM31zh393oyf0CfWdTuihRUgDwyryQuIqj203SnPHMJVK7VvLGm/KtfIpUncw==");

            CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = blobClient.GetContainerReference("facecontainer");
            container.CreateIfNotExistsAsync();
            CloudBlockBlob blockBlob = container.GetBlockBlobReference("pic.jpg");

            using (var fileStream = System.IO.File.OpenRead(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg"))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            using (var fileStream = System.IO.File.OpenRead(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg"))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            double[] ages = await UploadAndDetectFaceAges(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient);
            string[] genders = await UploadAndDetectFaceGender(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient);
            Guid[] ids = await UploadAndDetectFaceId(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient);

            InsertData(ids[0].ToString(), genders[0], ages[0].ToString(), textBox1.Text);
        }
开发者ID:McGiver-,项目名称:PrincetonHackMMSolutions,代码行数:35,代码来源:Form1.cs

示例12: Upload

        static public void Upload(string filepath, string blobname, string accountName, string accountKey)
        {
            try
            {
                StorageCredentials creds = new StorageCredentials(accountName, accountKey);
                CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
                CloudBlobClient client = account.CreateCloudBlobClient();
                CloudBlobContainer sampleContainer = client.GetContainerReference("public-samples");
                sampleContainer.CreateIfNotExists();

                // for public access ////
                BlobContainerPermissions permissions = new BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                sampleContainer.SetPermissions(permissions);
                /////////////////////////

                CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(blobname);
                using (Stream file = File.OpenRead(filepath))
                {
                    blob.UploadFromStream(file);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
开发者ID:martin-chambers,项目名称:AzureBlobDemo,代码行数:28,代码来源:Program.cs

示例13: ProcessMethod

 public static void ProcessMethod(TextWriter log)
 {
     StorageCredentials credential = new StorageCredentials(ConfigurationManager.AppSettings["AccountName"], ConfigurationManager.AppSettings["AccountKey"]);
     CloudStorageAccount account = new CloudStorageAccount(credential, true);
     string logwrite = UploadToBlog(account);
     log.Write(logwrite);
 }
开发者ID:Data-Online,项目名称:CimscoManage,代码行数:7,代码来源:Program.cs

示例14: GetStorageClient

 private CloudBlobClient GetStorageClient()
 {
     var accountName = StorageAccountName.Contains(".") ? StorageAccountName.Substring(0, StorageAccountName.IndexOf('.')) : StorageAccountName;
     var storageCredentials = new StorageCredentials(accountName, StorageAccountKey);
     var storageAccount = new CloudStorageAccount(storageCredentials, true);
     return storageAccount.CreateCloudBlobClient();
 }
开发者ID:rtandonmsft,项目名称:azure-sdk-for-net,代码行数:7,代码来源:AzureStorageAccess.cs

示例15: CloudQueueClient

        /// <summary>
        /// Initializes a new instance of the <see cref="CloudQueueClient"/> class.
        /// </summary>
        /// <param name="usePathStyleUris">True to use path style Uris.</param>
        /// <param name="baseUri">The queue service endpoint to use to create the client.</param>
        /// <param name="credentials">The account credentials.</param>
        internal CloudQueueClient(bool? usePathStyleUris, Uri baseUri, StorageCredentials credentials)
        {
            CommonUtils.AssertNotNull("baseUri", baseUri);

            if (credentials == null)
            {
                credentials = new StorageCredentials();
            }

            if (baseUri == null)
            {
                throw new ArgumentNullException("baseUri");
            }

            if (!baseUri.IsAbsoluteUri)
            {
                string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.RelativeAddressNotPermitted, baseUri.ToString());
                throw new ArgumentException(errorMessage, "baseUri");
            }

            this.BaseUri = baseUri;
            this.Credentials = credentials;
            this.RetryPolicy = new ExponentialRetry();
            this.ServerTimeout = Constants.DefaultServerSideTimeout;

            if (usePathStyleUris.HasValue)
            {
                this.UsePathStyleUris = usePathStyleUris.Value;
            }
            else
            {
                // Automatically decide whether to use host style uri or path style uri
                this.UsePathStyleUris = CommonUtils.UsePathStyleAddressing(this.BaseUri);
            }
        }
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:41,代码来源:CloudQueueClientBase.cs


注:本文中的Microsoft.WindowsAzure.Storage.Auth.StorageCredentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。