Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        private void CoreModuleInit()
        {
            //Send login if needed
            if (this.loginUser.Length > 0 && this.loginPass.Length > 0)
            {
                this.SendLogin();
            }

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

            this.SendDebug("Initialized");
            this.isInitialized = true;

            foreach (var item in this.SimplClients)
            {
                item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsRegistered, (SimplSharpString)"true", 1));
                item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsConnected, (SimplSharpString)"true", 1));
            }

            this.SendDebug("Requesting all named components and controls");
            this.commandQueue.Enqueue(JsonConvert.SerializeObject(new GetComponents()));

            if (Controls.Count() > 0)
            {
                AddControlToChangeGroup addControls;
                addControls                        = new AddControlToChangeGroup();
                addControls.method                 = "ChangeGroup.AddControl";
                addControls.ControlParams          = new AddControlToChangeGroupParams();
                addControls.ControlParams.Controls = new List <string>();
                foreach (var item in Controls)
                {
                    addControls.ControlParams.Controls.Add(item.Key);
                    this.SendDebug(string.Format("Adding named control: {0} to change group", item.Key));
                }
                this.commandQueue.Enqueue(JsonConvert.SerializeObject(addControls));
            }

            if (Components.Count() > 0)
            {
                AddComponentToChangeGroup addComponents;
                foreach (var item in Components)
                {
                    addComponents                           = new AddComponentToChangeGroup();
                    addComponents.method                    = "ChangeGroup.AddComponentControl";
                    addComponents.ComponentParams           = new AddComponentToChangeGroupParams();
                    addComponents.ComponentParams.Component = item.Key;
                    this.SendDebug(string.Format("Adding named component: {0} to change group", item.Key));
                    commandQueue.Enqueue(JsonConvert.SerializeObject(addComponents));
                }
            }
        }
Ejemplo n.º 3
0
        static internal bool RegisterControl(Control control)
        {
            try
            {
                lock (Controls)
                {
                    if (!Controls.ContainsKey(control))
                    {
                        Controls.Add(control, new InternalEvents());

                        if (isInitialized && IsConnected)
                        {
                            AddControlToChangeGroup addControl;

                            addControl                        = new AddControlToChangeGroup();
                            addControl.method                 = "ChangeGroup.AddControl";
                            addControl.ControlParams          = new AddControlToChangeGroupParams();
                            addControl.ControlParams.Controls = new List <string>();
                            addControl.ControlParams.Controls.Add(control.Name);
                            commandQueue.Enqueue(JsonConvert.SerializeObject(addControl));

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

                return(true);
            }
            catch (Exception e)
            {
                if (debug == 1 || debug == 2)
                {
                    ErrorLog.Error("Error registering QsysClient to the QsysProcessor: {0}", e.Message);
                }
                return(false);
            }
        }
Ejemplo n.º 4
0
 internal bool RegisterNamedControl(string _control)
 {
     try
     {
         lock (Controls)
         {
             if (!Controls.ContainsKey(_control))
             {
                 this.Controls.Add(_control, new InternalEvents());
                 this.SendDebug(string.Format("Adding named control: {0}", _control));
                 if (isInitialized && isConnected)
                 {
                     AddControlToChangeGroup addControl;
                     addControl                        = new AddControlToChangeGroup();
                     addControl.method                 = "ChangeGroup.AddControl";
                     addControl.ControlParams          = new AddControlToChangeGroupParams();
                     addControl.ControlParams.Controls = new List <string>();
                     addControl.ControlParams.Controls.Add(_control);
                     this.SendDebug(string.Format("Adding named control: {0} to core change group", _control));
                     this.commandQueue.Enqueue(JsonConvert.SerializeObject(addControl));
                 }
                 return(true);
             }
             else
             {
                 this.SendDebug(string.Format("Failed to add named control as it alreadt exists: {0}", _control));
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         ErrorLog.Error("Error registering Named Control to the Qsys core {0} : {1}", this.coreID, e.Message);
         return(false);
     }
 }
Ejemplo n.º 5
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)
            {
            }
        }