Ejemplo n.º 1
0
        public override bool MoveToFirstChild()
        {
            // Check whether it has already been set.

            if (xmlNodeInfo.FirstChild != null)
            {
                xmlNodeInfo = xmlNodeInfo.FirstChild;
                return(true);
            }

            switch (xmlNodeInfo.Type)
            {
            case XPathNodeType.Root:
            case XPathNodeType.Element:
            {
                IEnumerator enumerator = xmlNodeInfo.SiteMapNode.ChildNodes.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    XmlNodeInfo xmlChildInfo = new XmlNodeInfo(XPathNodeType.Element, xmlNodeInfo.Root, xmlNodeInfo, enumerator, null, null, enumerator.Current);
                    xmlNodeInfo.FirstChild = xmlChildInfo;
                    xmlNodeInfo            = xmlChildInfo;
                    return(true);
                }
            }

            break;
            }

            return(false);
        }
Ejemplo n.º 2
0
 void NavigateSelection()
 {
     foreach (DataGridViewRow row in resultsGridView.SelectedRows)
     {
         XmlNodeInfo info = (XmlNodeInfo)row.DataBoundItem;
         NavigateTo(info);
         return;
     }
 }
Ejemplo n.º 3
0
 void resultsGridView_DoubleClick(object sender, EventArgs e)
 {
     foreach (DataGridViewRow row in this.resultsGridView.SelectedRows)
     {
         XmlNodeInfo info = (XmlNodeInfo)row.DataBoundItem;
         NavigateTo(info);
         return;
     }
 }
Ejemplo n.º 4
0
        void OnMarkerDeleted(object sender, EventArgs a)
        {
            XmlNodeInfo old = sender as XmlNodeInfo;

            old.MarkerDeleted -= new EventHandler(OnMarkerDeleted);
            old.MarkerChanged -= new EventHandler(OnMarkerChanged);

            this.results.Remove(old);
            this.resultsGridView.Invalidate();
        }
Ejemplo n.º 5
0
 public XmlNodeInfo(object nodeObject)
 {
     root            = this;
     firstSibling    = this;
     type            = XPathNodeType.Element;
     this.nodeObject = nodeObject;
     if (this.nodeObject is SiteMapNode)
     {
         Debug.Assert(this.nodeObject is NavigationSiteMapNode);
     }
 }
Ejemplo n.º 6
0
 public override bool MoveToParent()
 {
     if (xmlNodeInfo == xmlNodeInfo.Root)
     {
         return(false);
     }
     else
     {
         xmlNodeInfo = xmlNodeInfo.Parent;
         return(true);
     }
 }
Ejemplo n.º 7
0
 public override bool MoveToPrevious()
 {
     if (xmlNodeInfo.PreviousSibling == null)
     {
         return(false);
     }
     else
     {
         xmlNodeInfo = xmlNodeInfo.PreviousSibling;
         return(true);
     }
 }
Ejemplo n.º 8
0
        public override bool MoveTo(XPathNavigator other)
        {
            NavigationSiteMapNavigator navigator = other as NavigationSiteMapNavigator;

            if (navigator != null)
            {
                xmlNodeInfo = navigator.xmlNodeInfo;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
 void NavigateTo(XmlNodeInfo info)
 {
     try
     {
         this.currentDocument.Show();
         TextSpan          span = info.CurrentSpan;
         CodeWindowManager mgr  = this.currentDocument.Source.LanguageService.GetCodeWindowManagerForSource(this.currentDocument.Source);
         IVsTextView       view;
         mgr.CodeWindow.GetLastActiveView(out view);
         view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex);
         view.EnsureSpanVisible(span);
     }
     catch { }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Parse(object sender, RoutedEventArgs e)
        {
            if (filePath == "" || savePath == "")
            {
                clsTxt.Text = "请选择文件和输出路径!";
                return;
            }

            xmlInfoList.Clear();
            columnList.Clear();
            warningList.Clear();

            FileStream fs = File.OpenRead(filePath);

            XmlDocument xml = new XmlDocument();

            xml.Load(fs);

            //Console.Write(xml.InnerXml.ToString());
            XmlNode xn = xml.SelectSingleNode("config/table");
            XmlAttributeCollection xc = xn.Attributes;

            saveFileName = xc.GetNamedItem("name").Value + ".bytes";

            className = xc.GetNamedItem("name").Value + "Def";

            excelFilePath = filePath.Substring(0, filePath.LastIndexOf('\\') + 1) + xc.GetNamedItem("ExcelFile").Value;

            xn = xml.SelectSingleNode("config/table/fields");
            for (int i = 0; i < xn.ChildNodes.Count; i++)
            {
                XmlNode node = xn.ChildNodes.Item(i);

                XmlNodeInfo info = new XmlNodeInfo();
                info.codeName  = node.Attributes.GetNamedItem("codename").Value;
                info.excelName = node.Attributes.GetNamedItem("name").Value;
                info.type      = node.Attributes.GetNamedItem("type").Value;

                XmlNode attNode = node.Attributes.GetNamedItem("size");
                if (attNode != null)
                {
                    info.size = Convert.ToInt32(attNode.Value.ToString());
                }

                xmlInfoList.Add(info);
            }

            ReadExcel();
        }
Ejemplo n.º 11
0
 public XmlNodeInfo(XPathNodeType type, XmlNodeInfo root, XmlNodeInfo parent, IEnumerator siblings, XmlNodeInfo firstSibling, XmlNodeInfo previousSibling, object nodeObject)
 {
     this.type            = type;
     this.root            = root;
     this.parent          = parent;
     this.siblings        = siblings;
     this.firstSibling    = firstSibling ?? this;
     this.previousSibling = previousSibling;
     this.nodeObject      = nodeObject;
     Debug.Assert(this.nodeObject != null);
     if (this.nodeObject is SiteMapNode)
     {
         Debug.Assert(this.nodeObject is NavigationSiteMapNode);
     }
 }
Ejemplo n.º 12
0
        private TextSpan GetNodeSpan(XmlNodeInfo info)
        {
            int       line  = info.Line;
            int       col   = info.Column + 1; // skip '<'.
            TokenInfo token = this.currentDocument.Source.GetTokenInfo(line, col);
            TextSpan  span  = new TextSpan();

            if (token != null)
            {
                span.iStartLine  = span.iEndLine = line;
                span.iStartIndex = token.StartIndex;
                span.iEndIndex   = token.EndIndex + 1; // include last character of the token.
            }
            return(span);
        }
Ejemplo n.º 13
0
        public override bool MoveToNext()
        {
            if (xmlNodeInfo.NextSibling != null)
            {
                xmlNodeInfo = xmlNodeInfo.NextSibling;
                return(true);
            }

            if (xmlNodeInfo.Type == XPathNodeType.Element && xmlNodeInfo.Siblings.MoveNext())
            {
                XmlNodeInfo xmlNextNode = new XmlNodeInfo(XPathNodeType.Element, xmlNodeInfo.Root, xmlNodeInfo.Parent, xmlNodeInfo.Siblings, xmlNodeInfo.FirstSibling, xmlNodeInfo, xmlNodeInfo.Siblings.Current);
                xmlNodeInfo.NextSibling = xmlNextNode;
                xmlNodeInfo             = xmlNextNode;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
        public void CreateXmlFile(string strCsvFile1, string strXmlFile2)
        {
            // 从csv 生成xml 配置文件
            //string strCsvFile1 = "ProtocolFiles\\csv\\parameters.csv";
            //string strXmlFile2 = "ProtocolFiles\\master_parameters1.xml";
            DataTable dataTable = CSVFileHelper.OpenCSV(strCsvFile1);

            List <XmlNodeInfo> listNode = new List <XmlNodeInfo>();

            //DataTable dt = dataSet.Tables[0];
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                XmlNodeInfo nodeInfo = new XmlNodeInfo();

                nodeInfo.Index = (i + 1).ToString();

                nodeInfo.DidNum = dataTable.Rows[i][0].ToString();

                nodeInfo.DidDescription = dataTable.Rows[i][1].ToString();

                nodeInfo.ByteNum = dataTable.Rows[i][2].ToString();

                nodeInfo.StrValue = "0";

                nodeInfo.MinValue = dataTable.Rows[i][6].ToString();

                nodeInfo.MaxValue = dataTable.Rows[i][7].ToString();

                nodeInfo.Unit = dataTable.Rows[i][8].ToString();

                nodeInfo.Scale = "0";

                nodeInfo.Conversion = dataTable.Rows[i][9].ToString();

                listNode.Add(nodeInfo);
            }


            XmlHelper.SaveAsXmlFileFromCsv_XmlNodeInfo(strXmlFile2, "master_parameters_config", "master_adjust_node", listNode);
        }
Ejemplo n.º 15
0
 internal NavigationSiteMapNavigator(NavigationSiteMapNode node)
 {
     xmlNodeInfo = new XmlNodeInfo(node);
     nameTable   = new NameTable();
     nameTable.Add(String.Empty);
 }
Ejemplo n.º 16
0
        private void XPathQueryButton_Click(object sender, EventArgs e)
        {
            try
            {
                //ErrorListBox.Items.Clear();
                this.errors.Clear();;
                this.resultsGridView.DataSource = null;
                ClearResults();

                GetCurrentSource();

                if (!this.currentDocument.IsValidXmlDocument())
                {
                    ReportError(new ErrorInfoLine("Invalid XML Document – see Error List Window for details", errors.Count + 1, ErrorInfoLine.ErrorType.Warning));
                    return;
                }

                try
                {
                    foreach (DataGridViewRow CurrentRow in namespaceGridView.Rows)
                    {
                        if (CurrentRow.Cells[0].Value == null && CurrentRow.Cells[1].Value == null)
                        {
                            //skip empty rows
                            continue;
                        }
                        else
                        {
                            if (CurrentRow.Cells[0].Value == null)
                            {
                                ReportError(new ErrorInfoLine("Invalid Namespace Table - a prefix is required for all namespaces", errors.Count + 1, ErrorInfoLine.ErrorType.Warning));
                                return;
                            }
                            else
                            {
                                if (CurrentRow.Cells[1].Value == null)
                                {
                                    this.currentDocument.XmlNamespaceManager.AddNamespace((string)CurrentRow.Cells[0].Value, string.Empty);
                                }
                                else
                                {
                                    this.currentDocument.XmlNamespaceManager.AddNamespace((string)CurrentRow.Cells[0].Value, (string)CurrentRow.Cells[1].Value);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //We should never get here
                    //ReportError(ex);
                    return;
                }

                XmlNodeList XPathResultNodeList = null;
                try
                {
                    XPathResultNodeList = this.currentDocument.Query(xpathTextBox.Text);
                }
                catch (XPathException ex)
                {
                    ReportError(ex);
                    return;
                }

                results = new BindingList <XmlNodeInfo>();

                if (XPathResultNodeList != null)
                {
                    foreach (XmlNode Node in XPathResultNodeList)
                    {
                        LineInfo CurrentLineInfo = this.currentDocument.GetLineInfo(Node);
                        if (CurrentLineInfo != null)
                        {
                            XmlNodeInfo info = new XmlNodeInfo(Node, CurrentLineInfo.LineNumber, CurrentLineInfo.LinePosition);
                            results.Add(info);
                            TextSpan            span  = GetNodeSpan(info);
                            IVsTextLineMarker[] amark = new IVsTextLineMarker[1];
                            int hr = this.currentDocument.TextEditorBuffer.CreateLineMarker((int)MARKERTYPE2.MARKER_EXSTENCIL,
                                                                                            span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex,
                                                                                            info, amark);
                            info.Marker         = amark[0];
                            info.MarkerChanged += new EventHandler(OnMarkerChanged);
                            info.MarkerDeleted += new EventHandler(OnMarkerDeleted);
                        }
                    }
                }

                this.resultsGridView.AutoGenerateColumns = false;
                this.resultsGridView.DataSource          = results;

                if (this.results.Count > 0)
                {
                    this.resultsGridView.Focus();
                    this.queryTabControl.SelectedTab = this.resultsTabPage;
                }
                else
                {
                    // If no results and XmlDoc has a default namespace, display a warning
                    if (!String.IsNullOrEmpty(this.currentDocument.DocumentElementDefaultNamespace) && !(this.currentDocument.DocumentElementDefaultNamespace == ""))
                    {
                        this.ReportError(new ErrorInfoLine("Document has a default namespace.  Did you make sure to add it to the Namespace Table and use its prefix in your XPath query?", errors.Count + 1, ErrorInfoLine.ErrorType.Warning));
                        return;
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 17
0
 public XmlCollectionInfo(XmlNodeInfo collectionNode, XmlNodeInfo elementNode)
 {
     CollectionNode = collectionNode;
     ElementNode    = elementNode;
 }
Ejemplo n.º 18
0
 public XmlCollectionInfo(string collectionName, string elementName)
 {
     CollectionNode = new XmlNodeInfo(collectionName);
     ElementNode    = new XmlNodeInfo(elementName);
 }
Ejemplo n.º 19
0
 private NavigationSiteMapNavigator(NavigationSiteMapNavigator navigator)
 {
     xmlNodeInfo = navigator.xmlNodeInfo;
     nameTable   = navigator.nameTable;
 }
Ejemplo n.º 20
0
        private void CreateCode()
        {
            classTemp = "";
            //StreamReader sr = File.OpenText("Template\\DefTemplate.txt");
            //classTemp = sr.ReadToEnd();
            //sr.Close();

            classTemp = classStr.Replace("$classname", className);
            //
            string propStr    = "";
            string contentStr = "";

            for (int i = 0; i < xmlInfoList.Count; i++)
            {
                XmlNodeInfo info = xmlInfoList[i];
                propStr += "\t//" + info.excelName + "\r";
                propStr += "\tpublic " + info.type + " " + info.codeName + ";\r";


                string readStr = "";
                if (info.type == "string")
                {
                    readStr = "buf.ReadUTFByte(" + info.size + ");";
                }
                else if (info.type == "int")
                {
                    readStr = "buf.ReadSignedInt();";
                }
                else if (info.type == "float")
                {
                    readStr = "buf.ReadFloat();";
                }

                contentStr += "\t\t" + info.codeName + " = " + readStr + "\r";
            }
            classTemp = classTemp.Replace("$prop", propStr);
            //
            classTemp = classTemp.Replace("$content", contentStr);

            Console.WriteLine(classTemp);

            clsTxt.Text = classTemp;


            string warning = "";

            foreach (var item in warningList)
            {
                warning += item + "\r";
            }

            warningTxt.Text = warning;
            //ByteArray by = new ByteArray();
            //by.WriteUTFBytes(classTemp, classTemp.Length);
            //byte[] strbytes = classTemp.to;
            //BitConverter.GetBytes();

            byte[] strbytes = Encoding.Default.GetBytes(classTemp);

            FileStream fs = new FileStream(savePath + className + ".cs", FileMode.Create);

            fs.Write(strbytes, 0, strbytes.Length);
            fs.Close();
        }
Ejemplo n.º 21
0
 public override void MoveToRoot()
 {
     xmlNodeInfo = xmlNodeInfo.Root;
 }
Ejemplo n.º 22
0
 public override bool MoveToFirst()
 {
     Debug.Assert(xmlNodeInfo.FirstSibling != null);
     xmlNodeInfo = xmlNodeInfo.FirstSibling;
     return(true);
 }
		// StartElement

		public override void WriteStartElement (
			string prefix, string localName, string namespaceUri)
		{
			if (state == WriteState.Error || state == WriteState.Closed)
				throw StateError ("StartTag");
			node_state = XmlNodeType.Element;

			bool anonPrefix = (prefix == null);
			if (prefix == null)
				prefix = String.Empty;

			// Crazy namespace check goes here.
			//
			// 1. if Namespaces is false, then any significant 
			//    namespace indication is not allowed.
			// 2. if Prefix is non-empty and NamespaceURI is
			//    empty, it is an error in 1.x, or it is reset to
			//    an empty string in 2.0.
			// 3. null NamespaceURI indicates that namespace is
			//    not considered.
			// 4. prefix must not be equivalent to "XML" in
			//    case-insensitive comparison.
			if (!namespaces && namespaceUri != null && namespaceUri.Length > 0)
				throw ArgumentError ("Namespace is disabled in this XmlTextWriter.");
			if (!namespaces && prefix.Length > 0)
				throw ArgumentError ("Namespace prefix is disabled in this XmlTextWriter.");

			// If namespace URI is empty, then either prefix
			// must be empty as well, or there is an
			// existing namespace mapping for the prefix.
			if (prefix.Length > 0 && namespaceUri == null) {
				namespaceUri = nsmanager.LookupNamespace (prefix, false);
				if (namespaceUri == null || namespaceUri.Length == 0)
					throw ArgumentError ("Namespace URI must not be null when prefix is not an empty string.");
			}
			// Considering the fact that WriteStartAttribute()
			// automatically changes argument namespaceURI, this
			// is kind of silly implementation. See bug #77094.
			if (namespaces &&
			    prefix != null && prefix.Length == 3 &&
			    namespaceUri != XmlNamespace &&
			    (prefix [0] == 'x' || prefix [0] == 'X') &&
			    (prefix [1] == 'm' || prefix [1] == 'M') &&
			    (prefix [2] == 'l' || prefix [2] == 'L'))
				throw new ArgumentException ("A prefix cannot be equivalent to \"xml\" in case-insensitive match.");


			if (xmldecl_state == XmlDeclState.Auto)
				OutputAutoStartDocument ();
			if (state == WriteState.Element)
				CloseStartElement ();
			if (open_count > 0)
				elements [open_count - 1].HasElements = true;

			nsmanager.PushScope ();

			if (namespaces && namespaceUri != null) {
				// If namespace URI is empty, then prefix must 
				// be empty as well.
				if (anonPrefix && namespaceUri.Length > 0)
					prefix = LookupPrefix (namespaceUri);
				if (prefix == null || namespaceUri.Length == 0)
					prefix = String.Empty;
			}
			
			WriteEmptyLines (formatSettings.EmptyLinesBeforeStart);
			ResetEmptyLineCount ();
			WriteIndent ();

			writer.Write ("<");

			if (prefix.Length > 0) {
				writer.Write (prefix);
				writer.Write (':');
			}
			writer.Write (localName);

			if (elements.Length == open_count) {
				XmlNodeInfo [] tmp = new XmlNodeInfo [open_count << 1];
				Array.Copy (elements, tmp, open_count);
				elements = tmp;
			}
			if (elements [open_count] == null)
				elements [open_count] =
					new XmlNodeInfo ();
			XmlNodeInfo info = elements [open_count];
			info.Prefix = prefix;
			info.LocalName = localName;
			info.NS = namespaceUri;
			info.HasSimple = false;
			info.HasElements = false;
			info.XmlLang = XmlLang;
			info.XmlSpace = XmlSpace;
			open_count++;

			if (namespaces && namespaceUri != null) {
				string oldns = nsmanager.LookupNamespace (prefix, false);
				if (oldns != namespaceUri) {
					nsmanager.AddNamespace (prefix, namespaceUri);
					new_local_namespaces.Push (prefix);
				}
			}

			state = WriteState.Element;
		}
Ejemplo n.º 24
0
        private void ReadExcel()
        {
            Excel.Application excel = new Excel.Application();
            if (File.Exists(excelFilePath) == false)
            {
                clsTxt.Text = "excel文件不存在!";
                return;
            }

            Excel.Workbook wb = excel.Workbooks.Open(excelFilePath);
            //取得第一个工作薄
            Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.get_Item(1);
            //取得总记录行数    (包括标题列)
            int rowsint = ws.UsedRange.Cells.Rows.Count;    //得到行数
            int colint  = ws.UsedRange.Cells.Columns.Count; //得到列数

            for (int i = 0; i < xmlInfoList.Count; i++)
            {
                XmlNodeInfo info = xmlInfoList[i];
                for (int j = 1; j <= colint; j++)
                {
                    string str = (string)ws.Cells[1, j].Text;

                    if (str == info.excelName)
                    {
                        columnList.Add(j);
                        break;
                    }
                }
            }
            //
            ByteArray byteArr = new ByteArray();
            //
            int dataLen = rowsint - 1;

            byteArr.WriteSignedInt(dataLen);

            for (int i = 2; i <= rowsint; i++)
            {
                for (int j = 0; j < xmlInfoList.Count; j++)
                {
                    XmlNodeInfo info = xmlInfoList[j];
                    if (info.type == "int")
                    {
                        string str = (string)ws.Cells[i, columnList[j]].Text;
                        if (str == "")
                        {
                            str = "0";
                        }
                        int intvalue = 0;

                        try
                        {
                            intvalue = Convert.ToInt32(str);
                        }
                        catch (Exception)
                        {
                            warningList.Add("int 解析错误 已赋值为 0 ---- 字段名称:" + info.excelName + "  错误值:" + str);
                            //throw;
                        }
                        Console.WriteLine(intvalue);
                        byteArr.WriteSignedInt(intvalue);
                    }
                    else if (info.type == "float")
                    {
                        string str = (string)ws.Cells[i, columnList[j]].Text;
                        if (str == "")
                        {
                            str = "0";
                        }
                        float floatvalue = 0;
                        try
                        {
                            floatvalue = float.Parse(str);
                        }
                        catch (Exception)
                        {
                            warningList.Add("float 解析错误 已赋值为 0 ---- 字段名称:" + info.excelName + "  错误值:" + str);
                            //throw;
                        }
                        Console.WriteLine(floatvalue);
                        byteArr.WriteBytes(BitConverter.GetBytes(floatvalue), 4);
                    }
                    else if (info.type == "string")
                    {
                        string strvalue = (string)ws.Cells[i, columnList[j]].Text;
                        Console.WriteLine(strvalue);
                        byteArr.WriteUTFBytes(strvalue, info.size);
                    }
                }
            }

            byteArr.Compress();

            FileStream fs = new FileStream(savePath + saveFileName, FileMode.Create);

            fs.Write(byteArr.Bytes, 0, byteArr.Length);
            fs.Close();

            //
            excel.Quit();
            excel = null;
            //
            //
            CreateCode();

            //
            SaveSelectPath();
        }