Пример #1
0
        private void Init()
        {
            AddComoponentToChangeGroup addComponent;

            foreach (var item in Components)
            {
                addComponent = new AddComoponentToChangeGroup()
                {
                    method = "ChangeGroup.AddComponentControl", ComponentParams = new AddComponentToChangeGroupParams()
                    {
                        Component = item.Key
                    }
                };
                commandQueue.Enqueue(JsonConvert.SerializeObject(addComponent));
            }

            AddControlToChangeGroup addControl;

            foreach (var item in Controls)
            {
                addControl = new AddControlToChangeGroup()
                {
                    method = "ChangeGroup.AddControl", ControlParams = new AddControlToChangeGroupParams()
                    {
                        Controls = new List <string>()
                        {
                            item.Key.Name
                        }
                    }
                };
                commandQueue.Enqueue(JsonConvert.SerializeObject(addControl));
            }

            commandQueue.Enqueue(JsonConvert.SerializeObject(new CreateChangeGroup()));

            if (heartbeatTimer != null)
            {
                heartbeatTimer.Stop();
                heartbeatTimer.Dispose();
            }

            heartbeatTimer = new CTimer(SendHeartbeat, null, 0, 15000);

            if (debug == 1 || debug == 2)
            {
                ErrorLog.Notice("QsysProcessor is initialized.");
            }

            isInitialized = true;

            if (onIsRegistered != null)
            {
                onIsRegistered(1);
            }
        }
Пример #2
0
        static internal bool RegisterComponent(Component component)
        {
            try
            {
                lock (Components)
                {
                    if (!Components.ContainsKey(component))
                    {
                        Components.Add(component, new InternalEvents());

                        if (isInitialized && IsConnected)
                        {
                            AddComoponentToChangeGroup addControl;

                            addControl                           = new AddComoponentToChangeGroup();
                            addControl.method                    = "ChangeGroup.AddComponentControl";
                            addControl.ComponentParams           = new AddComponentToChangeGroupParams();
                            addControl.ComponentParams.Component = component;
                            commandQueue.Enqueue(JsonConvert.SerializeObject(addControl));

                            if (debug == 2)
                            {
                                CrestronConsole.PrintLine("Registered {0} Component", component.Name);
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                if (debug == 1 || debug == 2)
                {
                    ErrorLog.Error("Error registering QsysClient to the QsysProcessor: {0}", e.Message);
                }
                return(false);
            }
        }
Пример #3
0
        static void client_ConnectionStatus(int status, int id)
        {
            try
            {
                if (status == 2 && !IsConnected)
                {
                    if (debug == 1 || debug == 2)
                    {
                        ErrorLog.Notice("QsysProcessor is connected.");
                    }
                    IsConnected = true;
                    foreach (var item in SimplClients)
                    {
                        item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsConnected, "true", 1));
                    }

                    CrestronEnvironment.Sleep(1500);

                    //commandQueue.Enqueue(JsonConvert.SerializeObject(new GetComponents()));

                    AddComoponentToChangeGroup addComponent;


                    foreach (var item in Components)
                    {
                        addComponent                           = new AddComoponentToChangeGroup();
                        addComponent.method                    = "ChangeGroup.AddComponentControl";
                        addComponent.ComponentParams           = new AddComponentToChangeGroupParams();
                        addComponent.ComponentParams.Component = item.Key;
                        commandQueue.Enqueue(JsonConvert.SerializeObject(addComponent));
                    }

                    AddControlToChangeGroup addControl;

                    foreach (var item in Controls)
                    {
                        addControl                        = new AddControlToChangeGroup();
                        addControl.method                 = "ChangeGroup.AddControl";
                        addControl.ControlParams          = new AddControlToChangeGroupParams();
                        addControl.ControlParams.Controls = new List <string>();
                        addControl.ControlParams.Controls.Add(item.Key.Name);
                        commandQueue.Enqueue(JsonConvert.SerializeObject(addControl));
                    }

                    commandQueue.Enqueue(JsonConvert.SerializeObject(new CreateChangeGroup()));

                    if (heartbeatTimer != null)
                    {
                        heartbeatTimer.Stop();
                        heartbeatTimer.Dispose();
                    }

                    heartbeatTimer = new CTimer(SendHeartbeat, null, 0, 15000);

                    if (debug == 1 || debug == 2)
                    {
                        ErrorLog.Notice("QsysProcessor is initialized.");
                    }
                    isInitialized = true;

                    foreach (var item in SimplClients)
                    {
                        item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsRegistered, "true", 1));
                    }
                }
                else if (IsConnected && status != 2)
                {
                    if (debug == 1 || debug == 2)
                    {
                        ErrorLog.Error("QsysProcessor disconnected!");
                    }
                    IsConnected   = false;
                    isInitialized = false;
                    heartbeatTimer.Dispose();
                    foreach (var item in SimplClients)
                    {
                        item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsRegistered, "false", 0));
                        item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsConnected, "false", 0));
                    }
                }
            }
            catch (Exception e)
            {
            }
        }