private static void UpdateLog(MongoCollections collections, string json) { JObject jObj = JObject.Parse(json); dynamic results = JsonConvert.DeserializeObject <dynamic>(json); long taskID = (long)results.task_id; string userID = results.user_id; string typeDetection = results.type; string typeProcc = results.results.type; string resultPath = results.results.resultpath; string typeResult = results.file_type; //JObject jObj = JObject.Parse(strMessage); //JObject resultObj = JObject.Parse(jObj["results"].ToString()); BsonDocument processingResult = BsonDocument.Parse(results.results.ToString()); JArray procRes = JArray.Parse(results.results.result.ToString()); JArray summary = JArray.Parse(results.summary.ToString()); double fps = (double)results.fps; bool aod = (bool)results.aod_enable; BsonArray bProcRes = BsonDocument.Parse("{\"res\":" + procRes + "}")["res"].AsBsonArray; BsonArray deserializedArray = BsonDocument.Parse("{\"sum\":" + summary + "}")["sum"].AsBsonArray; //Console.WriteLine("before: " +data); //string processingResult = data.ToString(Formatting.None); //Console.WriteLine("after: " + processingResult); string unitProcID = results.unit_id; DateTime timeStart = results.time_stamp; TimeSpan timeProcess = DateTime.UtcNow - timeStart; var filter = Builders <CommandStatusTable> .Filter.Eq(s => s.TaskId, taskID); var update = Builders <CommandStatusTable> .Update.Set(u => u.Status, 1) .Set(u => u.TimeFinish, DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK")) .Set(u => u.UnitProcessingId, unitProcID) .Set(u => u.TimeProccess, timeProcess.ToString()) .Set("aod_enable", aod) .Set("result", bProcRes) .Set("result_path", resultPath) .Set("summary", deserializedArray) .Set("fps", fps); collections.cmd.UpdateOne(filter, update); Console.WriteLine("Data_Logger {1} : Update result Task ID {0} in Command Status Table", taskID, DateTime.Now); }
static void Main(string[] args) { //mongo init MongoCollections collections = new MongoCollections(); ConnectionFactory factory = new ConnectionFactory { HostName = ConnectionConstants.HostName, UserName = ConnectionConstants.User, Password = ConnectionConstants.Password, VirtualHost = ConnectionConstants.VHost }; //factory2 ConnectionFactory factory2 = new ConnectionFactory { HostName = ConnectionConstants.HostName, UserName = ConnectionConstants.User, Password = ConnectionConstants.Password, VirtualHost = ConnectionConstants.VHost2 }; publicConnection = factory.CreateConnection(); publicChannel = publicConnection.CreateModel(); publicChannel.BasicQos(0, 1, false); // Process only one message at a time //internal vhost connection = factory2.CreateConnection(); channel = connection.CreateModel(); string dataResponderQueue = channel.QueueDeclare().QueueName; channel.QueueBind(dataResponderQueue, "amq.topic", ConnectionConstants.ResponderRoutingKey); Console.WriteLine("Data Responder Ready"); Console.WriteLine("Consume to topic {0}", ConnectionConstants.ResponderRoutingKey); EventingBasicConsumer eventingBasicConsumer = new EventingBasicConsumer(channel); int counter = 0; eventingBasicConsumer.Received += (model, ea) => { counter++; String strMessage = System.Text.Encoding.UTF8.GetString(ea.Body); dynamic results = JsonConvert.DeserializeObject <dynamic>(strMessage); string type = results.type; Console.WriteLine("Data_Responder {1} : Received result for Task ID {0} from routing key {2}", results.task_id, DateTime.Now, ea.RoutingKey); UpdateLog(collections, strMessage); PublishTaskRestAPI((long)results.task_id, strMessage, ConnectionConstants.QueueListener); //if (!(type.Equals("face")))//kecuali pengenalan wajah, lakukan abandoned object detection //{ // if (ea.RoutingKey.Equals(ConnectionConstants.QueueAbandonedObjectDetection)) // { // PublishAODQueue((long)results.task_id, strMessage, ConnectionConstants.QueueAbandonedObjectDetection); // } //} // Acknowledge channel.BasicAck(ea.DeliveryTag, false); }; channel.BasicConsume(dataResponderQueue, false, eventingBasicConsumer); }