Exemplo n.º 1
0
        private CloudTable Table()
        {
            if (_table == null)
            {
                _creatingTable.WaitOne();
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Configuration.StorageAccount);
                CloudTableClient    client         = storageAccount.CreateCloudTableClient();

                var tbl = client.GetTableReference(EntityDefinition.TableName());
                if (tbl.Exists())
                {
                    if (!CheckSchema(tbl))
                    {
                        if (!EntityDefinition.AutoRebuildPartitionIfRequire)
                        {
                            throw new StorageArgumentException("Schema table has changed or not exist");
                        }

                        RebuildPartitions(tbl);
                    }
                }
                else
                {
                    tbl.CreateIfNotExists();
                    WriteSchema(tbl);
                }
                _table = tbl;
                _creatingTable.Set();
            }
            return(_table);
        }
Exemplo n.º 2
0
        private async Task <CloudTable> TableAsync()
        {
            if (_table == null)
            {
                if (_creatingTable.WaitOne(TimeoutForStorageResource))
                {
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Configuration.StorageAccount);
                    CloudTableClient    client         = storageAccount.CreateCloudTableClient();

                    var tbl = client.GetTableReference(EntityDefinition.TableName());
                    if (await tbl.ExistsAsync().ConfigureAwait(false))
                    {
                        if (!CheckSchema(tbl))
                        {
                            if (!EntityDefinition.AutoRebuildPartitionIfRequire)
                            {
                                throw new StorageArgumentException("Schema table has changed or not exist");
                            }

                            await RebuildPartitionsAsync(tbl).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        await tbl.CreateIfNotExistsAsync().ConfigureAwait(false);
                        await WriteSchemaAsync(tbl).ConfigureAwait(false);
                    }
                    _table = tbl;
                    _creatingTable.Set();
                }
                else
                {
                    throw new TimeoutException($"Timeout waiting resource {EntityDefinition.TableName()}");
                }
            }
            return(_table);
        }