public FullItem RetrieveForProcessing() { FullItem rawItem = null; var item = _queue.Dequeue(); if (item != null) { rawItem = new FullItem(item); rawItem.File = _rawBlob.Retrieve(item.ResourceId); } return rawItem; }
//purposefully slow processing method w/ less than ideal memory usage to simulate real work public FullItem ProcessItem(FullItem rawItem) { string originalData = new UTF8Encoding().GetString(rawItem.File); string[] dataRows = originalData.Split('\n'); List<string> result = new List<string>(); foreach (string s in dataRows) { string s2 = s; foreach (char c in s.ToCharArray()) { s2 = s2.Replace(c.ToString(), c.ToString().ToUpper()); } result.Add(s2); } rawItem.MarkAsProcessed(); rawItem.File = new UTF8Encoding().GetBytes(String.Join("\n", result)); return rawItem; }
public ActionResult AddFile(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var item = new FullItem() { ResourceId = Guid.NewGuid(), Received = DateTime.Now.ToUniversalTime(), IsProcessed = false, FileName = file.FileName }; item.ReadFileFromStream(file.InputStream); new ItemStore(_storageLocator).AddNewItem(item); TempData["file"] = file.FileName + " uploaded and queued for processing."; } else { TempData["file"] = "Processor ignores empty files, sorry."; } return RedirectToAction("Index"); }
public void StoreFinishedItem(FullItem item) { _finishedBlob.Create(item.ResourceId, item.File); _rawBlob.Delete(item.ResourceId); _table.Update(item.AsSummary()); }
public void AddNewItem(FullItem item) { _rawBlob.Create(item.ResourceId, item.File); _queue.Enqueue(item.AsSummary()); _table.Create(item.AsSummary()); }