public void Start(Block block) { Block = block; new Thread(() => { Log.Write(Block.BlockID, $"Started thread for queue {Block.BlockName}"); while (true) { IControlAction action = null; ControlResponse response; try { action = _queue.Take(); Log.Write(Block.BlockID, $"RECV:{action.GetType().Name}:{action.MessageID}"); RequestReceived?.Invoke(this, new ControlActionEventArgs() { ID = action.MessageID, TimeStamp = action.Timestamp, MessageType = "Request" }); if (action is StopAction) { break; } //process the message using (ServiceProvider.Current.DataAccess.StartUnitOfWork()) { response = action.Execute(_connection); } _responses.Add(action.MessageID, response); lock (locker) { _lastMessage = action; } } catch (Exception ex) { // If a return message is expected make sure one is sent back even when an error occurred. // There is no way to get a message back via _responses if action is null because we don't // know which MessageID to use. The only thing we can do in this case is just log it. if (action != null) { response = new ErrorResponse(ex); _responses.Add(action.MessageID, response); } Log.Write(Block.BlockID, ex.ToString()); } } }).Start(); }
void dGrid_LoadRowDetailComplete(object sender, ActionCompletedEventArgs <UIElement> e) { if (this.EditForm.OperationType == OperationTypes.Audit) { IControlAction form = e.Result as IControlAction; form.InitControl(OperationTypes.Edit); } }
public void Push(IControlAction action) { //put a WagoMessage on the queue Log.Write(Block.BlockID, $"SEND:{action.GetType().Name}:{action.MessageID}"); _queue.Add(action); //when WagoService sees the message it will communicate with the wago block and add an entry to the response collection }
public static IList <InstanceAuthorization> Create(IClient client, string location, LocationType locationType, string actionName) { IList <InstanceAuthorization> result = new List <InstanceAuthorization>(); if (actionName == "ByPass") { actionName = "AlarmByPass"; } IControlAction action = ServiceProvider.Current.Control.GetControlAction(actionName); if (action == null) { throw new Exception(string.Format("Unable to find action: {0}", actionName)); } string[] locs = { "1", location, ((int)locationType).ToString() }; IList <IControlAuthorization> query = ServiceProvider.Current.Control.GetControlAuthorizations().ToList(); IControlAuthorization[] auths = query .Where(x => (x.ClientID == -1 * client.ClientID || (x.ClientID & (int)client.Privs) > 0) && locs.Contains(x.Location) && x.ActionID == action.ActionID).ToArray(); foreach (IControlAuthorization ca in auths) { IList <IActionInstance> act = ServiceProvider.Current.Control.GetActionInstances(actionName, ca.ActionInstanceID).ToList(); if (act.Count > 0) { foreach (IActionInstance inst in act) { IPoint p = inst.GetPoint(); result.Add(new InstanceAuthorization() { Index = ca.ActionInstanceID, Name = inst.Name, Point = inst.Point, ActionID = inst.ActionID, BlockID = p.BlockID, BlockName = p.BlockName, Status = null }); } } else { result.Add(new InstanceAuthorization() { Index = ca.ActionInstanceID, Name = null, Point = null, ActionID = null, BlockID = null, BlockName = null, Status = null }); } } return(result); }
private void SetRowDetailTemplate() { if (this.orderDetailGridInfo.RowDetailDataPanel != null) { #region RowDetailTemplate DataTemplate dt = DataTemplateHelper.GetEmptyGrid(); this.ADGrid.RowDetailsTemplate = dt; this.ADGrid.LoadingRowDetails += (o, e) => { IDataPanel panel = this.orderDetailGridInfo.RowDetailDataPanel; IControlAction control = panel.GetUIElement(); Grid grid = e.DetailsElement as Grid; grid.Background = e.Row.Background; if (grid.Children.Count == 0) { Border border = new Border(); border.Style = (Style)Application.Current.Resources["DetailShow_1"]; grid.Children.Add(border); if (control.GetType() == typeof(DetailGrid)) { DetailGrid dgrid = control as DetailGrid; border.Child = dgrid; // dgrid.Margin = new Thickness(80, 0, 0, 0); control.InitControl(this.operationType); } else { border.Child = (control as UIElement); OperationTypes cOpType = this.operationType; if (this.operationType == OperationTypes.Audit) { cOpType = OperationTypes.Edit; } control.InitControl(cOpType); } } DependencyObject dObj = VisualTreeHelper.GetChild(e.DetailsElement,0); UIElement curControl = (dObj as Border).Child; if (curControl.GetType() == typeof(DetailGrid)) { DetailGrid dgrid = curControl as DetailGrid; string entityType = dgrid.OrderDetailGridInfo.OrderDetailEntityInfo.Entity.Type; FBEntity source = e.Row.DataContext as FBEntity; ; if (source != null) { ObservableCollection<FBEntity> list = source.GetRelationFBEntities(entityType); if (list.Count > 0) { dgrid.ItemsSource = list; } else { dgrid.Visibility = Visibility.Collapsed; } } } if (LoadRowDetailComplete != null) { ActionCompletedEventArgs<UIElement> args = new ActionCompletedEventArgs<UIElement>(curControl); LoadRowDetailComplete(o, args); } }; #endregion } }
public ControlResponse Execute(Block block, IControlAction action) { throw new NotImplementedException(); }