예제 #1
0
        private static Entity ReadRow(Entity parent, System.Xml.XmlTextReader r)
        {
            if (parent != null && r.AttributeCount <= 1) //tabular section, no attributes or "key"
            {
                String tsName = r.Name;

                if (r.MoveToFirstAttribute())
                {
                    if (r.Name.ToLower().Equals("key")) //only key attrbute is allowed
                    {
                        parent.AddTabularSection(tsName, r.Value);
                    }
                    else
                    {
                        throw new Exception(String.Format("Invalid tabular section attribute '{0}'", r.Name));
                    }
                }
                else
                {
                    parent.AddTabularSection(tsName);
                }

                return(parent);
            }
            else
            {
                Entity entity = new Entity(r.Depth);
                if (r.MoveToFirstAttribute())
                {
                    do
                    {
                        String name = r.Name;
                        r.ReadAttributeValue();
                        entity.Attributes.Add(name, r.ReadContentAsString());
                    }while (r.MoveToNextAttribute());
                }

                if (parent != null)
                {
                    parent.CurrentTabularSection.AddEntity(entity);
                    return(parent);
                }
                else
                {
                    return(entity);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// deserialize xml document to name and description and optionally fill stream with content
        /// </summary>
        /// <param name="xml">xml containing data</param>
        /// <param name="name">Name attribute in xml</param>
        /// <param name="description">description attribute</param>
        /// <param name="outputStream">null if no content is not required</param>
        public static void XmlToTempFile(string xml, string tmpFilePath, out string name, out string description, out FluidTrade.Reporting.Interfaces.IStaticReportTranslation translator)
        {
            Stream outputStream = null;

            if (string.IsNullOrEmpty(tmpFilePath) == false)
            {
                outputStream = File.Open(tmpFilePath, FileMode.CreateNew);
            }
            name        = null;
            description = null;
            string base64File = null;
            string base64TranslationContent = null;

            translator = null;
            //create the xmlReader to walk the xml doc
            using (StringReader stringReader = new StringReader(xml))
            {
                using (System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(stringReader))
                {
                    xmlReader.WhitespaceHandling = System.Xml.WhitespaceHandling.Significant;
                    //read to get to the first node
                    xmlReader.Read();

                    //get the name and description attributes
                    name        = xmlReader.GetAttribute(Name);
                    description = xmlReader.GetAttribute(Description);


                    if (outputStream == null)
                    {
                        return;                        //dont need to do anymore
                    }
                    //get to the content
                    xmlReader.Read();
                    base64File = xmlReader.ReadElementContentAsString();

                    //get to the translator
                    if (xmlReader.NodeType != System.Xml.XmlNodeType.EndElement)
                    {
                        xmlReader.Read();
                        base64TranslationContent = xmlReader.ReadContentAsString();
                    }
                    xmlReader.ReadEndElement();
                }
            }

            //if no outputStream or no content in xml then nothing left to do
            if (outputStream == null || string.IsNullOrEmpty(base64File))
            {
                return;
            }

            //convert the content to bytes
            Byte[] bytes = Convert.FromBase64String(base64File);

            //write the bytes to the stream
            using (BinaryWriter binWriter = new BinaryWriter(outputStream))
            {
                binWriter.Write(bytes);
                binWriter.Flush();
            }


            if (string.IsNullOrEmpty(base64TranslationContent) == false)
            {
                //convert the content to bytes
                Byte[] translationBytes = Convert.FromBase64String(base64TranslationContent);

                System.Reflection.Assembly translationAssembly = AppDomain.CurrentDomain.Load(translationBytes);
                Type[] types = translationAssembly.GetTypes();
                foreach (Type t in types)
                {
                    if (t.GetInterface("FluidTrade.Reporting.Interfaces.IStaticReportTranslation") != null)
                    {
                        translator = Activator.CreateInstance(t) as FluidTrade.Reporting.Interfaces.IStaticReportTranslation;
                        break;
                    }
                }
            }
        }