private static void RunTool(ref Dispatch dispatch, Tool tool, List <DeviceDTO> devices) { Int64 scheduleid = dispatch.ScheduleID; Int64 dispatchid = dispatch.Id; ScheduleContextData data = new ScheduleContextData() { ScheduleID = scheduleid, DispatchID = dispatchid, Devices = devices, CallbackInfo = dispatch.CallbackInfo }; // current implementation only supports one tool per schedule var factory = new ChannelFactory <ISchedulableTool>(new BasicHttpBinding(), tool.EndPointAddress); var wcfclient = factory.CreateChannel(); try { wcfclient.Run(data); dispatch.StatusID = DispatchStatus.Completed; } catch (Exception ex) { dispatch.ErrorCode = ex.GetType().ToString(); dispatch.ErrorMsg = ex.Message; dispatch.RetryCount++; } ((IClientChannel)wcfclient).Close(); factory.Close(); }
protected override CallbackResult Execute(CodeActivityContext context) { ScheduleContextData data = context.GetValue(this.ContextData); string endpoint = context.GetValue(this.Endpoint); data.Devices = null; data.CallbackInfo = "Insert Callback data here"; data.NextStartDateTimeUtc = DateTime.UtcNow; var factory = new ChannelFactory <IScheduleCallback>(new BasicHttpBinding(), endpoint); var wcfclient = factory.CreateChannel(); var result = wcfclient.Callback(data); ((IClientChannel)wcfclient).Close(); factory.Close(); return(result); }
protected override CallbackResult Execute(CodeActivityContext context) { Dispatch dispatch; IrqHandle handle; List <CallbackDevice> devices2remove = new List <CallbackDevice>(); ScheduleContextData data = context.GetValue(this.ContextData); CallbackResult result = new CallbackResult() { ScheduleID = data.ScheduleID, DispatchID = data.DispatchID, Success = false, }; using (DispatchEngineContainer dec = new DispatchEngineContainer()) { try { dispatch = dec.Dispatches.Where(d => d.Id == data.DispatchID).Single(); dispatch.CallbackInfo = data.CallbackInfo; // Remove any devices not needed for callback if (data.Devices != null) { var deviceids = (from d in data.Devices select d.Id).ToList(); devices2remove = (from cd in dec.CallbackDevices where cd.DispatchID == data.DispatchID && !(from id in deviceids select id).Contains(cd.DeviceID) select cd).ToList(); } else { devices2remove = (from cd in dec.CallbackDevices where cd.DispatchID == data.DispatchID select cd).ToList(); } foreach (var callbackdevice in devices2remove) { dec.CallbackDevices.Remove(callbackdevice); } // set dispatch to callback status dispatch.StatusID = DispatchStatus.Callback; // Interrupt engine at dispatch level handle = new IrqHandle() { ScheduleID = dispatch.ScheduleID, DispatchID = dispatch.Id, Level = IRQL.Dispatch, TimeStamp = DateTime.Now }; dec.IrqQueue.Add(handle); dec.SaveChanges(); result.Success = true; } catch (Exception ex) { result.Success = false; result.ErrorMsg = ex.Message; } } return(result); }