Esempio n. 1
0
        private void ConnectionManagerOnActiveCommandsChanged(object sender, ActiveCommandsUpdate activeCommandsUpdate)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                foreach (var activeCommandUpdateInfo in activeCommandsUpdate.UpdatedCommands)
                {
                    var commandViewModel =
                        _commands.FirstOrDefault(x => x.DynamicCommand.Id == activeCommandUpdateInfo.CommandId);
                    if (commandViewModel != null)
                    {
                        commandViewModel.DynamicCommandStatus = DynamicCommandStatus.Active;
                        commandViewModel.ExecutingClients.Update(activeCommandUpdateInfo.Clients.Select(
                                                                     x => _connectionManager.ClientProvider.Clients.FirstOrDefault(y => y.Id == x))
                                                                 .Where(x => x != null));
                    }
                }

                foreach (var commandStatusInfo in activeCommandsUpdate.CommandsDeactivated)
                {
                    var commandViewModel =
                        _commands.FirstOrDefault(x => x.DynamicCommand.Id == commandStatusInfo.CommandId);
                    if (commandViewModel != null)
                    {
                        commandViewModel.DynamicCommandStatus = commandStatusInfo.Status;
                        commandViewModel.ExecutingClients.Clear();
                    }
                }
            }));
        }
Esempio n. 2
0
        private void ActiveCommandEventManagerBrakeOnPushChanges(object sender,
                                                                 List <ActiveCommandEvent> activeCommandEvents)
        {
            if (_isDisposed)
            {
                return;
            }

            var activeCommandsUpdate = new ActiveCommandsUpdate
            {
                CommandsDeactivated =
                    activeCommandEvents.Where(x => x.ActiveCommandEventType == ActiveCommandEventType.Removed)
                    .Select(
                        x =>
                        new CommandStatusInfo
                {
                    CommandId = x.ActiveCommandInfo.DynamicCommand.Id,
                    Status    =
                        x.ActiveCommandInfo.DynamicCommand.Status != DynamicCommandStatus.Active
                                            ? x.ActiveCommandInfo.DynamicCommand.Status
                                            : DynamicCommandStatus.Done
                })
                    .ToList(),
                UpdatedCommands =
                    activeCommandEvents.Where(x => x.ActiveCommandEventType != ActiveCommandEventType.Removed).Select(
                        x =>
                {
                    lock (x.ActiveCommandInfo.ClientsLock)
                        return new ActiveCommandUpdateInfo
                        {
                            CommandId = x.ActiveCommandInfo.DynamicCommand.Id,
                            Clients   = x.ActiveCommandInfo.Clients.Select(y => y.Id).ToList()
                        };
                }).ToList()
            };

            var serializer = new Serializer(typeof(ActiveCommandsUpdate));
            var data       = serializer.Serialize(activeCommandsUpdate);

            try
            {
                Logger.Debug(
                    "Send active commands changed package to AI-{0} with {1} deactivated commands and {2} updated commands",
                    Id, activeCommandsUpdate.CommandsDeactivated.Count, activeCommandsUpdate.UpdatedCommands.Count);
                lock (_sendLock)
                {
                    Connection.BinaryWriter.Write((byte)FromClientPackage.ActiveCommandsChanged);
                    Connection.BinaryWriter.Write(data.Length);
                    Connection.BinaryWriter.Write(data);
                }
            }
            catch (Exception ex)
            {
                ReportError(ex, MethodBase.GetCurrentMethod().Name);
            }
        }