Example #1
0
    public void ReadXml(XmlReader reader)
    {
        reader.ReadStartElement(); //wrapping element

        this.name = reader.ReadElementContentAsString();
        this.extension = reader.ReadElementContentAsString();

        string tempFileName = Path.GetTempFileName();
        this.streamFileName = tempFileName;
        using (FileStream fs = File.Create(tempFileName))
        {
            byte[] buffer = new byte[1000];
            int bytesRead;
            reader.ReadStartElement();
            do
            {
                bytesRead = reader.ReadContentAsBase64(buffer, 0, buffer.Length);
                fs.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);

            reader.ReadEndElement();
        }

        reader.ReadEndElement(); //wrapping element
    }
Example #2
0
    public void ParseContextSetupReply(XmlReader reader)
    {
        // verify node is "context_setup_reply
        if (reader.Name == "context_setup_reply")
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "apiversion")
                {
                    csr.apiversion = reader.ReadElementContentAsString();
                    //UnityEngine.Debug.Log("apiversion=" + csr.apiversion);
                }
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "setup_request_status")
                {
                    csr.setup_request_status = reader.ReadElementContentAsInt();
                    //UnityEngine.Debug.Log("setup_request_status=" + csr.setup_request_status);
                }
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "context_uid")
                {
                    csr.context_uid = reader.ReadElementContentAsString();
					
#if SHOW_INIT
                    QuickInfoMsg msg = new QuickInfoMsg();
                    msg.title = "NLU STATUS";
                    msg.text = "NLU Initialized : " + CmdTime + " seconds";
                    msg.timeout = 2.0f;
                    QuickInfoDialog.GetInstance().PutMessage(msg);
#endif

                    Initialized = true;

                    //UnityEngine.Debug.Log("context_uid=" + csr.context_uid);
                }
            }
        }
    }
        public static void ReadObjectProperties(XmlReader reader, object obj, PropertyConversionHandler handler = null)
        {
            // Build property lookup table
            PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
            Dictionary<string, PropertyInfo> propHash = new Dictionary<string, PropertyInfo>(props.Length);
            foreach (var pi in props)
                if (!Attribute.IsDefined(pi, typeof(XmlIgnoreAttribute), false))
                    propHash.Add(GetPropertyElementName(pi), pi);

            while (reader.MoveToContent() == System.Xml.XmlNodeType.Element)
            {
                PropertyInfo pi;
                if (propHash.TryGetValue(reader.LocalName, out pi))
                {
                    if (IsStandardType(pi.PropertyType))
                    {
                        object value = null;
                        if (pi.PropertyType.IsEnum)
                            value = Enum.Parse(pi.PropertyType, reader.ReadElementContentAsString());
                        else
                            value = reader.ReadElementContentAs(pi.PropertyType, null);

                        if (handler != null)
                            handler(pi, obj, ref value);

                        pi.SetValue(obj, value, null);
                    }
                    else
                    {
                        ReadObject(reader, pi.GetValue(obj, null));
                    }
                }
                else
                {
                    reader.Skip();
                    reader.MoveToContent();
                }
            }
        }
Example #4
0
                void ParseHeaderElement( XmlReader reader, float parentWidth, float parentHeight, uint? parentBGColor, out PlatformLabel element, ref RectangleF elementBounds, ref Styles.Style defaultStyle )
                {
                    element = PlatformLabel.Create( );

                    // header elements are weird with styles. We don't want any of our parent's styles,
                    // so we create our own and mix that with our defaults
                    Styles.Style elementStyle = new Styles.Style( );
                    elementStyle.Initialize( );
                    elementStyle.mBackgroundColor = parentBGColor.HasValue ? parentBGColor.Value : 0; //one exception is background color. We do want to inherit that.
                    Styles.Style.ParseStyleAttributesWithDefaults( reader, ref elementStyle, ref defaultStyle );

                    // Note: Margins and padding are not supported by the individual elements of the header.

                    element.SetFont( elementStyle.mFont.mName, elementStyle.mFont.mSize.Value );
                    element.TextColor = elementStyle.mFont.mColor.Value;

                    if( elementStyle.mBackgroundColor.HasValue )
                    {
                        element.BackgroundColor = elementStyle.mBackgroundColor.Value;
                    }

                    element.Bounds = elementBounds;

                    // get text
                    switch( elementStyle.mTextCase )
                    {
                        case Styles.TextCase.Upper:
                        {
                            element.Text = reader.ReadElementContentAsString( ).ToUpper( );
                            break;
                        }

                        case Styles.TextCase.Lower:
                        {
                            element.Text = reader.ReadElementContentAsString( ).ToLower( );
                            break;
                        }

                        case Styles.TextCase.Normal:
                        {
                            element.Text = reader.ReadElementContentAsString( );
                            break;
                        }
                    }
                    element.SizeToFit( );

                    // horizontally position the controls according to their
                    // requested alignment
                    Styles.Alignment controlAlignment = elementStyle.mAlignment.Value;

                    // adjust by our position
                    float xAdjust = 0;
                    switch( controlAlignment )
                    {
                        case Styles.Alignment.Center:
                        {
                            xAdjust = elementBounds.X + ( ( parentWidth / 2 ) - ( element.Bounds.Width / 2 ) );
                            element.TextAlignment = TextAlignment.Center;
                            break;
                        }
                        case Styles.Alignment.Right:
                        {
                            xAdjust = elementBounds.X + ( parentWidth - element.Bounds.Width );
                            element.TextAlignment = TextAlignment.Right;
                            break;
                        }
                        case Styles.Alignment.Left:
                        {
                            xAdjust = elementBounds.X;
                            element.TextAlignment = TextAlignment.Left;
                            break;
                        }
                    }

                    // adjust position
                    element.Position = new PointF( elementBounds.X + xAdjust, elementBounds.Y );
                }
Example #5
0
 public void ReadXml(XmlReader reader)
 {
     _Value = new Uri(reader.ReadElementContentAsString());
 }
        public static ushort ReadFile()
        {
            ErrorLog.Notice(String.Format("Checking For SmartThings Credentials File"));
            bool success = false;
            int isRead = 0;
            FileStream myFS = null;
            XmlReader myXMLReader = null;
            myCC.Enter(); // Will not finish, until you have the Critical Section
            try
            {
                //Check if the File Exists
                if (!Crestron.SimplSharp.CrestronIO.File.Exists(String.Format("\\NVRAM\\{0}\\SmartThings\\Credentials.xml", InitialParametersClass.ProgramIDTag)))
                {
                    ErrorLog.Error(String.Format("SmartThings Credentials File Not Found\n"));
                    ErrorLog.Error("Please Re Run the Authentication Sequence");
                    isRead = 1;
                }

                //File was Found, Now Read It.
                if (isRead == 0)
                {
                    myFS = new FileStream(String.Format("\\NVRAM\\{0}\\SmartThings\\Credentials.xml", InitialParametersClass.ProgramIDTag), FileMode.Open);
                    myXMLReader = new XmlReader(myFS);
                    myXMLReader.Read();
                    while (!myXMLReader.EOF)
                    {
                        if (myXMLReader.NodeType == XmlNodeType.Element)
                        {
                            switch (myXMLReader.Name.ToUpper())
                            {
                                case "CLIENTID":
                                    {
                                        string sTemp = myXMLReader.ReadElementContentAsString();
                                        if (SmartThingsReceiver.ClientID != sTemp)
                                        {
                                            ErrorLog.Error("SmartThings Credential File Does Not Match the Client ID provided in the Program!");
                                            ErrorLog.Error("Please Re Run the Authentication Sequence");
                                            ErrorLog.Notice("Module = {0}, File = {1}", ClientID, sTemp);
                                            break;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                case "AUTHCODE":
                                    {
                                        SmartThingsReceiver.AuthCode = myXMLReader.ReadElementContentAsString();
                                        break;
                                    }
                                case "ACCESSTOKEN":
                                    {
                                        SmartThingsReceiver.AccessToken = myXMLReader.ReadElementContentAsString();
                                        break;
                                    }
                                case "INSTALLATIONURL":
                                    {
                                        SmartThingsReceiver.InstallationURL = myXMLReader.ReadElementContentAsString();
                                        break;
                                    }
                               

                                default:
                                    {
                                        myXMLReader.Read();
                                        break;
                                    }
                            }
                        }
                        else
                        {
                            myXMLReader.Read();
                        }
                    }
                    success = true;
                    Authorized = 1;

                }
                else
                {
                    success = true;
                }
            }
            catch (Exception e)
            {
                //Crestron.SimplSharp.ErrorLog.Error(String.Format("ReadFile Error: {0}\n", e.Message));
                success = false;
            }
            finally
            {
                if (myXMLReader != null)
                    myXMLReader.Close();
                if (myFS != null)
                    myFS.Close();
                myCC.Leave();
            }
            if (success)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }