private bool AddQuotesToNewTable()
        {
            bool Worked = false;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            try
            {
                CloudTable tableReference = QuoteDB.GetQuotesTableReference();

                //
                // this process of adding batchs of 90 came from an error
                // when I created all 220 entries in one batch
                // error received: "Unexpected response code for operation : 99"
                // solution option: http://stackoverflow.com/questions/18170920/azure-table-storage-error-unexpected-response-code-for-operation-99
                //

                var quoteList = BasicQuotes.GetQuoteList();
                int CntQuote  = 0;
                foreach (var chunk in quoteList.Chunk(90))
                {
                    TableBatchOperation batchOperation = new TableBatchOperation();

                    foreach (var quote in chunk)
                    {
                        var      thisQuote = BasicQuotes.BuildQuote(quote);
                        QuoteRec q         = new QuoteRec {
                            Author = thisQuote.Author, Quote = thisQuote.Quote, ModeratorApproved = true, QuoteSubmitter = Guid.Empty
                        };
                        QuoteTableEntity qte = new QuoteTableEntity {
                            PartitionKey = "quoter", RowKey = Guid.NewGuid().ToString("N"), idxQuoteAsLoaded = ++CntQuote
                        };
                        qte.StoreQuoteRecord(q);
                        batchOperation.Insert(qte);
                    }
                    tableReference.ExecuteBatch(batchOperation);
                }
                Worked = true;
            }
            catch (Exception ex)
            {
                new LogException(ex);
            }
            finally
            {
                sw.Stop();
                System.Diagnostics.Debug.WriteLine(">>>> Table Load times:" + sw.Elapsed.ToString());
            }
            return(Worked);
        }
Exemplo n.º 2
0
        public List <QuoteRecord> Get()
        {
            List <QuoteRecord> returned = new List <QuoteRecord>();
            List <string>      Quotes   = BasicQuotes.GetQuoteList();

            if (Quotes == null)
            {
                return(ReturnNotFound());
            }

            int Idx = random.Next(0, Quotes.Count);

            QuoteRecord qr = BasicQuotes.BuildQuote(Quotes[Idx]);

            returned.Add(qr);

            return(returned);
        }
Exemplo n.º 3
0
        public List <QuoteRecord> Get(string id, int maxToReturn)
        {
            if (id == null || id == "")
            {
                id = " ";
            }
            List <string>      Quotes   = BasicQuotes.GetQuoteList();
            List <QuoteRecord> returned = new List <QuoteRecord>();

            if (Quotes == null)
            {
                return(ReturnNotFound());
            }

            var results = Quotes.Where(q => q.IndexOf(id, StringComparison.CurrentCultureIgnoreCase) > 0).OrderBy(r => Guid.NewGuid()).Take(maxToReturn);

            foreach (var q in results)
            {
                QuoteRecord qr = BasicQuotes.BuildQuote(q);
                returned.Add(qr);
            }

            return(returned);
        }