public TableSearchService( CloudTableClient client, IUrlGenerator url) { _table = client?.GetTableReference(TableName) ?? throw new ArgumentNullException(nameof(client)); _url = url ?? throw new ArgumentNullException(nameof(url)); }
public TableSearchService( CloudTableClient client, ISearchResponseBuilder responseBuilder) { _table = client?.GetTableReference(TableName) ?? throw new ArgumentNullException(nameof(client)); _responseBuilder = responseBuilder ?? throw new ArgumentNullException(nameof(responseBuilder)); }
public TablePackageService( TableOperationBuilder operationBuilder, CloudTableClient client, ILogger <TablePackageService> logger) { _operationBuilder = operationBuilder ?? throw new ArgumentNullException(nameof(operationBuilder)); _table = client?.GetTableReference(TableName) ?? throw new ArgumentNullException(nameof(client)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Tries to resolve a table in the storage defined by the given connection string and table name. /// </summary> /// <param name="connectionString">The Azure storage connection string.</param> /// <param name="tableName">The name of the table to resolve and return.</param> /// <returns>The resolved table or null in case of an error.</returns> /// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="FormatException"></exception> public static CloudTable GetTable(string connectionString, string tableName) { CloudStorageAccount cloudStorageAccount = null; try { cloudStorageAccount = CloudStorageAccount.Parse(connectionString); } catch { throw; } CloudTableClient cloudTableClient = cloudStorageAccount?.CreateCloudTableClient(); return(cloudTableClient?.GetTableReference(tableName)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log) { log.LogTrace("C# HTTP trigger function processed a request."); dynamic body = await req.Content.ReadAsStringAsync(); Guid? CompanyId; string CompanyName = null; try { var data = JsonConvert.DeserializeObject <AssessmentProfile>(body as string); CompanyId = data?.CompanyId; CompanyName = data?.CompanyName; } catch (Exception ex) { throw ex; } // parse query parameter string connectionstring2 = "DefaultEndpointsProtocol=https;AccountName=spassessservices20190227;AccountKey=KLx/VDJ279oOZ2Z2wELr90GauiVlEN4pr8r2ss2xAiokZJGAi4PF6eGz0nI0Vz0IieEwtKxqkgoM+ukeVoWxMw==;EndpointSuffix=core.windows.net"; string json = null; if (CompanyName == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a company name")); } try { //this code will do a insert and do a check for the id CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring2); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable cloudTable = tableClient.GetTableReference("AssessmentProfile"); TableOperation tableOperation = TableOperation.Retrieve <AssessmentProfile>(CompanyId.ToString(), CompanyName); TableResult tableResult = await cloudTable.ExecuteAsync(tableOperation); AssessmentProfile person = tableResult.Result as AssessmentProfile; if (person != null) { // add the code here to pass the id back to the client json = JsonConvert.SerializeObject(person, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });; } } catch (StorageException se) { log.LogTrace(se.Message); } catch (Exception ex) { log.LogTrace(ex.Message); } //change this to return the companyid return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(json, Encoding.UTF8, "application/json") }); }
public IndexStore <T> GetIndexReference <T>(string name) { var table = tableClient.GetTableReference(string.Format("wazindex{0}", name)); return(new IndexStore <T>(table, name)); }
private static async Task <EventListResponse> QueryEventAsync( EventQuery eventQuery, EventQueryContinuationToken continuationToken, int?maxCount, CancellationToken cancellationToken) { if (maxCount.HasValue && maxCount.Value <= 0) { throw new ArgumentOutOfRangeException("maxCount"); } if (eventQuery == null) { throw new ArgumentNullException("eventQuery"); } if (eventQuery.TableInfos == null) { throw new ArgumentException("eventQuery.TableInfos is null"); } var response = new EventListResponse { Events = new List <EventModel>(), ContinuationToken = new EventQueryContinuationToken() }; var tableinfoIterator = eventQuery.TableInfos.GetEnumerator(); do { if (tableinfoIterator.MoveNext()) { cancellationToken.ThrowIfCancellationRequested(); continue; } response.ContinuationToken = null; return(response); } while (continuationToken != null && tableinfoIterator.Current.TableName != continuationToken.NextTableName); try { var tableClient = new CloudTableClient( new Uri(eventQuery.TableEndpoint), new StorageCredentials(tableinfoIterator.Current.SasToken)); var cloudTable = tableClient.GetTableReference(tableinfoIterator.Current.TableName); var tableQuery = new TableQuery <DynamicTableEntity>().Where(eventQuery.FilterUri).Take(maxCount); cancellationToken.ThrowIfCancellationRequested(); var tableContinuationToken = continuationToken == null ? null : continuationToken.NextTableContinuationToken; var tableResults = await cloudTable.ExecuteQuerySegmentedAsync(tableQuery, tableContinuationToken, cancellationToken); response.Events = tableResults.Select( _ => new EventModel { Properties = ResolveEventEntity(_) }).ToList(); response.ContinuationToken.NextTableContinuationToken = tableResults.ContinuationToken; if (response.ContinuationToken.NextTableContinuationToken == null) { if (!tableinfoIterator.MoveNext()) { response.ContinuationToken = null; return(response); } } response.ContinuationToken.NextTableName = tableinfoIterator.Current.TableName; } catch (StorageException error) { throw new EventQueryException("Error occurs when query event table", error); } return(response); }
public void TestCleanup() { var table = _client.GetTableReference(_tableName); table.DeleteAsync().Wait(); }
private async Task CreateTableAsync() { _cloudTable = _tableClient.GetTableReference(_tableName); await _cloudTable.CreateIfNotExistsAsync(); }
public void startingCode() { Trace.TraceInformation("WorkerRole1 is running"); CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.AppSettings["StorageConnectionString"]); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); table = tableClient.GetTableReference("urltable"); table.CreateIfNotExists(); infoTable = tableClient.GetTableReference("infotable"); infoTable.CreateIfNotExists(); errorTable = tableClient.GetTableReference("errortable"); errorTable.CreateIfNotExists(); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); queue = queueClient.GetQueueReference("urlstoqueue"); queue.CreateIfNotExists(); startStopQueue = queueClient.GetQueueReference("startstop"); startStopQueue.CreateIfNotExists(); state = "idle"; infoEntity newState = new infoEntity("state", state); TableOperation insertInfoOperation = TableOperation.InsertOrReplace(newState); infoTable.Execute(insertInfoOperation); acceptedURLs = new HashSet <string>(); urlsCrawled = 0; urlsAccepted = 0; numErrors = 0; queueSize = 0; numTitles = 0; lastTitle = "No titles crawled yet"; lastTen = new List <string>(); infoEntity newTotalNum = new infoEntity("total", urlsCrawled.ToString()); TableOperation insertTotalOperation = TableOperation.InsertOrReplace(newTotalNum); infoTable.Execute(insertTotalOperation); infoEntity newNumAccepted = new infoEntity("accepted", urlsAccepted.ToString()); TableOperation insertAcceptedOperation = TableOperation.InsertOrReplace(newNumAccepted); infoTable.Execute(insertAcceptedOperation); infoEntity newQueueSize = new infoEntity("queue", queueSize.ToString()); TableOperation insertNewQSize = TableOperation.InsertOrReplace(newQueueSize); infoTable.Execute(insertNewQSize); infoEntity num = new infoEntity("numTitles", numTitles.ToString()); TableOperation insertNum = TableOperation.InsertOrReplace(num); infoTable.Execute(insertNum); infoEntity last = new infoEntity("lastTitle", lastTitle); TableOperation insertLast = TableOperation.InsertOrReplace(last); infoTable.Execute(insertLast); }
// GET: 복덩이/Home public ActionResult Index() { ViewBag.Building = "2지구"; ViewBag.Floor = "1층"; ViewBag.Location = "서마12"; ViewBag.URL = "SecondFirst"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString")); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("SecondBuilding"); // Construct the query operation for all customer entities where PartitionKey="Smith". // Create a retrieve operation that takes a customer entity. TableOperation retrieveOperation = TableOperation.Retrieve <ShopInfoEntity>("1층", "서마12"); // Execute the retrieve operation. TableResult retrievedResult = table.Execute(retrieveOperation); ShopInfoEntity retrievedEntity = (ShopInfoEntity)retrievedResult.Result; if (retrievedEntity == null) { return(RedirectToAction("EmptyShop", new { Building = ViewBag.Building, Floor = "1층", Shop = "서마12" })); } // Print the phone number of the result. CloudTable tableUserInfo = tableClient.GetTableReference("UserInformation"); TableOperation retrieveUserInfoOperation = TableOperation.Retrieve <UserInfoEntity>(retrievedEntity.OwnerID, "SecondBuilding:1층:서마12"); TableResult retrievedUserInfoResult = tableUserInfo.Execute(retrieveUserInfoOperation); UserInfoEntity retrievedUserInfoEntity = (UserInfoEntity)retrievedUserInfoResult.Result; //오너 값으로 등록된 사진 가져오기 string[] tempOwnerId = retrievedEntity.OwnerID.Split('@'); CloudTable tableOwner = tableClient.GetTableReference(tempOwnerId[0]); TableQuery <ContentsEntity> rangeQuery = new TableQuery <ContentsEntity>().Where( TableQuery.GenerateFilterCondition("ShopName", QueryComparisons.Equal, retrievedEntity.ShopName)); //IDictionary<string, string> myActivity = new Dictionary<string, string> //{ // { "ShopName", retrievedEntity.ShopName }, // { "ShopOwner", retrievedEntity.OwnerID.Split('@')[0] }, // { "PhoneNumber", retrievedUserInfoEntity.PhoneNumber } //}; ViewBag.ShopName = retrievedEntity.ShopName; ViewBag.PhoneNumber = retrievedUserInfoEntity.PhoneNumber; List <IndexToView> myActivity = new List <IndexToView>(); foreach (ContentsEntity entity in tableOwner.ExecuteQuery(rangeQuery)) { var imageURL = "https://westgateproject.blob.core.windows.net/" + entity.PartitionKey.Split('@')[0] + "/" + entity.RowKey; var text = entity.Context; IndexToView temp = new IndexToView(imageURL, text); myActivity.Add(temp); } myActivity.Reverse(); return(View(myActivity)); //return View(); }
public async static Task Run(TimerInfo myTimer, Binder binder, TraceWriter log) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Environment.GetEnvironmentVariable("hobbystreakblob", EnvironmentVariableTarget.Process)); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable searchMetaDataTable = tableClient.GetTableReference("SearchMetaData"); await searchMetaDataTable.CreateIfNotExistsAsync(); CloudTable settingsTable = tableClient.GetTableReference("Settings"); await settingsTable.CreateIfNotExistsAsync(); TableOperation retrieveOperation = TableOperation.Retrieve <Settings>("Settings", "RefreshUrl"); TableResult result = await settingsTable.ExecuteAsync(retrieveOperation); Settings refreshUrl = result.Result as Settings; if (refreshUrl == null) { refreshUrl = new Settings(); refreshUrl.PartitionKey = "Settings"; refreshUrl.RowKey = "RefreshUrl"; refreshUrl.Value = "?f=tweets&vertical=default&q=%23hobbystreak&src=typd"; } string consumerkey = System.Net.WebUtility.UrlEncode(System.Environment.GetEnvironmentVariable("TwitterKey", EnvironmentVariableTarget.Process)); string consumersecret = System.Net.WebUtility.UrlEncode(System.Environment.GetEnvironmentVariable("TwitterSecret", EnvironmentVariableTarget.Process)); string combined = $"{consumerkey}:{consumersecret}"; byte[] encodedBytes = System.Text.Encoding.UTF8.GetBytes(combined); string encodedTxt = Convert.ToBase64String(encodedBytes); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", $"{encodedTxt}"); var authResponse = await client.PostAsync("https://api.twitter.com/oauth2/token", new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded")); authResponse.EnsureSuccessStatusCode(); var responseToken = await authResponse.Content.ReadAsStringAsync(); var access_token = Newtonsoft.Json.Linq.JObject.Parse(responseToken)["access_token"]; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{access_token}"); int counter = 0; var currentRunTime = DateTime.UtcNow.ToString("yyyy-MM-dd-HH:mm:ss"); IEnumerable <dynamic> statusses = null; string nextResultsUrl = refreshUrl.Value; do { var searchedTweetsResponse = await client.GetAsync("https://api.twitter.com/1.1/search/tweets.json" + nextResultsUrl); var tweets = JObject.Parse(await searchedTweetsResponse.Content.ReadAsStringAsync()); statusses = tweets["statuses"]; string fileName = $"tweets/{currentRunTime}-{counter}.json"; if (statusses != null && statusses.Any()) { var attributes = new Attribute[] { new BlobAttribute(fileName), new StorageAccountAttribute("hobbystreakblob") }; using (var writer = await binder.BindAsync <TextWriter>(attributes)) { writer.Write(statusses); writer.Flush(); } } else { fileName = string.Empty; } dynamic metadata = tweets["search_metadata"]; if (counter == 0) { refreshUrl.Value = metadata["refresh_url"]; await Ops.InsertOrMerge(settingsTable, refreshUrl); } SearchMetaData meta = new SearchMetaData(); meta.PartitionKey = currentRunTime; meta.RowKey = counter.ToString(); meta.CompletedIn = metadata["completed_in"]; meta.Count = metadata["count"]; meta.FileName = fileName; meta.MaxId = metadata["max_id"]; meta.MaxIdStr = metadata["max_id_str"]; meta.NextResults = metadata["next_results"]; meta.Query = metadata["query"]; meta.RefreshUrl = metadata["refresh_url"]; meta.SinceId = metadata["since_id"]; meta.SinceIdStr = metadata["since_id_str"]; nextResultsUrl = metadata["next_results"]; await Ops.InsertOrMerge(searchMetaDataTable, meta); if (!string.IsNullOrWhiteSpace(nextResultsUrl)) { counter++; } else { statusses = null; } }while (statusses != null && statusses.Any()); } }
/// <summary> /// Get a table reference /// </summary> /// <param name="name">Table name</param> /// <returns>Cloud table object</returns> public CloudTable GetTableReference(string name) { return(tableClient.GetTableReference(name)); }
/// <summary> /// Migrate users with random password /// </summary> /// <returns></returns> static async Task MigrateUsersWithRandomPasswordAsync() { string appDirecotyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string dataFilePath = Path.Combine(appDirecotyPath, Program.MigrationFile); // Check file existence if (!File.Exists(dataFilePath)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"File '{dataFilePath}' not found"); Console.ResetColor(); return; } // Read the data file and convert to object LocalAccountsModel users = LocalAccountsModel.Parse(File.ReadAllText(dataFilePath)); // Create B2C graph client object B2CGraphClient b2CGraphClient = new B2CGraphClient(Program.Tenant, Program.ClientId, Program.ClientSecret); // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Program.BlobStorageConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to the table. CloudTable table = tableClient.GetTableReference("users"); // Create the table if it doesn't exist. table.CreateIfNotExists(); // Create the batch operation. TableBatchOperation batchOperation = new TableBatchOperation(); int successes = 0; int fails = 0; foreach (var item in users.Users) { bool success = await b2CGraphClient.CreateAccount(users.userType, item.signInName, item.issuer, item.issuerUserId, item.email, item.password, item.displayName, item.firstName, item.lastName, true); // Create a new customer entity. // Note: Azure Blob Table query is case sensitive, always set the email to lower case TableEntity user = new TableEntity("B2CMigration", item.email.ToLower()); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation = TableOperation.InsertOrReplace(user); // Execute the insert operation. table.Execute(insertOperation); if (success) { successes += 1; } else { fails += 1; } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"\r\nUsers migration report:\r\n\tSuccesses: {successes}\r\n\tFails: {fails} "); Console.ResetColor(); }
public Repository(string name) { cloudTableClient = AzureTableService.GetCloudTableClient(); cloudTable = cloudTableClient.GetTableReference(name); }
internal void CreateTableIfNotExists(string tableName) { _clienteTableAzure.GetTableReference(tableName).CreateIfNotExists(); }
public Handler(CloudTableClient client) { this._settingsTable = client.GetTableReference("NetlifyMappings"); this._contactsTable = client.GetTableReference("NetlifyContacts"); }
/// <summary> /// Insert the Audit detail data now into Azure Table /// </summary> /// <param name="auditDetailedReports"></param> /// <param name="auditLogDataAnalytics"></param> /// <returns></returns> public AuditLogAnalyticsDataInfo addDatatoAzureStore(List <AuditDetailedReport> auditDetailedReports, AuditLogAnalyticsDataInfo auditLogDataAnalytics) { try { List <string> operations = getAuditOperations(); List <string> IncludedOperations = new List <string>(); List <string> ExcludedOperations = new List <string>(); int includedRecords = 0; int excludedRecords = 0; // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AuditLogStorageConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "Audit Log" table. CloudTable auditDataLogTable = tableClient.GetTableReference(AuditLogDataTableName); //// Add the Audit log information to Azure Table -- Primary Table to capture Audit log data foreach (AuditDetailedReport auditDetailReport in auditDetailedReports) { if (operations.Contains(auditDetailReport.Operation, StringComparer.OrdinalIgnoreCase)) { includedRecords++; string auditlogpartitionPrefix = AuditLogPartitionKeyPrefix + "_" + getAuditShortDateStringFromUTC(auditDetailReport.CreationTime); string auditlogrowprefix = auditDetailReport.Id; O365AuditLogData auditLogTableData = new O365AuditLogData(auditlogpartitionPrefix, auditlogrowprefix); O365MgmtApiEntities <AuditDetailedReport, O365AuditLogData> .Copy(auditDetailReport, auditLogTableData); auditLogTableData.CreationTime = auditLogTableData.CreationTime.ToLocalTime(); // Create the TableOperation object that inserts the customer entity. TableOperation auditLoginsertOperation = TableOperation.InsertOrMerge(auditLogTableData); log.LogInformation($"Inserting Operation - {auditDetailReport.Operation} Id - {auditDetailReport.Id} "); // Execute the insert operation. TableResult result = auditDataLogTable.ExecuteAsync(auditLoginsertOperation).GetAwaiter().GetResult(); if (result.HttpStatusCode.ToEnum <HttpStatusCode>() == HttpStatusCode.BadGateway || result.HttpStatusCode.ToEnum <HttpStatusCode>() == HttpStatusCode.BadRequest) { throw new Exception($"Table Update failed for Audit Log data entry. Captured error {result.HttpStatusCode} for Operation - { auditDetailReport.Operation }, Id {auditDetailReport.Id} "); } if (!IncludedOperations.Contains(auditDetailReport.Operation, StringComparer.OrdinalIgnoreCase)) { IncludedOperations.Add(auditDetailReport.Operation); } } else { excludedRecords++; if (!ExcludedOperations.Contains(auditDetailReport.Operation, StringComparer.OrdinalIgnoreCase)) { ExcludedOperations.Add(auditDetailReport.Operation); } log.LogInformation($"Record not entered. Operation - { auditDetailReport.Operation }, Id {auditDetailReport.Id} "); } } //// Capture the audit log report analytics for each run into the table for future reference -- Secondary Table for capturing analytics of each run log.LogInformation($"\r\n Included Records count {includedRecords} and Excluded Records count {excludedRecords}"); auditLogDataAnalytics.ExcludedOperations = string.Join(",", ExcludedOperations.ToArray()); auditLogDataAnalytics.IncludedOperations = string.Join(",", IncludedOperations.ToArray()); auditLogDataAnalytics.IncludedRecords = includedRecords; auditLogDataAnalytics.ExcludedRecords = excludedRecords; auditLogDataAnalytics.TotalRecords = auditDetailedReports.Count; auditLogDataAnalytics.LogOperationStatus = "Completed"; auditLogDataAnalytics.LogOperationSuccessful = true; } catch (Exception ex) { log.LogError(ex.Message); auditLogDataAnalytics.LogOperationStatus = "Failed"; auditLogDataAnalytics.LogOperationSuccessful = false; } return(auditLogDataAnalytics); }
public StoragePopulator(GitHubClient githubClient, CloudTableClient tableClient) : this( githubClient, tableClient.GetTableReference(TableNames.RoachIssueTable), tableClient.GetTableReference(TableNames.RoachMilestoneTable)) { }
public StorageQueryUtil(CloudTableClient tableClient) : this( tableClient.GetTableReference(TableNames.RoachIssueTable), tableClient.GetTableReference(TableNames.RoachMilestoneTable)) { }
private CloudTable TableConnection(string tableName) { CloudTable cloudTable = tableClient.GetTableReference(tableName); return(cloudTable); }
public TestFixture() { RandomNameResolver nameResolver = new TestNameResolver(); JobHostConfiguration hostConfiguration = new JobHostConfiguration() { NameResolver = nameResolver, TypeLocator = new FakeTypeLocator(typeof(MultipleStorageAccountsEndToEndTests)), }; Config = hostConfiguration; Account1 = CloudStorageAccount.Parse(hostConfiguration.StorageConnectionString); string secondaryConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(Secondary); Account2 = CloudStorageAccount.Parse(secondaryConnectionString); CleanContainers(); CloudBlobClient blobClient1 = Account1.CreateCloudBlobClient(); string inputName = nameResolver.ResolveInString(Input); CloudBlobContainer inputContainer1 = blobClient1.GetContainerReference(inputName); inputContainer1.Create(); string outputName = nameResolver.ResolveWholeString(Output); OutputContainer1 = blobClient1.GetContainerReference(outputName); OutputContainer1.CreateIfNotExists(); CloudBlobClient blobClient2 = Account2.CreateCloudBlobClient(); CloudBlobContainer inputContainer2 = blobClient2.GetContainerReference(inputName); inputContainer2.Create(); OutputContainer2 = blobClient2.GetContainerReference(outputName); OutputContainer2.CreateIfNotExists(); CloudQueueClient queueClient1 = Account1.CreateCloudQueueClient(); CloudQueue inputQueue1 = queueClient1.GetQueueReference(inputName); inputQueue1.CreateIfNotExists(); OutputQueue1 = queueClient1.GetQueueReference(outputName); OutputQueue1.CreateIfNotExists(); CloudQueueClient queueClient2 = Account2.CreateCloudQueueClient(); CloudQueue inputQueue2 = queueClient2.GetQueueReference(inputName); inputQueue2.CreateIfNotExists(); OutputQueue2 = queueClient2.GetQueueReference(outputName); OutputQueue2.CreateIfNotExists(); CloudTableClient tableClient1 = Account1.CreateCloudTableClient(); string outputTableName = nameResolver.ResolveWholeString(OutputTableName); OutputTable1 = tableClient1.GetTableReference(outputTableName); OutputTable2 = Account2.CreateCloudTableClient().GetTableReference(outputTableName); // upload some test blobs to the input containers of both storage accounts CloudBlockBlob blob = inputContainer1.GetBlockBlobReference("blob1"); blob.UploadText(TestData); blob = inputContainer2.GetBlockBlobReference("blob2"); blob.UploadText(TestData); // upload some test queue messages to the input queues of both storage accounts inputQueue1.AddMessage(new CloudQueueMessage(TestData)); inputQueue2.AddMessage(new CloudQueueMessage(TestData)); Host = new JobHost(hostConfiguration); Host.Start(); }
static void Main(string[] args) { try { // validate args ValidateArguments(args); // get inclusion tables if (_inclusionTableList == null) { // get all tables in alphabetical order _inclusionTableList = _sourceTableClient .ListTables() .Select(o => o.Name) .OrderBy(o => o) .ToList(); } // exclude tables prior to continue from if (!string.IsNullOrWhiteSpace(_continueFrom)) { _inclusionTableList.RemoveAll(o => string.CompareOrdinal(o, _continueFrom) < 0); } // exclude provided list _inclusionTableList = _inclusionTableList.Except(_exclusionTableList).ToList(); // exclude Azure metrics tables _inclusionTableList.RemoveAll(o => o.StartsWith("$Metrics")); // exclude Azure diagnostics tables _inclusionTableList.RemoveAll(o => o.StartsWith("WAD")); // delete tables to sync __("Deleting tables"); var deleteTaskList = _inclusionTableList.Select(tableName => { var destinationTable = _destinationTableClient.GetTableReference(tableName); return(destinationTable.DeleteIfExistsAsync()); }).ToList(); // wait for completion while (deleteTaskList.Any(o => o.Status < TaskStatus.RanToCompletion)) { Thread.Sleep(500); } // re-create tables __("Re-creating tables"); new Thread(StartAnimation).Start(); var tablesReadyList = new ConcurrentBag <string>(); _animationProgress = 0.ToString("p"); _inclusionTableList.AsParallel().ForAll(tableName => { var success = false; do { try { // attempt creation var destinationTable = _destinationTableClient.GetTableReference(tableName); destinationTable.CreateIfNotExists(); // we're good, refresh progress tablesReadyList.Add(tableName); var progress = 1 - _inclusionTableList.Except(tablesReadyList).Count() / (double)_inclusionTableList.Count; _animationProgress = progress.ToString("p"); success = true; } catch (StorageException ex) { if (ex.Message.Contains("409")) { // a table couldn't be recreated, wait and attempt again Thread.Sleep(10000); } else { throw; } } } while (!success); }); _isAnimationCancelling = true; _inclusionTableList.ForEach(tableName => { // get table references var sourceTable = _sourceTableClient.GetTableReference(tableName); var destinationTable = _destinationTableClient.GetTableReference(tableName); CopyTables(sourceTable, destinationTable); }); Console.Write("Done. Press any key to exit..."); Console.ReadKey(); return; // get all tables var sourceTableList = _sourceTableClient.ListTables().ToList(); var destinationTableList = _destinationTableClient.ListTables().ToList(); // synchronize tables between source and destination SyncDestinationTables(sourceTableList, ref destinationTableList); // clear existing destination tables one by one and repopulate from source for (var i = 55; i < destinationTableList.Count; i++) { var destinationTable = destinationTableList[i]; __("----- {0} ({1} of {2})-----", destinationTable.Name, i + 1, destinationTableList.Count); // Initialize a default TableQuery to retrieve all the entities in the table. TableQuery <DynamicTableEntity> tableQuery = new TableQuery <DynamicTableEntity> { SelectColumns = new List <string>() }; // Initialize the continuation token to null to start from the beginning of the table. TableContinuationToken continuationToken = null; do { // Retrieve a segment (up to 1,000 entities). TableQuerySegment <DynamicTableEntity> tableQueryResult = destinationTable.ExecuteQuerySegmented(tableQuery, continuationToken); // Assign the new continuation token to tell the service where to // continue on the next iteration (or null if it has reached the end). continuationToken = tableQueryResult.ContinuationToken; // Print the number of rows retrieved. Console.WriteLine("Rows retrieved {0}", tableQueryResult.Results.Count); // Loop until a null continuation token is received, indicating the end of the table. } while (continuationToken != null); // delete all table rows and recieve initial record count to decided if table needs to be copied var initialRecordCount = TruncateTable(destinationTable); if (initialRecordCount > 0) { // find matching source table and use AzCopy to move data from it to the destination var sourceTable = sourceTableList.First(o => o.Name == destinationTable.Name); CopyTables(sourceTable, destinationTable); } Console.Clear(); } __("Complete"); Console.ReadKey(); } catch (Exception ex) { __(ex.Message); throw; } }
/// <summary> /// Inserts an entity using an 'Insert' operation. /// </summary> public void Insert <T>(string tableName, T entity, bool createIfNotExists = false) where T : TableEntity { var table = _tableClient.GetTableReference(tableName); var op = TableOperation.Insert(entity); if (createIfNotExists) { table.CreateIfNotExists(); } table.Execute(op); }
public SummaryAzureTableStorage(CloudTableClient cloudTableClient, string episodeSummarizedTableName) { _episodeSummarizedTable = cloudTableClient.GetTableReference(episodeSummarizedTableName); }
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"); DynamicTableEntity ent = new DynamicTableEntity() { PartitionKey = Guid.NewGuid().ToString(), RowKey = DateTime.Now.Ticks.ToString() }; ent.Properties.Add("EncryptedProp1", new EntityProperty(string.Empty)); ent.Properties.Add("EncryptedProp2", new EntityProperty("bar")); ent.Properties.Add("NotEncryptedProp", new EntityProperty(1234)); // This is used to indicate whether a property should be encrypted or not given the partition key, row key, // and the property name. Func <string, string, string, bool> encryptionResolver = (pk, rk, propName) => { if (propName.StartsWith("EncryptedProp")) { return(true); } return(false); }; TableRequestOptions insertOptions = new TableRequestOptions() { EncryptionPolicy = new TableEncryptionPolicy(key, null), EncryptionResolver = encryptionResolver }; // 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(); } }
public AzureStorageService() { storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString()); tableClient = storageAccount.CreateCloudTableClient(); tokenTable = tableClient.GetTableReference(Settings.tokenTableName); }
public void TableSasInvalidOperations() { CloudTableClient tableClient = GenerateCloudTableClient(); CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N")); try { table.Create(); // Prepare SAS authentication with full permissions string sasString = table.GetSharedAccessSignature( new SharedAccessTablePolicy { Permissions = SharedAccessTablePermissions.Delete, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30) }, null, null, null, null, null); CloudTableClient sasClient = new CloudTableClient(tableClient.BaseUri, new StorageCredentials(sasString)); // Construct a valid set of service properties to upload. ServiceProperties properties = new ServiceProperties(); properties.Logging.Version = Constants.AnalyticsConstants.LoggingVersionV1; properties.HourMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1; properties.Logging.RetentionDays = 9; sasClient.GetServiceProperties(); sasClient.SetServiceProperties(properties); // Test invalid client operations // BUGBUG: ListTables hides the exception. We should fix this // TestHelpers.ExpectedException(() => sasClient.ListTablesSegmented(), "List tables with SAS", HttpStatusCode.NotFound); TestHelper.ExpectedException(() => sasClient.GetServiceProperties(), "Get service properties with SAS", HttpStatusCode.NotFound); TestHelper.ExpectedException(() => sasClient.SetServiceProperties(properties), "Set service properties with SAS", HttpStatusCode.NotFound); CloudTable sasTable = sasClient.GetTableReference(table.Name); // Verify that creation fails with SAS TestHelper.ExpectedException(() => sasTable.Create(), "Create a table with SAS", HttpStatusCode.NotFound); // Create the table. table.Create(); // Test invalid table operations TestHelper.ExpectedException(() => sasTable.Delete(), "Delete a table with SAS", HttpStatusCode.NotFound); TestHelper.ExpectedException(() => sasTable.GetPermissions(), "Get ACL with SAS", HttpStatusCode.NotFound); TestHelper.ExpectedException(() => sasTable.SetPermissions(new TablePermissions()), "Set ACL with SAS", HttpStatusCode.NotFound); } finally { table.DeleteIfExists(); } }
public async Task <Player> CreatePlayer(Player player, IEnumerable <Question> startingQuestions) { var table = _tableClient.GetTableReference(TableNames.Player); player.Id = Guid.NewGuid(); TableOperation insertOperation = TableOperation.Insert(new PlayerEntity(player), true); TableResult result = await table.ExecuteAsync(insertOperation); if (result.Result is PlayerEntity newPlayerEntity) { // Create starting questions var questionEntities = startingQuestions.Select((x, index) => { x.Id = Guid.NewGuid(); x.PlayerId = player.Id; x.SequenceNumber = (uint)index + 1; return(new QuestionEntity(x)); }); var questionsResult = await AddQuestionsToPlayer(questionEntities); if (questionsResult.Any(x => x.HttpStatusCode != 201)) { _logger.LogError($"Failed to add at least one starting question when creating player {player.Id}"); } return(newPlayerEntity.ToPlayer()); } else { _logger.LogError($"Failed to create new player with name {player.Name}. Table HTTP Code: {result.HttpStatusCode}"); return(null); } }
private CloudTable GetTable(string name) => _tableClient.GetTableReference($"{_options.Prefix}{name}");
public void CreateTable(string tableName) { var table = client.GetTableReference(tableName); table.CreateIfNotExists(); }