public AzureSystemStatUpdate(POCO.System system, POCO.SystemStat stat) { string jsonstat = JsonConvert.SerializeObject(stat); this.PartitionKey = system.PartitionKey; this.RowKey = system.RowKey; this.JsonSystemStats = jsonstat; }
public static void UpdateSystemStat(DataConfig providerConfig, POCO.System system, POCO.SystemStat systemStat) { switch (providerConfig.ProviderType) { case "azure.tableservice": AzureSystemStatUpdate az = new AzureSystemStatUpdate(system, systemStat); CloudTable table = Utils.GetCloudTable(providerConfig, System.TableNames.System); TableOperation operation = TableOperation.InsertOrMerge(az); Task tUpdate = table.ExecuteAsync(operation); tUpdate.Wait(); break; case "internal.mongodb": IMongoCollection <MongoSystemStatUpdate> collection = Utils.GetMongoCollection <MongoSystemStatUpdate>(providerConfig, "stlpsystems"); MongoSystemStatUpdate mongoObject = Utils.ConvertType <MongoSystemStatUpdate>(system); // Create the update filter List <DataFactory.Filter> filters = new List <DataFactory.Filter>(); DataFactory.Filter pkFilter = new DataFactory.Filter("PartitionKey", Utils.CleanTableKey(mongoObject.PartitionKey), "eq"); //DataFactory.Filter rkFilter = new DataFactory.Filter("RowKey", Utils.CleanTableKey(mongoObject.RowKey), "eq"); filters.Add(pkFilter); //filters.Add(rkFilter); FilterDefinition <MongoSystemStatUpdate> filter = Utils.GenerateMongoFilter <MongoSystemStatUpdate>(filters); // Serialize the stats object string jsonStatsSerialized = JsonConvert.SerializeObject(systemStat); //string updateParam = "{$set: {JsonSystemStats: '" + jsonStatsSerialized + "'}}"; //BsonDocument updateDoc = BsonDocument.Parse(updateParam); var update = Builders <MongoSystemStatUpdate> .Update .Set("JsonSystemStats", jsonStatsSerialized); // Update the batch status UpdateResult result = collection.UpdateOne(filter, update); return; default: throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType); } return; }