//public QuoteRec Post([FromBody] QuoteRec submittedQuote) //{ // System.Diagnostics.Debug.WriteLine(submittedQuote.ToString()); // QuoteRec qr = submittedQuote; // AddQuote(qr); // return qr; //} // public List<QuoteRec> Post([FromBody] string RowKey, [FromBody] bool VoteUp) public List <QuoteRec> Post(string RowKey, bool VoteUp) { List <QuoteRec> QuoteRecs = QuoteDB.GetQuoteList(); QuoteRec qr = QuoteRecs.Find(q => q.RowKey == RowKey); if (qr == null) { return(ReturnNotFound()); } if (VoteUp) { qr.VoteUp++; } else { qr.VoteDown++; } List <QuoteRec> quoterecs = new List <QuoteRec>() { qr }; // WIP update Table Store data, and to be really cool, update it in the background after returning to the browser return(quoterecs); }
public QuoteRecord Post([FromBody] QuoteRec submittedQuote) { System.Diagnostics.Debug.WriteLine(submittedQuote.ToString()); QuoteRecord qr = new QuoteRecord { Author = submittedQuote.Author, Quote = submittedQuote.Quote }; AddQuote(qr); return(qr); }
public List <QuoteRec> Get() { List <QuoteRec> returned = new List <QuoteRec>(); List <QuoteRec> QuoteRecs = QuoteDB.GetQuoteList(); QuoteRec qr = QuoteRecs[random.Next(0, QuoteRecs.Count)]; returned.Add(qr); return(returned); }
private static void AddQuote(QuoteRec qr) { string NewQuote = qr.Quote + "--" + qr.Author; // WIP lock this access from multiple users var app = HttpContext.Current.Application; List <string> Quotes = (List <string>)app["AppQuotes"]; Quotes.Add(NewQuote); app["AppQuotes"] = Quotes; string QuoteFile = HttpContext.Current.Server.MapPath("~/App_Data/sig.dat"); // WIP save the file }
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); }
private List <QuoteRec> GetRecordsFromDatabase( ) { List <QuoteRec> results = new List <QuoteRec>(); CloudTable tableReference = QuoteDB.GetQuotesTableReference(); TableQuery <QuoteTableEntity> query = new TableQuery <QuoteTableEntity>(); foreach (QuoteTableEntity qte in tableReference.ExecuteQuery(query)) { QuoteRec qr = qte.ExtractQuoteRecord(); qr.Reference = qr.Reference ?? ""; qr.Email = qr.Email ?? ""; results.Add(qr); } return(results); }
private void LoadFullQuotesFromDatabase() { try { List <QuoteRec> quoteRecs = new List <QuoteRec> { new QuoteRec { Author = "DB", Quote = "loading data " } }; Application["QuoteDBDataCache"] = quoteRecs; var qtr = QuoteDB.GetQuotesTableReference(); // Construct the query operation for all entities TableQuery <QuoteTableEntity> query = new TableQuery <QuoteTableEntity>(); // note: WIP: might need to do this , like this: TableQuery<QuoteTableEntity> query = new TableQuery<QuoteTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith")); var results = qtr.ExecuteQuery(query); List <QuoteTableEntity> quoteTableEntitiess = results.ToList(); quoteRecs = new List <QuoteRec>(); foreach (QuoteTableEntity qte in quoteTableEntitiess) { QuoteRec qr = qte.ExtractQuoteRecord(); quoteRecs.Add(qr); } Application["QuoteDBDataCache"] = quoteRecs; } catch (Microsoft.WindowsAzure.Storage.StorageException ex) { new LogException(ex); List <QuoteRec> quoteRecs = new List <QuoteRec> { new QuoteRec { Author = "DB", Quote = "Database error loading data" } }; Application["QuoteDBDataCache"] = quoteRecs; } catch (Exception ex) { new LogException(ex, true); } finally { } }
public HttpResponseMessage Put(QuoteRec submittedQuote) { var rsp = "Failed"; var code = HttpStatusCode.InternalServerError; try { RecreateTableStorage(); rsp = "Worked"; code = HttpStatusCode.OK; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); rsp = ex.ToString(); } return(Request.CreateResponse(code, rsp)); }
private List <QuoteRec> GetRecordsFromDatabase(string filter) { List <QuoteRec> results = new List <QuoteRec>(); CloudTable tableReference = QuoteDB.GetQuotesTableReference(); // WIP this is poor performance cause it pulls all data from Table Space before it checks for contents // WIP this is poor performance cause it pulls all data from Table Space before it checks for contents // WIP this is poor performance cause it pulls all data from Table Space before it checks for contents TableQuery <QuoteTableEntity> query = new TableQuery <QuoteTableEntity>(); filter = filter.ToLower(); foreach (QuoteTableEntity qte in tableReference.ExecuteQuery(query)) { if (qte.ActualQuoteRec.ToLower().Contains(filter)) { QuoteRec qr = qte.ExtractQuoteRecord(); results.Add(qr); } } // WIP next attempt, review how to get context and reference table // http://msdn.microsoft.com/en-us/library/azure/dd894039.aspx // //// WIP: this returns 501 Not Supported from Azure //TableQuery<QuoteTableEntity> tq = tableReference.CreateQuery<QuoteTableEntity>(); //var selected = tq.Where( d=>d.ActualQuoteRec.Contains(filter)); //foreach (var qtr in selected) //{ // results.Add( (QuoteRec)qtr.ExtractQuoteRecord()); //} return(results); }
public HttpResponseMessage Post(QuoteRec submittedQuote) { var rsp = "WIP: Not Implemented Yet"; return Request.CreateResponse(HttpStatusCode.InternalServerError, rsp); }
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; }
public HttpResponseMessage Put(QuoteRec submittedQuote) { var rsp = "Failed"; var code = HttpStatusCode.InternalServerError; try { RecreateTableStorage(); rsp = "Worked"; code = HttpStatusCode.OK; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); rsp = ex.ToString(); } return Request.CreateResponse(code, rsp); }
private static void AddQuote(QuoteRec qr) { string NewQuote = qr.Quote + "--" + qr.Author; // WIP lock this access from multiple users var app = HttpContext.Current.Application; List<string> Quotes = (List<string>)app["AppQuotes"]; Quotes.Add(NewQuote); app["AppQuotes"] = Quotes; string QuoteFile = HttpContext.Current.Server.MapPath("~/App_Data/sig.dat"); // WIP save the file }
public void StoreQuoteRecord(QuoteRec q) { this.ActualQuoteRec = JsonConvert.SerializeObject(q); }
public HttpResponseMessage Post(QuoteRec submittedQuote) { var rsp = "WIP: Not Implemented Yet"; return(Request.CreateResponse(HttpStatusCode.InternalServerError, rsp)); }