Beispiel #1
0
    public bool Load(string strFileName)
    {
#pragma warning disable 0618
        XmlTextReader       rXmlTextReader;
        XmlValidatingReader rXmlValidatingReader;
        bool fRet;

        rXmlTextReader = new XmlTextReader(strFileName);
        rXmlTextReader.WhitespaceHandling = _eWhitespaceMode;
        rXmlTextReader.Namespaces         = _fNamespaces;

        _eEncoding = rXmlTextReader.Encoding;

        rXmlValidatingReader = new XmlValidatingReader(rXmlTextReader);
        rXmlValidatingReader.ValidationType = _eValidationMode;
        rXmlValidatingReader.EntityHandling = _eEntityMode;
#pragma warning restore 0618

        if (_fValidationCallback)
        {
            rXmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);
        }

        try
        {
            fRet = Load((XmlReader)rXmlValidatingReader);
        }
        catch (Exception e)
        {
            fRet = false;
            rXmlValidatingReader.Dispose();
            rXmlTextReader.Dispose();

            if (_strParseError == string.Empty)
            {
                _strParseError = e.ToString();
            }

            if (_fThrow)
            {
                throw (e);
            }
        }

        rXmlValidatingReader.Dispose();
        rXmlTextReader.Dispose();
        return(fRet);
    }
Beispiel #2
0
        public String SelectBrowser(String browserToSelect, String fileName)
        {
            //string startupPath = System.IO.Directory.GetCurrentDirectory();
            //string frameWorkPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(startupPath)));
            //string configDir = Path.Combine(frameWorkPath + "\\Ingenta.Framework\\Browser\\" + fileName);

            //string configDir = @"C:\MoorepayDemo\MoorepayDemo\MoorepayDemo\Resources\" + fileName;
            string configDir = @"MoorepayDemo\Resources\" + fileName;

            // This is to load the config.xml file
            XmlTextReader reader = new XmlTextReader(configDir);
            XmlDocument   doc    = new XmlDocument();

            doc.Load(reader);

            // Move the control to 'Configuration' node.
            XmlNode parentNode = doc.SelectSingleNode("browsers");

            // get the list of 'Project' node.
            XmlNode browser = parentNode.SelectSingleNode(browserToSelect);

            String selectedBrowser = browser.InnerText.Trim();

            reader.Close();
            reader.Dispose();
            return(selectedBrowser);
        }
Beispiel #3
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver_Evidence
        //  -------------------------------------------------------------------------------------------------------------

        /*public int LoadXSL_Resolver_Evidence(String _strXslFile, XmlResolver xr, Evidence e)
         * {
         *  _strXslFile = FullFilePath(_strXslFile);
         *  xslt = new XslCompiledTransform();
         *
         *  switch (_nInputXsl)
         *  {
         *      case XslInputType.Reader:
         *          switch (_readerType)
         *          {
         *              case ReaderType.XmlTextReader:
         *                  XmlReader trTemp = XmlReader.Create(_strXslFile);
         *                  try
         *                  {
         *                      _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile);
         *                      //xslt.Load(trTemp, xr, e); //Evidence is not supported on V2 XSLT Load
         *                      xslt.Load(trTemp, XsltSettings.TrustedXslt, xr);
         *                  }
         *                  catch (Exception ex)
         *                  {
         *                      throw (ex);
         *                  }
         *                  finally
         *                  {
         *                      if (trTemp != null)
         *                          trTemp.Dispose();
         *                  }
         *                  break;
         *
         *              case ReaderType.XmlNodeReader:
         *                  XmlDocument docTemp = new XmlDocument();
         *                  docTemp.Load(_strXslFile);
         *                  XmlNodeReader nrTemp = new XmlNodeReader(docTemp);
         *                  try
         *                  {
         *                      _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile);
         *                      //xslt.Load(nrTemp, xr, e); Evidence is not supported in V2 XSLT Load
         *                      xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr);
         *                  }
         *                  catch (Exception ex)
         *                  {
         *                      throw (ex);
         *                  }
         *                  finally
         *                  {
         *                      if (nrTemp != null)
         *                          nrTemp.Dispose();
         *                  }
         *                  break;
         *
         *              case ReaderType.XmlValidatingReader:
         *              default:
         *                  XmlReaderSettings xrs = new XmlReaderSettings();
         #pragma warning disable 0618
         *                  xrs.ProhibitDtd = false;
         #pragma warning restore 0618
         *                  XmlReader vrTemp = null;
         *                  try
         *                  {
         *                      vrTemp = XmlReader.Create(_strXslFile, xrs);
         *                      _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile);
         *                      //xslt.Load(vrTemp, xr, e); Evidence is not supported in V2 XSLT Load
         *                      xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr);
         *                  }
         *                  catch (Exception ex)
         *                  {
         *                      throw (ex);
         *                  }
         *                  finally
         *                  {
         *                      if (vrTemp != null)
         *                          vrTemp.Dispose();
         *                  }
         *                  break;
         *          }
         *          break;
         *
         *      case XslInputType.Navigator:
         *          XmlReader xrLoad = XmlReader.Create(_strXslFile);
         *          XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve);
         *          xrLoad.Dispose();
         *          _output.WriteLine("Loading style sheet as Navigator " + _strXslFile);
         *          xslt.Load(xdTemp.CreateNavigator(), XsltSettings.TrustedXslt, xr);
         *          break;
         *  }
         *  return 1;
         * }*/

        //VerifyResult
        public void VerifyResult(string expectedValue)
        {
            XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff();
            xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.NormalizeNewline;

            StreamReader sr          = new StreamReader(new FileStream("out.xml", FileMode.Open, FileAccess.Read));
            string       actualValue = sr.ReadToEnd();

            sr.Dispose();

            //Output the expected and actual values
            _output.WriteLine("Expected : " + expectedValue);
            _output.WriteLine("Actual : " + actualValue);

            //Load into XmlTextReaders
            XmlTextReader tr1 = new XmlTextReader("out.xml");
            XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue));

            bool result = xmldiff.Compare(tr1, tr2);

            //Close the readers
            tr1.Dispose();
            tr2.Dispose();

            Assert.True(result);
        }
Beispiel #4
0
        /// <summary>
        /// Lecture d'un fichier XML.
        /// </summary>
        /// <param name="FichierEntre">Nom du fichier.</param>
        /// <param name="option">Objet Option où les paramètres seront enregistrés.</param>
        private void LectureOption(string FichierEntre, ref ConfigJoueur option)
        {
            try
            {
                lecteur           = new XmlTextReader(FichierEntre);
                option            = (ConfigJoueur)serializer.Deserialize(lecteur);
                chargementReussis = true;
            }


            catch (Exception ex)
            {
                option            = null;
                chargementReussis = false;
                Console.WriteLine(ex.Message);
                return;
            }

            finally
            {
                if (lecteur != null)
                {
                    lecteur.Close();
                    lecteur.Dispose();
                }
            }
        }
Beispiel #5
0
        private void CheckForUpdate()
        {
            string        downloadUrl = "";
            Version       newVersion  = null;
            string        aboutUpdate = "";
            string        xmlUrl      = "http://www.ctnieves.com/projects/software.xml";
            XmlTextReader reader      = new XmlTextReader(xmlUrl);
            XmlDocument   updateDoc   = new XmlDocument();

            updateDoc.Load(reader);
            XmlNode softwareNameNode = updateDoc.SelectSingleNode("ctnievesSoftware").SelectSingleNode("XEXAssistant");

            newVersion  = Version.Parse(softwareNameNode.SelectSingleNode("version").InnerText);
            downloadUrl = softwareNameNode.SelectSingleNode("url").InnerText;
            aboutUpdate = softwareNameNode.SelectSingleNode("about").InnerText;

            reader.Close();
            reader.Dispose();

            Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            if (applicationVersion.CompareTo(newVersion) < 0)
            {
                MessageBox.Show("New Version Available : " + newVersion.ToString() + "\n" +
                                "Url : " + downloadUrl + "\n" +
                                "About Update : " + aboutUpdate);
                Process.Start(downloadUrl);
            }
        }
Beispiel #6
0
        public String SelectBrowser(String browserToSelect, String fileName)
        {
            try
            {
                string configDir = AppDomain.CurrentDomain.BaseDirectory + "\\Browser\\" + fileName;

                // This is to load the config.xml file
                XmlTextReader reader = new XmlTextReader(configDir);
                XmlDocument   doc    = new XmlDocument();
                doc.Load(reader);

                // Move the control to 'Configuration' node.
                XmlNode parentNode = doc.SelectSingleNode("browsers");

                // get the list of 'Project' node.
                XmlNode browser = parentNode.SelectSingleNode(browserToSelect);

                String selectedBrowser = browser.InnerText.Trim();

                reader.Close();
                reader.Dispose();

                return(selectedBrowser);
            }
            catch (Exception e)
            {
                Logger.log.Error(e);
                return(null);
            }
        }
Beispiel #7
0
        private void içeAktarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dosyaAc.Title            = "Bir XML dosyası seçiniz";
            dosyaAc.Filter           = "(XML Dosyası) | *.xml";
            dosyaAc.FileName         = "Kişiler.xml";
            dosyaAc.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (dosyaAc.ShowDialog() == DialogResult.OK)
            {
                XmlSerializer xmlserializer = new XmlSerializer(typeof(List <Kisi>));
                XmlReader     reader        = new XmlTextReader(dosyaAc.FileName);
                if (xmlserializer.CanDeserialize(reader))
                {
                    kisiler = xmlserializer.Deserialize(reader) as List <Kisi>;
                    MessageBox.Show($"{kisiler.Count} kisi sisteme basarıyla eklendi");
                    lstKisiler.Items.AddRange(kisiler.ToArray());
                    reader.Close();
                    reader.Dispose();
                }
                else
                {
                    MessageBox.Show("Lutfen dogru bir xml dosyasını seciniz");
                }
            }
        }
Beispiel #8
0
        public static bool CheckRootNode(string strXMLFilename)
        {
            var CheckRootNode = false;

            if (File.Exists(strXMLFilename))
            {
                var reader = new XmlTextReader(strXMLFilename);
                reader.WhitespaceHandling = WhitespaceHandling.None;

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "AppValues")
                        {
                            Console.WriteLine(reader.Name);
                            CheckRootNode = true;
                        }
                    }
                }
                reader.Close();
                reader.Dispose();
            }
            return(CheckRootNode);
        }
Beispiel #9
0
        private XmlException ParseInternal(string text)
        {
            stream.SetText(text);

            if (reader == null)
            {
                reader = new XmlTextReader(stream);
            }

            try
            {
                while (!ReachedEnd())
                {
                    reader.Read();
                }

                // No errors. Reset the text reader for next time.
                reader.ResetState();
                return(null);
            }
            catch (XmlException ex)
            {
                // The reader is in a bad state and ResetState isn't going to help (because it has already
                // consumed bad text from the underlying stream and that can't be undone).
                // So, dispose of it and recreate a new one next time we get called.
                reader.Dispose();
                reader = null;
                return(ex);
            }
        }
Beispiel #10
0
        public String SelectBrowser(String browserToRun, String filename)
        {
            try
            {
                String configDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\Browser\\" + filename;

                XmlTextReader reader   = new XmlTextReader(configDirectory);
                XmlDocument   document = new XmlDocument();
                document.Load(reader);

                XmlNode parentNode = document.SelectSingleNode("browsers");

                XmlNode browser = parentNode.SelectSingleNode(browserToRun);

                String selectedBrowser = browser.InnerText.Trim();

                reader.Close();
                reader.Dispose();

                return(selectedBrowser);
            }
            catch (Exception e)
            {
                Logger.log.Error(e);
                return(null);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Deserializes an xml file into an object list
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static T DeSerializeObject <T>(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(default(T));
            }

            T objectOut = default(T);

            string attributeXml = string.Empty;

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);
            string xmlString = xmlDocument.OuterXml;

            using (StringReader read = new StringReader(xmlString))
            {
                Type outType = typeof(T);

                XmlSerializer serializer = new XmlSerializer(outType);
                using (XmlReader reader = new XmlTextReader(read))
                {
                    objectOut = (T)serializer.Deserialize(reader);
                    reader.Close();
                    reader.Dispose();
                }

                read.Close();
                read.Dispose();
            }

            return(objectOut);
        }
Beispiel #12
0
        public Configs(string path)
        {
            path     += @"\config.xml";
            this.path = path;

            if (File.Exists(path))
            {
                XmlTextReader xtr = new XmlTextReader(path);

                try
                {
                    while (xtr.Read())
                    {
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "x")
                        {
                            posX = Convert.ToInt32(xtr.ReadElementContentAsString());
                        }
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "y")
                        {
                            posY = Convert.ToInt32(xtr.ReadElementContentAsString());
                        }

                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "click")
                        {
                            click = xtr.ReadElementContentAsString();
                        }
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "type")
                        {
                            typeScan = xtr.ReadElementContentAsString();
                        }
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "y2")
                        {
                            intervalClick = xtr.ReadElementContentAsString();
                        }

                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "R")
                        {
                            R = Convert.ToInt32(xtr.ReadElementContentAsString());
                        }
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "G")
                        {
                            G = Convert.ToInt32(xtr.ReadElementContentAsString());
                        }
                        if (xtr.NodeType == XmlNodeType.Element && xtr.Name == "B")
                        {
                            B = Convert.ToInt32(xtr.ReadElementContentAsString());
                        }
                    }
                }
                catch { }

                xtr.Dispose();
                xtr.Close();
            }
            else
            {
                Save();
            }
        }
Beispiel #13
0
    /// <summary>
    /// reads the specified plugin to generate the structure of the plugin
    /// </summary>
    /// <param name="type">the type of the tag</param>
    public static plugins_field Get_Tag_stucture_from_plugin(string type)
    {
        //Plugin Search Stuff
        string plugin_loc = Application.StartupPath + "\\plugins\\" + type + ".xml";

        if (File.Exists(plugin_loc))
        {
            FileStream    fs = new FileStream(plugin_loc, FileMode.Open, FileAccess.Read, FileShare.Read);
            XmlTextReader xr = new XmlTextReader(fs);

            //well i am gonna run some checks for plugin structure
            //the number of element and end_element should be same in the plugin file
            int element     = 0;
            int end_element = 0;
            while (xr.Read())
            {
                if ((xr.NodeType == XmlNodeType.Element))
                {
                    switch (xr.Name.ToLower())
                    {
                    case "reflexive":
                        element++;
                        break;
                    }
                }
                if (xr.NodeType == XmlNodeType.EndElement)
                {
                    switch (xr.Name.ToLower())
                    {
                    case "reflexive":
                        end_element++;
                        break;
                    }
                }
            }
            //has to dispose of old streams due to unaccounted problems
            xr.Dispose();
            fs.Dispose();

            if (element == end_element)
            {
                //recreating newer streams
                fs = new FileStream(plugin_loc, FileMode.Open, FileAccess.Read, FileShare.Read);
                xr = new XmlTextReader(fs);

                return(Get_nodes(type, 0x0, 0x0, xr, false));//well we do have a base size for the tables inside the meta,but i simply dont care
            }
            else
            {
                throw new Exception("Plugin structure invalid " + type + ".xml");
            }
        }
        else
        {
            MessageBox.Show("Error", "couldnt find the plugin of type " + type);
        }

        return(null);
    }
Beispiel #14
0
        private string HttpPostDataTable(string method, string param)
        {
            string url    = "http://localhost/WebService.asmx";
            string result = string.Empty;

            byte[]          bytes    = null;
            Stream          writer   = null;
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;


            bytes = Encoding.UTF8.GetBytes(param);

            request               = (HttpWebRequest)HttpWebRequest.Create(url + "/" + method);
            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = bytes.Length;

            try
            {
                writer = request.GetRequestStream();        //获取用于写入请求数据的Stream对象
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            writer.Write(bytes, 0, bytes.Length);       //把参数数据写入请求数据流
            writer.Close();

            try
            {
                response = (HttpWebResponse)request.GetResponse();      //获得响应
            }
            catch (WebException ex)
            {
                return(ex.Message);
            }

            #region 这种方式读取到的是一个返回的结果字符串
            Stream        stream = response.GetResponseStream(); //获取响应流
            XmlTextReader Reader = new XmlTextReader(stream);
            Reader.MoveToContent();
            result = Reader.ReadInnerXml();
            #endregion

            response.Dispose();
            response.Close();

            Reader.Dispose();
            Reader.Close();

            stream.Dispose();
            stream.Close();
            DataTable dt = JsonConvert.DeserializeObject <DataTable>(result);

            int i = dt.Rows.Count;
            return(result);
        }
Beispiel #15
0
        public void import(String filename)
        {
            WindowTitle = "Importing Tags";

            XmlTextReader inFile = null;

            try
            {
                inFile = new XmlTextReader(filename);
                Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) };

                DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List <TagDTO>), knownTypes);

                List <Tag>    tags    = new List <Tag>();
                List <TagDTO> tagDTOs = (List <TagDTO>)tagSerializer.ReadObject(inFile);

                foreach (TagDTO tagDTO in tagDTOs)
                {
                    var tag = Mapper.Map <TagDTO, Tag>(tagDTO, new Tag());
                    tags.Add(tag);
                }

                TotalProgressMax = tags.Count;
                TotalProgress    = 0;

                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested == true)
                        {
                            return;
                        }

                        ItemInfo     = "Merging: " + tag.Name;
                        ItemProgress = 0;
                        tagCommands.merge(tag);
                        ItemProgress = 100;
                        TotalProgress++;
                        InfoMessages.Add("Merged: " + tag.Name);
                    }
                }
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error importing tags " + e.Message);
            }
            finally
            {
                operationFinished();

                if (inFile != null)
                {
                    inFile.Dispose();
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Получение списка узлов из файла XML-документа
        /// </summary>
        /// <param name="fileName">Имя файла</param>
        /// <returns>Список XML-узлов</returns>
        public static List <XMLNode> ReadXMLDocument(string fileName)
        {
            List <XMLNode> nodeList = new List <XMLNode>();

            try
            {
                Dictionary <int, string> encodingDictionary = new Dictionary <int, string>();
                XmlTextReader            reader             = new XmlTextReader(fileName);
                Stack <int> currentNodeIdStack = new Stack <int>();
                int         currentNodeId      = -1;
                int         code = -1;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:     // Узел является элементом
                        currentNodeId++;
                        XMLNode node = new XMLNode(currentNodeId, reader.Name, reader.Depth, reader.LineNumber);
                        nodeList.Add(node);
                        if (!encodingDictionary.Values.Contains(node.Tag))
                        {
                            code++;
                            encodingDictionary.Add(code, node.Tag);
                            nodeList[currentNodeId].Code = code;
                        }
                        else
                        {
                            nodeList[currentNodeId].Code = encodingDictionary.FirstOrDefault(x => x.Value == node.Tag).Key;
                        }
                        currentNodeIdStack.Push(currentNodeId);
                        if (reader.IsEmptyElement)
                        {
                            nodeList[currentNodeId].LineNumberEnd = reader.LineNumber;
                            currentNodeIdStack.Pop();
                        }
                        break;

                    case XmlNodeType.Text:     // Вывести текст в каждом элементе
                        nodeList[currentNodeId].Text = reader.Value;
                        break;

                    case XmlNodeType.EndElement:     // Вывести конец элемента
                        int lastNodeId = currentNodeIdStack.Peek();
                        nodeList[lastNodeId].LineNumberEnd = reader.LineNumber;
                        currentNodeIdStack.Pop();
                        break;
                    }
                }
                reader.Dispose();
            }
            catch
            {
                throw new System.Exception("Файл имеет неверный формат");
            }
            return(nodeList);
        }
Beispiel #17
0
        public static CIMObject Clone(this CIMObject cimObject)
        {
            var clone        = System.Activator.CreateInstance("ArcGIS.Core", cimObject.GetType().ToString()).Unwrap() as CIMObject;
            var stringReader = new StringReader(cimObject.ToXml());
            var xmlReader    = new XmlTextReader(stringReader);

            //xmlReader.MoveToContent();
            clone.ReadXml(xmlReader);
            xmlReader.Dispose();
            return(clone);
        }
Beispiel #18
0
        /// <summary>
        /// DeSerializes settings from XML
        /// </summary>
        /// <param name="settingsFile">full path to settings file</param>
        public static AppSettings Deserialize(String settingsFile)
        {
            AppSettings settings = null;

            var serializer = new XmlSerializer(typeof(AppSettings));
            // A FileStream is needed to read the XML document.
            FileStream fs     = null;
            XmlReader  reader = null;

            try {
                fs       = new FileStream(settingsFile, FileMode.Open, FileAccess.Read);
                reader   = new XmlTextReader(fs);
                settings = (AppSettings)serializer.Deserialize(reader);

                settings.DisableInternalCommands = Convert.ToBoolean(
                    Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Kindel Systems\MCE Controller",
                                      "DisableInternalCommands", false), new NumberFormatInfo());
                Logger.Instance.Log4.Info("Settings: Loaded settings from " + settingsFile);
            }
            catch (FileNotFoundException) {
                // First time through, so create file with defaults
                Logger.Instance.Log4.Info($"Settings: Creating settings file with defaults: {settingsFile}");
                settings = new AppSettings();
                settings.Serialize(settingsFile);

                // even if it's first run, read global commands
                settings.DisableInternalCommands = Convert.ToBoolean(
                    Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Kindel Systems\MCE Controller",
                                      "DisableInternalCommands", false), new NumberFormatInfo());
            }
            catch (UnauthorizedAccessException e) {
                Logger.Instance.Log4.Info($"Settings: Settings file could not be loaded. {e.Message}");
                MessageBox.Show($"Settings file could not be loaded. {e.Message}");
            }
            finally {
                if (reader != null)
                {
                    reader.Dispose();
                }

                if (fs != null)
                {
                    fs.Dispose();
                }
            }

            // TELEMETRY:
            // what: Settings
            // why: To understand what settings get changed and which dont
            // how is PII protected: only settings clearly identified as not containing PII are collected
            TelemetryService.Instance.TrackEvent("Settings", settings.GetTelemetryDictionary());

            return(settings);
        }
Beispiel #19
0
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter   = "image files (*.img)|*.img";
            openFileDialog1.FileName = "";
            openFileDialog1.Title    = "Please select an image file";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                tbXmlFile.Text = "";
                try
                {
                    doc.Dispose();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (openFileDialog1.CheckFileExists == true)
                    {
                        if (Path.GetExtension(openFileDialog1.FileName) == ".img")
                        {
                            tbXmlFile.Text = openFileDialog1.FileName;
                            doc            = new XmlTextReader(tbXmlFile.Text);

                            while (doc.Read())
                            {
                                if (doc.NodeType == XmlNodeType.Element)
                                {
                                    if (doc.Name == "FIRMWARE")
                                    {
                                        doc.MoveToFirstAttribute();
                                        tbDebug.Text += "> Found Firmware \"" + doc.Value + "\"\r\n";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void LoadSqlSyntaxHighlightRules()
        {
            Stream                  stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SalesforceSQLSchemaGenerator.AvalonEdit.SQLSyntax.xhsd");
            XmlTextReader           reader = new XmlTextReader(stream);
            IHighlightingDefinition highlightingDefinition = HighlightingLoader.Load(reader, HighlightingManager.Instance);

            HighlightingManager.Instance.RegisterHighlighting(highlightingDefinition.Name, new string[] { "*.sql", "*.txt" }, highlightingDefinition);
            reader.Close();
            reader.Dispose();
            stream.Close();
            stream.Dispose();
        }
Beispiel #21
0
        public string readXMLFile(String projectName, string ModuleName, String key, String fileName)
        {
            string        path         = "D:\\Selenium\\ClassLibrary1\\ClassLibrary1\\" + fileName;
            string        requireddata = null;
            XmlTextReader reader       = new XmlTextReader(path);
            XmlDocument   doc          = new XmlDocument();

            doc.Load(reader);
            XmlNode node = doc.SelectSingleNode("Configuration");

            XmlNodeList projectNodeList = node.SelectNodes("Project");

            foreach (XmlNode tempNode in projectNodeList)
            {
                //get the value of 'name' attribute of current project node
                String attribute = tempNode.Attributes["name"].Value;
                if (attribute.Equals(projectName))
                {
                    XmlNodeList modulenodelist = tempNode.ChildNodes;
                    string      eleAttribute   = null;
                    foreach (XmlNode tempModuleNode in modulenodelist)
                    {
                        String attributeOfModuleNode = tempModuleNode.Attributes["name"].Value;
                        if (attributeOfModuleNode.Equals(ModuleName))
                        {
                            XmlNodeList elemnetNodeList = tempModuleNode.ChildNodes;
                            foreach (XmlNode tempElementNode in elemnetNodeList)
                            {
                                if (fileName.Equals("Config.xml"))
                                {
                                    eleAttribute = tempElementNode.Attributes["key"].Value;
                                }
                                else if (fileName.Equals("ReadXML.xml"))
                                {
                                    eleAttribute = tempElementNode.Name;
                                    requireddata = tempElementNode.InnerText;
                                }
                                if (eleAttribute.Equals(key))
                                {
                                    requireddata = tempElementNode.InnerText;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            reader.Close();
            reader.Dispose();
            return(requireddata);
        }
Beispiel #22
0
        public static void getDetails2(String inputEdp, List <string> label_store, List <string> label_productName, List <string> label_productdescription,
                                       List <string> label_Price, List <string> imageSourceUrl, List <string> label_Manufacturer, List <string> label_availabilityDescription) // VERSION 3
        {
            String inputurl = ("http://afs-sl-pservice01.afservice.org:8080/productservice2/getProductInfo/pcmall?edplist=" + inputEdp + "&ignoreCatalog=true");

            System.Xml.XmlTextReader reader = new XmlTextReader(inputurl);
            while (reader.Read())
            {
                while (reader.ReadToFollowing("result"))
                {
                    reader.ReadToFollowing("productDetails");
                    while (reader.ReadToFollowing("manufacturer"))
                    {
                        label_Manufacturer.Add(reader.ReadElementString("manufacturer"));
                        reader.ReadToFollowing("storeSpecific");
                        reader.ReadToFollowing("store");
                        label_store.Add(reader.ReadElementString("store"));
                        label_productName.Add(reader.ReadElementString("name"));


                        while (reader.ReadToFollowing("description"))
                        {
                            label_productdescription.Add(reader.Value); break;
                        }
                        while (reader.ReadToFollowing("finalPrice"))
                        {
                            label_Price.Add(reader.ReadElementString("finalPrice")); break;
                        }
                        while (reader.ReadToFollowing("availabilityDescription"))
                        {
                            label_availabilityDescription.Add(reader.ReadElementString("availabilityDescription")); break;
                        }
                        if (reader.ReadToFollowing("images"))
                        {
                            if (reader.Name == "image")
                            {
                                while (reader.ReadToFollowing("xlg"))
                                {
                                    imageSourceUrl.Add(reader.ReadElementString("xlg")); break;
                                }
                            }
                            else if (reader.ReadToFollowing("hasImage"))
                            {
                                imageSourceUrl.Add("NO IMAGE");
                            }
                        }
                    }
                }
            }
            reader.Dispose();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateFile"></param>
        /// <param name="file"></param>
        /// <param name="diskId">realative path to files ItemFiles folder</param>
        public static void readTemplate(string templateFile, MyInfoFile file, UInt64 diskId)
        {
            XmlTextReader reader = new XmlTextReader(Managers.FileManager.PathToHFOFolder + "\\FITemplates\\" + templateFile);

            try
            {
                InfoGroup actualGroup = null;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                        case "group":
                            if (actualGroup != null)
                            {
                                actualGroup = actualGroup.AddGroup(reader.GetAttribute("name"));
                            }
                            else
                            {
                                actualGroup = file.AddGroup(reader.GetAttribute("name"));
                            }
                            break;

                        case "value":
                            Item it = Parsing.ParseItem(reader.GetAttribute("type"), reader.GetAttribute("name"), reader, diskId);
                            it.SetValue(reader.GetAttribute("default"));
                            if (actualGroup != null)
                            {
                                actualGroup.AddItem(it);
                            }
                            else
                            {
                                file.AddItem(it);
                            }
                            break;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name == "group")
                        {
                            actualGroup = actualGroup.Up;
                        }
                        break;
                    }
                }
            }
            finally { reader.Dispose(); }
        }
Beispiel #24
0
        private static void SetData()
        {
            try
            {
                XmlTextReader Reader = new XmlTextReader("GetInfo.XML");
                XmlNodeType   type;
                while (Reader.Read())
                {
                    type = Reader.NodeType;
                    if (type == XmlNodeType.Element)
                    {
                        if (Reader.Name == "Server")
                        {
                            Reader.Read();
                            Server = Reader.Value;
                        }
                        if (!OldSac)
                        {
                            if (Reader.Name == "DatabaseName")
                            {
                                Reader.Read();
                                DatabaseName = Reader.Value;
                            }
                        }
                        else
                        {
                            DatabaseName = OldDbName;
                        }
                        if (Reader.Name == "Admin")
                        {
                            Reader.Read();
                            AdminUser = Reader.Value;
                        }
                        if (Reader.Name == "Pass")
                        {
                            Reader.Read();
                            AdminPass = Reader.Value;
                        }
                    }
                }

                Reader.Close();
                Reader.Dispose();
            }
            catch (Exception e)
            {
                Server       = "192.168.1.220";
                DatabaseName = "sacCustomer";
            }
        }
Beispiel #25
0
        protected virtual void Dispose(bool disposing)
        {
            if (_reader != null)
            {
                _reader.Dispose();
                _reader = null;
            }

            if (_preservationProvider != null)
            {
                _preservationProvider.Close();
                _preservationProvider = null;
            }
        }
Beispiel #26
0
        /// <summary>
        /// Check to make sure an Xml file is valid
        /// </summary>
        /// <param name="xmlString">The Xml text string</param>
        /// <param name="fileName">the name of the file, used for debugging purposes</param>
        /// <returns>True if valid Xml, false otherwise</returns>
        public static bool IsValidXml(string xmlString, string fileName)
        {
            XmlTextReader read = new XmlTextReader(xmlString);

            try
            {
                //continue to read the entire document
                while (read.Read())
                {
                    ;
                }
                read.Close();
                read.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                Logging.Error("Invalid Xml file: {0}\n{1}", fileName, e.Message);
                read.Close();
                read.Dispose();
                return(false);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="file">file path, only file name</param>
        /// <returns></returns>
        public static List <MyDevice> readOverview(string file)
        {
            List <MyDevice> dil    = new List <MyDevice>();
            XmlTextReader   reader = new XmlTextReader(Managers.FileManager.PathToHFOFolder + "\\" + file);

            try
            {
                MyDevice computer = null;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                        case "disk":
                            if (computer != null)
                            {
                                MyDisk disk = new MyDisk(ulong.Parse(reader.GetAttribute("deviceId")), reader.GetAttribute("name"));
                                computer.disks.Add(disk);
                            }
                            else
                            {
                                MyDevice device = new MyDevice(ulong.Parse(reader.GetAttribute("deviceId")), reader.GetAttribute("name"), Communication.PeriferDisk, reader.GetAttribute("syncedTo"), reader.GetAttribute("runOn"), reader.GetAttribute("deviceFile"));
                                MyDisk   disk   = new MyDisk(device.Id, device.Name);
                                device.disks.Add(disk);
                                dil.Add(device);
                            }
                            break;

                        case "computer":
                            computer = new MyDevice(ulong.Parse(reader.GetAttribute("deviceId")), reader.GetAttribute("name"), Communication.Network, reader.GetAttribute("syncedTo"), reader.GetAttribute("runOn"), reader.GetAttribute("deviceFile"));
                            dil.Add(computer);
                            break;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name == "computer")
                        {
                            computer = null;
                        }
                        break;
                    }
                }
            }
            finally { reader.Dispose(); }
            return(dil);
        }
Beispiel #28
0
        //Effective For Search ProductDetails
        public static void getDetails(String inputEdp, Label label_store, Label label_productName, Label label_productdescription,
                                      Label label_Price, Image imageSourceUrl, Label label_Manufacturer, Label label_availabilityDescription) // VERSION 3
        {
            String inputurl = ("http://afs-sl-pservice01.afservice.org:8080/productservice2/getProductInfo/pcmall?edplist=" + inputEdp + "&ignoreCatalog=true");

            System.Xml.XmlTextReader reader = new XmlTextReader(inputurl);
            while (reader.Read())
            {
                reader.ReadToFollowing("productDetails");
                while (reader.ReadToFollowing("manufacturer"))
                {
                    label_Manufacturer.Text = reader.ReadElementString("manufacturer");
                    if (listBrand.Contains(label_Manufacturer.Text))
                    {
                    }
                    else
                    {
                        listBrand.Add(label_Manufacturer.Text);
                    }

                    reader.ReadToFollowing("storeSpecific");
                    reader.ReadToFollowing("store");
                    label_store.Text       = reader.ReadElementString("store");
                    label_productName.Text = reader.ReadElementString("name");
                    while (reader.Read())
                    {
                        label_productdescription.Text = reader.Value;
                        break;
                    }
                    while (reader.ReadToFollowing("finalPrice"))
                    {
                        label_Price.Text = reader.ReadElementString("finalPrice"); break;
                    }
                    reader.ReadToFollowing("availabilityDescription");
                    if (reader.Name == "availabilityDescription") //
                    {
                        label_availabilityDescription.Text = reader.ReadElementString("availabilityDescription");
                    }
                    reader.ReadToFollowing("image");
                    reader.ReadToFollowing("xlg");
                    if (reader.Name == "xlg") //
                    {
                        imageSourceUrl.ImageUrl = reader.ReadElementString("xlg"); break;
                    }
                }
            }
            reader.Dispose();
        }
        /// <summary>
        /// Changes the reference version.
        /// </summary>
        /// <param name="projectFile">The project file.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        public static bool ChangeReferenceVersion(string projectFile, string assemblyName, string version)
        {
            const string        xmlns  = "http://schemas.microsoft.com/developer/msbuild/2003";
            var                 xmlDoc = new XmlDocument();
            XmlNamespaceManager nsMngr;

            using (var reader = new XmlTextReader(projectFile))
            {
                nsMngr = new XmlNamespaceManager(reader.NameTable);
                nsMngr.AddNamespace("a", xmlns);

                xmlDoc.Load(reader);
                reader.Dispose();
            }

            var nodes = xmlDoc.SelectNodes("//a:Reference", nsMngr);

            if (nodes != null)
            {
                foreach (XmlNode refElement in nodes)
                {
                    var includeAtt = refElement.Attributes["Include"];
                    var data       = includeAtt.Value.Split(',');
                    var assName    = data[0];

                    if (assName.Equals(assemblyName, StringComparison.CurrentCultureIgnoreCase) && data.Length >= 2)
                    {
                        var oldVersion = data[1].Split('=')[1];
                        if (string.Equals(oldVersion, version))
                        {
                            return(false);
                        }
                        var newVersion = data[1].Replace(oldVersion, version);

                        data[1] = newVersion;

                        var newIncludeData = String.Join(",", data);
                        includeAtt.Value = newIncludeData;

                        // Update project version
                        xmlDoc.Save(projectFile);
                        break;
                    }
                }
            }

            return(true);
        }
Beispiel #30
0
 private void AddStudent_Load(object sender, EventArgs e)
 {
     using (XmlReader xmlRead = new XmlTextReader(path))
     {
         if (serializer.CanDeserialize(xmlRead))
         {
             xmlRead.Dispose();
             xmlRead.Close();
             using (FileStream fs = new FileStream(path, FileMode.Open))
             {
                 studs = new Students((List <Student>)serializer.Deserialize(fs));
             }
         }
     }
     SerializeXml();
 }
Beispiel #31
0
    public bool Load(string strFileName)
    {
#pragma warning disable 0618
        XmlTextReader rXmlTextReader;
        XmlValidatingReader rXmlValidatingReader;
        bool fRet;

        rXmlTextReader = new XmlTextReader(strFileName);
        rXmlTextReader.WhitespaceHandling = _eWhitespaceMode;
        rXmlTextReader.Namespaces = _fNamespaces;

        _eEncoding = rXmlTextReader.Encoding;

        rXmlValidatingReader = new XmlValidatingReader(rXmlTextReader);
        rXmlValidatingReader.ValidationType = _eValidationMode;
        rXmlValidatingReader.EntityHandling = _eEntityMode;
#pragma warning restore 0618

        if (_fValidationCallback)
            rXmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);

        try
        {
            fRet = Load((XmlReader)rXmlValidatingReader);
        }
        catch (Exception e)
        {
            fRet = false;
            rXmlValidatingReader.Dispose();
            rXmlTextReader.Dispose();

            if (_strParseError == string.Empty)
                _strParseError = e.ToString();

            if (_fThrow)
                throw (e);
        }

        rXmlValidatingReader.Dispose();
        rXmlTextReader.Dispose();
        return fRet;
    }