protected override void DeserializeElement(System.Xml.XmlReader reader, bool serializeCollectionKey)
        {
            if (reader.HasAttributes && reader.MoveToFirstAttribute())
            {
                do
                {
                    var attrName  = reader.LocalName;
                    var attrValue = reader.Value;

                    Configs[attrName] = attrValue;
                } while (reader.MoveToNextAttribute());
            }

            //base.DeserializeElement(reader, serializeCollectionKey);
        }
Exemplo n.º 2
0
        public static IObjectList <T> ImportFromXML <T>(System.Xml.XmlReader reader, Siaqodb siaqodb)
        {
            ObjectTable obTable = new ObjectTable();

            reader.Read();
            reader.ReadStartElement("SiaqodbObjects");
            SqoTypeInfo            ti         = siaqodb.GetSqoTypeInfo <T>();
            bool                   colFinish  = false;
            ObjectRow              currentRow = null;
            int                    index      = 0;
            Dictionary <int, Type> members    = new Dictionary <int, Type>();

            while (reader.Read())
            {
                if (reader.IsStartElement() && reader.Name == "objects")
                {
                    colFinish = true;
                }

                if (reader.IsStartElement() && !colFinish)
                {
                    reader.MoveToFirstAttribute();
                    //string type = reader.Value;
                    Type t = Type.GetType(reader.Value);
                    reader.MoveToElement();

                    reader.ReadStartElement();
                    string columnName = reader.ReadContentAsString();
                    if (columnName == "OID")
                    {
                        throw new SiaqodbException("OID is set only internally, cannot be imported");
                    }
                    obTable.Columns.Add(columnName, index);
                    if (t.IsGenericType())
                    {
                        Type genericTypeDef = t.GetGenericTypeDefinition();
                        if (genericTypeDef == typeof(Nullable <>))
                        {
                            t = t.GetGenericArguments()[0];
                        }
                    }
                    members.Add(index, t);
                    index++;
                }
                if (reader.IsStartElement() && reader.Name == "object")
                {
                    currentRow = obTable.NewRow();
                    obTable.Rows.Add(currentRow);
                    index = 0;
                }
                if (reader.IsStartElement() && reader.Name == "memberValue")
                {
                    ReadMemberValue(currentRow, reader, index, members);
                    index++;
                    while (reader.Name == "memberValue")
                    {
                        ReadMemberValue(currentRow, reader, index, members);
                        index++;
                    }
                }
            }
            return(ObjectTableHelper.CreateObjectsFromTable <T>(obTable, ti));
        }
        /// <summary>
        /// Identifies the commands exposed by a bundle represented by the "packageZipFilePath"
        /// </summary>
        /// <param name="packageZipFilePath">Path to the zip file of the bundle</param>
        /// <param name="localCommands">Returns the local commands identified from packagecontents.xml</param>
        /// <param name="globalCommands">Returns the global commands identified from packagecontents.xml</param>
        public static void FindListedCommands(String packageZipFilePath, ref StringCollection localCommands, ref StringCollection globalCommands)
        {
            String tempPath = System.IO.Path.GetTempPath();

            if (File.Exists(packageZipFilePath))
            {
                using (System.IO.Compression.ZipArchive za = System.IO.Compression.ZipFile.OpenRead(packageZipFilePath))
                {
                    foreach (ZipArchiveEntry entry in za.Entries)
                    {
                        if (entry.FullName.EndsWith("PackageContents.xml", StringComparison.OrdinalIgnoreCase))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(tempPath, entry.FullName)));
                            String packageContentsXmlFilePath = Path.Combine(tempPath, entry.FullName);

                            if (File.Exists(packageContentsXmlFilePath))
                            {
                                File.Delete(packageContentsXmlFilePath);
                            }

                            entry.ExtractToFile(packageContentsXmlFilePath);

                            localCommands.Clear();
                            globalCommands.Clear();

                            System.IO.TextReader tr = new System.IO.StreamReader(packageContentsXmlFilePath);
                            using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(tr))
                            {
                                while (reader.ReadToFollowing("Command"))
                                {
                                    reader.MoveToFirstAttribute();
                                    if (reader.Name.Equals("Local"))
                                    {
                                        localCommands.Add(reader.Value);
                                    }
                                    else if (reader.Name.Equals("Global"))
                                    {
                                        globalCommands.Add(reader.Value);
                                    }

                                    while (reader.MoveToNextAttribute())
                                    {
                                        if (reader.Name.Equals("Local"))
                                        {
                                            localCommands.Add(reader.Value);
                                        }
                                        else if (reader.Name.Equals("Global"))
                                        {
                                            globalCommands.Add(reader.Value);
                                        }
                                    }
                                }
                            }
                            tr.Close();

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public DataTable GetProjectTable(string subFolder)
        {
            DataTable table = new DataTable();

            table.Columns.Add(new DataColumn("TemplateName", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("TemplateDescription", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("TemplatePath", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("TemplateCreateDate", System.Type.GetType("System.String")));

            table.Columns.Add(new DataColumn("Name", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("Location", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("Description", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("EpiVersion", System.Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("CreateDate", System.Type.GetType("System.String")));
            DataRow row;

            string projectFolderPath = Path.Combine(templatesPath, subFolder);

            if (Directory.Exists(projectFolderPath) != true)
            {
                return(table);
            }

            String[] projectTemplates = GetFiles(projectFolderPath, "*.xml;*.eit");

            foreach (string path in projectTemplates)
            {
                row = table.NewRow();

                try
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(path))
                    {
                        while (reader.ReadToFollowing("Template"))
                        {
                            if (reader.MoveToFirstAttribute())
                            {
                                AddAttributeToProjectTableRow(row, reader);

                                while (reader.MoveToNextAttribute())
                                {
                                    AddAttributeToProjectTableRow(row, reader);
                                }

                                while (reader.ReadToFollowing("Project"))
                                {
                                    if (reader.MoveToFirstAttribute())
                                    {
                                        if (table.Columns.Contains(reader.Name))
                                        {
                                            row[reader.Name] = reader.Value;
                                        }

                                        while (reader.MoveToNextAttribute())
                                        {
                                            if (table.Columns.Contains(reader.Name))
                                            {
                                                row[reader.Name] = reader.Value;
                                            }
                                        }
                                    }
                                }

                                row["TemplatePath"] = path;
                                table.Rows.Add(row);
                            }
                        }
                    }
                }
                catch { }
            }

            return(table);
        }
        private void AddSchemaDataAttributes(string _kmlURL, GraphicCollection graphics)
        {
            try
            {
                Dictionary <string, Dictionary <string, string> > extendedData = new Dictionary <string, Dictionary <string, string> >();

                using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(_kmlURL))
                {
                    while (reader.ReadToFollowing("Placemark"))
                    {
                        string description = string.Empty;
                        Dictionary <string, string> extendedData_SimpleData = new Dictionary <string, string>();

                        if (reader.ReadToFollowing("description"))
                        {
                            description = reader.ReadElementString();
                        }

                        if (reader.ReadToFollowing("SimpleData"))
                        {
                            while (reader.ReadToNextSibling("SimpleData"))
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    extendedData_SimpleData.Add(reader.Value, reader.ReadElementString());
                                }
                            }
                        }

                        if (extendedData.ContainsKey(description) == false)
                        {
                            extendedData.Add(description, extendedData_SimpleData);
                        }
                    }
                }

                foreach (Graphic graphic in graphics)
                {
                    if (graphic.Attributes.ContainsKey("name"))
                    {
                        string name        = (string)graphic.Attributes["name"];
                        string description = (string)graphic.Attributes["description"];

                        if (graphic.Attributes.ContainsKey("extendedData") == false)
                        {
                            graphic.Attributes.Add("extendedData", new List <KmlExtendedData>());
                        }

                        if (extendedData.ContainsKey(description))
                        {
                            foreach (KeyValuePair <string, string> kvp in extendedData[description])
                            {
                                KmlExtendedData datum = new KmlExtendedData();
                                datum.DisplayName = kvp.Key;
                                datum.Name        = kvp.Key;
                                datum.Value       = kvp.Value;
                                ((List <KmlExtendedData>)graphic.Attributes["extendedData"]).Add(datum);
                            }
                        }
                    }
                }
            }
            catch { }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parses an instance of the specified type from the specified stream
        /// </summary>
        public object Parse(System.Xml.XmlReader s, Type useType, Type currentInteractionType, XmlIts1FormatterParseResult resultContext)
        {
            ConstructorInfo ci = useType.GetConstructor(Type.EmptyTypes);

            if (ci == null)
            {
                throw new InvalidOperationException(String.Format("Cannot create an instance of type '{0}' as it defines no default constructor", useType.FullName));
            }

            // Create the instance
            object instance = ci.Invoke(null);

            PropertyInfo[] properties = useType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            // Move the reader to the first attribute
            if (s.MoveToFirstAttribute())
            {
                // Now we read the attributes and match with the properties
                do
                {
#if WINDOWS_PHONE
                    PropertyInfo pi = properties.Find(o => o.GetCustomAttributes(true).Count(pa => pa is PropertyAttribute && (pa as PropertyAttribute).Name == s.LocalName) > 0);
#else
                    PropertyInfo pi = Array.Find <PropertyInfo>(properties, o => o.GetCustomAttributes(true).Count(pa => pa is PropertyAttribute && (pa as PropertyAttribute).Name == s.LocalName) > 0);
#endif
                    // Can we set the PI?
                    if (s.LocalName == "ITSVersion" && s.Value != "XML_1.0")
                    {
                        throw new System.InvalidOperationException(System.String.Format("This formatter can only parse XML_1.0 structures. This structure claims to be '{0}'.", s.Value));
                    }
                    else if (s.Prefix == "xmlns" || s.LocalName == "xmlns" || s.LocalName == "ITSVersion" || s.NamespaceURI == XmlIts1Formatter.NS_XSI)
                    {
                        continue;
                    }
                    else if (pi == null)
                    {
                        resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("@{0}", s.LocalName), s.NamespaceURI, s.ToString(), null));
                        continue;
                    }

                    var paList = pi.GetCustomAttributes(typeof(PropertyAttribute), true); // property attributes

                    // VAlidate list of PA
                    if (paList == null || paList.Length != 1)
                    {
                        resultContext.AddResultDetail(new ResultDetail(ResultDetailType.Warning, String.Format("Invalid number of PropertyAttributes on property '{0}', ignoring", pi.Name), s.ToString(), null));
                        continue; // not a property to be parsed
                    }

                    if (pi.GetSetMethod() == null)
                    {
                        if (!Util.ToWireFormat(pi.GetValue(instance, null)).Equals(s.Value))
                        {
                            resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(s.Value, pi.GetValue(instance, null).ToString(), true, s.ToString()));
                        }
                    }
                    else if (!String.IsNullOrEmpty((paList[0] as PropertyAttribute).FixedValue))
                    {
                        if (!(paList[0] as PropertyAttribute).FixedValue.Equals(s.Value))
                        {
                            resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(s.Value, (paList[0] as PropertyAttribute).FixedValue, false, s.ToString()));
                            pi.SetValue(instance, Util.FromWireFormat(s.Value, pi.PropertyType), null);
                        }
                    }
                    else
                    {
                        pi.SetValue(instance, Util.FromWireFormat(s.Value, pi.PropertyType), null);
                    }
                }while (s.MoveToNextAttribute());
                s.MoveToElement();
            }

            // Nil?
            // BUG: Fixed, xsi:nil may also have a null-flavor
            String nil = s.GetAttribute("nil", XmlIts1Formatter.NS_XSI);
            if (!String.IsNullOrEmpty(nil) && Convert.ToBoolean(nil))
            {
                return(instance);
            }


            // Is reader at an empty element
            if (s.IsEmptyElement)
            {
                return(instance);
            }

            // Read content
            string currentElementName = s.LocalName,
                   lastElementRead    = s.LocalName;
            while (true)
            {
                // End of stream or item not read
                if (lastElementRead == s.LocalName && !s.Read())
                {
                    break;
                }

                lastElementRead = s.LocalName;

                // Element is end element and matches the starting element namd
                if (s.NodeType == System.Xml.XmlNodeType.EndElement && s.LocalName == currentElementName)
                {
                    break;
                }
                // Element is an end element
                //else if (s.NodeType == System.Xml.XmlNodeType.EndElement)
                //    currentDepth--;
                // Element is a start element
                else if (s.NodeType == System.Xml.XmlNodeType.Element)
                {
                    // Get the element choice property
#if WINDOWS_PHONE
                    PropertyInfo pi = properties.Find(o => o.GetCustomAttributes(true).Count(a =>
                                                                                             a is PropertyAttribute &&
                                                                                             (a as PropertyAttribute).Name == s.LocalName &&
                                                                                             ((a as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) > 0);
#else
                    PropertyInfo pi = Array.Find(properties, o => o.GetCustomAttributes(true).Count(a =>
                                                                                                    a is PropertyAttribute &&
                                                                                                    (a as PropertyAttribute).Name == s.LocalName &&
                                                                                                    ((a as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) > 0);
#endif
                    if (pi == null)
                    {
                        resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                        continue;
                    }

                    // Get the property attribute that defined the choice
#if WINDOWS_PHONE
                    PropertyAttribute pa = pi.GetCustomAttributes(true).Find(p =>
                                                                             p is PropertyAttribute &&
                                                                             (p as PropertyAttribute).Name == s.LocalName &&
                                                                             ((p as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) as PropertyAttribute;
#else
                    PropertyAttribute pa = Array.Find(pi.GetCustomAttributes(true), p =>
                                                      p is PropertyAttribute &&
                                                      (p as PropertyAttribute).Name == s.LocalName &&
                                                      ((p as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) as PropertyAttribute;
#endif
                    // Can we set the PI?
                    if (pi == null || !pi.CanWrite)
                    {
                        continue;
                    }

                    // Now time to set the PI
                    if (String.IsNullOrEmpty(s.GetAttribute("specializationType")) && s is MARC.Everest.Xml.XmlStateReader && (this.Host.Settings & SettingsType.AllowFlavorImposing) == SettingsType.AllowFlavorImposing)
                    {
                        (s as MARC.Everest.Xml.XmlStateReader).AddFakeAttribute("specializationType", pa.ImposeFlavorId);
                    }

                    // Cannot deserialize this
                    if (pa.Type == null && pi.PropertyType == typeof(System.Object))
                    {
                        resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, pi.Name, pa.NamespaceUri, s.ToString(), null));
                    }
                    // Simple deserialization if PA type has IGraphable or PI type has IGraphable and PA type not specified
                    else if (pi.GetSetMethod() != null &&
                             (pa.Type != null && pa.Type.GetInterface(typeof(IGraphable).FullName, false) != null) ||
                             (pa.Type == null && pi.PropertyType.GetInterface(typeof(IGraphable).FullName, false) != null))
                    {
                        object tempFormat = Host.ParseObject(s, pa.Type ?? pi.PropertyType, currentInteractionType, resultContext);
                        if (!String.IsNullOrEmpty(pa.FixedValue) && !pa.FixedValue.Equals(Util.ToWireFormat(tempFormat)) && pa.PropertyType != PropertyAttribute.AttributeAttributeType.Traversable)
                        {
                            resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(Util.ToWireFormat(tempFormat), pa.FixedValue, s.ToString()));
                        }
                        pi.SetValue(instance, Util.FromWireFormat(tempFormat, pa.Type ?? pi.PropertyType), null);
                    }
                    // Call an Add method on a collection type
                    else if (pi.PropertyType.GetMethod("Add") != null) // Collection type
                    {
                        pi.PropertyType.GetMethod("Add").Invoke(pi.GetValue(instance, null), new object[] {
                            Util.FromWireFormat(Host.ParseObject(s, pi.PropertyType.GetGenericArguments()[0], currentInteractionType, resultContext), pi.PropertyType.GetGenericArguments()[0])
                        });
                    }
                    // Call the ParseXML custom function on object
                    else if (pi.GetSetMethod() != null && pi.PropertyType.GetMethod("ParseXml", BindingFlags.Public | BindingFlags.Static) != null)
                    {
                        pi.SetValue(instance, pi.PropertyType.GetMethod("ParseXml").Invoke(instance, new object[] { s }), null);
                    }
                    // Property type is a simple string
                    else if (pi.GetSetMethod() != null && pi.PropertyType == typeof(string)) // Read content...
                    {
                        pi.SetValue(instance, Util.FromWireFormat(s.ReadInnerXml(), typeof(String)), null);
                    }
                    // No Set method is used, fixed value?
                    else
                    {
                        object tempFormat = Host.ParseObject(s, pa.Type ?? pi.PropertyType, currentInteractionType, resultContext);
                        if (tempFormat.ToString() != pi.GetValue(instance, null).ToString() && pa.PropertyType != PropertyAttribute.AttributeAttributeType.Traversable)
                        {
                            resultContext.AddResultDetail(new MARC.Everest.Connectors.FixedValueMisMatchedResultDetail(tempFormat.ToString(), pi.GetValue(instance, null).ToString(), s.ToString()));
                        }
                    }
                }
            }

            return(instance);
        }