private IEnumerable <mwc.Incumbent> GetIncumbentsFromTable(string tableName, string partitionKey, IncumbentType incumbentType) { // Todo: this is a temporary method provided until the backend supports retriving incumbents of type "tv_us" Microsoft.WhiteSpaces.AzureTableAccess.AzureTableOperation azureTableOperations = new Microsoft.WhiteSpaces.AzureTableAccess.AzureTableOperation(); string tableQuery = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); if (incumbentType != IncumbentType.None) { tableQuery = TableQuery.CombineFilters(tableQuery, TableOperators.And, TableQuery.GenerateFilterConditionForInt("Type", QueryComparisons.Equal, (int)incumbentType)); } IEnumerable <mwc.Incumbent> tvEngDataList = azureTableOperations.GetAllEntities <CDBSTvEngData>(tableName, tableQuery) .Select(cdbsTvEndData => { List <Position> contourPoints = WhitespacesManager.GetContourPointsSpaceSeperator(cdbsTvEndData.Contour); mwc.Incumbent incumbent = new mwc.Incumbent( cdbsTvEndData.CallSign, cdbsTvEndData.Channel, contourPoints, null, incumbentType, null, new Location(cdbsTvEndData.Latitude, cdbsTvEndData.Longitude)); return(incumbent); }); return(tvEngDataList); }
/// <summary> /// Gets all the incumbents based on either channel numbers or position (if channels value is not null, then it will /// retrieve based on Channel number; otherwise it will retrieve incumbents based on location). /// </summary> /// <param name="channels">Retrieves incumbents that match the specified channels (if null, then it will use the latitude and longitude field)</param> /// <param name="incumbentType">Retrieves incumbents that match the specified type</param> /// <param name="latitude">Retrieves incumbents that are near the specified latitude (only used if channels parameter is null).</param> /// <param name="longitude">Retrieves incumbents that are near the specified longitude (only used if channels parameter is null).</param> /// <returns>List of incumbents that match the passed in parameters</returns> private List <mwc.Incumbent> GetIncumbentsFromTable(IEnumerable <int> channels, IncumbentType incumbentType = IncumbentType.None, double latitude = 0, double longitude = 0) { // Todo: this is a temporary method provided until the back-end supports retrieving incumbents of type "tv_us" Microsoft.WhiteSpaces.AzureTableAccess.AzureTableOperation azureTableOperations = new Microsoft.WhiteSpaces.AzureTableAccess.AzureTableOperation(); List <mwc.Incumbent> incumbents = new List <mwc.Incumbent>(); if (channels == null) { // Just get the TV Towers that are located around the specified latitude or longitude. string partitionKey = string.Format("RGN1-Lat{0}Long{1}", (int)latitude, (int)longitude); IEnumerable <mwc.Incumbent> tvEngDataList = this.GetIncumbentsFromTable("PortalSummary", partitionKey, incumbentType); incumbents.AddRange(tvEngDataList); } else { // Get all incumbents associated with the specified channels. // NB: Creating multiple queries and executing them in parallel will get the results faster, rather scanning through entire table. // For more reference refer http://msdn.microsoft.com/en-us/magazine/ff796231.aspx try { Parallel.ForEach <int>( channels, channel => { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); System.Diagnostics.Trace.TraceError(string.Format("***PERF: Retrieving {0} channel elements", channel)); int elementsCount = 0; IEnumerable <mwc.Incumbent> tvEngDataList = GetIncumbentsFromTable("PortalContours", "RGN1-" + channel, incumbentType); if (tvEngDataList != null) { lock (lockObject) { elementsCount = incumbents.Count; incumbents.AddRange(tvEngDataList); elementsCount = incumbents.Count - elementsCount; } } watch.Stop(); System.Diagnostics.Trace.TraceError(string.Format("***PERF: Retrieved {0} elements in {1} seconds ({2})", tvEngDataList != null ? elementsCount : 0, watch.Elapsed.ToString(), channel)); }); } catch (AggregateException) { throw; } } return(incumbents); }