public List <string> Query(string query) { WikiCount = 0; CreateStopWords(); query = query.ToLower(); if (SmartCache.ContainsKey(query.ToLower())) { return(SmartCache[query]); } else { //Dictionary<string, string[]> results = new Dictionary<string, string[]>(); List <LinkRow> results = new List <LinkRow>(); List <string> qWords = new List <string>(); string[] queryWords = query.Split(new Char[] { ' ', ',', '.', ':', '!', '?', '-', '%', '"', '(', ')', ':', '#', '_' }); foreach (string wd in queryWords) { if (!stopwordstitle.Contains(wd.ToLower()) && !qWords.Contains(wd.ToLower()) && !qWords.Contains(String.Concat(wd, "s").ToLower()) && wd.Length > 1) { if (!qWords.Contains(wd.Substring(0, wd.Length - 1))) { if (wd.Contains("'")) { string nwd = wd.Replace("'", ""); qWords.Add(nwd.ToLower()); } else { qWords.Add(wd.ToLower()); } } } } foreach (string word in qWords) { try { TableQuery <LinkRow> rangeQuery = new TableQuery <LinkRow>() .Where( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, word) ); var result = DBConnect.GetLinkTable().ExecuteQuery(rangeQuery).ToList(); results.AddRange(result); /* * foreach (var row in result) * { * if (results.ContainsKey(row.URL)) * { * string[] update = results[row.URL]; * int old = int.Parse(update[3]); * int newInt = old + 1; * //RANKING * // Titlematch = 4pt * // Wikipedia Article = 2pt * // Bodymatch = 1pt * if (row.Title.ToLower().Contains(word.ToLower())) * { * newInt = old + 4; * } * else * { * newInt = old + 1; * } * string[] newInfo = new string[] { update[0], update[1], update[2], newInt.ToString(), update[4], update[5] }; * results[row.URL] = newInfo; * } * else * { * string[] source = row.Body.Split(new char[] { '.', '?', '!' }); * StringBuilder sbd = new StringBuilder(""); * for (int i = 0; i < source.Length; i++) * { * if (source[i].Contains(word)) * { * sbd.Append(source[i]); * try * { * sbd.Append(". "); * sbd.Append(source[i + 1]); * } * catch { } * sbd.Append("..."); * break; * } * } * if (sbd.ToString() == "") * { * try * { * sbd.Append(source[0]); * try * { * sbd.Append(". "); * sbd.Append(source[1]); * } * catch { } * sbd.Append("..."); * } * catch * { } * } * var snippet = sbd.ToString(); * string suggest = ""; * if (row.URL.Contains("wikipedia")) * { * try * { * suggest = row.Suggestions; * } * catch { } * } * string starterPoints = "1"; * //RANKING * // Titlematch = 4pt * // Wikipedia Article = 2pt * // Bodymatch = 1pt * if (row.Title.ToLower().Contains(word.ToLower()) && row.URL.Contains("wikipedia")) * { * starterPoints = "6"; * } * else if (row.Title.ToLower().Contains(word.ToLower())) * { * starterPoints = "4"; * } * else * { * starterPoints = "1"; * } * string[] info = new string[] { row.Title, row.DatePublished.ToString(), snippet, starterPoints, row.Img, suggest }; * results.Add(row.URL, info); * * } * } */ } catch { System.Diagnostics.Debug.WriteLine("TableQuery Failed"); } } //var sorted = results.OrderByDescending(x => int.Parse(x.Value[3])).Take(15); var sorted = results.GroupBy(x => x.URL) .Select(x => new Tuple <LinkRow, int>(x.ToList().First(), calculateScore(x.ToList().First(), qWords))) .OrderByDescending(x => x.Item2) .ThenByDescending(x => x.Item1.DatePublished) .Take(10).ToList(); // calculateScore(x.ToList().First(), qWords) // x.ToList().Count List <string> r = new List <string>(); foreach (var pair in sorted) { StringBuilder sb = new StringBuilder(); sb.Append(pair.Item1.URL); sb.Append("~"); sb.Append(pair.Item1.Title); sb.Append("~"); sb.Append(pair.Item1.DatePublished); sb.Append("~"); sb.Append(pair.Item1.Body); sb.Append("~"); sb.Append("null"); sb.Append("~"); sb.Append(pair.Item1.Img); sb.Append(pair.Item1.Suggestions); r.Add(sb.ToString()); } SmartCache.Add(query.ToLower(), r); return(r); } }
public async Task <ElevEntity> GetElevAsyncTask(string cnp) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=storeksq6lvimcn6gy;AccountKey=okS17G921c6N5lN7Czxi1QJ+DF/fbripzaWiEDoRdp4oh42RoJFz3A5Nfn70dHaoh3mUaFzQIcu9MVDTeHmmiQ==;EndpointSuffix=core.windows.net"); // Create a table client for interacting with the table service CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create a table client for interacting with the table service CloudTable table = tableClient.GetTableReference("elevipssc"); await table.CreateIfNotExistsAsync(); TableQuery <ElevEntity> query = new TableQuery <ElevEntity>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, cnp)); TableContinuationToken token = null; TableQuerySegment <ElevEntity> resultSegment = await table.ExecuteQuerySegmentedAsync(query, token); token = resultSegment.ContinuationToken; foreach (ElevEntity entity in resultSegment.Results) { return(entity); } return(null); }
public static void Run([TimerTrigger("0 30 * * * *", RunOnStartup = true)] TimerInfo myTimer, TraceWriter log) { log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); int numberOfStates = 12; // Retrieve storage account from connection string. var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureWebJobsStorage")); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("snotelmergetracker"); table.CreateIfNotExists(); #if DEBUG int numberOfHoursToCheck = 3 * 7 * 24; //was 1; #else int numberOfHoursToCheck = 7 * 24; //one week #endif //look back x days and fill in any missing values; TableQuery <FileProcessedTracker> dateQuery = new TableQuery <FileProcessedTracker>().Where( TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionName), TableOperators.And, TableQuery.GenerateFilterConditionForDate("ForecastDate", QueryComparisons.GreaterThan, DateTime.UtcNow.AddDays(-1 * numberOfHoursToCheck)) ) ); var results = table.ExecuteQuery(dateQuery); //refactoring the below code to a shared method can cause an .net issue //related to binding redirect to arise; leave this here for now. See AzureUtilities.cs //for more info log.Info($"Attempting to sign in to ad for datalake upload"); var adlsAccountName = CloudConfigurationManager.GetSetting("ADLSAccountName"); //auth secrets var domain = CloudConfigurationManager.GetSetting("Domain"); var webApp_clientId = CloudConfigurationManager.GetSetting("WebAppClientId"); var clientSecret = CloudConfigurationManager.GetSetting("ClientSecret"); var clientCredential = new ClientCredential(webApp_clientId, clientSecret); var creds = ApplicationTokenProvider.LoginSilentAsync(domain, clientCredential).Result; var fullAdlsAccountName = CloudConfigurationManager.GetSetting("ADLSFullAccountName"); // Create client objects and set the subscription ID var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds); var adlsClient = AdlsClient.CreateClient(fullAdlsAccountName, creds); var checkDate = DateTime.UtcNow.AddHours(-1 * numberOfHoursToCheck); while (checkDate < DateTime.UtcNow) { //has it already been marked as complete in the table string nameToCheck = SnotelUtilities.CreateSnotelFileDate(checkDate) + ".snotel.csv"; if (results.Where(r => r.RowKey == nameToCheck).Count() == 0) { log.Info($"{nameToCheck} doesn't exist in completed table, need to see if all files exist to concat"); var lexStartAndEnd = SnotelUtilities.CreateSnotelFileDate(checkDate); var hourlyFilesOnAdls = adlsClient.EnumerateDirectory(csvDirectory).Where(f => f.Name.StartsWith(lexStartAndEnd)).Select(f => f.Name).ToList(); if (hourlyFilesOnAdls.Count == numberOfStates) { if (ConcatFiles(adlsClient, nameToCheck, hourlyFilesOnAdls)) { //mark file as finished in table FileProcessedTracker tracker = new FileProcessedTracker { ForecastDate = checkDate, PartitionKey = partitionName, RowKey = nameToCheck, Url = "unknown" }; table.Execute(TableOperation.Insert(tracker)); } else { log.Error($"Missing data for {checkDate} need to manually backfill, can't concat"); } } else { log.Info($"all state files don't exist for {checkDate}, waiting until next run"); } } else { log.Info($"{nameToCheck} marked as already concated"); } checkDate = checkDate.AddHours(1); } }
public IHttpActionResult Get() { // Construct the query operation for all customer entities where PartitionKey="Smith". TableQuery <TableEntityAdapter <Form> > query = new TableQuery <TableEntityAdapter <Form> >().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "test")); return(Ok(FormTable.ExecuteQuery(query).Select(result => result.OriginalEntity))); }
public static string PropertyEqual(this string property, string value) { return(TableQuery.GenerateFilterCondition(property, QueryComparisons.Equal, value)); }
private void ProcessSubscribeQueueMessage(CloudQueueMessage msg) { Stopwatch requestTimer = Stopwatch.StartNew(); var request = RequestTelemetryHelper.StartNewRequest("ProcessSubscribeQueueMessage", DateTimeOffset.UtcNow); CallContext.LogicalSetData(CORRELATION_SLOT, request.Id); //Thread.SetData(Thread.GetNamedDataSlot(CORRELATION_SLOT), request.Id); try { // Log and delete if this is a "poison" queue message (repeatedly processed // and always causes an error that prevents processing from completing). // Production applications should move the "poison" message to a "dead message" // queue for analysis rather than deleting the message. if (msg.DequeueCount > 5) { Trace.TraceError("Deleting poison subscribe message: message {0}.", msg.AsString, GetRoleInstance()); subscribeQueue.DeleteMessage(msg); request.Properties.Add(new KeyValuePair <string, string>("FailureCode", "PoisonMessage")); request.Properties.Add(new KeyValuePair <string, string>("DequeueCount", msg.DequeueCount.ToString())); if (msg.InsertionTime != null) { request.Metrics.Add(new KeyValuePair <string, double>("SubscribeProcessingTimeMs", ((TimeSpan)(DateTimeOffset.Now - msg.InsertionTime)).Milliseconds)); } RequestTelemetryHelper.DispatchRequest(request, requestTimer.Elapsed, false); return; } // Parse message retrieved from queue. Message consists of // subscriber GUID and list name. // Example: 57ab4c4b-d564-40e3-9a3f-81835b3e102e,contoso1 var messageParts = msg.AsString.Split(new char[] { ',' }); var subscriberGUID = messageParts[0]; var listName = messageParts[1]; Trace.TraceInformation("ProcessSubscribeQueueMessage start: subscriber GUID {0} listName {1} Role Instance {2}.", subscriberGUID, listName, GetRoleInstance()); // Get subscriber info. string filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, listName), TableOperators.And, TableQuery.GenerateFilterCondition("SubscriberGUID", QueryComparisons.Equal, subscriberGUID)); var query = new TableQuery <Subscriber>().Where(filter); var subscriber = mailingListTable.ExecuteQuery(query).ToList().Single(); // Get mailing list info. var retrieveOperation = TableOperation.Retrieve <MailingList>(subscriber.ListName, "mailinglist"); var retrievedResult = mailingListTable.Execute(retrieveOperation); var mailingList = retrievedResult.Result as MailingList; SendSubscribeEmail(subscriberGUID, subscriber, mailingList); subscribeQueue.DeleteMessage(msg); Trace.TraceInformation("ProcessSubscribeQueueMessage complete: subscriber GUID {0} Role Instance {1}.", subscriberGUID, GetRoleInstance()); if (msg.InsertionTime != null) { request.Metrics.Add(new KeyValuePair <string, double>("SubscribeProcessingTimeMs", ((TimeSpan)(DateTimeOffset.Now - msg.InsertionTime)).Milliseconds)); } RequestTelemetryHelper.DispatchRequest(request, requestTimer.Elapsed, true); } catch (Exception ex) { request.Properties.Add(new KeyValuePair <string, string>("FailureCode", "Exception")); if (msg.InsertionTime != null) { request.Metrics.Add(new KeyValuePair <string, double>("FailedSubscribeProcessingTimeMs", ((TimeSpan)(DateTimeOffset.Now - msg.InsertionTime)).Milliseconds)); } RequestTelemetryHelper.DispatchRequest(request, requestTimer.Elapsed, false); throw ex; } }
public static string GetServiceRequestAuditDetailsQuery(string id) { return(TableQuery.GenerateFilterCondition("PartitionKey", Constants.Equal, id)); }
public async Task <Dictionary <ExperimentID, ExperimentEntity> > GetExperiments(ExperimentManager.ExperimentFilter?filter = default(ExperimentManager.ExperimentFilter?)) { var dict = new Dictionary <ExperimentID, ExperimentEntity>(); TableQuery <ExperimentEntity> query = new TableQuery <ExperimentEntity>(); List <string> experimentFilters = new List <string>(); experimentFilters.Add(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ExperimentEntity.PartitionKeyDefault)); if (filter.HasValue) { if (filter.Value.BenchmarkContainerEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("BenchmarkContainer", QueryComparisons.Equal, filter.Value.BenchmarkContainerEquals)); } if (filter.Value.CategoryEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("Category", QueryComparisons.Equal, filter.Value.CategoryEquals)); } if (filter.Value.ExecutableEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("Executable", QueryComparisons.Equal, filter.Value.ExecutableEquals)); } if (filter.Value.ParametersEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("Parameters", QueryComparisons.Equal, filter.Value.ParametersEquals)); } if (filter.Value.NotesEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("Note", QueryComparisons.Equal, filter.Value.NotesEquals)); } if (filter.Value.CreatorEquals != null) { experimentFilters.Add(TableQuery.GenerateFilterCondition("Creator", QueryComparisons.Equal, filter.Value.CreatorEquals)); } } if (experimentFilters.Count > 0) { string finalFilter = experimentFilters[0]; for (int i = 1; i < experimentFilters.Count; ++i) { finalFilter = TableQuery.CombineFilters(finalFilter, TableOperators.And, experimentFilters[i]); } query = query.Where(finalFilter); } TableContinuationToken continuationToken = null; do { TableQuerySegment <ExperimentEntity> tableQueryResult = await experimentsTable.ExecuteQuerySegmentedAsync(query, continuationToken); continuationToken = tableQueryResult.ContinuationToken; foreach (var e in tableQueryResult.Results) { dict.Add(int.Parse(e.RowKey, System.Globalization.CultureInfo.InvariantCulture), e); } } while (continuationToken != null); return(dict); }
/// <summary> /// method to get all userbackends synch /// </summary> /// <param name="UserID">takes user id as input</param> /// <returns>returns list of backends synch entity for user</returns> public List <SynchEntity> GetAllUserBackendsSynch(string UserID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //generate query to get user backend synch from azure table TableQuery <SynchEntity> query = new TableQuery <SynchEntity>().Where(TableQuery.GenerateFilterCondition(CoreConstants.AzureTables.PartitionKey, QueryComparisons.Equal, string.Concat(CoreConstants.AzureTables.BackendSynchPK, UserID))); //call dataprovider method to get entities from azure table List <SynchEntity> alluserbackendsynch = DataProvider.GetEntitiesList <SynchEntity>(CoreConstants.AzureTables.UserDeviceConfiguration, query); return(alluserbackendsynch); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error while retrieving all userbackendssynch from userdeviceconfig azure table in DAL : " //+ exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new DataAccessException(); } }
protected string CreatePartitionKeyFilterCondition(string partitionKey) { return(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey)); }
internal bool CheckDiagnosticsTable(string storageAccountName, string resId, string host, string waitChar, string osType, int TimeoutinMinutes = 15) { var tableExists = true; StorageAccount account = null; if (!String.IsNullOrEmpty(storageAccountName)) { account = this.GetStorageAccountFromCache(storageAccountName); } if (account != null) { var endpoint = this.GetCoreEndpoint(storageAccountName); var key = this.GetAzureStorageKeyFromCache(storageAccountName); var credentials = new StorageCredentials(storageAccountName, key); var cloudStorageAccount = new CloudStorageAccount(credentials, endpoint, true); var tableClient = cloudStorageAccount.CreateCloudTableClient(); var checkStart = DateTime.Now; var searchTime = DateTime.UtcNow.AddMinutes(-5); foreach (var tableName in AEMExtensionConstants.WADTablesV2[osType]) { var query = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("DeploymentId", QueryComparisons.Equal, resId), TableOperators.And, TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("Host", QueryComparisons.Equal, host), TableOperators.And, TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, searchTime))); var perfCounterTable = tableClient.GetTableReference(tableName); bool wait = true; while (wait) { var results = perfCounterTable.ExecuteQuerySegmentedAsync(new TableQuery() { FilterString = query }, token: null) .ConfigureAwait(false).GetAwaiter().GetResult(); if (results.Count() > 0) { tableExists &= true; break; } else { WriteHost(waitChar, newLine: false); TestMockSupport.Delay(5000); } wait = ((DateTime.Now) - checkStart).TotalMinutes < TimeoutinMinutes; } if (!wait) { WriteVerbose("PerfCounter Table " + tableName + " not found"); tableExists = false; break; } } } return(tableExists); }
public async Task <IActionResult> Cart(int?foodID, double price, int?qty) { var managementClient = new ManagementClient(configure["ConnectionStrings:ServiceBusConnection"]); var queue = await managementClient.GetQueueRuntimeInfoAsync(QueueName); ViewBag.MessageCount = queue.MessageCount; CloudTable orderTable = GetTableStorageInformation("Order"); CloudTable detailTable = GetTableStorageInformation("OrderDetails"); TableContinuationToken continuationToken; Order order; // Query Pending Order from Logged-in User TableQuery <Order> query = new TableQuery <Order>() .Where(TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, User.Identity.Name), TableOperators.And, TableQuery.GenerateFilterCondition("OrderStatus", QueryComparisons.Equal, "Pending")) ); List <Order> results = new List <Order>(); continuationToken = null; do { TableQuerySegment <Order> queryResults = await orderTable.ExecuteQuerySegmentedAsync(query, continuationToken); continuationToken = queryResults.ContinuationToken; results.AddRange(queryResults.Results); } while (continuationToken != null); if (results.Count == 0) // If there is no pending order { order = new Order(User.Identity.Name); TableOperation insertOrder = TableOperation.Insert(order); // Add new order orderTable.ExecuteAsync(insertOrder).Wait(); } else { order = results[0]; // Link to existing order } ViewBag.orderId = order.PartitionKey; // Store order ID for assignment of params in View if (foodID != null && qty != null) // New food added { try { // Add food into OrderDetail Table with quantity OrderItem item = new OrderItem(foodID.ToString(), order.PartitionKey, price, (int)qty); TableOperation insertFood = TableOperation.Insert(item); detailTable.ExecuteAsync(insertFood).Wait(); } catch (Exception) { } } else if (foodID != null) { try { // Add food into OrderDetail Table without quantity (default to 1) OrderItem item = new OrderItem(foodID.ToString(), order.PartitionKey, price); TableOperation insertFood = TableOperation.Insert(item); detailTable.ExecuteAsync(insertFood).Wait(); } catch (Exception) { } } // Query All Order Details (Cart Items) from Pending Order TableQuery <OrderItem> detailQuery = new TableQuery <OrderItem>() .Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, order.PartitionKey)); List <OrderItem> orderDetails = new List <OrderItem>(); continuationToken = null; do { TableQuerySegment <OrderItem> queryResults = await detailTable.ExecuteQuerySegmentedAsync(detailQuery, continuationToken); continuationToken = queryResults.ContinuationToken; orderDetails.AddRange(queryResults.Results); } while (continuationToken != null); List <OrderFoodViewModel> foods = new List <OrderFoodViewModel>(); foreach (var d in orderDetails) { var f = _context.Food.Find(int.Parse(d.PartitionKey)); foods.Add(new OrderFoodViewModel { FoodModel = f, OrderItemModel = d }); } return(View(foods)); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [Table("Orders", Connection = "StorageConnection")] CloudTable ordersTable, TraceWriter log) { string fileName = req.Query["fileName"]; if (string.IsNullOrWhiteSpace(fileName)) { return(new BadRequestResult()); } TableQuery <PhotoOrder> query = new TableQuery <PhotoOrder>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, fileName)); TableQuerySegment <PhotoOrder> tableQueryResult = await ordersTable.ExecuteQuerySegmentedAsync(query, null); var resultList = tableQueryResult.Results; if (resultList.Any()) { var firstElement = resultList.First(); return(new JsonResult(new { firstElement.CustomerEmail, firstElement.FileName, firstElement.RequiredHeight, firstElement.RequiredWidth })); } return(new NotFoundResult()); }
public string GetAggregationStats(string ontologyUri = "") { string storageAccountConnectionString = Configuration.GetConnectionString("AzureCloudStorage"); //Utils.GetStorageAccountConnectionString(); CloudStorageAccount account = CloudStorageAccount.Parse(storageAccountConnectionString); // Create the table client. //log.Info("Creating cloud table client"); CloudTableClient tableClient = account.CreateCloudTableClient(); // Create the table if it doesn't exist. //log.Info("Getting table reference"); CloudTable table = tableClient.GetTableReference("stlpstats"); Task tCreate = table.CreateIfNotExistsAsync(); tCreate.Wait(); string combinedFilter = ""; string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "CountByAggregation"); if (ontologyUri != "") { combinedFilter = pkFilter; } else { // Single filter on partition key combinedFilter = pkFilter; } TableQuery <RecordStats> query = new TableQuery <RecordStats>().Where(combinedFilter); RecordStatsJson allStats = new RecordStatsJson(); TableContinuationToken token = null; var runningQuery = new TableQuery <RecordStats>() { FilterString = query.FilterString, SelectColumns = query.SelectColumns }; do { runningQuery.TakeCount = query.TakeCount - allStats.stats.Count; Task <TableQuerySegment <RecordStats> > tSeg = table.ExecuteQuerySegmentedAsync <RecordStats>(runningQuery, token); tSeg.Wait(); token = tSeg.Result.ContinuationToken; allStats.stats.AddRange(tSeg.Result); } while (token != null && (query.TakeCount == null || allStats.stats.Count < query.TakeCount.Value)); //!ct.IsCancellationRequested && // Top 10 order by descending var itemList = from t in allStats.stats orderby t.StatsCount descending select t; allStats.stats = itemList.Take(10).ToList(); string jsonStats = JsonConvert.SerializeObject(allStats); return(jsonStats); }
public List <string> getUrl(string title) { title = Robotom.CleanWord(title); if (searchcache == null || searchcache.Count > 100) { searchcache = new Dictionary <string, Tuple <List <string>, DateTime> >(); } if (searchcache.ContainsKey(title)) { if (searchcache[title].Item2.AddMinutes(30) > DateTime.Now) { return(searchcache[title].Item1); } else { searchcache.Remove(title); } } List <string> returnthis = new List <string>(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.AppSettings["StorageConnectionString"]); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable statsTable = tableClient.GetTableReference("crawltable"); try { var results = new Dictionary <string, int>(); foreach (string word in title.Split(' ')) { TableQuery <UriEntity> query = new TableQuery <UriEntity>() .Where( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, word)); var stuffs = statsTable.ExecuteQuery(query); foreach (UriEntity stuff in stuffs) { string key = stuff.Title + " " + stuff.Site; if (results.ContainsKey(key)) { results[key]++; } else { results.Add(key, 1); } } } returnthis = results.OrderByDescending(x => x.Value).Select(x => x.Key).Take(20).ToList(); } catch (Exception e) { returnthis.Add("Could not access table: " + e.Message); } if (returnthis.Count == 0) { returnthis.Add("Could not find any results..."); } searchcache.Add(title, new Tuple <List <string>, DateTime>(returnthis, DateTime.Now)); return(returnthis); }
/// <summary> ///method to get list of all backends /// </summary> /// <returns>returns list of user backend entities</returns> public List <BackendEntity> GetBackends() { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //generate query to retrive backends TableQuery <BackendEntity> query = new TableQuery <BackendEntity>().Where(TableQuery.GenerateFilterCondition(CoreConstants.AzureTables.PartitionKey, QueryComparisons.Equal, CoreConstants.AzureTables.Backend)); //call dataprovider method to get entities from azure table List <BackendEntity> allBackends = DataProvider.GetEntitiesList <BackendEntity>(CoreConstants.AzureTables.ReferenceData, query); return(allBackends); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error while retrieving all backends from referencedata azure table in DAL : " //+ exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new DataAccessException(); } }
public async Task <HttpResponseMessage> GetList(string code, DateTimeOffset?startTime, DateTimeOffset?endTime, string orchestratorName, HttpRequestMessage request) { var table = _tableClient.GetTableReference($"{_taskHubName}Instances"); if (!await table.ExistsAsync()) { return(request.CreateResponse(HttpStatusCode.NotFound)); } var query = default(TableQuery <InstanceTableEntity>); if (startTime.HasValue && endTime.HasValue) { var start = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, startTime.Value); var end = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, endTime.Value); var where = TableQuery.CombineFilters(start, TableOperators.And, end); if (!string.IsNullOrEmpty(orchestratorName)) { var nameQuery = TableQuery.GenerateFilterCondition("Name", QueryComparisons.Equal, orchestratorName); where = TableQuery.CombineFilters(where, TableOperators.And, nameQuery); } query = new TableQuery <InstanceTableEntity>() .Where(where) ; } else if (startTime.HasValue) { var start = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, startTime.Value); if (!string.IsNullOrEmpty(orchestratorName)) { var nameQuery = TableQuery.GenerateFilterCondition("Name", QueryComparisons.Equal, orchestratorName); start = TableQuery.CombineFilters(start, TableOperators.And, nameQuery); } query = new TableQuery <InstanceTableEntity>().Where(start); } else if (endTime.HasValue) { var end = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, endTime.Value); if (!string.IsNullOrEmpty(orchestratorName)) { var nameQuery = TableQuery.GenerateFilterCondition("Name", QueryComparisons.Equal, orchestratorName); end = TableQuery.CombineFilters(end, TableOperators.And, nameQuery); } query = new TableQuery <InstanceTableEntity>().Where(end); } else { if (!string.IsNullOrEmpty(orchestratorName)) { var nameQuery = TableQuery.GenerateFilterCondition("Name", QueryComparisons.Equal, orchestratorName); query = new TableQuery <InstanceTableEntity>().Where(nameQuery); } else { query = new TableQuery <InstanceTableEntity>(); } } var instances = await table .Query <InstanceTableEntity>(query); var vm = new IndexViewModel() { Code = code, StartTime = startTime?.ToString("yyyy-MM-ddTHH:mm:ss"), EndTime = endTime?.ToString("yyyy-MM-ddTHH:mm:ss"), List = instances.Select(x => new IndexItemViewModel() { InstanceId = x.PartitionKey, CreatedTime = x.CreatedTime, ExecutionId = x.ExecutionId, Input = x.Input, LastUpdatedTime = x.LastUpdatedTime, Name = x.Name, RuntimeStatus = x.RuntimeStatus, Version = x.Version, DetailUrl = GetDetailUrl(x.PartitionKey, request) }).ToList() }; var html = await _razorLightEngine.CompileRenderAsync( "Views.Index.cshtml", vm); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(html, Encoding.UTF8, "text/html") }); }
protected override object Extract() { List <GitHubRepository> ret = new List <GitHubRepository>(); string BuildStorageConnectionString = configManager.GetConfig("BackendJobs", "OPSBuildStorageConnectionString"); HashSet <string> OPGitRepoAccountWhitelist = new HashSet <string>(configManager.GetConfig("BackendJobs", "OPGitRepoAccountWhitelist").Split(';')); var StorageAccount = CloudStorageAccount.Parse(BuildStorageConnectionString); var TableClient = StorageAccount.CreateCloudTableClient(); var repoTable = TableClient.GetTableReference("RepositoryTableEntity"); var userTable = TableClient.GetTableReference("UserTableEntity"); TableQuery <RepositoryTableEntity> query = new TableQuery <RepositoryTableEntity>(); foreach (RepositoryTableEntity repo in repoTable.ExecuteQuery(query)) { TableQuery <UserTableEntity> userQuery = new TableQuery <UserTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, repo.CreatedBy)); UserTableEntity user = userTable.ExecuteQuery(userQuery).FirstOrDefault(); if (user != null) { ret.Add(new GitHubRepository() { Owner = repo.GitRepositoryAccount, RepositoryName = repo.GitRepositoryName, RepositoryUrl = repo.GitRepositoryUrl, AuthToken = user.AccessToken, PartitionKey = repo.PartitionKey, Timestamp = repo.Timestamp.ToString("yyyy-MM-dd"), GitRepositoryType = repo.GitRepositoryType }); } } return(ret); }
public static string GetDashboardQuery(DateTime?requestedDate, List <string> status = null, string email = "", string serviceEngineerEmail = "") { var finalQuery = string.Empty; var statusQueries = new List <string>(); // Add Requested Date Clause if (requestedDate.HasValue) { finalQuery = TableQuery.GenerateFilterConditionForDate("RequestedDate", Constants.GreaterThanOrEqual, requestedDate.Value); } // Add Email clause if email is passed as a parameter if (!string.IsNullOrWhiteSpace(email)) { finalQuery = !string.IsNullOrWhiteSpace(finalQuery) ? TableQuery.CombineFilters(finalQuery, TableOperators.And, TableQuery.GenerateFilterCondition("PartitionKey", Constants.Equal, email)) : TableQuery.GenerateFilterCondition("PartitionKey", Constants.Equal, email); } // Add Service Engineer Email clause if email is passed as a parameter if (!string.IsNullOrWhiteSpace(serviceEngineerEmail)) { finalQuery = !string.IsNullOrWhiteSpace(finalQuery) ? TableQuery.CombineFilters(finalQuery, TableOperators.And, TableQuery.GenerateFilterCondition("ServiceEngineer", Constants.Equal, serviceEngineerEmail)) : TableQuery.GenerateFilterCondition("ServiceEngineer", Constants.Equal, serviceEngineerEmail); } // Add Status clause if status is passed a parameter. // Individual status clauses are appended with OR Condition if (status != null) { foreach (var state in status) { statusQueries.Add(TableQuery.GenerateFilterCondition("Status", Constants.Equal, state)); } var statusQuery = string.Join(string.Format("{0} ", TableOperators.Or), statusQueries); finalQuery = !string.IsNullOrWhiteSpace(finalQuery) ? string.Format("{0} {1} ({2})", finalQuery, TableOperators.And, statusQuery) : string.Format("({0})", statusQuery); } return(finalQuery); }
public List <InvoiceDTO> GetAll() { //cloudTable.Execute(TableOperation.Retrieve, null, null); TableQuery <InvoiceEntity> query = new TableQuery <InvoiceEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "2019")); var invoices = table.ExecuteQuery(query); var invoiceList = invoices.Select(i => new InvoiceDTO { InvoiceID = i.InvoiceID, InvoiceYear = i.InvoiceYear }).ToList(); return(invoiceList); }
public IHttpActionResult Summary([FromODataUri] string formId) { var summary = new ResponseSummary(); TableQuery <TableEntityAdapter <Response> > queryResponses = new TableQuery <TableEntityAdapter <Response> >().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, formId)); var responses = ResponseTable.ExecuteQuery(queryResponses)?.Select(result => result.OriginalEntity); TableQuery <TableEntityAdapter <Choice> > queryChoices = new TableQuery <TableEntityAdapter <Choice> >().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, formId)); var choices = ChoiceTable.ExecuteQuery(queryChoices).Select(result => result.OriginalEntity); if (choices != null && choices.Count() != 0) { foreach (var choice in choices) { TableOperation shopRetrieveOperation = TableOperation.Retrieve <TableEntityAdapter <Shop> >("zgc", choice.ShopId); var shop = ((TableEntityAdapter <Shop>)ShopTable.Execute(shopRetrieveOperation).Result)?.OriginalEntity; var newItem = new ResponseSummaryItem() { ShopTitle = shop?.ShopTitle, Count = 0, ResponderAvatarUrls = new List <string>() }; var choiceResponses = responses.Where(res => res.ChoiceId == choice.Id); newItem.Count = choiceResponses.Count(); foreach (var response in choiceResponses) { TableOperation userRetrieveOperation = TableOperation.Retrieve <TableEntityAdapter <User> >("User", response.ResponderId); var user = ((TableEntityAdapter <User>)UserTable.Execute(userRetrieveOperation).Result)?.OriginalEntity; newItem.ResponderAvatarUrls.Add(user?.AvatarUrl ?? string.Empty); } summary.Items.Add(newItem); } summary.WinnerTitle = summary.Items.Count() != 0 ? summary.Items.OrderByDescending(item => item.Count).First()?.ShopTitle : string.Empty; summary.Total = summary.Items.Count() != 0 ? summary.Items.Sum(item => item.Count) : 0; } return(Ok(summary)); }
public void DeleteThisWeek() { var mondayPartitionKey = DateHelper.MondayThisWeek().ToString("yyyyMMdd"); DeleteAllEntitiesInBatches(_dishTable, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, mondayPartitionKey)); }
public IHttpActionResult Get([FromODataUri] string formId) { // Create a retrieve operation that takes a customer entity. TableOperation retrieveOperation = TableOperation.Retrieve <TableEntityAdapter <Form> >("test", formId); // Execute the retrieve operation. TableResult retrievedResult = FormTable.Execute(retrieveOperation); if (retrievedResult?.Result == null) { return(NotFound()); } var form = ((TableEntityAdapter <Form>)retrievedResult.Result).OriginalEntity; TableQuery <TableEntityAdapter <Question> > queryQuestions = new TableQuery <TableEntityAdapter <Question> >().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, formId)); var questions = QuestionTable.ExecuteQuery(queryQuestions).Select(result => result.OriginalEntity); if (questions != null) { TableQuery <TableEntityAdapter <Choice> > queryChoices = new TableQuery <TableEntityAdapter <Choice> >().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, formId)); var choices = ChoiceTable.ExecuteQuery(queryChoices).Select(result => result.OriginalEntity); foreach (var question in questions) { question.Choices = choices?.Where(choice => choice.QuestionId == question.Id).ToList(); foreach (var choice in question.Choices) { TableOperation shopRetrieveOperation = TableOperation.Retrieve <TableEntityAdapter <Shop> >("zgc", choice.ShopId); choice.Shop = ((TableEntityAdapter <Shop>)ShopTable.Execute(shopRetrieveOperation).Result)?.OriginalEntity; } form.Questions.Add(question); } } return(Ok(form)); }
/// <summary> /// Read all entries in one partition of the storage table. /// NOTE: This could be an expensive and slow operation for large table partitions! /// </summary> /// <param name="partitionKey">The key for the partition to be searched.</param> /// <returns>Enumeration of all entries in the specified table partition.</returns> public Task <IEnumerable <Tuple <T, string> > > ReadAllTableEntriesForPartitionAsync(string partitionKey) { string query = TableQuery.GenerateFilterCondition(nameof(ITableEntity.PartitionKey), QueryComparisons.Equal, partitionKey); return(ReadTableEntriesAndEtagsAsync(query)); }
public async Task Should_return_expected_entities() { // Arrange await _myTestModelRepository.InsertOrReplaceAsync(new MyTestModel { PartitionKey = "ReadAsyncPartition", RowKey = "ReadAsyncRow1", Name = "My Name 1" }); await _myTestModelRepository.InsertOrReplaceAsync(new MyTestModel { PartitionKey = "ReadAsyncPartition", RowKey = "ReadAsyncRow2", Name = "My Name 2" }); await _myTestModelRepository.InsertOrReplaceAsync(new MyTestModel { PartitionKey = "ReadAsyncPartition", RowKey = "ReadAsyncRow3", Name = "Some other name structure" }); await _myTestModelRepository.InsertOrReplaceAsync(new MyTestModel { PartitionKey = "AnotherPartition", RowKey = "ReadAsyncRow4", Name = "My Name 3" }); // Act var result = await sut.ReadAsync(query => { var projectFilter = TableQuery.GenerateFilterCondition( nameof(MyTestModel.PartitionKey), QueryComparisons.Equal, "ReadAsyncPartition" ); var nameFilter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition( nameof(MyTestModel.Name), QueryComparisons.GreaterThanOrEqual, "My Name" ), TableOperators.And, TableQuery.GenerateFilterCondition( nameof(MyTestModel.Name), QueryComparisons.LessThan, "My Namf" ) ); var combinedFilters = TableQuery.CombineFilters( projectFilter, TableOperators.And, nameFilter ); return(query.Where(combinedFilters)); }); // Assert Assert.NotNull(result); Assert.Collection(result.OrderBy(x => x.Name), model => Assert.Equal("My Name 1", model.Name), model => Assert.Equal("My Name 2", model.Name) ); }
/// <summary> /// Builds query string to match partitionkey /// </summary> /// <param name="partitionKey"></param> /// <returns></returns> public static string MatchPartitionKeyFilter(string partitionKey) { return(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey)); }
private List <SentenceStatsEntity> GetSentenceStatsForSystem(SystemFilter oFilter) { List <SentenceStatsEntity> systemSentences = new List <SentenceStatsEntity>(); CloudTable tRecordAssociationKeyphrases = Utils.GetCloudTable("stlpsystems", _logger); // Create a default query TableQuery <SentenceStatsEntity> query = new TableQuery <SentenceStatsEntity>(); string systemFilter = ""; // Add any record association filters if (oFilter.systems.Count > 0) { foreach (string sif in oFilter.systems) { if (sif != null && sif != "") { // Validate the record filter string cleanFilterPKey = Utils.CleanTableKey(sif); if (cleanFilterPKey.EndsWith("|")) { cleanFilterPKey = cleanFilterPKey + "|"; } string pkquery = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, cleanFilterPKey); if (systemFilter != "") { systemFilter = TableQuery.CombineFilters(systemFilter, TableOperators.Or, pkquery); } else { systemFilter = pkquery; } } } } // Create final combined query query = new TableQuery <SentenceStatsEntity>().Where(systemFilter); TableContinuationToken token = null; var runningQuery = new TableQuery <SentenceStatsEntity>() { FilterString = query.FilterString, SelectColumns = query.SelectColumns }; do { runningQuery.TakeCount = query.TakeCount - systemSentences.Count; Task <TableQuerySegment <SentenceStatsEntity> > tSeg = tRecordAssociationKeyphrases.ExecuteQuerySegmentedAsync <SentenceStatsEntity>(runningQuery, token); tSeg.Wait(); token = tSeg.Result.ContinuationToken; systemSentences.AddRange(tSeg.Result); } while (token != null && (query.TakeCount == null || systemSentences.Count < query.TakeCount.Value) && systemSentences.Count < 20000); //!ct.IsCancellationRequested && return(systemSentences); }
/// <summary> /// Builds query string to match rowkey /// </summary> /// <param name="rowKey"></param> /// <returns></returns> public static string MatchRowKeyFilter(string rowKey) { return(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); }
public async Task <IEnumerable <LogData> > GetAllLogs() { TableQuery <LogData> query = new TableQuery <LogData>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.NotEqual, "###")); TableQuerySegment <LogData> resultSegment = await _table.ExecuteQuerySegmentedAsync(query, null); return(resultSegment.Results.OrderByDescending(d => d.Timestamp)); }
static TableQuery PartitionKeyQuery(string partitionKey) => new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));