コード例 #1
0
ファイル: FastXmlReader.cs プロジェクト: Fedorm/core-master
        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
ファイル: XmlTableAnalyser.cs プロジェクト: dbshell/dbshell
        public static List<XmlReadInstructions> AnalyseXmlReader(System.Xml.XmlReader reader, bool globalUniqueColumnNames)
        {
            var root = new Node();
            var current = root;

            var resultSets = new Dictionary<string, Node>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        current = current.SubElement(reader.Name);
                        if (reader.HasAttributes)
                        {
                            reader.MoveToFirstAttribute();
                            do
                            {
                                current.Attribute(reader.Name);
                            } while (reader.MoveToNextAttribute());
                            reader.MoveToElement();
                        }
                        if (current.CurrentCount > 1)
                        {
                            string xpath = current.AbsXPath;
                            if (!resultSets.ContainsKey(xpath))
                            {
                                resultSets[xpath] = current;
                                current.IsRepetetive = true;
                            }
                        }
                        if (reader.IsEmptyElement) current = current.Parent;
                        break;
                    case XmlNodeType.Text:
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            current.HasText = true;
                        }
                        break;
                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.Comment:
                        continue;
                    case XmlNodeType.EndElement:
                        current = current.Parent;
                        break;
                }
            }

            // remove repetetive parents. Remains only innermost repetetives
            foreach (var resultSet in resultSets.Values.ToList())
            {
                var node = resultSet;
                node = node.Parent;
                while (node != null && !node.IsRepetetive) node = node.Parent;
                if (node != null)
                {
                    resultSets.Remove(node.AbsXPath);
                    node.IsRepetetive = false;
                }
            }

            if (!resultSets.Any())
            {
                resultSets["/"] = root;
            }

            var res = new List<XmlReadInstructions>();
            var addedColumns = new HashSet<string>();
            var collectionNames = new HashSet<string>();
            foreach (var resultSet in resultSets.Values)
            {
                var instruction = new XmlReadInstructions();
                instruction.XPath = resultSet.AbsXPath ?? "/";

                string collectionName = resultSet.Name;
                if (collectionNames.Contains(collectionName))
                {
                    int index = 2;
                    while (collectionNames.Contains(collectionName + index)) index++;
                    collectionName = collectionName + index;
                }
                instruction.CollectionName = collectionName;

                if (!globalUniqueColumnNames) addedColumns.Clear();

                CollectColumns(instruction, root, addedColumns, resultSet);
                if (resultSet != root)
                {
                    CollectColumns(instruction, resultSet, addedColumns, resultSet);
                }

                res.Add(instruction);
            }

            return res;
        }
コード例 #3
0
ファイル: Template.cs プロジェクト: NALSS/epiinfo-82474
        private View CreateView(System.Xml.XmlReader reader)
        {
            View newView = new View(mediator.Project);

            if (reader.MoveToFirstAttribute())
            {
                AddViewAttributeToView(reader.Name, reader.Value, newView);

                while (reader.MoveToNextAttribute())
                {
                    AddViewAttributeToView(reader.Name, reader.Value, newView);
                }
            }
            return newView;
        }
コード例 #4
0
        /// <summary>
        /// Returns a key/value pair representing the attributes in the element.
        /// </summary>
        /// <param name="reader">The bufferred xml to analyze.</param>
        /// <returns>A sorted list of the attributes with the name as the key and the value as the value.</returns>
        /// <remarks>Executing this method querries the current node for the attributes without advancing to the next node.</remarks>
        private System.Collections.SortedList GetAttributes(System.Xml.XmlReader reader)
        {
            System.Collections.SortedList _List = new System.Collections.SortedList();

            //FIX: December 9, 2005 - Fix to handle reading attributes from ReadXml routine
            if ((reader.NodeType != System.Xml.XmlNodeType.None) & (reader.MoveToFirstAttribute()))
            {
                do
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Attribute)
                    {
                        _List.Add(reader.Name, reader.Value);
                    }
                }
                while (reader.MoveToNextAttribute() | reader.NodeType != System.Xml.XmlNodeType.Attribute);
            }

            if (reader.NodeType == System.Xml.XmlNodeType.Attribute)
            {
                reader.MoveToElement();
            }

            return _List;
        }
コード例 #5
0
ファイル: Template.cs プロジェクト: NALSS/epiinfo-82474
        private Page CreatePage(System.Xml.XmlReader reader, bool isnewview, out View view)
        {
            Page newPage = new Page();

            if (reader.MoveToFirstAttribute())
            {
                AddPageAttributeToPage(reader.Name, reader.Value, newPage);

                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "Name")
                    {
                        if (!isnewview)
                        {
                            string _name;
                            ShowRenamePageDialog(reader.Value, out _name);
                            if (_name != string.Empty)
                                newPage.Name = _name;
                            else
                            {
                                view = null;
                                return newPage;
                            }
                        }
                        else
                            AddPageAttributeToPage(reader.Name, reader.Value, newPage);
                    }
                    else
                        AddPageAttributeToPage(reader.Name, reader.Value, newPage);
                }
            }

            if (pageIdViewNamePairs.Count == 0)
            {
                view = this.mediator.ProjectExplorer.currentPage.view;
            }
            else
            {
                view = mediator.Project.Views[pageIdViewNamePairs[newPage.Id]];
            }

            newPage.Id = 0;
            newPage.view = view;
            return newPage;
        }
コード例 #6
0
ファイル: Template.cs プロジェクト: NALSS/epiinfo-82474
        private void CreateSourceTable(System.Xml.XmlReader reader)
        {
            string[] columnNames;
            ArrayList names = new ArrayList();
            reader.MoveToAttribute("TableName");
            string codeTableName = reader.Value.ToString();

            DataTable fromXml = new DataTable(codeTableName);
            DataRow rowFromXml;

            reader.ReadToFollowing("Item");

            do
            {
                if (reader.MoveToFirstAttribute())
                {
                    string columnName = reader.Name.Replace("__space__", " ");

                    if (fromXml.Columns.Contains(columnName) == false)
                    {
                        fromXml.Columns.Add(columnName, System.Type.GetType("System.String"));
                    }

                    rowFromXml = fromXml.NewRow();
                    rowFromXml[columnName] = reader.Value;

                    while (reader.MoveToNextAttribute())
                    {
                        columnName = reader.Name.Replace("__space__", " ");
                        if (fromXml.Columns.Contains(columnName) == false)
                        {

                            fromXml.Columns.Add(columnName, System.Type.GetType("System.String"));
                            DataRow tempRow = fromXml.NewRow();
                            tempRow.ItemArray = rowFromXml.ItemArray;
                        }

                        rowFromXml[columnName] = reader.Value;
                    }

                    fromXml.Rows.Add(rowFromXml);
                }
            }
            while (reader.ReadToNextSibling("Item"));

            if (mediator.Project.Metadata.TableExists(codeTableName))
            {
                DataTable existing = mediator.Project.Metadata.GetCodeTableData(codeTableName);

                if (TablesAreDifferent(existing, fromXml))
                {
                    foreach (DataColumn column in fromXml.Columns)
                    {
                        names.Add(column.ColumnName);
                    }
                    columnNames = (string[])names.ToArray(typeof(string));

                    DialogResult replaceWithTemplate = MsgBox.ShowQuestion("A code table with the following name already exists in the database: " + existing + ".  Replace code table with the code table defined in the template?" );

                    if (replaceWithTemplate == DialogResult.Yes)
                    {
                        mediator.Project.Metadata.DeleteCodeTable(codeTableName);
                        mediator.Project.Metadata.CreateCodeTable(codeTableName, columnNames);
                        mediator.Project.Metadata.SaveCodeTableData(fromXml, codeTableName, columnNames);
                    }
                    else
                    {
                        string newCodeTableName = codeTableName;

                        DataSets.TableSchema.TablesDataTable tables = mediator.Project.Metadata.GetCodeTableList();

                        int arbitraryMax = 2048;

                        for (int nameExtension = 1; nameExtension < arbitraryMax; nameExtension++)
                        {
                            foreach (DataRow row in tables)
                            {
                                if (newCodeTableName.ToLower() == ((string)row[ColumnNames.TABLE_NAME]).ToLower())
                                {
                                    newCodeTableName = codeTableName + nameExtension.ToString();
                                    break;
                                }
                            }

                            if (newCodeTableName != codeTableName + nameExtension.ToString())
                            {
                                break;
                            }
                        }

                        _sourceTableRenames.Add(codeTableName, newCodeTableName);
                        mediator.Project.Metadata.CreateCodeTable(newCodeTableName, columnNames);
                        mediator.Project.Metadata.SaveCodeTableData(fromXml, newCodeTableName, columnNames);
                    }
                }
            }
            else
            {
                foreach (DataColumn column in fromXml.Columns)
                {
                    string columnName = column.ColumnName.Replace("__space__", " ");
                    names.Add(columnName);
                }
                columnNames = (string[])names.ToArray(typeof(string));

                mediator.Project.Metadata.CreateCodeTable(codeTableName, columnNames);
                mediator.Project.Metadata.SaveCodeTableData(fromXml, codeTableName, columnNames);
            }
        }
コード例 #7
0
ファイル: IVLFormatter.cs プロジェクト: oneminot/everest
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type ivlType = typeof(IVL<>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Sometimes there can be just a messy, unstructured value inline with this IVL (like in CCDA) so we still need to support that
            MemoryStream leftOvers = new MemoryStream();
            XmlWriter leftoverWriter = XmlWriter.Create(leftOvers);
            leftoverWriter.WriteStartElement(s.LocalName, s.NamespaceURI);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            if (s.MoveToFirstAttribute())
            {
                do
                {
                    switch (s.LocalName)
                    {
                        case "nullFlavor":

                            ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
                            break;
                        case "operator":
                            ivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                            break;
                        case "specializationType":
                            if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                                ((ANY)instance).Flavor = s.GetAttribute("specializationType");
                            break;
                        default:
                            leftoverWriter.WriteAttributeString(s.Prefix, s.LocalName, s.NamespaceURI, s.Value);
                            break;
                    }
                } while (s.MoveToNextAttribute());
                s.MoveToElement();
            }

            // Get property information
            PropertyInfo lowProperty = ivlGenericType.GetProperty("Low"),
                highProperty = ivlGenericType.GetProperty("High"),
                widthProperty = ivlGenericType.GetProperty("Width"),
                centerProperty = ivlGenericType.GetProperty("Center"),
                lowClosedProperty = ivlGenericType.GetProperty("LowClosed"),
                highClosedProperty = ivlGenericType.GetProperty("HighClosed"),
                valueProperty = ivlGenericType.GetProperty("Value");

            // Now process the elements
            #region Elements
            if (!s.IsEmptyElement)
            {

                int sDepth = s.Depth;
                string sName = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "low") // low value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            lowProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            highProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "center") // center
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            centerProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "width") // width
                        {
                            var parseResult = Host.Parse(s, typeof(PQ));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            widthProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            leftoverWriter.WriteNode(s, true);
                            //result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e) // Message validation error
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // Process any leftovers as Value !!!
            try
            {
                leftoverWriter.WriteEndElement();
                leftoverWriter.Flush();
                leftOvers.Seek(0, SeekOrigin.Begin);
                using (XmlReader xr = XmlReader.Create(leftOvers))
                {
                    xr.MoveToContent();
                    if (xr.AttributeCount > 1 || !xr.IsEmptyElement)
                    {
                        bool isNotEmpty = !xr.IsEmptyElement;
                        if (xr.MoveToFirstAttribute())
                            do
                            {
                                isNotEmpty |= xr.Prefix != "xmlns" && xr.LocalName != "xmlns" && xr.NamespaceURI != DatatypeFormatter.NS_XSI;
                            } while (!isNotEmpty && xr.MoveToNextAttribute());
                        xr.MoveToElement();
                        if (isNotEmpty)
                        {
                            var baseResult = base.Parse(xr, result);
                            valueProperty.SetValue(instance, Util.FromWireFormat(baseResult, valueProperty.PropertyType), null);
                        }
                    }
                }
            }
            catch { }
            // Validate
            base.Validate(instance as ANY, s.LocalName, result);

            return instance;
        }
コード例 #8
0
ファイル: Template.cs プロジェクト: NALSS/epiinfo-82474
        private Field CreateFields(System.Xml.XmlReader reader, DataTable metadataSchema, Page page, out int fieldIdFromTemplate)
        {
            DataRow row;
            Field field = null;
            MetaFieldType returnMetaFieldType = MetaFieldType.Text;
            fieldIdFromTemplate = int.MinValue;
            String relatedViewName = string.Empty;

            if (reader.MoveToFirstAttribute())
            {
                row = metadataSchema.NewRow();
                relatedViewName = string.Empty;
                CopyReaderValueToRow(reader, metadataSchema, row);

                while (reader.MoveToNextAttribute())
                {
                    CopyReaderValueToRow(reader, metadataSchema, row);

                    if (reader.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "fieldtypeid")
                    {
                        field = page.CreateField(((MetaFieldType)Int32.Parse(reader.Value)));
                    }

                    if (reader.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "relatedviewname")
                    {
                        relatedViewName = reader.Value.ToString();
                    }
                }

                fieldIdFromTemplate = (int)row["FieldId"];
                field.Name = (string)row["Name"];
                mediator.Canvas.UpdateHidePanel(string.Format("Creating {0} field.", field.Name));

                double controlLeftPercentage = (double)row["ControlLeftPositionPercentage"];
                double controlTopPercentage = (double)row["ControlTopPositionPercentage"];
                double promptLeftPercentage = row["PromptLeftPositionPercentage"] != DBNull.Value ? (double)row["PromptLeftPositionPercentage"] : double.NaN;
                double promptTopPercentage = row["PromptTopPositionPercentage"] != DBNull.Value ? (double)row["PromptTopPositionPercentage"] : double.NaN;

                if(_fieldDrop)
                {
                    double mouseOffsetOver = _fieldDropLocaton.X / (double)mediator.Canvas.PagePanel.Width;
                    double mouseOffsetDown = _fieldDropLocaton.Y / (double)mediator.Canvas.PagePanel.Height;

                    controlLeftPercentage = controlLeftPercentage + mouseOffsetOver;
                    controlTopPercentage = controlTopPercentage + mouseOffsetDown;
                    promptLeftPercentage = promptLeftPercentage + mouseOffsetOver;
                    promptTopPercentage = promptTopPercentage + mouseOffsetDown;
                }

                ((RenderableField)field).PromptText = row["PromptText"] != DBNull.Value ? (string)row["PromptText"] : string.Empty;
                ((RenderableField)field).ControlFont = new System.Drawing.Font(row["ControlFontFamily"].ToString(), float.Parse(row["ControlFontSize"].ToString()), (FontStyle)System.Enum.Parse(typeof(FontStyle), row["ControlFontStyle"].ToString(), true));
                ((RenderableField)field).HasTabStop = (bool)row["HasTabStop"];
                ((RenderableField)field).TabIndex = double.Parse(row["TabIndex"].ToString());

                ((RenderableField)field).ControlHeightPercentage = (double)row["ControlHeightPercentage"];
                ((RenderableField)field).ControlWidthPercentage = (double)row["ControlWidthPercentage"];

                ((RenderableField)field).ControlLeftPositionPercentage = controlLeftPercentage;
                ((RenderableField)field).ControlTopPositionPercentage = controlTopPercentage;

                ((RenderableField)field).Page = page;

                try
                {
                    string fontFamily = row["PromptFontFamily"].ToString();
                    float fontSize;

                    if(float.TryParse(row["PromptFontSize"].ToString(), out fontSize))
                    {
                        ((RenderableField)field).PromptFont = new System.Drawing.Font(fontFamily, fontSize, (FontStyle)System.Enum.Parse(typeof(FontStyle), row["PromptFontStyle"].ToString(), true));
                    }
                }
                catch { }

                if (field is InputFieldWithoutSeparatePrompt)
                {
                    ((InputFieldWithoutSeparatePrompt)field).ShouldRepeatLast = (bool)row["ShouldRepeatLast"];
                    ((InputFieldWithoutSeparatePrompt)field).IsRequired = (bool)row["IsRequired"];
                    ((InputFieldWithoutSeparatePrompt)field).IsReadOnly = (bool)row["IsReadOnly"];
                }

                if (field is InputFieldWithSeparatePrompt)
                {
                    ((InputFieldWithSeparatePrompt)field).PromptLeftPositionPercentage = promptLeftPercentage;
                    ((InputFieldWithSeparatePrompt)field).PromptTopPositionPercentage = promptTopPercentage;

                    ((InputFieldWithSeparatePrompt)field).ShouldRepeatLast = (bool)row["ShouldRepeatLast"];
                    ((InputFieldWithSeparatePrompt)field).IsRequired = (bool)row["IsRequired"];
                    ((InputFieldWithSeparatePrompt)field).IsReadOnly = (bool)row["IsReadOnly"];
                }

                if (field is GridField)
                {
                    ((GridField)field).PromptLeftPositionPercentage = promptLeftPercentage;
                    ((GridField)field).PromptTopPositionPercentage = promptTopPercentage;
                }

                if (field is ImageField)
                {
                    ((ImageField)field).ShouldRetainImageSize = (bool)row["ShouldRetainImageSize"];
                }

                if (field is TextField)
                {
                    if (row["SourceFieldId"] != System.DBNull.Value)
                    {
                        ((TextField)field).SourceFieldId = (int)row["SourceFieldId"];
                    }

                    if (row["MaxLength"] != System.DBNull.Value)
                    {
                        ((TextField)field).MaxLength = (int)(short)row["MaxLength"];
                    }
                }

                if (field is NumberField)
                {
                    if (row["Lower"] != System.DBNull.Value)
                    {
                        ((NumberField)field).Lower = (string)row["Lower"];
                    }
                    if (row["Upper"] != System.DBNull.Value)
                    {
                        ((NumberField)field).Upper = (string)row["Upper"];
                    }
                    if (row["Pattern"] != System.DBNull.Value)
                    {
                        ((NumberField)field).Pattern = (string)row["Pattern"];
                    }
                }

                if (field is DateField)
                {
                    if (row["Lower"] != System.DBNull.Value)
                    {
                        ((DateField)field).Lower = (string)row["Lower"];
                    }
                    if (row["Upper"] != System.DBNull.Value)
                    {
                        ((DateField)field).Upper = (string)row["Upper"];
                    }
                }

                if (field is PhoneNumberField)
                {
                    if (row["Pattern"] != System.DBNull.Value)
                    {
                        ((PhoneNumberField)field).Pattern = (string)row["Pattern"];
                    }
                }

                if (field is OptionField)
                {
                    string list = ((string)row["List"]);

                    if (list.Contains("||"))
                    {
                        list = list.Substring(0, list.IndexOf("||"));
                    }

                    ((OptionField)field).Options = new List<string>(list.Split(Constants.LIST_SEPARATOR));
                    ((OptionField)field).ShowTextOnRight = (bool)row["ShowTextOnRight"];
                    if (row["Pattern"] is String)
                    {
                        ((OptionField)field).Pattern = (string)row["Pattern"];
                    }
                    else
                    {
                        ((OptionField)field).Pattern = string.Empty;
                    }
                }

                if (field is RelatedViewField)
                {
                    View relatedView = null;

                    if (relatedViewName == string.Empty)
                    {
                        int relatedViewId = (int)row["RelatedViewId"];

                        if (viewIdViewNamePairs.ContainsKey(relatedViewId))
                        {
                            relatedViewName = viewIdViewNamePairs[relatedViewId];
                            relatedView = metadata.GetViewByFullName(relatedViewName);
                        }
                    }
                    else
                    {
                        if (viewIdViewNamePairs.ContainsValue(relatedViewName))
                        {
                            relatedView = metadata.GetViewByFullName(relatedViewName);
                        }
                    }

                    if (relatedView != null)
                    {
                        ((RelatedViewField)field).RelatedViewID = relatedView.Id;

                        if (row["RelateCondition"] is String)
                        {
                            ((RelatedViewField)field).Condition = (string)row["RelateCondition"];
                        }
                        else
                        {
                            ((RelatedViewField)field).Condition = string.Empty;
                        }

                        ((RelatedViewField)field).ShouldReturnToParent = (bool)row["ShouldReturnToParent"];
                    }
                }

                if (field is TableBasedDropDownField)
                {
                    string codeTableName = string.Empty;

                    if(row["SourceTableName"] != System.DBNull.Value)
                    {
                        codeTableName = (string)row["SourceTableName"];
                    }

                    if (_sourceTableRenames.ContainsKey(codeTableName))
                    {
                        codeTableName = _sourceTableRenames[codeTableName];
                    }

                    ((TableBasedDropDownField)field).SourceTableName = codeTableName;

                    if (row["CodeColumnName"] != System.DBNull.Value)
                    {
                        ((TableBasedDropDownField)field).CodeColumnName = (string)row["CodeColumnName"];
                    }

                    if (row["TextColumnName"] != System.DBNull.Value)
                    {
                        ((TableBasedDropDownField)field).TextColumnName = (string)row["TextColumnName"];
                    }

                    ((TableBasedDropDownField)field).ShouldSort = (bool)row["Sort"];
                    ((TableBasedDropDownField)field).IsExclusiveTable = (bool)row["IsExclusiveTable"];

                    if (row["RelateCondition"] != System.DBNull.Value && field is DDLFieldOfCodes)
                    {
                        ((Epi.Fields.DDLFieldOfCodes)field).AssociatedFieldInformation = row["RelateCondition"].ToString();
                    }
                }

                if (field is MirrorField)
                {
                    ((FieldWithSeparatePrompt)field).PromptLeftPositionPercentage = promptLeftPercentage;
                    ((FieldWithSeparatePrompt)field).PromptTopPositionPercentage = promptTopPercentage;

                    ((MirrorField)field).SourceFieldId = (int)row["SourceFieldId"];
                }

                if (field is GroupField)
                {
                    if (row["List"] != System.DBNull.Value && row["List"] is string)
                    {
                        ((GroupField)field).ChildFieldNames = (string)row["List"];
                    }
                    if (row["BackgroundColor"] != System.DBNull.Value)
                    {
                        ((GroupField)field).BackgroundColor = Color.FromArgb((int)row["BackgroundColor"]);
                    }
                }

                mediator.Canvas.MainForm.EndBusy();

                if (((RenderableField)field).Page == null)
                {
                }

                string nameTemplate = field.Name;

                mediator.PasteFromTemplate((RenderableField)field);

                if (field.Name != (string)row["Name"])
                {
                    _fieldRenames.Add((string)row["Name"], field.Name);
                }

                DataRow fieldRecordDataRow = _fieldRecord.NewRow();
                fieldRecordDataRow[FieldRecordColumn.NameTemplate.ToString()] = nameTemplate;
                fieldRecordDataRow[FieldRecordColumn.IdTemplate.ToString()] = fieldIdFromTemplate;
                fieldRecordDataRow[FieldRecordColumn.NameCreated.ToString()] = field.Name;
                fieldRecordDataRow[FieldRecordColumn.IdCreated.ToString()] = field.Id;

                _fieldRecord.Rows.Add(fieldRecordDataRow);
            }

            return field;
        }
コード例 #9
0
ファイル: FrmItem.cs プロジェクト: huutruongqnvn/vnecoo01
        /// <summary>
        /// Navigators the node.
        /// </summary>
        /// <param name="nav">The nav.</param>
        /// Created by khoaht at 4:32 PM on 11/25/2011
        private void NavigatorNode(System.Xml.XPath.XPathNavigator nav)
        {
            if (nav.HasAttributes)
            {
                XmlElement element = nav.UnderlyingObject as XmlElement;
                TreeNode tNode = null;
                if (element != null)
                {
                    var node = element.ParentNode;
                    tNode = GetTreeNode(tvTargetXML, node.Name);
                }

                nav.MoveToFirstAttribute();
                AddLinkWithAttribute(nav, tNode);
                if (!nav.MoveToNext() && !nav.MoveToFirstChild()) return;
            }
            if (nav.HasChildren || nav.HasAttributes)
            {
                nav.MoveToFirstChild();
                NavigatorNode(nav);

            }
        }
コード例 #10
0
 public virtual void LoadFromXml(System.Xml.XmlTextReader reader)
 {
     System.Xml.XmlNodeType nt = reader.MoveToContent();
     int depth = reader.Depth;
     bool readok = true;
     if (reader.HasAttributes && reader.Name == TagName)
     {
         readok = reader.MoveToFirstAttribute();
         while (readok)
         {
             LoadPropertiesFromXml(reader);
             readok = reader.MoveToNextAttribute();
         }
     }
     readok = reader.Read();
     while (readok && reader.Depth > depth)
     {
         bool processed = false;
         if (reader.NodeType == System.Xml.XmlNodeType.Element)
         {
             processed = LoadChildrenFromXml(reader);
         }
         if (!processed) readok = reader.Read();
     }
 }
コード例 #11
0
ファイル: RedlineDocument.cs プロジェクト: killbug2004/WSProf
 protected override void ReadAttributes(System.Xml.XmlReader reader)
 {
     if (reader.HasAttributes)
     {
         if (reader.MoveToFirstAttribute())
         {
             do
             {
                 Options.Add(reader.Name, reader.Value);
             } while (reader.MoveToNextAttribute());
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// Считывание текстовых областей для одного кадра
 /// </summary>
 /// <param name="xmlReader">xml - reader</param>
 /// <param name="textRegions">Текстовые области</param>
 /// <param name="frameNumber">Номер кадра</param>
 private static void ReadFrameTextBlocksInformation(System.Xml.XmlReader xmlReader, out List<TextRegion> textRegions,
     out int frameNumber)
 {
     try
     {
         textRegions = new List<TextRegion>();
         xmlReader.MoveToFirstAttribute();
         frameNumber = Convert.ToInt32(xmlReader.Value);
         xmlReader.MoveToNextAttribute();
         int textRegionsNumber = Convert.ToInt32(xmlReader.Value);
         if (textRegionsNumber != 0)
         {
             bool readingFrame = true;
             while (xmlReader.Read() && readingFrame)
             {
                 if (xmlReader.Name == "Frame")
                     readingFrame = false;
                 else if (xmlReader.Name == "TextRegion")
                 {
                     TextRegion textRegion = new TextRegion();
                     while (xmlReader.MoveToNextAttribute())
                     {
                         switch (xmlReader.Name)
                         {
                             case "LeftUpPointIndexI":
                                 textRegion.MinBorderIndexI = Convert.ToInt32(xmlReader.Value);
                                 break;
                             case "LeftUpPointIndexJ":
                                 textRegion.MinBorderIndexJ = Convert.ToInt32(xmlReader.Value);
                                 break;
                             case "RightDownPointIndexI":
                                 textRegion.MaxBorderIndexI = Convert.ToInt32(xmlReader.Value);
                                 break;
                             case "RightDownPointIndexJ":
                                 textRegion.MaxBorderIndexJ = Convert.ToInt32(xmlReader.Value);
                                 break;
                             default:
                                 break;
                         }
                     }
                     textRegions.Add(textRegion);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
コード例 #13
0
ファイル: ReflectFormatter.cs プロジェクト: oneminot/everest
        /// <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;
        }