private bool GetDocument(string documentID, out SystemEvent systemEvent)
 {
     systemEvent = null;
     try
     {
         var storageMan = new AzureStorageManager(ConfigurationManager.AppSettings["AzureStorageConnectionString"]);
         var table      = storageMan.GetTableReference(ConfigurationManager.AppSettings["TableName"]);
         var splitID    = SystemEvent.DecodeIDToPartitionAndRowKey(documentID);
         var op         = TableOperation.Retrieve <SystemEvent>(splitID.Item1, splitID.Item2);
         var doc        = table.Execute(op);
         if (doc == null)
         {
             return(false);
         }
         systemEvent           = (SystemEvent)doc.Result;
         ViewBag.pageException = HelperMethods.FormatException(systemEvent.CaughtException);
         ViewBag.objectDump    = HelperMethods.GetObjectDump(systemEvent.OperationParameters);
         return(true);
     }
     catch (Exception ex)
     {
         ViewBag.pageException = HelperMethods.FormatException(ex);
         return(false);
     }
 }
Пример #2
0
            public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
            {
                EventProcInfo[id] = TimeStampThis("Processing");
                var parsedData = messages.Select(eventData => Encoding.UTF8.GetString(eventData.GetBytes())).Select(JsonConvert.DeserializeObject <SystemEvent>).ToList();

                if (Engine.EngineIsRunning)
                {
                    await Engine.AddToMainQueue(parsedData);

                    EventProcInfo[id] = TimeStampThis(parsedData.Count + " events added to engine");
                }
                else
                {
                    EventProcInfo[id] = TimeStampThis("Engine is not running. Cannot add events. Aborting.");
                    return;
                }
                try
                {
                    var        storageMan = new AzureStorageManager(CloudConfigurationManager.GetSetting("AzureStorageConnectionString"));
                    CloudTable Table      = storageMan.GetTableReference(ConfigurationManager.AppSettings["OperationStorageTable"]);

                    var       batches    = new Dictionary <string, TableBatchOperation>();
                    var       batchNames = new Dictionary <string, string>();
                    const int maxOps     = Microsoft.WindowsAzure.Storage.Table.Protocol.TableConstants.TableServiceBatchMaximumOperations;
                    foreach (var operationResult in parsedData)
                    {
                        string batchName;
                        if (!batchNames.TryGetValue(operationResult.PartitionKey, out batchName))
                        {
                            batchName = operationResult.PartitionKey;
                        }
                        TableBatchOperation batchOperation;
                        if (!batches.ContainsKey(batchName))
                        {
                            batchOperation = new TableBatchOperation();
                            batches.Add(batchName, batchOperation);
                        }
                        else
                        {
                            batches.TryGetValue(batchName, out batchOperation);
                        }
                        Debug.Assert(batchOperation != null, "Could not find batchOperation in Dictionary.");

                        if (batchOperation.Count == maxOps)
                        {
                            batchOperation = new TableBatchOperation();
                            batches.Add(GetNewBatchName(operationResult.PartitionKey, batchNames), batchOperation);
                        }
                        batchOperation.Insert(operationResult);
                    }
                    EventProcInfo[id] = TimeStampThis("Running batches");
                    foreach (var batch in batches)
                    {
                        await Table.ExecuteBatchAsync(batch.Value);
                    }
                }
                catch (Exception ex) when(ex.Message.Contains("The specified entity already exists"))
                {
                    Logger.AddRow("Duplicate entry tried to be added to table storage.");
                }
                catch (Exception ex)
                {
                    EventProcInfo[id] = TimeStampThis("!ERROR! " + ex.Message);
                    Logger.AddRow("!ERROR! In event processor");
                    Logger.AddRow(ex.ToString());
                }
                finally
                {
                    EventProcInfo[id] = TimeStampThis("Setting Checkpoint");
                    await context.CheckpointAsync();

                    EventProcInfo[id] = TimeStampThis("Checkpoint set");
                }
            }