Пример #1
0
        protected IEnumerable <T> Query(string partitionKey)
        {
            var query = table.CreateQuery <T>()
                        .Where(e => e.PartitionKey == partitionKey)
                        .AsTableQuery();

            IEnumerator <T> enumerator;

            try
            {
                enumerator = query.Execute().GetEnumerator();

                if (!enumerator.MoveNext())
                {
                    yield break;
                }
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404)
                {
                    yield break;
                }

                throw;
            }

            yield return(enumerator.Current);

            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }
        }
 public List<WindGeneratorBase> GetAllWindGenerators()
 {
     IQueryable<WindGeneratorBase> requests = from g in _table.CreateQuery<WindGeneratorBase>()
                                              where g.PartitionKey == "WindGenerator"
                                              select g;
     return requests.ToList();
 }
Пример #3
0
        /// <summary>
        /// Returns a page of errors from the database in descending order
        /// of logged time.
        /// </summary>

        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }
            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            // Skip is not allowed, so we will take extra records and then discard ones that weren't requested.
            // This obviously has a performance hit, but since users are usually looking at the latest ones, this may be OK for most scenarios.
            var partitionKey = AzureHelper.EncodeAzureKey(ApplicationName);
            var tableQuery   = _cloudTable.CreateQuery <ElmahEntity>()
                               .Where(e => e.PartitionKey == partitionKey)
                               .Take((pageIndex + 1) * pageSize);

            var errorEntities = _cloudTable
                                .ExecuteQuery(tableQuery as TableQuery <ElmahEntity>)
                                .Skip(pageIndex * pageSize);

            foreach (var errorEntity in errorEntities)
            {
                var error = ErrorXml.DecodeString(errorEntity.AllXml);
                errorEntryList.Add(new ErrorLogEntry(this, errorEntity.RowKey, error));
            }

            // Azure Table Storage cannot return the total number of records,
            // so if the max number of errors are displayed,
            // we will report an extra element to indicate to the user that more records may exist
            return(errorEntryList.Count == pageSize
                ? (pageIndex + 1) * pageSize + 1
                : pageIndex *pageSize + errorEntryList.Count);
        }
Пример #4
0
        public IEnumerable <IStudent> GetStudents()
        {
            var query = from i in resourceTable.CreateQuery <StudentEntity>()
                        where i.PartitionKey == StudentEntity.EntityKey
                        select i.ToStudent();

            return(query.ToList());
        }
Пример #5
0
        public List <Bank> GetAllBanks()
        {
            IQueryable <Bank> requests = from g in _tableBank.CreateQuery <Bank>()
                                         where g.PartitionKey == "Bank"
                                         select g;

            return(requests.ToList());
        }
Пример #6
0
        public List <Bookstore> GetAllBookstores()
        {
            IQueryable <Bookstore> requests = from g in _tableBookstore.CreateQuery <Bookstore>()
                                              where g.PartitionKey == "Bookstore"
                                              select g;

            return(requests.ToList());
        }
Пример #7
0
        public List <Film> GetAllFilms()
        {
            IQueryable <Film> requests = from g in table.CreateQuery <Film>()
                                         where g.PartitionKey == "Film"
                                         select g;

            return(requests.ToList());
        }
Пример #8
0
        public IQueryable <Student> RetrieveAllStudents()
        {
            var results = from g in _table.CreateQuery <Student>()
                          where g.PartitionKey == "Student"
                          select g;

            return(results);
        }
        public List <WeatherBase> GetAllWeathers()
        {
            IQueryable <WeatherBase> requests = from g in _table.CreateQuery <WeatherBase>()
                                                where g.PartitionKey == "Weather"
                                                select g;

            return(requests.ToList());
        }
Пример #10
0
        public List <RequestCountInfo> GetAllRequest()
        {
            IQueryable <RequestCountInfo> requests = from g in _table.CreateQuery <RequestCountInfo>()
                                                     where g.PartitionKey == "Request"
                                                     select g;

            return(requests.ToList());
        }
Пример #11
0
        public List <Student> GetAllStudents()
        {
            IQueryable <Student> requests = from g in _table.CreateQuery <Student>()
                                            where g.PartitionKey == "Student"
                                            select g;

            return(requests.ToList());
        }
        public List <AggregateBase> GetAllAggregates()
        {
            IQueryable <AggregateBase> requests = from g in _table.CreateQuery <AggregateBase>()
                                                  where g.PartitionKey == "Aggregate"
                                                  select g;

            return(requests.ToList());
        }
Пример #13
0
        public IQueryable <Subject> ReadAllSubjects()
        {
            var results = from g in _table.CreateQuery <Subject>()
                          where g.PartitionKey == "Subject"
                          select g;

            return(results);
        }
Пример #14
0
        public IEnumerable <IStudent> GetStudentsInCourse(ICourse course)
        {
            var query = from s in mapTable.CreateQuery <JoinEntity>()
                        where s.PartitionKey == course.LinkKey()
                        select s;


            return(query.ToList().Select(s => GetStudent(s.RowKey)));
        }
Пример #15
0
        public async Task <IEnumerable <TViewModel> > GetAllAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var query    = _table.CreateQuery <TEntity>();
            var entities = await query.ExecuteQueryAsync(cancellationToken);

            return(_mapper.Map <IEnumerable <TEntity>, IEnumerable <TViewModel> >(entities));
        }
Пример #16
0
        static void Select()
        {
            TableQuery <ProductTesting> tableQuery = table.CreateQuery <ProductTesting>();
            //IQueryable<ProductTesting> pts = from productTesting in tableQuery select productTesting;
            IQueryable <ProductTesting> pts = from productTesting in tableQuery.Where <ProductTesting>(x => x.Result == "Pass") select productTesting;
            ProductTesting pt = pts.First <ProductTesting>();

            Console.WriteLine(HttpUtility.UrlDecode(pt.TestDate) + "," + pt.ProductSn + "," + pt.Result);
        }
Пример #17
0
        public static void BadQuery()
        {
            var badQuery   = table.CreateQuery <Transaction>().Take(10);
            var properties = table.ExecuteQuery(badQuery).ToArray();

            foreach (var prop in properties)
            {
                PrintTransaction(prop);
            }
        }
        /// <summary>
        /// Read data entries and their corresponding eTags from the Azure table.
        /// </summary>
        /// <param name="predicate">Predicate function to use for querying the table and filtering the results.</param>
        /// <returns>Enumeration of entries in the table which match the query condition.</returns>
        public async Task <IEnumerable <Tuple <T, string> > > ReadTableEntriesAndEtagsAsync(Expression <Func <T, bool> > predicate)
        {
            const string operation = "ReadTableEntriesAndEtags";
            var          startTime = DateTime.UtcNow;

            try
            {
                TableQuery <T> cloudTableQuery = predicate == null
                    ? tableReference.CreateQuery <T>()
                    : tableReference.CreateQuery <T>().Where(predicate).AsTableQuery();

                try
                {
                    Func <Task <List <T> > > executeQueryHandleContinuations = async() =>
                    {
                        TableQuerySegment <T> querySegment = null;
                        var list = new List <T>();
                        while (querySegment == null || querySegment.ContinuationToken != null)
                        {
                            querySegment = await cloudTableQuery.ExecuteSegmentedAsync(querySegment?.ContinuationToken);

                            list.AddRange(querySegment);
                        }

                        return(list);
                    };

                    IBackoffProvider backoff = new FixedBackoff(AzureTableDefaultPolicies.PauseBetweenTableOperationRetries);

                    List <T> results = await AsyncExecutorWithRetries.ExecuteWithRetries(
                        counter => executeQueryHandleContinuations(),
                        AzureTableDefaultPolicies.MaxTableOperationRetries,
                        (exc, counter) => AzureStorageUtils.AnalyzeReadException(exc.GetBaseException(), counter, TableName, Logger),
                        AzureTableDefaultPolicies.TableOperationTimeout,
                        backoff);

                    // Data was read successfully if we got to here
                    return(results.Select(i => Tuple.Create(i, i.ETag)).ToList());
                }
                catch (Exception exc)
                {
                    // Out of retries...
                    var errorMsg = $"Failed to read Azure storage table {TableName}: {exc.Message}";
                    if (!AzureStorageUtils.TableStorageDataNotFound(exc))
                    {
                        Logger.Warn(ErrorCode.AzureTable_09, errorMsg, exc);
                    }
                    throw new OrleansException(errorMsg, exc);
                }
            }
            finally
            {
                CheckAlertSlowAccess(startTime, operation);
            }
        }
Пример #19
0
 public IQueryable <TEntity> QueryAsync(Expression <Func <TEntity, bool> > expression)
 {
     try
     {
         return(_cloudTable.CreateQuery <TEntity>().Where(expression).AsQueryable());
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Пример #20
0
 public IQueryable <T> GetQuery()
 {
     try
     {
         return(_table.CreateQuery <T>().OrderByDesc(nameof(TableEntity.RowKey)));
     }
     catch (StorageException)
     {
         throw;
     }
 }
Пример #21
0
        public int GetAvailableSeats(string conferenceId)
        {
            var linqQuery = _eventProjectionsTable.CreateQuery <EventProjectionsEntity>()
                            .Where(x => x.PartitionKey == "Conference" && x.RowKey == conferenceId)
                            .Select(x => x.Payload)
                            .SingleOrDefault();

            var response = JsonConvert.DeserializeObject <ConferenceDataModel>(linqQuery);

            return(response.Seats);
        }
Пример #22
0
 public async Task <IList <T> > GetAllAsync()
 {
     try
     {
         return(_table.CreateQuery <T>().Where(x => x.PartitionKey == EntityBase.GlobalPartitionKey).ToArray());
     }
     catch (StorageException e)
     {
         _log.LogError(e, $"Unable to access data in table '{_table.Name}'");
         throw;
     }
 }
Пример #23
0
        // GET api/values
        public IEnumerable <UserEntity> Get()
        {
            InitializeTable();
            var query = (from user in Table.CreateQuery <UserEntity>()
                         select user).Take(100);
            var users = query.ToList();

            return(users.Select(x => new UserEntity()
            {
                Username = x.Username
            }));
        }
Пример #24
0
        public async Task <long> GetCurrentCountAsync(string counter)
        {
            var incOp = _table.CreateQuery <CounterOperation>()
                        .Where(x => x.PartitionKey == PartitionKeyFor(counter, IncrementKey))
                        .AsTableQuery();
            var decOp = _table.CreateQuery <CounterOperation>()
                        .Where(x => x.PartitionKey == PartitionKeyFor(counter, DecrementKey))
                        .AsTableQuery();
            var counts = await Task.WhenAll(CountAsync(incOp), CountAsync(decOp))
                         .ContinueOnExecutionContext();

            return(counts[0] - counts[1]);
        }
        public IActionResult GetCollection(string userId)
        {
            HttpContext.VerifyUserHasAnyAcceptedScope(new string[] { "demo.write" });

            /* Validate Post */
            if (userId == null)
            {
                return(BadRequest());
            }

            var tableQueryResult = table.CreateQuery <CollectedFilm>().Where(row => row.PartitionKey == userId);

            return(Ok(tableQueryResult));
        }
Пример #26
0
 public EvidenceEntity RetriveSingleEvidence(String rowKey)
 {
     try
     {
         var results = from g in table.CreateQuery <EvidenceEntity>()
                       where g.PartitionKey.Equals("Evidence") && g.RowKey.Equals(rowKey)
                       select g;
         return(results.First());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #27
0
        /// <summary>
        /// Note: This method should not be used implemented that way in a productive application
        /// </summary>
        public async Task <IList <T> > GetAllAsync()
        {
            await Task.Yield();

            try
            {
                return(_table.CreateQuery <T>().ToArray());
            }
            catch (StorageException e)
            {
                _log.LogError(e, $"Unable to access data in table '{_table.Name}'");
                throw;
            }
        }
Пример #28
0
        /// <summary>
        /// This method connects to table storage and queries for all the workspace/dataset combinations that are scheduled to
        /// refresh at the current timeslot.  This can run in one of two ways depending on the config setting of ignoreHour.
        ///
        /// If ignoreHour = True then the scehduler assumes that every entry defines the minute you want the refresh to kickoff
        /// and will do this every hour, and will consequently not filter the Azure Table on hour only on minute.  If you need
        /// multiple refreshes in a given hour you will need one row for each timeslot you want to refresh within the hour.
        /// Therefore if you want a dataset to refresh twice an hour you need two entries and ignoreHour set to true.
        ///
        /// If ignoreHoure = False then the scheduler will filter the AzureTable for both hour and minute.  This enables scenarios
        /// where you need refresh schedules that don't align to hour boundaries like every 90 minutes, every 2 hours, etc.  For
        /// this approach, you will need one row in the table for each time you want the refresh to run.
        /// </summary>
        /// <param name="hour">The current hour to query for in 00 format.</param>
        /// <param name="minute">The current minute to query for in 00 format.</param>
        /// <param name="log">The logwriter for telemetry</param>
        /// <returns>A list of ScheduleItems retreived form table storage.</returns>
        private static List <ScheduleItem> GetDatasets(string hour, string minute, TraceWriter log)
        {
            List <ScheduleItem> datasets = new List <ScheduleItem>();


            // Retrieve storage account information from connection string.
            string storageConnectionString = ConfigurationManager.AppSettings["TableConnectionString"];
            bool   ignoreHour = ConfigurationManager.AppSettings["ignoreHour"] == "True" ? true : false;

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

            // Create a table client for interacting with the table service
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("RefreshSchedule");

            try
            {
                //Get all the scheduled dataset refreshes for the current minute and hour combination.
                IEnumerable <ScheduleItem> query;
                if (ignoreHour)
                {
                    //For scenarios where you want to run at the same time every hour.
                    query = from scheduleItem in table.CreateQuery <ScheduleItem>()
                            where scheduleItem.minute == minute
                            select scheduleItem;
                }
                else
                {
                    //For scenarios where the schedules are not hourly (ie. every 90 minutes, every two hours etc).
                    query = from scheduleItem in table.CreateQuery <ScheduleItem>()
                            where scheduleItem.minute == minute &&
                            scheduleItem.hour == hour
                            select scheduleItem;
                }

                //Build result list for the query.
                foreach (ScheduleItem scheduleItem in query)
                {
                    datasets.Add(scheduleItem);
                }

                //log progress
                log.Info($"Retreived {datasets.Count} records to process from RequestSchedule using hour:{hour} and minute:{minute}");
            }
            catch (Exception e) {
                log.Warning($"Failed quering azure table. {e.InnerException.ToString()}");
            }

            return(datasets);
        }
Пример #29
0
        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable cloudTable = tableClient.GetTableReference("Tourists");

            cloudTable.ExecuteBatch(new TableBatchOperation()
            {
                TableOperation.InsertOrReplace(new TouristEntity("New York", "1")
                {
                    Custumer = "Watson",
                    Details  = "skyskrapers"
                }),

                TableOperation.InsertOrReplace(new TouristEntity("New York", "3")
                {
                    Custumer = "Gregson",
                    Details  = "police  office"
                })
            });



            List <TouristEntity> listReviewsByPoint = cloudTable.CreateQuery <TouristEntity>()
                                                      .Where(x => x.PartitionKey == "New York").ToList();



            List <TouristEntity> listReviewsByCustumer = cloudTable.CreateQuery <TouristEntity>()
                                                         .Where(x => x.PartitionKey == "Manchester" && x.Custumer == "Bob").ToList();

            List <TouristEntity> listDetailsOfOneRewiew = cloudTable.CreateQuery <TouristEntity>()
                                                          .Where(x => x.PartitionKey == "London" && x.RowKey == "0").ToList();



            foreach (var t in listReviewsByPoint)
            {
                Console.WriteLine(t.Custumer);
            }



            Console.WriteLine("Completed");
            Console.ReadLine();
        }
Пример #30
0
 public static IQueryable <QueueTicket> BuildQueueTicketsQuery(
     this CloudTable table, string stateType, Guid streamId)
 {
     return(from t in table.CreateQuery <QueueTicket>()
            where t.PartitionKey == $"~{stateType}:{streamId}"
            select t);
 }