Ejemplo n.º 1
0
        public List<ICatalogJob> GetAllCatalogJob(string organization)
        {
            string tableName = NameHelper.GetCatalogJobTableName(organization);
            tableName = TableDataAccess.ValidateTableName(tableName);
            TableDataAccess tableDataAccess = new TableDataAccess(TableClient);
            CloudTable table = tableDataAccess.GetTable(tableName);
            if (table == null)
                return null;

            TableQuery<CatalogEntity> query = new TableQuery<CatalogEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, organization));

            query.TakeCount = 100;
            TableRequestOptions a = new TableRequestOptions();
            OperationContext c = new OperationContext();

            var queryResult = table.ExecuteQuery(query);

            List<ICatalogJob> result = new List<ICatalogJob>(queryResult.Count());
            foreach (CatalogEntity entity in queryResult)
            {
                CatalogEntity.SetOtherByPartitionRowKeys(entity);
                result.Add(entity);
            }
            return result;
        }
        //
        // GET: /Subscription/
        //
        // Note: This way of handling may not scale and may need to use continuation tokens later
        //
        public ActionResult Index()
        {
            TableRequestOptions reqOptions = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(10),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };

            List<Subscription> subscribers;
            try
            {
                var query = new TableQuery<Subscription>().Select(new string[] {
                    "PartitionKey",
                    "RowKey",
                    "Description",
                    "Verified"
                });

                subscribers = subscribersTable.ExecuteQuery(query, reqOptions).ToList();
            }
            catch (StorageException se)
            {
                ViewBag.errorMessage = "Timeout error, try again.";
                Trace.TraceError(se.Message);
                return View("Error: " + se.Message);
            }

            return View(subscribers);
        }
Ejemplo n.º 3
0
        private static RESTCommand<TableQuerySegment> QueryImpl(TableQuery query, TableContinuationToken token, CloudTableClient client, string tableName, TableRequestOptions requestOptions)
        {
            UriQueryBuilder builder = query.GenerateQueryBuilder();

            if (token != null)
            {
                token.ApplyToUriQueryBuilder(builder);
            }

            StorageUri tempUriList = NavigationHelper.AppendPathToUri(client.StorageUri, tableName);
            RESTCommand<TableQuerySegment> queryCmd = new RESTCommand<TableQuerySegment>(client.Credentials, tempUriList);
            requestOptions.ApplyToStorageCommand(queryCmd);

            queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token);
            queryCmd.RetrieveResponseStream = true;
            queryCmd.Handler = client.AuthenticationHandler;
            queryCmd.BuildClient = HttpClientFactory.BuildHttpClient;
            queryCmd.Builder = builder;
            queryCmd.BuildRequest = (cmd, uri, queryBuilder, cnt, serverTimeout, ctx) => TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(uri, builder, serverTimeout, cnt, ctx);
            queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp.StatusCode, null /* retVal */, cmd, ex);
            queryCmd.PostProcessResponse = async (cmd, resp, ctx) =>
            {
                TableQuerySegment resSeg = await TableOperationHttpResponseParsers.TableQueryPostProcess(cmd.ResponseStream, resp, ctx);
                if (resSeg.ContinuationToken != null)
                {
                    resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation;
                }

                return resSeg;
            };

            return queryCmd;
        }
        // GET: /Subscribe/

        public async Task<ActionResult> Index(string id, string listName)
        {
            // We get to this method when they click on the Confirm link in the
            // email that's sent to them after the subscribe service method is called.
            TableRequestOptions reqOptions = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };
            string filter = TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, listName),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("SubscriberGUID", QueryComparisons.Equal, id));
            var query = new TableQuery<Subscriber>().Where(filter);
            TableContinuationToken token = null;
            OperationContext ctx = new OperationContext() { ClientRequestID = "" };
            TableQuerySegment<Subscriber> currentSegment = null;
            currentSegment = await mailingListTable.ExecuteQuerySegmentedAsync(query, token, reqOptions, ctx);
            var subscriber = currentSegment.Results.ToList().Single();

            //subscriberTableRow.Status = "Verified";
            subscriber.Verified = true;
            var replaceOperation = TableOperation.Merge(subscriber);
            mailingListTable.Execute(replaceOperation);

            var newSubscriber = new SubscribeVM();
            newSubscriber.EmailAddress = subscriber.EmailAddress;
            var mailingList = await FindRowAsync(subscriber.ListName, "mailinglist");
            newSubscriber.ListDescription = mailingList.Description;
            return View(newSubscriber);
        }
        public HttpResponseMessage Apps()
        {
            TableRequestOptions reqOptions = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };

            try
            {
                var query = new TableQuery<Subscription>().Select(new string[] { "PartitionKey" });

                List<Subscription> subscribers =
                    subscribersTable.ExecuteQuery(query, reqOptions).ToList();
                IEnumerable<string> apps =
                    subscribers.Select(s => s.ApplicationName).Distinct();
                return Request.CreateResponse(
                    HttpStatusCode.OK,
                    new
                    {
                        Success = true,
                        Apps = apps
                    },
                    Configuration.Formatters.JsonFormatter
                    );
            }
            catch (StorageException)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(
                    HttpStatusCode.ServiceUnavailable,
                    "Timeout error, try again."
                    ));
            }
        }
Ejemplo n.º 6
0
        public IEnumerable<CloudTable> ListTables(string prefix, TableRequestOptions requestOptions = null, OperationContext operationContext = null)
        {
            requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this);
            operationContext = operationContext ?? new OperationContext();

            return this.GenerateListTablesQuery(prefix, null).Execute(this, TableConstants.TableServiceTablesName, requestOptions, operationContext).Select(
                     tbl => new CloudTable(NavigationHelper.AppendPathToUri(this.BaseUri, tbl[TableConstants.TableName].StringValue), this));
        }
        internal TableResult Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();
            CommonUtility.AssertNotNullOrEmpty("tableName", table.Name);

            return Executor.ExecuteSync(this.GenerateCMDForOperation(client, table, modifiedOptions), modifiedOptions.RetryPolicy, operationContext);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableRequestOptions"/> class with the specified <see cref="TableRequestOptions"/>.
 /// </summary>
 /// <param name="other">The request options used to initialize this instance of the <see cref="TableRequestOptions"/> class.</param>
 public TableRequestOptions(TableRequestOptions other)
 {
     if (other != null)
     {
         this.ServerTimeout = other.ServerTimeout;
         this.RetryPolicy = other.RetryPolicy;
         this.MaximumExecutionTime = other.MaximumExecutionTime;
     }
 }
        static void Main(string[] args)
        {
            var accountName = args[0];
            var accountKey = args[1];
            var GifsDir = args[2];

            storageAccount =  CloudStorageAccount.Parse(String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",accountName,accountKey));
            
            // Create the blob client.
            CloudBlobClient blobClient = new CloudBlobClient (storageAccount.BlobEndpoint, storageAccount.Credentials);

            // Create blob container if it doesn't exist.
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("memes");
            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Container);

            // Create the table client.
            CloudTableClient tableClient = new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(storageAccount.TableEndpoint, storageAccount.Credentials);

            // Create the table if it doesn't exist.
            CloudTable table = tableClient.GetTableReference("MemeMetadata");
            var statusTable = table.CreateIfNotExists();

            var list = new List<ClipMemeEntity> {
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200312-horse-cannon.gif", BlobName = "20140401-200312-horse-cannon.gif", Description = "Deploy", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200344-updated-visual-studio-theme.gif", BlobName = "20140401-200344-updated-visual-studio-theme.gif", Description = "News vs Theme", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200447-oops.gif", BlobName = "20140401-200447-oops.gif", Description = "First Iteration", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200534-just-learned-about-git-rebase.gif", BlobName = "20140401-200534-just-learned-about-git-rebase.gif", Description = "Tests Pass on First Try", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200606-when-i-unstash-something.gif", BlobName = "20140401-200606-when-i-unstash-something.gif", Description = "Scale up", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200750-dog-race.gif", BlobName = "20140401-200750-dog-race.gif", Description = "Sprint", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200800-cookies.gif", BlobName = "20140401-200800-cookies.gif", Description = "Scottgu Promoted", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200849-when-i-merge-my-own-pull-requests.gif", BlobName = "20140401-200849-when-i-merge-my-own-pull-requests.gif", Description = "to the cloud", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200924-disco-girl.gif", BlobName = "20140401-200924-disco-girl.gif", Description = "Hanseldance", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", BlobName = "20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", Description = "accidental git push", Username = "******"  },
                new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", BlobName = "20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", Description = "msft at $40", Username = "******"  }                
            };

            foreach (var item in list)
	        {
                // Retrieve reference to a blob
                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(item.BlobName);

                using (var fileStream = System.IO.File.OpenRead(String.Format("{0}\\{1}",GifsDir,item.BlobName)))
                {
                    blockBlob.UploadFromStream(fileStream);
                } 

                var requestOptions = new Microsoft.WindowsAzure.Storage.Table.TableRequestOptions()
                {
                    RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromMilliseconds(500), 5)
                };

                table.Execute(Microsoft.WindowsAzure.Storage.Table.TableOperation.Insert(item), requestOptions);
	        }

            return;
        }
        internal TableQuerySegment<DynamicTableEntity> ExecuteQuerySegmented(TableContinuationToken token, CloudTableClient client, string tableName, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            CommonUtils.AssertNotNullOrEmpty("tableName", tableName);
            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();

            RESTCommand<TableQuerySegment<DynamicTableEntity>> cmdToExecute = QueryImpl(this, token, client, tableName, modifiedOptions);

            return Executor.ExecuteSync(cmdToExecute, modifiedOptions.RetryPolicy, operationContext);
        }
 internal List<MailingList> RetrivesTables(string rowKey)
 {
     TableRequestOptions reqOptions = new TableRequestOptions()
     {
         MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
         RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
     };
     var query = new TableQuery<MailingList>().Where(TableQuery.GenerateFilterCondition(rowKey, QueryComparisons.Equal, ConfigurationManager.AppSettings["TableMailinglist"]));            
    return mailingListTable.ExecuteQuery(query, reqOptions).ToList();
 }
 /// <summary>
 /// Get table reference from azure server
 /// </summary>
 /// <param name="name">Table name</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>A CloudTable object if the specified table exists, otherwise null.</returns>
 public CloudTable GetTableReferenceFromServer(string name, TableRequestOptions requestOptions, OperationContext operationContext)
 {
     foreach (CloudTable table in tableList)
     {
         if (table.Name == name)
         {
             return table;
         }
     }
     return null;
 }
 /// <summary>
 /// Delete the specified azure storage table
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 public void Delete(CloudTable table, TableRequestOptions requestOptions = null, OperationContext operationContext = null)
 {
     foreach (CloudTable tableRef in tableList)
     {
         if (table.Name == tableRef.Name)
         {
             tableList.Remove(tableRef);
             return;
         }
     }
 }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            /* Legacy Table SDK */
            var storageAccountLegacy = LEGACY_STORAGE.CloudStorageAccount.Parse(connectionTableSAS);
            var tableClientLegacy    = storageAccountLegacy.CreateCloudTableClient();

            Debug.Assert(tableClientLegacy.StorageUri.SecondaryUri != null); // demonstrate SecondaryUri initialised

            var tableRequestOptionsLegacy = new LEGACY_TABLE.TableRequestOptions()
            {
                LocationMode = LEGACY_RETRY.LocationMode.SecondaryOnly
            };

            tableClientLegacy.DefaultRequestOptions = tableRequestOptionsLegacy;

            var tableLegacy       = tableClientLegacy.GetTableReference("foo"); // don't need table to exist to show the issue
            var retrieveOperation = LEGACY_TABLE.TableOperation.Retrieve(string.Empty, string.Empty, new List <string>()
            {
                "bar"
            });

            var tableResult = tableLegacy.Execute(retrieveOperation);

            Console.WriteLine("Legacy PASS");


            /* Newset Table SDK */
            var storageAccountNewest = NEWEST_TABLE.CloudStorageAccount.Parse(connectionTableSAS);
            var tableClientNewest    = storageAccountNewest.CreateCloudTableClient(new TableClientConfiguration());

            Debug.Assert(tableClientNewest.StorageUri.SecondaryUri != null); // demonstrate SecondaryUri initialised

            var tableRequestOptionsNewest = new NEWEST_TABLE.TableRequestOptions()
            {
                LocationMode = NEWEST_TABLE.LocationMode.SecondaryOnly
            };

            tableClientNewest.DefaultRequestOptions = tableRequestOptionsNewest;

            var tableNewset             = tableClientNewest.GetTableReference("foo"); // don't need table to exist to show the issue
            var retrieveOperationNewset = NEWEST_TABLE.TableOperation.Retrieve(string.Empty, string.Empty, new List <string>()
            {
                "bar"
            });

            /* throws Microsoft.Azure.Cosmos.Table.StorageException
             * Exception thrown while initializing request: This operation can only be executed against the primary storage location
             */
            var tableResultNewset = tableNewset.Execute(retrieveOperationNewset);

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Table encryption sample");

            // Retrieve storage account information from connection string
            // How to create a storage connection string - https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
            CloudStorageAccount storageAccount = EncryptionShared.Utility.CreateStorageAccountFromConnectionString();
            CloudTableClient client = storageAccount.CreateCloudTableClient();
            CloudTable table = client.GetTableReference(DemoTable + Guid.NewGuid().ToString("N"));

            try
            {
                table.Create();

                // Create the IKey used for encryption.
                RsaKey key = new RsaKey("private:key1");

                EncryptedEntity ent = new EncryptedEntity() { PartitionKey = Guid.NewGuid().ToString(), RowKey = DateTime.Now.Ticks.ToString() };
                ent.Populate();

                TableRequestOptions insertOptions = new TableRequestOptions()
                {
                    EncryptionPolicy = new TableEncryptionPolicy(key, null)
                };

                // Insert Entity
                Console.WriteLine("Inserting the encrypted entity.");
                table.Execute(TableOperation.Insert(ent), insertOptions, null);

                // For retrieves, a resolver can be set up that will help pick the key based on the key id.
                LocalResolver resolver = new LocalResolver();
                resolver.Add(key);

                TableRequestOptions retrieveOptions = new TableRequestOptions()
                {
                    EncryptionPolicy = new TableEncryptionPolicy(null, resolver)
                };

                // Retrieve Entity
                Console.WriteLine("Retrieving the encrypted entity.");
                TableOperation operation = TableOperation.Retrieve(ent.PartitionKey, ent.RowKey);
                TableResult result = table.Execute(operation, retrieveOptions, null);

                Console.WriteLine("Press enter key to exit");
                Console.ReadLine();
            }
            finally
            {
                table.DeleteIfExists();
            }
        }
        internal static TableRequestOptions ApplyDefaults(TableRequestOptions requestOptions, CloudTableClient serviceClient)
        {
            TableRequestOptions modifiedOptions = new TableRequestOptions(requestOptions);
            modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy;
            modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout;
            modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime;

            if (!modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue)
            {
                modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value;
            }

            return modifiedOptions;
        }
        internal ICancellableAsyncResult BeginExecuteQuerySegmented(TableContinuationToken token, CloudTableClient client, string tableName, TableRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
        {
            CommonUtils.AssertNotNullOrEmpty("tableName", tableName);

            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();

            return Executor.BeginExecuteAsync(
                                          QueryImpl(this, token, client, tableName, modifiedOptions),
                                          modifiedOptions.RetryPolicy,
                                          operationContext,
                                          callback,
                                          state);
        }
Ejemplo n.º 18
0
        internal ICancellableAsyncResult BeginExecute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
        {
            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();

            CommonUtility.AssertNotNullOrEmpty("tableName", table.Name);

            return Executor.BeginExecuteAsync(
                                          this.GenerateCMDForOperation(client, table, modifiedOptions),
                                          modifiedOptions.RetryPolicy,
                                          operationContext,
                                          callback,
                                          state);
        }
Ejemplo n.º 19
0
        internal RESTCommand<TableResult> GenerateCMDForOperation(CloudTableClient client, CloudTable table, TableRequestOptions modifiedOptions)
        {
            if (this.OperationType == TableOperationType.Insert ||
                this.OperationType == TableOperationType.InsertOrMerge ||
                this.OperationType == TableOperationType.InsertOrReplace)
            {
                if (!this.isTableEntity && this.OperationType != TableOperationType.Insert)
                {
                    CommonUtility.AssertNotNull("Upserts require a valid PartitionKey", this.Entity.PartitionKey);
                    CommonUtility.AssertNotNull("Upserts require a valid RowKey", this.Entity.RowKey);
                }

                return InsertImpl(this, client, table, modifiedOptions);
            }
            else if (this.OperationType == TableOperationType.Delete)
            {
                if (!this.isTableEntity)
                {
                    CommonUtility.AssertNotNullOrEmpty("Delete requires a valid ETag", this.Entity.ETag);
                    CommonUtility.AssertNotNull("Delete requires a valid PartitionKey", this.Entity.PartitionKey);
                    CommonUtility.AssertNotNull("Delete requires a valid RowKey", this.Entity.RowKey);
                }

                return DeleteImpl(this, client, table, modifiedOptions);
            }
            else if (this.OperationType == TableOperationType.Merge)
            {
                CommonUtility.AssertNotNullOrEmpty("Merge requires a valid ETag", this.Entity.ETag);
                CommonUtility.AssertNotNull("Merge requires a valid PartitionKey", this.Entity.PartitionKey);
                CommonUtility.AssertNotNull("Merge requires a valid RowKey", this.Entity.RowKey);

                return MergeImpl(this, client, table, modifiedOptions);
            }
            else if (this.OperationType == TableOperationType.Replace)
            {
                CommonUtility.AssertNotNullOrEmpty("Replace requires a valid ETag", this.Entity.ETag);
                CommonUtility.AssertNotNull("Replace requires a valid PartitionKey", this.Entity.PartitionKey);
                CommonUtility.AssertNotNull("Replace requires a valid RowKey", this.Entity.RowKey);

                return ReplaceImpl(this, client, table, modifiedOptions);
            }
            else if (this.OperationType == TableOperationType.Retrieve)
            {
                return RetrieveImpl(this, client, table, modifiedOptions);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 20
0
        internal IAsyncOperation<TableQuerySegment> ExecuteQuerySegmentedAsync(TableContinuationToken continuationToken, CloudTableClient client, string tableName, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            CommonUtility.AssertNotNullOrEmpty("tableName", tableName);
            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();

            RESTCommand<TableQuerySegment> cmdToExecute = QueryImpl(this, continuationToken, client, tableName, modifiedOptions);

            return AsyncInfo.Run(async (cancellationToken) => await Executor.ExecuteAsync(
                                                                                       cmdToExecute,
                                                                                       modifiedOptions.RetryPolicy,
                                                                                       operationContext,
                                                                                       cancellationToken));
        }
 internal static TableRequestOptions ApplyDefaults(TableRequestOptions requestOptions, CloudTableClient client)
 {
     requestOptions = new TableRequestOptions(requestOptions);
     requestOptions.RetryPolicy = requestOptions.RetryPolicy == null
                                      ? client.RetryPolicy
                                      : requestOptions.RetryPolicy;
     requestOptions.ServerTimeout = requestOptions.ServerTimeout == null
                                           ? client.ServerTimeout
                                           : requestOptions.ServerTimeout;
     requestOptions.MaximumExecutionTime = requestOptions.MaximumExecutionTime == null
                                               ? client.MaximumExecutionTime
                                               : requestOptions.MaximumExecutionTime;
     return requestOptions;
 }
        /// <summary>
        /// Cloud a azure storage table if not exists.
        /// </summary>
        /// <param name="table">Cloud table object</param>
        /// <param name="requestOptions">Table request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>True if table was created; otherwise, false.</returns>
        public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            CloudTable tableRef = GetTableReferenceFromServer(table.Name, requestOptions, operationContext);

            if (tableRef != null)
            {
                return false;
            }
            else
            {
                tableRef = GetTableReference(table.Name);
                tableList.Add(tableRef);
                return true;
            }
        }
 public async Task RegisterSubscriber(string topic, string subscriberAddress)
 {
     try
     {
         var entity = new Entities.AzureStorageSubscription(topic, subscriberAddress);
         var t = GetTable();
         var operationContext = new OperationContext();
         var tableRequestOptions = new TableRequestOptions { RetryPolicy = new ExponentialRetry() };
         var res = await t.ExecuteAsync(TableOperation.InsertOrReplace(entity), tableRequestOptions, operationContext);
     }
     catch (Exception exception)
     {
         throw new RebusApplicationException(exception, $"Could not subscribe {subscriberAddress} to '{topic}'");
     }
 }
        public MailingListController()
        {
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            // If this is running in an Azure Web Site (not a Cloud Service) use the Web.config file:
            //    var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            var tableClient = storageAccount.CreateCloudTableClient();
            mailingListTable = tableClient.GetTableReference("mailinglist");

            webUIRetryPolicy = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };
        }
        async Task CopyAsync(TableRequestOptions requestOptions, OperationContext operationContext)
        {
            // Query all the entities!
            IQueryStream<MTableEntity> oldTableStream = await oldTable.ExecuteQueryStreamedAsync(
                new TableQuery<MTableEntity>(), requestOptions, operationContext);
            MTableEntity oldEntity;
            string previousPartitionKey = null;

            while ((oldEntity = await oldTableStream.ReadRowAsync()) != null)
            {
                if (RowKeyIsInternal(oldEntity.RowKey))
                    continue;

                if (oldEntity.PartitionKey != previousPartitionKey)
                {
                    previousPartitionKey = oldEntity.PartitionKey;
                    await EnsurePartitionSwitchedAsync(oldEntity.PartitionKey, requestOptions, operationContext);
                    if (IsBugEnabled(MTableOptionalBug.InsertBehindMigrator))
                    {
                        // More reasonable formulation of this bug.  If we're going
                        // to allow CopyAsync while some clients are still writing
                        // to the old table, give the developer credit for realizing
                        // that the stream might be stale by the time the partition
                        // is switched.
                        oldTableStream = await oldTable.ExecuteQueryStreamedAsync(
                            new TableQuery<MTableEntity> {
                                FilterString = TableQuery.GenerateFilterCondition(
                                    TableConstants.PartitionKey,
                                    QueryComparisons.GreaterThanOrEqual,
                                    oldEntity.PartitionKey)
                            }, requestOptions, operationContext);
                        continue;
                    }
                }

                // Can oldEntity be stale by the time we EnsurePartitionSwitchedAsync?
                // Currently no, because we don't start the copy until all clients have
                // entered PREFER_NEW state, meaning that all writes go to the new
                // table.  When we implement the Kstart/Kdone optimization (or similar),
                // then clients will be able to write to the old table in parallel with
                // our scan and we'll need to rescan after EnsurePartitionSwitchedAsync.

                // Should we also stream from the new table and copy only the
                // entities not already copied?
                await TryCopyEntityToNewTableAsync(oldEntity, requestOptions, operationContext);
            }
        }
Ejemplo n.º 26
0
        //
        // GET: /Snapshot/
        //
        // Note: This way of handling may not scale and may need to use continuation tokens later
        //
        public ActionResult Index()
        {
            TableRequestOptions reqOptions = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(10),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };

            var query = new TableQuery<Snapshot>().Where(
                TableQuery.GenerateFilterCondition(
                    "PartitionKey",
                    QueryComparisons.LessThanOrEqual,
                    Utils.NextOperationTB.Ticks.ToString()
                ));
            var snapshots = snapshotsTable.ExecuteQuery(query, reqOptions).ToList();
            return View(snapshots);
        }
        // PartitionKey = Topic
        // RowKey = Address

        public async Task<string[]> GetSubscriberAddresses(string topic)
        {
            try
            {
                var query =
                    new TableQuery<AzureStorageSubscription>().Where(TableQuery.GenerateFilterCondition("PartitionKey",
                        QueryComparisons.Equal, topic));
                var t = GetTable();
                var operationContext = new OperationContext();
                var tableRequestOptions = new TableRequestOptions { RetryPolicy = new ExponentialRetry() };
                var items = await t.ExecuteQueryAsync(query, tableRequestOptions, operationContext);
                return items.Select(i => i.RowKey).ToArray();
            }
            catch (Microsoft.WindowsAzure.Storage.StorageException exception)
            {
                throw new RebusApplicationException(exception, $"Could not get subscriber addresses for '{topic}'");
            }
        }
        public MessageController()
        {
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            // If this is running in a Windows Azure Web Site (not a Cloud Service) use the Web.config file:
            //    var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            // Get context object for working with tables and a reference to the blob container.
            var tableClient = storageAccount.CreateCloudTableClient();
            mailingListTable = tableClient.GetTableReference("mailinglist");
            messageTable = tableClient.GetTableReference("message");
            var blobClient = storageAccount.CreateCloudBlobClient();
            blobContainer = blobClient.GetContainerReference("azuremailblobcontainer");

            webUIRetryPolicy = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };
        }
        internal IEnumerable<DynamicTableEntity> Execute(CloudTableClient client, string tableName, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            CommonUtils.AssertNotNullOrEmpty("tableName", tableName);
            TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
            operationContext = operationContext ?? new OperationContext();

            IEnumerable<DynamicTableEntity> enumerable =
                General.LazyEnumerable<DynamicTableEntity>(
                (continuationToken) =>
                {
                    TableQuerySegment<DynamicTableEntity> seg = this.ExecuteQuerySegmented((TableContinuationToken)continuationToken, client, tableName, modifiedOptions, operationContext);

                    return new ResultSegment<DynamicTableEntity>(seg.Results) { ContinuationToken = seg.ContinuationToken };
                },
                this.takeCount.HasValue ? this.takeCount.Value : long.MaxValue,
                operationContext);

            return enumerable;
        }
        public Task<IEnumerable<Meme>> GetPageAsync(int page, int offset)
        {
            var tableClient = this.storageAccount.CreateCloudTableClient();
            var table = tableClient.GetTableReference("MemeMetadata");
            var query = new TableQuery<MemeMetadata>();
            var requestOptions = new TableRequestOptions()
            {
                RetryPolicy = new LinearRetry(TimeSpan.FromMilliseconds(500), 5)
            };

            var memesMetadata = table.ExecuteQuery(query, requestOptions).OrderByDescending(md => md.BlobName).Skip(page * offset).Take(offset);

            IEnumerable<Meme> result = new List<Meme>();
            foreach (var memeMetadata in memesMetadata)
            {
                (result as List<Meme>).Add(new Meme { Name = memeMetadata.Description, URL = memeMetadata.BlobUri, Username = memeMetadata.Username });
            }

            return Task.FromResult(result);
        }
Ejemplo n.º 31
0
        public List<OrgInfo> GetOrgInfoList()
        {
            TableRequestOptions reqOptions = new TableRequestOptions()
            {
                MaximumExecutionTime = TimeSpan.FromSeconds(1.5),
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3)
            };
            List<OrgInfo> list = null;
            try
            {
                var query = new TableQuery<OrgInfo>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Organization"));
                list = OrgInfoTable.ExecuteQuery(query, reqOptions).ToList();
            }
            catch (StorageException se)
            {
                Trace.TraceError(se.Message);
            }

            return list;
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            var accountName = args[0];
            var accountKey  = args[1];
            var GifsDir     = args[2];

            storageAccount = CloudStorageAccount.Parse(String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountName, accountKey));

            // Create the blob client.
            CloudBlobClient blobClient = new CloudBlobClient(storageAccount.BlobEndpoint, storageAccount.Credentials);

            // Create blob container if it doesn't exist.
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("memes");

            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Container);

            // Create the table client.
            CloudTableClient tableClient = new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(storageAccount.TableEndpoint, storageAccount.Credentials);

            // Create the table if it doesn't exist.
            CloudTable table       = tableClient.GetTableReference("MemeMetadata");
            var        statusTable = table.CreateIfNotExists();

            var list = new List <ClipMemeEntity> {
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200312-horse-cannon.gif", BlobName = "20140401-200312-horse-cannon.gif", Description = "Deploy", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200344-updated-visual-studio-theme.gif", BlobName = "20140401-200344-updated-visual-studio-theme.gif", Description = "News vs Theme", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200447-oops.gif", BlobName = "20140401-200447-oops.gif", Description = "First Iteration", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200534-just-learned-about-git-rebase.gif", BlobName = "20140401-200534-just-learned-about-git-rebase.gif", Description = "Tests Pass on First Try", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200606-when-i-unstash-something.gif", BlobName = "20140401-200606-when-i-unstash-something.gif", Description = "Scale up", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200750-dog-race.gif", BlobName = "20140401-200750-dog-race.gif", Description = "Sprint", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200800-cookies.gif", BlobName = "20140401-200800-cookies.gif", Description = "Scottgu Promoted", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200849-when-i-merge-my-own-pull-requests.gif", BlobName = "20140401-200849-when-i-merge-my-own-pull-requests.gif", Description = "to the cloud", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200924-disco-girl.gif", BlobName = "20140401-200924-disco-girl.gif", Description = "Hanseldance", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", BlobName = "20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", Description = "accidental git push", Username = "******"
                },
                new ClipMemeEntity {
                    BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", BlobName = "20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", Description = "msft at $40", Username = "******"
                }
            };

            foreach (var item in list)
            {
                // Retrieve reference to a blob
                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(item.BlobName);

                using (var fileStream = System.IO.File.OpenRead(String.Format("{0}\\{1}", GifsDir, item.BlobName)))
                {
                    blockBlob.UploadFromStream(fileStream);
                }

                var requestOptions = new Microsoft.WindowsAzure.Storage.Table.TableRequestOptions()
                {
                    RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromMilliseconds(500), 5)
                };

                table.Execute(Microsoft.WindowsAzure.Storage.Table.TableOperation.Insert(item), requestOptions);
            }

            return;
        }