public AzureTableServiceContext(string baseAddress, StorageCredentials credentials, IConverter converter)
     : base(baseAddress, credentials)
 {
     _converter = converter;
     WritingEntity += OnWritingEntity;
     ReadingEntity += OnReadingEntity;
 }
        internal static void CheckAllowInsecureEndpoints(bool allowInsecureRemoteEndpoints, StorageCredentials info, Uri baseUri)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (allowInsecureRemoteEndpoints)
            {
                return;
            }

            if (baseUri == null || string.IsNullOrEmpty(baseUri.Scheme))
            {
                throw new SecurityException("allowInsecureRemoteEndpoints is set to false (default setting) but the endpoint URL seems to be empty or there is no URL scheme." +
                                            "Please configure the provider to use an https enpoint for the storage endpoint or " +
                                            "explicitly set the configuration option allowInsecureRemoteEndpoints to true.");
            }

            if (baseUri.Scheme.ToUpper(CultureInfo.InvariantCulture) == Uri.UriSchemeHttps.ToUpper(CultureInfo.InvariantCulture))
            {
                return;
            }

            if (baseUri.IsLoopback)
            {
                return;
            }

            throw new SecurityException("The provider is configured with allowInsecureRemoteEndpoints set to false (default setting) but the endpoint for " +
                                        "the storage system does not seem to be an https or local endpoint. " +
                                        "Please configure the provider to use an https enpoint for the storage endpoint or " +
                                        "explicitly set the configuration option allowInsecureRemoteEndpoints to true.");
        }
        public ComplexTypeTableServiceContext(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        {
            IgnoreMissingProperties = true;

            ReadingEntity += OnReadingEntity;
            WritingEntity += OnWritingEntity;
        }
Пример #4
0
 public EncryptionService()
 {
     var storageAccount = Microsoft.WindowsAzure.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
     _baseAddress = storageAccount.TableEndpoint.AbsoluteUri;
     _credentials = storageAccount.Credentials;
     var section = (NameValueCollection)WebConfigurationManager.GetSection("encryption");
     LoadCertificateByThumbprint(section["certificateThumbprint"]);
 }
        /// <summary>
        /// Get analytics settings
        /// </summary>
        /// <param name="baseUri"></param>
        /// <param name="credentials"></param>
        /// <param name="useSharedKeyLite"></param>
        /// <returns></returns>
        public static AnalyticsSettings GetSettings(Uri baseUri, StorageCredentials credentials, bool useSharedKeyLite)
        {
            UriBuilder builder = new UriBuilder(baseUri);
            builder.Query = string.Format(
                CultureInfo.InvariantCulture,
                "comp=properties&restype=service&timeout={0}",
                DefaultTimeout.TotalSeconds);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(builder.Uri);
            request.Headers.Add(VersionHeaderName, Sep2009Version);
            request.Method = "GET";

            StorageCredentialsAccountAndKey accountAndKey = credentials as StorageCredentialsAccountAndKey;

            if (useSharedKeyLite)
            {
                credentials.SignRequestLite(request);
            }
            else
            {
                credentials.SignRequest(request);
            }

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    Console.WriteLine("Response Request Id={0} Status={1}", response.Headers[RequestIdHeaderName], response.StatusCode);

                    if (HttpStatusCode.OK != response.StatusCode)
                    {
                        throw new Exception("expected HttpStatusCode.OK");
                    }

                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(stream))
                        {
                            string responseString = streamReader.ReadToEnd();
                            Console.WriteLine(responseString);

                            XmlReader reader = XmlReader.Create(new MemoryStream(ASCIIEncoding.UTF8.GetBytes(responseString)));
                            return SettingsSerializerHelper.DeserializeAnalyticsSettings(reader);
                        }
                    }
                }
            }
            catch (WebException e)
            {
                Console.WriteLine(
                    "Response Request Id={0} Status={1}",
                    e.Response != null ? e.Response.Headers[RequestIdHeaderName] : "Response is null",
                    e.Status);
                throw;
            }
        }
Пример #6
0
        public MetaDataContext(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        {
            // Alternative method of creating table
            //CloudTableClient.CreateTablesFromModel(typeof(MetaDataContext),
            //                           baseAddress, credentials);

            // Prevent DataServiceQueryException when no records
            // match a query
            IgnoreResourceNotFoundException = true;
        }
 public static StorageServiceProperties GetServiceProperties(Uri baseUri, StorageCredentials creds, bool useSharedKeyLite)
 {
     var req = CreateServicePropertiesRequest(baseUri);
     if (useSharedKeyLite) creds.SignRequestLite(req);
     else creds.SignRequest(req);
     using (var response = req.GetResponse())
     using (var stream = response.GetResponseStream())
     {
         return (StorageServiceProperties)new XmlSerializer(typeof(StorageServiceProperties)).Deserialize(stream);
     }
 }
Пример #8
0
        public static AzureContainer Connect(string containerName, string blobEndpointUri,
            StorageCredentials credentials)
        {
            // Requirements
            Require.NotEmpty(containerName, "containerName");
            Require.NotEmpty(blobEndpointUri, "blobEndpointUri");
            Require.NotNull(credentials, "credentials");

            var blobClient = CreateBlobClient(blobEndpointUri, credentials);
            var container = CreateContainer(containerName, blobClient);
            return new AzureContainer(blobClient, container);
        }
Пример #9
0
        public SymmetricKeyService(string baseAddress, StorageCredentials credentials, X509Certificate2 certificate)
        {
            _certificate = certificate;

            try
            {
                if (credentials != null)
                {
                    _context = new SymmetricKeyContext(baseAddress, credentials);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #10
0
        private static AzureContainer SetupBlobContainer(string containerName, string blobEndpointUri, StorageCredentials credentials)
        {
            PrintStep("Creating " + containerName + " blob container...");
            AzureContainer.Create(containerName, blobEndpointUri, credentials);
            var container = AzureContainer.Connect(containerName, blobEndpointUri, credentials);
            if (_doReset)
            {
                PrintStep(" * Resetting its content");
                container.Clear();
            }

            PrintStep(" * Setting permissions up");
            container.Permissions.PublicAccess = BlobContainerPublicAccessType.Off;

            return container;
        }
        public TaskDataContext(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        {
            // we are setting up a dictionary of types to resolve in order
            // to workaround a performance bug in astoria during serialization
            this.resolverTypes = new Dictionary<string, Type>();
            this.resolverTypes.Add(TaskTable, typeof(TaskRow));
            this.resolverTypes.Add(TaskListTable, typeof(TaskListRow));

            this.ResolveType = name =>
            {
                var parts = name.Split('.');
                if (parts.Length == 2)
                {
                    return resolverTypes[parts[1]];
                }

                return null;
            };
        }
 public static void SetServiceProperties(Uri baseUri, StorageCredentials creds, StorageServiceProperties properties, bool useSharedKeyLite)
 {
     var req = CreateServicePropertiesRequest(baseUri);
     req.Method = "PUT";
     var ms = new MemoryStream();
     new XmlSerializer(typeof(StorageServiceProperties)).Serialize(ms, properties);
     ms.Position = 0;
     req.ContentLength = ms.Length;
     if (useSharedKeyLite) creds.SignRequestLite(req);
     else creds.SignRequest(req);
     using (var stream = req.GetRequestStream())
     {
         ms.CopyTo(stream);
     }
     using (var response = (HttpWebResponse)req.GetResponse())
     {
         if (response.StatusCode != HttpStatusCode.Accepted)
         {
             throw new Exception("Request failed to return 202 status code.");
         }
     }
 }
Пример #13
0
 public TestContext(string tableEndpoint, StorageCredentials credentials)
     : base(tableEndpoint, credentials)
 {
 }
Пример #14
0
 public SampleArchTableContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
Пример #15
0
 public FtpAccountDataContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
     var tableStorage = new CloudTableClient(baseAddress, credentials);
     tableStorage.CreateTableIfNotExist("AzureFtpAccount");
 }
Пример #16
0
 public SymmetricKeyContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
     var storageAccount = Microsoft.WindowsAzure.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
     var client = storageAccount.CreateCloudTableClient().CreateTableIfNotExist("SymmetricKeys");
 }
 public PlaybookTableContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
Пример #18
0
 public ViewDataContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress)
 {
 }
 public FunnyAppContext(string baseAddress, StorageCredentials credentials) 
     : base(baseAddress, credentials)
 {
 }
Пример #20
0
 public EmailQueueClient(string baseAddress, StorageCredentials credentials, string queueName)
     : base(baseAddress, credentials)
 {
     _queueName = queueName;
 }
 public MessageDataServiceContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
Пример #22
0
 public TrackPointsHistoryContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
        /// <summary>
        /// Set analytics settings
        /// </summary>
        /// <param name="baseUri"></param>
        /// <param name="credentials"></param>
        /// <param name="settings"></param>
        /// <param name="useSharedKeyLite"></param>
        public static void SetSettings(Uri baseUri, StorageCredentials credentials, AnalyticsSettings settings, Boolean useSharedKeyLite)
        {
            UriBuilder builder = new UriBuilder(baseUri);
            builder.Query = string.Format(
                CultureInfo.InvariantCulture,
                "comp=properties&restype=service&timeout={0}",
                DefaultTimeout.TotalSeconds);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(builder.Uri);
            request.Headers.Add(VersionHeaderName, Sep2009Version);
            request.Method = "PUT";

            StorageCredentialsAccountAndKey accountAndKey = credentials as StorageCredentialsAccountAndKey;
            using (MemoryStream buffer = new MemoryStream())
            {
                XmlTextWriter writer = new XmlTextWriter(buffer, Encoding.UTF8);
                SettingsSerializerHelper.SerializeAnalyticsSettings(writer, settings);
                writer.Flush();
                buffer.Seek(0, SeekOrigin.Begin);
                request.ContentLength = buffer.Length;

                if (useSharedKeyLite)
                {
                    credentials.SignRequestLite(request);
                }
                else
                {
                    credentials.SignRequest(request);
                }

                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(buffer.GetBuffer(), 0, (int)buffer.Length);
                }

                try
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        Console.WriteLine("Response Request Id = {0} Status={1}", response.Headers[RequestIdHeaderName], response.StatusCode);
                        if (HttpStatusCode.Accepted != response.StatusCode)
                        {
                            throw new Exception("Request failed with incorrect response status.");
                        }
                    }
                }
                catch (WebException e)
                {
                    Console.WriteLine(
                        "Response Request Id={0} Status={1}",
                        e.Response != null ? e.Response.Headers[RequestIdHeaderName] : "Response is null",
                        e.Status);
                    throw;
                }
            }
        }
Пример #24
0
 public MsdnQueue(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
 public WindowsAzureLogDataServiceContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
 public DatasetInfoDataContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
 public ExpenseDataContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
     ResolveType = ResolveEntityType;
 }
 internal static string GetInitExceptionDescription(StorageCredentials credentials, Uri tableBaseUri, Uri blobBaseUri)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append(GetInitExceptionDescription(credentials, tableBaseUri, "table storage configuration"));
     builder.Append(GetInitExceptionDescription(credentials, blobBaseUri, "blob storage configuration"));
     return builder.ToString();
 }
Пример #29
0
 /// <summary>
 /// Create an instance of the FollowerDataContext class 
 /// and initialize the base
 /// class with storage access information.
 /// </summary>
 /// <param name="baseAddress"></param>
 /// <param name="credentials"></param>
 public FollowerDataContext(string baseAddress, StorageCredentials credentials)
     : base(baseAddress, credentials)
 {
 }
 internal static string GetInitExceptionDescription(StorageCredentials info, Uri baseUri, string desc)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("The reason for this exception is typically that the endpoints are not correctly configured. " + Environment.NewLine);
     if (info == null)
     {
         builder.Append("The current " + desc + " is null. Please specify a table endpoint!" + Environment.NewLine);
     }
     else
     {
         builder.Append("The current " + desc + " is: " + baseUri + Environment.NewLine);
         builder.Append("Please also make sure that the account name and the shared key are specified correctly. This information cannot be shown here because of security reasons.");
     }
     return builder.ToString();
 }