public void ReceiveWorkOrderUpdateRequest(int workOrderId) { WorkOrderWS.WorkOrderTrimmed wo = new WorkOrderWS.WorkOrderSvc().GetWorkOrder(App.GetAuthToken(this), App.GetDeviceId(this), true, workOrderId, true); // TODO: handle it }
public void AddSlaveWorkItem(int workOrderId) { // Get it WorkOrderWS.WorkOrderTrimmed wo = new WorkOrderWS.WorkOrderSvc().GetWorkOrder(App.GetAuthToken(this), App.GetDeviceId(this), true, workOrderId, true); // Acknowledge it new WorkOrderWS.WorkOrderSvc().AcknowledgeWorkOrder(App.GetAuthToken(this), workOrderId, true); App.UpdateLastTransmit(); // Submit comm package to Background service Intent doWork = new Intent(); doWork.PutExtra("CommPackage", System.Text.RegularExpressions.Regex.Unescape(wo.CommPackageJsonk__BackingField)); doWork.SetAction(wo.ComputeAppIntentk__BackingField); this.ApplicationContext.SendBroadcast(doWork); // Store it wo.WorkOrderStatusk__BackingField = "SUBMITTED_TO_APP"; SlaveWorkItems.Add(wo); }
public void ReceiveWorkOrderResult(int workOrderId) { WorkOrderWS.WorkOrderTrimmed wo = new WorkOrderWS.WorkOrderSvc().GetWorkOrder(App.GetAuthToken(this), App.GetDeviceId(this), true, workOrderId, true); ComputeAndroidSDK.Communication.WorkOrderTrimmed testWo = new WorkOrderTrimmed(); testWo.ApplicationId = wo.ApplicationIdk__BackingField; testWo.ApplicationUIResultIntent = wo.ApplicationUIResultIntentk__BackingField; testWo.CommPackageJson = wo.CommPackageJsonk__BackingField; testWo.ComputeAppIntent = wo.ComputeAppIntentk__BackingField; testWo.DeviceId = wo.DeviceIdk__BackingField; testWo.DeviceLocalRequestId = wo.DeviceLocalRequestIdk__BackingField; testWo.DeviceUIRef = wo.DeviceUIRefk__BackingField; testWo.ReceiveTime = wo.ReceiveTimek__BackingField; testWo.SlaveWorkerId = wo.SlaveWorkerIdk__BackingField; testWo.SlaveWorkerSubmit = wo.SlaveWorkerSubmitk__BackingField; testWo.SlaveWorkOrderLastCommunication = wo.SlaveWorkOrderLastCommunicationk__BackingField; testWo.WorkOrderId = wo.WorkOrderIdk__BackingField; testWo.WorkOrderResultJson = wo.WorkOrderResultJsonk__BackingField; testWo.WorkOrderStatus = wo.WorkOrderStatusk__BackingField; // Send to listener (intent attached to application) Intent newIntent = new Intent(wo.ApplicationUIResultIntentk__BackingField); string fileName = Android.OS.Environment.ExternalStorageDirectory + Java.IO.File.Separator + testWo.WorkOrderId + "-ResultRet.txt"; StreamWriter fs = new StreamWriter(fileName, false); fs.Write(JsonConvert.SerializeObject(testWo)); fs.Close(); newIntent.PutExtra("FileLocation", fileName); //newIntent.PutExtra("WorkOrderTrimmed", JsonConvert.SerializeObject(testWo)); this.ApplicationContext.SendBroadcast(newIntent); }
public void FetchComms() { if (hasCommPackageGetThreadRunning) { return; } hasCommPackageGetThreadRunning = true; int deviceId = App.GetDeviceId(this); string authToken = App.GetAuthToken(this); // get comms and handle them int noSecsNoComms = 0; try { while (noSecsNoComms < 120) { Log.Info("ControllerService", "Fetching outstanding comms"); List <WorkOrderWS.CommunicationPackage> cps = new WorkOrderWS.WorkOrderSvc().GetOutstandingCommunications(authToken, deviceId, true).ToList(); if (cps.Count() == 0) { noSecsNoComms += 5; // Was 10 } else { // Handle all the comms noSecsNoComms = 0; Log.Info("ControllerService", "Got some outstanding comms"); foreach (WorkOrderWS.CommunicationPackage cp in cps) { UpdateType ut = (UpdateType)cp.CommunicationTypek__BackingField; int? workOrderId = cp.WorkOrderIdk__BackingField; int commId = cp.CommunicationIdk__BackingField; Log.Info(BroadcastReceiver.TAG, "Handling comm id: " + commId); new WorkOrderWS.WorkOrderSvc().AcknowledgeCommunication(authToken, commId, true, DateTime.Now, true); App.UpdateLastTransmit(); if (ut == UpdateType.NewWorkOrder) { AddSlaveWorkItem(workOrderId.Value); Log.Info(BroadcastReceiver.TAG, "Handling new work order id: " + workOrderId); } else if (ut == UpdateType.Result) { ReceiveWorkOrderResult(workOrderId.Value); Log.Info(BroadcastReceiver.TAG, "Handling result work order id: " + workOrderId); } else if (ut == UpdateType.UpdateRequest) { //TODO: Handle update request } else if (ut == UpdateType.Cancel) { //TODO: Handle cancel request } else if (ut == UpdateType.FetchRequest) { } } } // Sleep before checking again. Thread.Sleep(new TimeSpan(0, 0, 5)); // Was 10 } } catch (Exception e) { Log.Error("ControllerService", e.InnerException.Message); } hasCommPackageGetThreadRunning = false; }
public void FetchComms() { if (hasCommPackageGetThreadRunning) return; hasCommPackageGetThreadRunning = true; int deviceId = App.GetDeviceId(this); string authToken = App.GetAuthToken(this); // get comms and handle them int noSecsNoComms = 0; try { while (noSecsNoComms < 120) { Log.Info("ControllerService", "Fetching outstanding comms"); List<WorkOrderWS.CommunicationPackage> cps = new WorkOrderWS.WorkOrderSvc().GetOutstandingCommunications(authToken, deviceId, true).ToList(); if (cps.Count() == 0) { noSecsNoComms += 5; // Was 10 } else { // Handle all the comms noSecsNoComms = 0; Log.Info("ControllerService", "Got some outstanding comms"); foreach (WorkOrderWS.CommunicationPackage cp in cps) { UpdateType ut = (UpdateType)cp.CommunicationTypek__BackingField; int? workOrderId = cp.WorkOrderIdk__BackingField; int commId = cp.CommunicationIdk__BackingField; Log.Info(BroadcastReceiver.TAG, "Handling comm id: " + commId); new WorkOrderWS.WorkOrderSvc().AcknowledgeCommunication(authToken, commId, true, DateTime.Now, true); App.UpdateLastTransmit(); if (ut == UpdateType.NewWorkOrder) { AddSlaveWorkItem(workOrderId.Value); Log.Info(BroadcastReceiver.TAG, "Handling new work order id: " + workOrderId); } else if (ut == UpdateType.Result) { ReceiveWorkOrderResult(workOrderId.Value); Log.Info(BroadcastReceiver.TAG, "Handling result work order id: " + workOrderId); } else if (ut == UpdateType.UpdateRequest) { //TODO: Handle update request } else if (ut == UpdateType.Cancel) { //TODO: Handle cancel request } else if (ut == UpdateType.FetchRequest) { } } } // Sleep before checking again. Thread.Sleep(new TimeSpan(0, 0, 5)); // Was 10 } } catch (Exception e) { Log.Error("ControllerService", e.InnerException.Message); } hasCommPackageGetThreadRunning = false; }