GetStorageAccount() public method

Gets a CloudStorageAccount instace for the current connection.
public GetStorageAccount ( ) : Microsoft.WindowsAzure.CloudStorageAccount
return Microsoft.WindowsAzure.CloudStorageAccount
示例#1
0
        /// <summary>
        /// Build a model of the current Azure storage account. This model will be used to generate
        /// the typed code as well as the schema needed by LINQPad.
        /// </summary>
        /// <param name="properties">The current configuration.</param>
        /// <returns>A list of <see cref="CloudTable"/> instances that describe the current Azure
        /// storage model.</returns>
        private static IEnumerable <CloudTable> GetModel(StorageAccountProperties properties)
        {
            // make sure that we can make at least ModelLoadMaxParallelism concurrent
            // cals to azure table storage
            ServicePointManager.DefaultConnectionLimit = properties.ModelLoadMaxParallelism;

            var tableClient = properties.GetStorageAccount().CreateCloudTableClient();

            // First get a list of all tables
            var model = (from tableName in tableClient.ListTables()
                         select new CloudTable
            {
                Name = tableName.Name
            }).ToList();

            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = properties.ModelLoadMaxParallelism
            };

            Parallel.ForEach(model, options, table =>
            {
                var threadTableClient = properties.GetStorageAccount().CreateCloudTableClient();

                var tableColumns = threadTableClient.GetTableReference(table.Name).ExecuteQuery(new TableQuery().Take(properties.NumberOfRows))
                                   .SelectMany(row => row.Properties)
                                   .GroupBy(column => column.Key)
                                   .Select(grp => new TableColumn
                {
                    Name     = grp.Key,
                    TypeName = GetType(grp.First().Value.PropertyType)
                });

                var baseColumns = new List <TableColumn>
                {
                    new TableColumn {
                        Name = "PartitionKey", TypeName = GetType(EdmType.String)
                    },
                    new TableColumn {
                        Name = "RowKey", TypeName = GetType(EdmType.String)
                    },
                    new TableColumn {
                        Name = "Timestamp", TypeName = GetType(EdmType.DateTime)
                    },
                    new TableColumn {
                        Name = "ETag", TypeName = GetType(EdmType.String)
                    }
                };

                table.Columns = tableColumns.Concat(baseColumns).ToArray();
            });

            return(model);
        }
示例#2
0
        /// <summary>
        /// Gets the context constructor arguments.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <returns>An ordered collection of objects to pass to the data context as arguments.</returns>
        public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
        {
            var properties = new StorageAccountProperties(connectionInfo);

            var storageAccount = properties.GetStorageAccount();

            return(new object[]
            {
                storageAccount.CreateCloudTableClient()
            });
        }
        /// <summary>
        /// Build a model of the current Azure storage account. This model will be used to generate
        /// the typed code as well as the schema needed by LINQPad.
        /// </summary>
        /// <param name="properties">The current configuration.</param>
        /// <returns>A list of <see cref="CloudTable"/> instances that describe the current Azure
        /// storage model.</returns>
        private static IEnumerable <CloudTable> GetModel(StorageAccountProperties properties)
        {
            var tableClient = properties.GetStorageAccount().CreateCloudTableClient();

            var dataContext = tableClient.GetDataServiceContext();

            // Entity deserialization has to be handled in a particular way since we are using a GenericEntity to
            // to read all tables
            dataContext.ReadingEntity += OnReadingEntity;

            // First get a list of all tables
            var model = (from tableName in tableClient.ListTables()
                         select new CloudTable
            {
                Name = tableName
            }).ToList();

            // Then go through them
            foreach (var table in model)
            {
                // Read the first entity to determine the table's schema
                var firstRow = dataContext.CreateQuery <GenericEntity>(table.Name).Take(1).FirstOrDefault();

                if (null == firstRow)
                {
                    // If there is no first entity, set a list with the mandatory PartitionKey, RowKey and
                    // Timestamp columns, which we know always exist
                    table.Columns = new[]
                    {
                        new TableColumn {
                            Name = "PartitionKey", TypeName = GetType("Edm.String")
                        },
                        new TableColumn {
                            Name = "RowKey", TypeName = GetType("Edm.String")
                        },
                        new TableColumn {
                            Name = "Timestamp", TypeName = GetType("Edm.DateTime")
                        }
                    };
                }
                else
                {
                    // Otherwise create a new TableColumn for each type
                    table.Columns = from columnName in firstRow.Properties
                                    select new TableColumn
                    {
                        Name     = columnName.Key,
                        TypeName = GetType(columnName.Value)
                    };
                }
            }

            return(model);
        }
        /// <summary>
        /// Gets the context constructor arguments.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <returns>An ordered collection of objects to pass to the data context as arguments.</returns>
        public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
        {
            var properties = new StorageAccountProperties(connectionInfo);

            var storageAccount = properties.GetStorageAccount();

            return(new object[]
            {
                storageAccount.TableEndpoint.ToString(),
                storageAccount.Credentials,
                storageAccount
            });
        }
示例#5
0
        /// <summary>
        /// Build a model of the current Azure storage account. This model will be used to generate
        /// the typed code as well as the schema needed by LINQPad.
        /// </summary>
        /// <param name="properties">The current configuration.</param>
        /// <returns>A list of <see cref="CloudTable"/> instances that describe the current Azure
        /// storage model.</returns>
        private static IEnumerable <CloudTable> GetModel(StorageAccountProperties properties)
        {
            var tableClient = properties.GetStorageAccount().CreateCloudTableClient();

            // First get a list of all tables
            var model = (from tableName in tableClient.ListTables()
                         select new CloudTable
            {
                Name = tableName.Name
            }).ToList();

            // Then go through them
            foreach (var table in model)
            {
                var tableColumns = tableClient.GetTableReference(table.Name).ExecuteQuery(new TableQuery().Take(properties.NumberOfRows))
                                   .SelectMany(row => row.Properties)
                                   .GroupBy(column => column.Key)
                                   .Select(grp => new TableColumn
                {
                    Name     = grp.Key,
                    TypeName = GetType(grp.First().Value.PropertyType)
                });

                var baseColumns = new List <TableColumn>
                {
                    new TableColumn {
                        Name = "PartitionKey", TypeName = GetType(EdmType.String)
                    },
                    new TableColumn {
                        Name = "RowKey", TypeName = GetType(EdmType.String)
                    },
                    new TableColumn {
                        Name = "Timestamp", TypeName = GetType(EdmType.DateTime)
                    },
                    new TableColumn {
                        Name = "ETag", TypeName = GetType(EdmType.String)
                    }
                };

                table.Columns = tableColumns.Concat(baseColumns).ToArray();
            }

            return(model);
        }
        /// <summary>
        /// Gets the context constructor arguments.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <returns>An ordered collection of objects to pass to the data context as arguments.</returns>
        public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
        {
            var properties = new StorageAccountProperties(connectionInfo);

            var storageAccount = properties.GetStorageAccount();

            return new object[]
            {
                storageAccount.TableEndpoint.ToString(),
                storageAccount.Credentials,
                storageAccount
            };
        }
示例#7
0
        /// <summary>
        /// Build a model of the current Azure storage account. This model will be used to generate
        /// the typed code as well as the schema needed by LINQPad.
        /// </summary>
        /// <param name="properties">The current configuration.</param>
        /// <returns>A list of <see cref="CloudTable"/> instances that describe the current Azure
        /// storage model.</returns>
        private static IEnumerable<CloudTable> GetModel(StorageAccountProperties properties)
        {
            var tableClient = properties.GetStorageAccount().CreateCloudTableClient();

            // First get a list of all tables
            var model = (from tableName in tableClient.ListTables()
                         select new CloudTable
                         {
                             Name = tableName.Name
                         }).ToList();

            // Then go through them
            foreach (var table in model)
            {
                var tableColumns = tableClient.GetTableReference(table.Name).ExecuteQuery(new TableQuery().Take(properties.NumberOfRows))
                    .SelectMany(row => row.Properties)
                    .GroupBy(column => column.Key)
                    .Select(grp => new TableColumn
                     {
                         Name = grp.Key,
                         TypeName = GetType(grp.First().Value.PropertyType)
                     });

                var baseColumns = new List<TableColumn>
                {
                    new TableColumn { Name = "PartitionKey", TypeName = GetType(EdmType.String) },
                    new TableColumn { Name = "RowKey", TypeName = GetType(EdmType.String) },
                    new TableColumn { Name = "Timestamp", TypeName = GetType(EdmType.DateTime) },
                    new TableColumn { Name = "ETag", TypeName = GetType(EdmType.String) }
                };

                table.Columns = tableColumns.Concat(baseColumns).ToArray();
            }

            return model;
        }
        /// <summary>
        /// Build a model of the current Azure storage account. This model will be used to generate
        /// the typed code as well as the schema needed by LINQPad.
        /// </summary>
        /// <param name="properties">The current configuration.</param>
        /// <returns>A list of <see cref="CloudTable"/> instances that describe the current Azure
        /// storage model.</returns>
        private static IEnumerable<CloudTable> GetModel(StorageAccountProperties properties)
        {
            var tableClient = properties.GetStorageAccount().CreateCloudTableClient();

            var dataContext = tableClient.GetDataServiceContext();

            // Entity deserialization has to be handled in a particular way since we are using a GenericEntity to
            // to read all tables
            dataContext.ReadingEntity += OnReadingEntity;

            // First get a list of all tables
            var model = (from tableName in tableClient.ListTables()
                         select new CloudTable
                         {
                             Name = tableName
                         }).ToList();

            // Then go through them
            foreach (var table in model)
            {
                // Read the first entity to determine the table's schema
                var firstRow = dataContext.CreateQuery<GenericEntity>(table.Name).Take(1).FirstOrDefault();

                if (null == firstRow)
                {
                    // If there is no first entity, set a list with the mandatory PartitionKey, RowKey and
                    // Timestamp columns, which we know always exist
                    table.Columns = new[]
                    {
                        new TableColumn { Name = "PartitionKey", TypeName = GetType("Edm.String") },
                        new TableColumn { Name = "RowKey", TypeName = GetType("Edm.String") },
                        new TableColumn { Name = "Timestamp", TypeName = GetType("Edm.DateTime") }
                    };
                }
                else
                {
                    // Otherwise create a new TableColumn for each type
                    table.Columns = from columnName in firstRow.Properties
                                    select new TableColumn
                                    {
                                        Name = columnName.Key,
                                        TypeName = GetType(columnName.Value)
                                    };
                }
            }

            return model;
        }
示例#9
0
        /// <summary>
        /// Gets the context constructor arguments.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <returns>An ordered collection of objects to pass to the data context as arguments.</returns>
        public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
        {
            var properties = new StorageAccountProperties(connectionInfo);

            var storageAccount = properties.GetStorageAccount();

            return new object[]
            {
                storageAccount.CreateCloudTableClient()
            };
        }