Пример #1
0
 public QsysInternalEventsArgs(ChangeResult _changeResult)
 {
     this.changeResult = _changeResult;
 }
Пример #2
0
        private void ParseInternalResponse(string returnString)
        {
            try
            {
                if (returnString.Length > 0)
                {
                    if (returnString == "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":\"crestron\"}")
                    {
                        if (!isLoggedIn)
                        {
                            isLoggedIn = true;

                            if (onIsLoggedIn != null)
                            {
                                onIsLoggedIn(1);
                            }

                            Init();
                        }
                    }
                    else
                    {
                        JObject response = JObject.Parse(returnString);

                        if (returnString.Contains("Changes"))
                        {
                            IList <JToken> changes = response["params"]["Changes"].Children().ToList();

                            IList <ChangeResult> changeResults = new List <ChangeResult>();

                            foreach (JToken change in changes)
                            {
                                ChangeResult changeResult = JsonConvert.DeserializeObject <ChangeResult>(change.ToString(), new JsonSerializerSettings {
                                    MissingMemberHandling = MissingMemberHandling.Ignore
                                });

                                if (changeResult.Component != null)
                                {
                                    foreach (var item in Components)
                                    {
                                        List <string> choices;

                                        if (changeResult.Choices != null)
                                        {
                                            choices = changeResult.Choices.ToList();
                                        }
                                        else
                                        {
                                            choices = new List <string>();
                                        }

                                        if (item.Key.Name == changeResult.Component)
                                        {
                                            item.Value.Fire(new QsysInternalEventsArgs(changeResult.Name, changeResult.Value, changeResult.Position, changeResult.String, choices));
                                        }
                                    }
                                }
                                else if (changeResult.Name != null)
                                {
                                    List <string> choices;

                                    if (changeResult.Choices != null)
                                    {
                                        choices = changeResult.Choices.ToList();
                                    }
                                    else
                                    {
                                        choices = new List <string>();
                                    }

                                    foreach (var item in Controls)
                                    {
                                        if (item.Key.Name.Contains(changeResult.Name))
                                        {
                                            item.Value.Fire(new QsysInternalEventsArgs(changeResult.Name, changeResult.Value, changeResult.Position, changeResult.String, choices));
                                        }
                                    }
                                }
                            }
                        }
                        else if (returnString.Contains("EngineStatus"))
                        {
                            if (response["params"] != null)
                            {
                                JToken engineStatus = response["params"];

                                if (engineStatus["DesignName"] != null)
                                {
                                    designName = engineStatus["DesignName"].ToString();
                                }

                                if (engineStatus["IsRedundant"] != null)
                                {
                                    isRedundant = Convert.ToBoolean(engineStatus["IsRedundant"].ToString());
                                }

                                if (engineStatus["IsEmulator"] != null)
                                {
                                    isEmulator = Convert.ToBoolean(engineStatus["IsEmulator"].ToString());
                                }

                                if (onNewCoreStatus != null)
                                {
                                    onNewCoreStatus(designName, Convert.ToUInt16(isRedundant), Convert.ToUInt16(isEmulator));
                                }
                            }

                            if (!isLoggedIn)
                            {
                                if (debug == 1 || debug == 2)
                                {
                                    ErrorLog.Notice("QsysProcessor server ready, starting to send intialization strings.");
                                }

                                if (password.Length > 0 && username.Length > 0)
                                {
                                    logonAttempts = 1;
                                    commandQueue.Enqueue(JsonConvert.SerializeObject(new Logon()
                                    {
                                        Params = new LogonParams()
                                        {
                                            User = username, Password = password
                                        }
                                    }));
                                }
                                else
                                {
                                    isLoggedIn = true;

                                    if (onIsLoggedIn != null)
                                    {
                                        onIsLoggedIn(1);
                                    }

                                    Init();
                                }
                            }
                        }
                        else if (returnString.Contains("error"))
                        {
                            if (logonAttempts < maxLogonAttempts)
                            {
                                JToken error = response["error"];

                                if (error["code"] != null)
                                {
                                    if (error["code"].ToString().Replace("\'", string.Empty) == "10")
                                    {
                                        logonAttempts++;
                                        commandQueue.Enqueue(JsonConvert.SerializeObject(new Logon()
                                        {
                                            Params = new LogonParams()
                                            {
                                                User = username, Password = password
                                            }
                                        }));
                                    }
                                }
                            }
                            else
                            {
                                if (debug == 1)
                                {
                                    ErrorLog.Error("Error in QsysProcessor max logon attempts reached");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (debug == 1 || debug == 2)
                {
                    ErrorLog.Error("Error in QsysProcessor ParseInternalResponse: {0}:\r\n{1}", e.Message, returnString);
                }
            }
        }
Пример #3
0
        private static void ParseInternalResponse(string returnString)
        {
            try
            {
                if (returnString.Length > 0)
                {
                    JObject response = JObject.Parse(returnString);

                    if (returnString.Contains("Changes"))
                    {
                        IList <JToken> changes = response["params"]["Changes"].Children().ToList();

                        IList <ChangeResult> changeResults = new List <ChangeResult>();

                        foreach (JToken change in changes)
                        {
                            //ChangeResult changeResult = (ChangeResult)change.Cast<ChangeResult>();

                            ChangeResult changeResult = JsonConvert.DeserializeObject <ChangeResult>(change.ToString(), new JsonSerializerSettings {
                                MissingMemberHandling = MissingMemberHandling.Ignore
                            });

                            if (changeResult.Component != null)
                            {
                                foreach (var item in Components)
                                {
                                    List <string> choices;

                                    if (changeResult.Choices != null)
                                    {
                                        choices = changeResult.Choices.ToList();
                                    }
                                    else
                                    {
                                        choices = new List <string>();
                                    }

                                    if (item.Key.Name == changeResult.Component)
                                    {
                                        item.Value.Fire(new QsysInternalEventsArgs(changeResult.Name, changeResult.Value, changeResult.Position, changeResult.String, choices));
                                    }
                                }
                            }
                            else if (changeResult.Name != null)
                            {
                                List <string> choices;

                                if (changeResult.Choices != null)
                                {
                                    choices = changeResult.Choices.ToList();
                                }
                                else
                                {
                                    choices = new List <string>();
                                }

                                foreach (var item in Controls)
                                {
                                    if (item.Key.Name.Contains(changeResult.Name))
                                    {
                                        item.Value.Fire(new QsysInternalEventsArgs(changeResult.Name, changeResult.Value, changeResult.Position, changeResult.String, choices));
                                    }
                                }
                            }
                        }
                    }
                    else if (returnString.Contains("EngineStatus"))
                    {
                        if (response["params"] != null)
                        {
                            JToken engineStatus = response["params"];

                            if (engineStatus["DesignName"] != null)
                            {
                                designName = engineStatus["DesignName"].ToString();
                            }

                            if (engineStatus["IsRedundant"] != null)
                            {
                                isRedundant = Convert.ToBoolean(engineStatus["IsRedundant"].ToString());
                            }

                            if (engineStatus["IsEmulator"] != null)
                            {
                                isEmulator = Convert.ToBoolean(engineStatus["IsEmulator"].ToString());
                            }

                            foreach (var item in SimplClients)
                            {
                                item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.NewCoreStatus, string.Empty, 1));
                            }
                        }
                    }
                    else if (returnString.Contains("Properties"))
                    {
                        IList <JToken> components = response["result"].Children().ToList();

                        IList <ComponentResults> componentResults = new List <ComponentResults>();

                        foreach (var component in components)
                        {
                            ComponentResults result = JsonConvert.DeserializeObject <ComponentResults>(component.ToString());

                            if (result.Type == "gain")
                            {
                                foreach (var item in Components)
                                {
                                    if (item.Key.Name == result.Name)
                                    {
                                        List <ComponentProperties> props = result.Properties.ToList();
                                        ComponentProperties        prop;
                                        if ((prop = props.Find(x => x.Name == "max_gain")) != null)
                                        {
                                            //item.Value.Fire(new QsysInternalEventsArgs("max_gain", Convert.ToDouble(prop.Value), 0, string.Empty));
                                        }
                                        if ((prop = props.Find(x => x.Name == "min_gain")) != null)
                                        {
                                            //item.Value.Fire(new QsysInternalEventsArgs("min_gain", Convert.ToDouble(prop.Value), 0, string.Empty));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (debug == 1 || debug == 2)
                {
                    ErrorLog.Error("Error in QsysProcessor ParseInternalResponse: {0}:\r\n{1}", e.Message, returnString);
                }
            }
        }
Пример #4
0
        private void ParseInternalResponse(string _returnString)
        {
            if (_returnString.Length > 0)
            {
                try
                {
                    JObject response = JObject.Parse(_returnString);
                    if (_returnString.Contains("Changes"))
                    {
                        IList <JToken>       changes       = response["params"]["Changes"].Children().ToList();
                        IList <ChangeResult> changeResults = new List <ChangeResult>();
                        foreach (JToken change in changes)
                        {
                            ChangeResult changeResult = JsonConvert.DeserializeObject <ChangeResult>(change.ToString());
                            if (changeResult.Component != null)
                            {
                                foreach (var item in this.Components)
                                {
                                    if (item.Key.Name == changeResult.Component)
                                    {
                                        item.Value.Fire(new QsysInternalEventsArgs(changeResult));
                                    }
                                }
                            }
                            else
                            {
                                foreach (var item in this.Controls)
                                {
                                    if (item.Key == changeResult.Name)
                                    {
                                        item.Value.Fire(new QsysInternalEventsArgs(changeResult));
                                    }
                                }
                            }
                        }
                    }
                    else if (_returnString.Contains("Properties"))
                    {
                        //IList<JToken> components = response["result"].Children().ToList();
                        //IList<ComponentResults> componentResults = new List<ComponentResults>();
                        //foreach (var component in components)
                        //{
                        //    ComponentResults result = JsonConvert.DeserializeObject<ComponentResults>(component.ToString());
                        //    if (result.Type == "gain")
                        //    {
                        //        foreach (var item in this.Components)
                        //        {
                        //            if (item.Key.Name == result.Name)
                        //            {
                        //                List<ComponentProperties> props = result.Properties.ToList();
                        //                ComponentProperties prop;
                        //                if ((prop = props.Find(x => x.Name == "max_gain")) != null)
                        //                {
                        //                    item.Value.Fire(new QsysInternalEventsArgs("max_gain", Convert.ToDouble(prop.Value), string.Empty));
                        //                }
                        //                if ((prop = props.Find(x => x.Name == "min_gain")) != null)
                        //                {
                        //                    item.Value.Fire(new QsysInternalEventsArgs("min_gain", Convert.ToDouble(prop.Value), string.Empty));
                        //                }
                        //            }
                        //        }
                        //    }
                        //}
                    }
                    else if (_returnString.Contains("EngineStatus") || _returnString.Contains("StatusGet"))
                    {
                        EngineStatusResult statusResult = JsonConvert.DeserializeObject <EngineStatusResult>(_returnString);
                        this.coreState    = (eCoreState)Enum.Parse(typeof(eCoreState), statusResult.Properties.State, true);
                        this.platform     = statusResult.Properties.Platform;
                        this.designName   = statusResult.Properties.DesignName;
                        this.designCode   = statusResult.Properties.DesignCode;
                        this.isRedundant  = Convert.ToBoolean(statusResult.Properties.IsRedundant);
                        this.isEmulator   = Convert.ToBoolean(statusResult.Properties.IsEmulator);
                        this.statusCode   = statusResult.Properties.Status.Code;
                        this.statusString = statusResult.Properties.Status.String;
                        foreach (var item in SimplClients)
                        {
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.CoreState, "", (ushort)coreState));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.Platform, this.platform, 0));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.DesignName, designName, 0));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.DesignCode, designCode, 0));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsRedundant, Convert.ToString(isRedundant), (ushort)Convert.ToInt16(isRedundant)));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsEmulator, Convert.ToString(isEmulator), (ushort)Convert.ToInt16(isEmulator)));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.StatusCode, Convert.ToString(statusCode), (ushort)statusCode));
                            item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.StatusString, statusString, 0));
                        }

                        if (!this.isInitialized)
                        {
                            this.CoreModuleInit();
                            this.SendCreateChangeGroup();
                        }
                    }
                    else if (_returnString.Contains("error"))
                    {
                        CoreError err = JsonConvert.DeserializeObject <CoreError>(_returnString);
                        this.SendDebug(String.Format("Core sent error: {0}:{1}", err.Error.Code, err.Error.Message));
                        switch (err.Error.Code)
                        {
                        case -32700:     //Parse error. Invalid JSON was received by the server.
                            break;

                        case -32600:     //Invalid request. The JSON sent is not a valid Request object.
                            break;

                        case -32601:     //Method not found.
                            break;

                        case -32602:     //Invalid params.
                            break;

                        case -32603:     //Server error.
                            break;

                        case 2:     //Invalid Page Request ID
                            break;

                        case 3:     //Bad Page Request - could not create the requested Page Request
                            break;

                        case 4:     //Missing file
                            break;

                        case 5:     //Change Groups exhausted
                            break;

                        case 6:     //Unknown change 6roup
                            this.SendCreateChangeGroup();
                            break;

                        case 7:     //Unknown component name
                            break;

                        case 8:     //Unknown control
                            break;

                        case 9:     //Illegal mixer channel index
                            break;

                        case 10:     //Login required
                            if (this.loginAttempt == false)
                            {
                                this.SendLogin();
                                this.loginAttempt = true;
                            }
                            else
                            {
                                this.SendDebug("The login attempt failed - check the username/pass to make sure its correct");
                                this.badLogin = true;
                            }
                            break;
                        }
                        this.SendDebug(string.Format("core error message - {0}-{1}", err.Error.Code, err.Error.Message));
                    }
                }
                catch (Exception e)
                {
                    this.SendDebug(String.Format("Parse internal error: \r\n--------MESSAGE---------\r\n{0}\r\n--------TRACE---------\r\n{1}\r\n--------ORIGINAL---------\r\n{2}\r\n---------------------\r\n", e.Message, e.StackTrace, _returnString));
                    this.responseQueueTimer = new CTimer(ResponseQueueDequeue, null, 0, 50);
                }
            }
        }