Ejemplo n.º 1
0
        public static string ProcessRegisterXml(string xml)
        {
            string message = "";
            bool error = false;

            try
            {
                // Load the result into an XML document
                XmlDocument result = new XmlDocument();
                result.LoadXml(xml);
                
                // Test the XML
                if (result.DocumentElement.Attributes["code"].Value == "READY")
                {
                    // Get the config element
                    if (result.DocumentElement.ChildNodes.Count <= 0)
                        throw new Exception("Configuration not set for this display");

                    // Hash after removing the date
                    result.DocumentElement.Attributes["date"].Value = "";
                    string md5 = Hashes.MD5(result.OuterXml);

                    if (md5 == ApplicationSettings.Default.Hash)
                        return result.DocumentElement.Attributes["message"].Value;

                    foreach (XmlNode node in result.DocumentElement.ChildNodes)
                    {
                        // Are we a commands node?
                        if (node.Name == "commands")
                        {
                            List<Command> commands = new List<Command>();

                            foreach (XmlNode commandNode in node.ChildNodes)
                            {
                                Command command = new Command();
                                command.Code = commandNode.Name;
                                command.CommandString = commandNode.SelectSingleNode("commandString").InnerText;
                                command.Validation = commandNode.SelectSingleNode("validationString").InnerText;

                                commands.Add(command);
                            }

                            // Store commands
                            ApplicationSettings.Default.Commands = commands;
                        }
                        else
                        {
                            Object value = node.InnerText;

                            switch (node.Attributes["type"].Value)
                            {
                                case "int":
                                    value = Convert.ToInt32(value);
                                    break;

                                case "double":
                                    value = Convert.ToDecimal(value);
                                    break;

                                case "string":
                                case "word":
                                    value = node.InnerText;
                                    break;

                                case "checkbox":
                                    value = (node.InnerText == "0") ? false : true;
                                    break;

                                default:
                                    message += String.Format("Unable to set {0} with value {1}", node.Name, value) + Environment.NewLine;
                                    continue;
                            }

                            // Match these to settings
                            try
                            {
                                if (ApplicationSettings.Default[node.Name] != null)
                                {
                                    value = Convert.ChangeType(value, ApplicationSettings.Default[node.Name].GetType());
                                }

                                ApplicationSettings.Default[node.Name] = value;
                            }
                            catch
                            {
                                error = true;
                                message += "Invalid Configuration Option from CMS [" + node.Name + "]" + Environment.NewLine;
                            }
                        }
                    }

                    // Store the MD5 hash and the save
                    ApplicationSettings.Default.Hash = (error) ? "0" : md5;
                    ApplicationSettings.Default.Save();
                }
                else
                {
                    message += result.DocumentElement.Attributes["message"].Value;
                }

                if (string.IsNullOrEmpty(message))
                    message = result.DocumentElement.Attributes["message"].Value;
            }
            catch (Exception ex)
            {
                message += ex.Message;
            }

            return message;
        }
Ejemplo n.º 2
0
 public Rs232Command(Command command)
 {
     _command = command;
 }