Exemplo n.º 1
0
        public static MachineConnection CreateConnection(IProcessManagerEventHandler processManagerEventHandler, Machine machine)
        {
            ProcessManagerServiceHandler serviceHandler    = ProcessManagerServiceConnectionHandler.Instance.CreateServiceHandler(processManagerEventHandler, machine);
            MachineConnection            machineConnection = new MachineConnection(machine, serviceHandler);

            Connections[machine] = machineConnection;
            return(machineConnection);
        }
Exemplo n.º 2
0
        private void DistributionConnectionManagementThread()
        {
            try
            {
                Logger.Add("STARTUP -- Starting distribution connection management thread...");

                while (!_shutDownRequested)
                {
                    try
                    {
                        lock (_pendingDistributionWork)
                        {
                            ConnectionStore.Connections.Keys
                            .Where(machine => !_pendingDistributionWork.Any(work => Comparer.MachinesEqual(work.DestinationMachine, machine)))
                            .ToList()
                            .ForEach(ConnectionStore.RemoveConnection);
                        }

                        List <Machine> machinesToConnect;
                        lock (_pendingDistributionWork)
                        {
                            machinesToConnect = _pendingDistributionWork
                                                .Select(work => work.DestinationMachine)
                                                .Distinct(new MachineEqualityComparer())
                                                .Where(destinationMachine => !ConnectionStore.Connections.ContainsKey(destinationMachine))
                                                .ToList();
                        }

                        machinesToConnect.ForEach(destinationMachine =>
                        {
                            MachineConnection connection = ConnectionStore.CreateConnection(this, destinationMachine);
                            connection.ServiceHandler.Initialize();
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Add("An unexpected error occurred in distribution connection management thread", ex);
                    }

                    Thread.Sleep(Settings.Service.Read <int>("DistributionConnectionCleanInterval"));
                }

                Logger.Add("SHUTDOWN -- Shutting down distribution connection management thread...");
            }
            catch (Exception ex)
            {
                Logger.Add("Fatal exception in distribution connection management thread, dying....", ex);
            }
            finally
            {
                // indicate that we are no longer running
                _distributionConnectionManagementThread = null;
            }
        }
Exemplo n.º 3
0
        public bool SendLine(string line)
        {
            if (line.Length < BufferSpace)
            {
                CharBufferCount += line.Length;
                ActiveCommands.Enqueue(line);
                MachineConnection.SendLine(line);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static void ModifyMachineConfiguration(ProcessManagerServiceHandler serviceHandler, bool retrieve)
        {
            MachineConnection machineConnection = ConnectionStore.Connections.Values.FirstOrDefault(x => x.ServiceHandler == serviceHandler);

            if (machineConnection == null)
            {
                return;
            }

            try
            {
                machineConnection.Configuration = retrieve ? machineConnection.ServiceHandler.Service.GetConfiguration().FromDTO() : null;
            }
            catch (Exception ex)
            {
                Logger.Add("Failed to retrieve machine configuration", ex);
            }
        }
Exemplo n.º 5
0
        public static void ConnectMachines()
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException("ServiceHelper not initialized");
            }

            ConnectionStore.Connections.Keys.Where(machine => !Settings.Client.Machines.Contains(machine)).ToList().ForEach(ConnectionStore.RemoveConnection);

            if (Settings.Client.Machines.Any(machine => !ConnectionStore.ConnectionCreated(machine)))
            {
                Worker.Do("Connecting to machines...", () =>
                {
                    foreach (Machine machine in Settings.Client.Machines.Where(machine => !ConnectionStore.ConnectionCreated(machine)))
                    {
                        MachineConnection connection = ConnectionStore.CreateConnection(ProcessManagerEventHandler, machine);
                        connection.ServiceHandler.Initialize();
                    }
                });
            }
        }
Exemplo n.º 6
0
 public override void RequestStatus()
 {
     MachineConnection.Send("?");
 }
Exemplo n.º 7
0
 public override void Reset()
 {
     MachineConnection.Send("\u0018");
 }
Exemplo n.º 8
0
 public void Disconnect()
 {
     MachineConnection.Disconnect();
 }