Example #1
0
        private void btnLoadScreen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string MainFileName = openFileDialog1.FileName;// +".scr";
                string IDsFileName  = MainFileName.Substring(0, MainFileName.Length - 4) + ".ids";

                // сначала открываем основной файл и читаем настройки экрана
                //System.IO.FileStream fm = new System.IO.FileStream(MainFileName, System.IO.FileMode.Open);

                /*byte cstr = 0, cbtn = 0;
                 * Screen.LoadScreen(fm, ref cstr, ref cbtn);*/
                // далее читаем xml и создаем структуру элементов
                System.Xml.XmlReader ids = System.Xml.XmlReader.Create(IDsFileName);
                Screen.LoadElements(ids);
                propertyGrid2.Refresh();
                // потом из основного файла читаем сами элементы

                /*int i=0;
                 * while (cstr + cbtn > i)
                 * {
                 *  Screen.LoadProperties(fm);
                 *  i++;
                 * }*/
                // закрываем все
                //fm.Close();
                //fm.Dispose();
                ids.Close();
            }
        }
Example #2
0
        public static System.Xml.XmlDocument LoadFromFile(string fileName, ref string sError)
        {
            System.Xml.XmlDocument       returnValue = default(System.Xml.XmlDocument);
            System.Xml.XmlReaderSettings xmlSet      = new System.Xml.XmlReaderSettings();
            xmlSet.CheckCharacters = false;
            xmlSet.DtdProcessing   = System.Xml.DtdProcessing.Ignore;
            //xmlSet.ProhibitDtd = False
            xmlSet.ValidationType = System.Xml.ValidationType.None;
            xmlSet.XmlResolver    = null;

            System.Xml.XmlReader   xmlr   = System.Xml.XmlTextReader.Create(fileName, xmlSet);
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

            sError = "";
            try
            {
                xmlDoc.Load(xmlr);
                xmlr.Close();
                returnValue = xmlDoc;
            }
            catch (Exception ex)
            {
                sError      = ex.Message;
                returnValue = null;
            }
            return(returnValue);
        }
Example #3
0
        public static List <Tweet> GetTweets(string _TwitterUser)
        {
            List <Tweet> resultTweets = new List <Tweet>();

            try
            {
                string rssAddress = "http://twitrss.me/twitter_user_to_rss/?user=" + _TwitterUser;

                System.Xml.XmlReader reader = System.Xml.XmlReader.Create(rssAddress);
                System.ServiceModel.Syndication.SyndicationFeed feed = System.ServiceModel.Syndication.SyndicationFeed.Load(reader);
                reader.Close();
                foreach (System.ServiceModel.Syndication.SyndicationItem item in feed.Items)
                {
                    Tweet newTweet = new Tweet();
                    newTweet.m_Creator   = _TwitterUser;
                    newTweet.m_Text      = item.Title.Text;
                    newTweet.m_TweetLink = item.Id;
                    newTweet.m_PostDate  = item.PublishDate.UtcDateTime;
                    resultTweets.Add(newTweet);
                }
            }
            catch (Exception)
            {}
            return(resultTweets);
        }
Example #4
0
        public static void MsBuild(System.Xml.XmlReader xmlProj)
        {
            var msbuild = new Microsoft.Build.Evaluation.Project(xmlProj);

            msbuild.Build();
            xmlProj.Close();
        }
Example #5
0
        //</snippetOutputDimensionSchemaRowset>

        //<snippetOutputDataWithXML>
        void OutputDataWithXML()
        {
            //Open a connection to the local server.
            AdomdConnection conn = new AdomdConnection("Data Source=localhost");

            conn.Open();

            //Create a command to retrieve the data.
            AdomdCommand cmd = new AdomdCommand(@"WITH MEMBER [Measures].[FreightCostPerOrder] AS 
[Measures].[Reseller Freight Cost]/[Measures].[Reseller Order Quantity],  
FORMAT_STRING = 'Currency'

SELECT [Geography].[Geography].[Country].&[United States].Children ON ROWS, 
[Date].[Calendar].[Calendar Year] ON COLUMNS
FROM [Adventure Works]
WHERE [Measures].[FreightCostPerOrder]", conn);

            //Execute the command, retrieving an XmlReader.
            System.Xml.XmlReader reader = cmd.ExecuteXmlReader();

            //Do something with the reader: Parse data, Parse metadata,
            //                              Save for later loading into CellSet, etc.
            Console.WriteLine(reader.ReadOuterXml());

            //Close the reader, then the connection
            reader.Close();
            conn.Close();

            //Await user input.
            Console.ReadLine();
        }
Example #6
0
        /// <summary>
        /// Use when youve got xml data. Like for xml statements
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="sqlParameters"></param>
        /// <returns></returns>
        public string SqlXmlGet(string sql, List <DynaParameter> sqlParameters = null)
        {
            string value;

            using (var conn = new SqlConnection(ConnString))
            {
                var cmd = new SqlCommand(sql, conn);
                if (sqlParameters != null)
                {
                    foreach (var param in sqlParameters)
                    {
                        cmd.Parameters.AddWithValue(param.Name, param.Value);
                    }
                }
                conn.Open();
                System.Xml.XmlReader rdr = cmd.ExecuteXmlReader();
                try
                {
                    var sb = new System.Text.StringBuilder();

                    rdr.Read(); while (!rdr.EOF)
                    {
                        sb.Append(rdr.ReadOuterXml());
                    }

                    value = sb.ToString();
                }
                finally { rdr.Close(); }
                conn.Close();
            }

            return(value);
        }
Example #7
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            System.Xml.XmlReader r = System.Xml.XmlReader.Create("/RichNotepad;component/sample.sav");

            DocumentPersister.parseSavedDocument(r, rta.Blocks);
            r.Close();
        }
Example #8
0
 public override void WriteObject(System.Xml.XmlDictionaryWriter writer, object graph)
 {
     if (this.info.IsWrapped)
     {
         this.serializer.Serialize(writer, graph);
     }
     else
     {
         System.IO.MemoryStream       ms       = new System.IO.MemoryStream();
         System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
         settings.OmitXmlDeclaration = true;
         System.Xml.XmlWriter innerWriter = System.Xml.XmlDictionaryWriter.Create(ms, settings);
         this.serializer.Serialize(innerWriter, graph);
         innerWriter.Close();
         ms.Position = 0;
         System.Xml.XmlReader innerReader = System.Xml.XmlDictionaryReader.Create(ms);
         innerReader.Read();
         writer.WriteAttributes(innerReader, false);
         if ((innerReader.IsEmptyElement == false))
         {
             innerReader.Read();
             for (
                 ; ((innerReader.NodeType == System.Xml.XmlNodeType.EndElement)
                    == false);
                 )
             {
                 writer.WriteNode(innerReader, false);
             }
         }
         innerReader.Close();
     }
 }
Example #9
0
        private void InfoFromPL(Stream stmX, Dictionary <string, string> aC, DataSet ds,
                                ref string sErr, int nRetSrv)
        {
            DataTable dt = xNSI.DT[NSI.TBD_TTN].dt;

            // время с сервера
            xAvt.SrvCTM = aC["CTM"].Trim();
            // сохранить параметры для разбора
            xAvt.SrvAns     = aC["PAR"].Trim();
            xAvt.SrvAns     = xAvt.SrvAns.Substring(1, xAvt.SrvAns.Length - 2);
            xAvt.KolTTN_EBD = 0;

            sErr = "Ошибка чтения XML";
            string sXMLFile  = "";
            int    nFileSize = ServClass.ReadXMLWrite2File(stmX, ref sXMLFile);

            sErr = "Ошибка загрузки XML";

            dt.BeginLoadData();
            dt.Clear();
            System.Xml.XmlReader xmlRd = System.Xml.XmlReader.Create(sXMLFile);
            dt.ReadXml(xmlRd);
            xmlRd.Close();
            xAvt.KolTTN_EBD = dt.Rows.Count;;

            dt.EndLoadData();
            sErr = "OK";
        }
Example #10
0
        public frm_main(bool minimode)
        {
            InitializeComponent();
            mini = new miniNotice();
            if (minimode)
            {
                minimize();
            }
            if (System.IO.File.Exists(Application.StartupPath + "/config.xml"))
            {
                System.Xml.Serialization.XmlSerializer xser = new System.Xml.Serialization.XmlSerializer(typeof(xConfig));
                System.Xml.XmlReader xrea = System.Xml.XmlReader.Create(Application.StartupPath + "/config.xml");
                xConfig c = (xConfig)xser.Deserialize(xrea);
                xrea.Close();
                c.ToRealConfig();
            }
            else if (System.IO.File.Exists(Application.UserAppDataPath + "/config.xml"))
            {
                System.Xml.Serialization.XmlSerializer xser = new System.Xml.Serialization.XmlSerializer(typeof(xConfig));
                System.Xml.XmlReader xrea = System.Xml.XmlReader.Create(Application.UserAppDataPath + "/config.xml");
                xConfig c = (xConfig)xser.Deserialize(xrea);
                xrea.Close();
                c.ToRealConfig();
            }

            UpdateSyncList();
        }
Example #11
0
        public void ReadXmlComponents(System.Xml.XmlReader reader)
        {
            reader.Read();
            try
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        System.Xml.XmlReader implementsReader;
                        System.Xml.XmlReader availableInterfaceReader;

                        DanuComponent comp = new DanuComponent(reader["Name"]);
                        comp.EshuPath = reader["FileLocation"];

                        XmlSerializer eshuSerializer = new XmlSerializer(typeof(EshuComponent));

                        //removed comp.EshuPath -> impossible to store location :( dããã...

                        TextReader eshuReader = new StreamReader(Environment.CurrentDirectory + "/Cache/" + reader["Name"] + ".eshu");
                        comp.Specification = (EshuComponent)eshuSerializer.Deserialize(eshuReader);

                        this.components.Add(comp.Name, comp);

                        reader.Read();
                        implementsReader = reader.ReadSubtree();
                        ReadXmlComponentImplements(implementsReader, comp);
                        implementsReader.Close();

                        reader.Read();
                        availableInterfaceReader = reader.ReadSubtree();
                        ReadXmlComponentAvailableInterfaces(availableInterfaceReader, comp);
                        availableInterfaceReader.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                reader.Close();

                throw ex;
            }
            reader.Close();
        }
        /// <summary>
        /// 根据xml名称从数据库中获取该xml定义的数据
        /// </summary>
        /// <typeparam name="T">数据类型或该类型的基类</typeparam>
        /// <param name="xmlName">xml名称</param>
        /// <returns>该xml中的数据</returns>
        public T Get <T>(string xmlName) where T : class
        {
            if (string.IsNullOrEmpty(xmlName))
            {
                return(null);
            }
            Type     type;
            DataInfo info;

            if (!mDataInfos.TryGetValue(xmlName, out info))
            {
                return(null);
            }
            info.usedTimes++;

            T            ret = null;
            StreamReader sr  = null;

            System.Xml.XmlReader xr = null;
            string path             = string.Format("{0}/../{1}", Application.dataPath, info.path);

            try
            {
                sr   = File.OpenText(path);
                xr   = System.Xml.XmlReader.Create(sr);
                type = info.typeFinder.GetType((ushort)info.typeIndex);
                if (type == null)
                {
                    type = typeof(T);
                }
                if (typeof(T) == type || type.IsSubclassOf(typeof(T)))
                {
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(type);
                    ret = (T)xs.Deserialize(xr);
                }
            }
            catch (Exception e)
            {
                System.Xml.XmlTextReader xtr = xr as System.Xml.XmlTextReader;
                if (xtr != null)
                {
                    Debug.LogError(string.Format("Xml Parse Error At '{0}:{1},{2}'", path, xtr.LineNumber, xtr.LinePosition));
                }
                Debug.LogException(e);
            }
            if (xr != null)
            {
                xr.Close();
            }
            if (sr != null)
            {
                sr.Close();
            }
            return(ret);
        }
Example #13
0
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="XmlReader" /> stream from which the object is deserialized.</param>
        public void ReadXml(System.Xml.XmlReader reader)
        {
            System.Xml.XmlReader shareReader = reader;
            if (reader.IsStartElement())
            {
                shareReader = reader.ReadSubtree();
            }

            while (shareReader.Read())
            {
                while (shareReader.IsStartElement())
                {
                    switch (shareReader.Name)
                    {
                    case IdElementName:
                        this.Id = shareReader.ReadString();
                        break;

                    case TimestampElementName:
                        this.Timestamp = long.Parse(shareReader.ReadString());
                        break;

                    case CommentElementName:
                        this.Comment = shareReader.ReadString();
                        break;

                    case ContentElementName:
                        ShareContent content = new ShareContent();
                        content.ReadXml(shareReader.ReadSubtree());
                        this.Content = content;
                        break;

                    case VisibilityElementName:
                        Visibility visibility = new Visibility();
                        visibility.ReadXml(shareReader);
                        this.Visibility = visibility;
                        break;

                    case SourceElementName:
                        this.Source = Utility.Utilities.DeserializeXml <ShareSource>(shareReader.ReadOuterXml());
                        break;

                    case AuthorElementName:
                        this.Author = Utility.Utilities.DeserializeXml <Person>(string.Format("<person>{0}</person>", shareReader.ReadInnerXml()));
                        break;

                    default:
                        shareReader.Read();
                        break;
                    }
                }
            }

            shareReader.Close();
        }
Example #14
0
        private void ReadReportsInfo()
        {
            var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Demo.Reports.xml");

            System.Xml.XmlReader tr = System.Xml.XmlReader.Create(stream);

            StiTreeViewItem categoryNode    = null;
            BitmapImage     browserCategory = new BitmapImage(new Uri("/Demo;component/Images/browserCategory.png", UriKind.RelativeOrAbsolute));
            BitmapImage     browserReport   = new BitmapImage(new Uri("/Demo;component/Images/browserReport.png", UriKind.RelativeOrAbsolute));

            tr.Read();
            while (!tr.EOF)
            {
                if (tr.IsStartElement())
                {
                    if (tr.Name == "Category")
                    {
                        categoryNode = new StiTreeViewItem();
                        Image img = new Image();
                        img.Width           = 16;
                        img.Height          = 16;
                        img.Source          = browserCategory;
                        categoryNode.Header = GetTreeViewContent(tr.GetAttribute("name"), img);
                        categoryNode.Tag    = tr.GetAttribute("name");
                        reportsDescription[categoryNode.Tag] = tr.GetAttribute("description");
                        treeViewReports.Items.Add(categoryNode);
                    }
                    else if (tr.Name == "Report")
                    {
                        StiTreeViewItem reportNode = new StiTreeViewItem();
                        Image           img        = new Image();
                        img.Width         = 16;
                        img.Height        = 16;
                        img.Source        = browserReport;
                        reportNode.Header = GetTreeViewContent(tr.GetAttribute("name"), img);
                        reportNode.Tag    = tr.GetAttribute("file");
                        reportNode.Cursor = Cursors.Hand;
                        tr.Read();
                        reportsDescription[reportNode.Tag] = tr.Value;
                        categoryNode.Items.Add(reportNode);
                    }
                }
                tr.Read();
            }

            tr.Close();
            stream.Close();
            stream.Dispose();
            tr     = null;
            stream = null;

            ((StiTreeViewItem)treeViewReports.Items[0]).IsExpanded = true;
        }
Example #15
0
        public static List <T> DeserializeListFromXDocument <T>(XDocument xDocument)
        {
            List <T> result = new List <T>();

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List <T>));
            using (System.Xml.XmlReader reader = xDocument.CreateReader())
            {
                result = (List <T>)serializer.Deserialize(reader);
                reader.Close();
            }
            return(result);
        }
Example #16
0
        private List <T> DeserializeParams <T>(XDocument doc)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <T>));

            System.Xml.XmlReader reader = doc.CreateReader();

            List <T> result = (List <T>)serializer.Deserialize(reader);

            reader.Close();

            return(result);
        }
        private void deserialize()
        {
            Locations.Clear();
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List <String>));
            System.Xml.XmlReader reader        = System.Xml.XmlReader.Create(configFile);
            List <String>        locationPaths = serializer.Deserialize(reader) as List <String>;

            foreach (String path in locationPaths)
            {
                Locations.Add(new SystemDirectory(path, this.Dispatcher));
            }
            reader.Close();
        }
Example #18
0
        /// <summary>
        /// 读取XML数据
        /// </summary>
        /// <param name="xmlFile">虚拟路径</param>
        /// <param name="rootName">节点路径(例:/root/resourceclassify)</param>
        /// <param name="keyFiledName">主属性名称</param>
        /// <param name="arrFiledName">子节点名称数组</param>
        /// <returns></returns>
        public static DataTable GetXMLData(string xmlFile, string rootName, string keyFiledName, string[] arrFiledName)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(keyFiledName, typeof(string));
            foreach (string filed in arrFiledName)
            {
                dt.Columns.Add(filed, typeof(string));
            }

            System.Xml.XmlDocument       xmlDoc   = new System.Xml.XmlDocument();
            System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
            settings.IgnoreComments = true;//忽略文档里面的注释

            System.Xml.XmlReader reader = System.Xml.XmlReader.Create(xmlFile, settings);
            xmlDoc.Load(reader);                                       //加载Xml文件

            System.Xml.XmlNode xn = xmlDoc.SelectSingleNode(rootName); //获取根节点

            System.Xml.XmlNodeList xnl = xn.ChildNodes;                //得到根节点的所有子节点
            DataRow dr;

            foreach (System.Xml.XmlNode xn1 in xnl)
            {
                // 将节点转换为元素,便于得到节点的属性值
                System.Xml.XmlElement xe = (System.Xml.XmlElement)xn1;


                dr = dt.NewRow();

                //得到keyFiledName属性的属性值
                dr[keyFiledName] = xe.GetAttribute(keyFiledName).ToString();

                //得到Book节点的所有子节点
                System.Xml.XmlNodeList xnl0 = xe.ChildNodes;
                foreach (System.Xml.XmlNode xn2 in xnl0)
                {
                    foreach (string filed in arrFiledName)
                    {
                        if (xn2.Name == filed)
                        {
                            dr[filed] = xn2.InnerXml;
                            break;
                        }
                    }
                }
                dt.Rows.Add(dr);
            }
            reader.Close();
            return(dt);
        }
Example #19
0
        static StackObject *Close_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Xml.XmlReader instance_of_this_method = (System.Xml.XmlReader) typeof(System.Xml.XmlReader).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Close();

            return(__ret);
        }
 public void Close()
 {
     if (mReader != null)
     {
         mReader.Close();
     }
     if (mFile != null)
     {
         mFile.Close();
     }
     mReader = null;
     mFile   = null;
     mPath   = string.Empty;
 }
Example #21
0
        public static titleItems getNews(String url)
        {
            //declared at this stage to return the value
            titleItems mainItems;

            //using the xml reader to read the url passed through from Program class
            using (System.Xml.XmlReader rdr = System.Xml.XmlReader.Create(url))
            {
                //Syndication feed loads the feed from the given url
                SyndicationFeed feed = SyndicationFeed.Load(rdr);

                //declaring mainItems class
                mainItems = new titleItems();
                //declaring the itemlist of child news items
                List <Items> itemList = new List <Items>();

                //for each item within the feed
                foreach (var item in feed.Items)
                {
                    // creation of main object follows the children containing each news feed
                    if (item.Title.Text == "BBC News Channel")
                    {
                        //sets the main title, link and desc if the title text == the title usually given
                        //very error prone although it works in this instance
                        mainItems.title       = item.Title.Text;
                        mainItems.link        = item.Id;
                        mainItems.description = item.Summary.Text;
                    }
                    else
                    {
                        //otherwise it sets the items accordingly
                        Items newsItemList = new Items();
                        newsItemList.title       = item.Title.Text;
                        newsItemList.link        = item.Id;
                        newsItemList.description = item.Summary.Text;
                        newsItemList.pubDate     = item.PublishDate.ToString();

                        // adds the news to the main object
                        itemList.Add(newsItemList);
                    }
                }

                mainItems.items = itemList;
                //close reader once we have finished reading feed and return feed object.
                rdr.Close();
            }
            //value being returned
            return(mainItems);
        }
Example #22
0
        /// <summary>
        /// Sends a custom SOAP Envelope request to Analysis Services and displays the result in Console.
        /// </summary>
        private static void StartAndEndXmlaRequest(Server server)
        {
            //--------------------------------------------------------------------------------
            // To run a custom full SOAP Envelope request on Analysis Services server, we
            // need to follow 5 steps:
            //
            // 1. Start the XML/A request and specify its type (Discover or Execute).
            //    For native connections (direct over TCP/IP with DIME protocol), local
            //    cube connections and stored procedures connections we don't need to
            //    specify the XML/A request type in advance (an Undefined value is
            //    available). But for HTTP and HTTPS connections we need to.
            //
            // 2. Write the xml request (as an xml SOAP Envelope containing the command
            //    for Analysis Services).
            //
            // 3. End the xml request; this will send the previously written request to the
            //    server for execution.
            //
            // 4. Read/Parse the xml response from the server (with System.Xml.XmlReader).
            //
            // 5. Close the System.Xml.XmlReader from the previous step, to release the
            //    connection to be used after.
            //--------------------------------------------------------------------------------

            // Step 1: start the XML/A request.
            System.Xml.XmlWriter xmlWriter = server.StartXmlaRequest(XmlaRequestType.Undefined);

            // Step 2: write the XML/A request.
            WriteSoapEnvelopeWithEmptyBatch(xmlWriter, server.SessionID);

            // Step 3: end the XML/A request and get the System.Xml.XmlReader for parsing the result from server.
            System.Xml.XmlReader xmlReader = server.EndXmlaRequest();

            // Step 4: read/parse the XML/A response from server.
            xmlReader.MoveToContent();
            string fullEnvelopeResponseFromServer = xmlReader.ReadOuterXml();

            // Step 5: close the System.Xml.XmlReader, to release the connection for future use.
            xmlReader.Close();


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("========== XML/A RESPONSE ==========");
            Console.WriteLine(fullEnvelopeResponseFromServer);
        }
Example #23
0
        private void Deserialize()
        {
            var d = new System.IO.DirectoryInfo(ProgramsDirectory);

            System.IO.FileInfo[] files = d.GetFiles("*.sbc");
            foreach (System.IO.FileInfo file in files)
            {
                var str = _programsDirectory + @"\" + file.Name;

                using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(str))
                {
                    try
                    {
                        while (reader.Read())
                        {
                            switch (reader.NodeType)
                            {
                            case System.Xml.XmlNodeType.Element:
                                if (reader.Name == "TaskItem")
                                {
                                    TaskItem document = new TaskItem();
                                    document.ReadXml(reader);
                                    _taskList.Add(document);
                                }
                                break;

                            case System.Xml.XmlNodeType.EndElement:
                                if (reader.Name == "TaskItem")
                                {
                                    return;
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }

            File.WriteAllText(@"C:\temp\logfile.txt", _taskList.Count.ToString());
            _isDeserialized = true;
        }
Example #24
0
        private void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            btnNew_Click(sender, e);

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            ofd.Filter      = "Saved Files|*.sav|All Files|*.*";

            if (ofd.ShowDialog().Value)
            {
                FileInfo             fi = ofd.File;
                System.Xml.XmlReader r  = System.Xml.XmlReader.Create(fi.OpenText());

                DocumentPersister.parseSavedDocument(r, rta.Blocks);
                r.Close();
            }
        }
Example #25
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;

            XmlSerializer interfaceSerializer = new XmlSerializer(typeof(EshuInterface));
            XmlSerializer classSerializer     = new XmlSerializer(typeof(EshuClass));

            Name = reader["Name"];

            reader.ReadToFollowing("Interfaces");
            System.Xml.XmlReader interfaceReader = reader.ReadSubtree();

            interfaceReader.Read();
            while (interfaceReader.ReadToFollowing("EshuInterface"))
            {
                interfaces.Add((EshuInterface)interfaceSerializer.Deserialize(interfaceReader));
            }
            interfaceReader.Close();

            reader.ReadToFollowing("Classes");
            System.Xml.XmlReader classReader = reader.ReadSubtree();

            classReader.Read();
            while (classReader.ReadToFollowing("EshuClass"))
            {
                if (classReader.Name.Equals("EshuClass"))
                {
                    EshuClass newClass = new EshuClass(reader["Name"]);
                    while (classReader.ReadToFollowing("Interface"))
                    {
                        newClass.AddInterface(GetInterface(reader.ReadElementString()));
                    }
                    foreach (EshuInterface io in newClass.Interfaces)
                    {
                        io.Parent = newClass;
                    }
                    newClass.Parent = this;
                    classes.Add(newClass);
                }
            }
            classReader.Close();
        }
Example #26
0
        private void LoadEmoticons()
        {
            System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(
                                                                          (string)LANChat.Resources.Properties.Resources.ResourceManager.GetObject("emoticon_defs")));

            emotList   = new List <Emoticon>();
            emotMapper = new List <KeyValuePair <int, string> >();

            int id = -1;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element:
                    if (reader.Name.Equals("Emoticon"))
                    {
                        id++;
                        //  Get emoticon code.
                        reader.MoveToNextAttribute();
                        string code = reader.Value;
                        //  Get emoticon description.
                        reader.MoveToNextAttribute();
                        string description = reader.Value;
                        //  Get emoticon image key.
                        reader.MoveToNextAttribute();
                        string imageKey = reader.Value;

                        emotList.Add(new Emoticon(id, code, description, imageKey));
                    }
                    break;

                case System.Xml.XmlNodeType.Text:
                    string text = reader.Value;

                    emotMapper.Add(new KeyValuePair <int, string>(id, text));
                    break;
                }
            }
            if (reader != null)
            {
                reader.Close();
            }
        }
Example #27
0
        private static void deserializeStacks()
        {
            if (Interop.Shell.Exists(stackConfigFile))
            {
                System.Xml.XmlReader reader        = System.Xml.XmlReader.Create(stackConfigFile);
                List <String>        locationPaths = serializer.Deserialize(reader) as List <String>;
                foreach (String path in locationPaths)
                {
                    StacksManager.AddLocation(path);
                }
                reader.Close();
            }
            else
            {
                // Add some default folders on FirstRun

                // Check for Documents Folder
                String myDocsPath = Interop.KnownFolders.GetPath(Interop.KnownFolder.Documents);
                if (Directory.Exists(myDocsPath))
                {
                    SystemDirectory myDocsSysDir = new SystemDirectory(myDocsPath, Dispatcher.CurrentDispatcher);
                    // Don't duplicate defaults
                    if (!StackLocations.Contains(myDocsSysDir))
                    {
                        StackLocations.Add(myDocsSysDir);
                    }
                }
                // Check for Downloads folder
                String downloadsPath = Interop.KnownFolders.GetPath(Interop.KnownFolder.Downloads);
                if (Directory.Exists(downloadsPath))
                {
                    SystemDirectory downloadsSysDir = new SystemDirectory(downloadsPath, Dispatcher.CurrentDispatcher);
                    // Don't duplicate defaults
                    if (!StackLocations.Contains(downloadsSysDir))
                    {
                        StackLocations.Add(downloadsSysDir);
                    }
                }

                // save
                serializeStacks();
            }
        }
Example #28
0
        private void AvtoList(SocketStream stmX, Dictionary <string, string> aC, DataSet ds,
                              ref string sErr, int nRetSrv)
        {
            object xDS = dgShlyuz.DataSource;

            dgShlyuz.SuspendLayout();
            dgShlyuz.DataSource = null;
            try
            {
                sErr = "Ошибка чтения XML";
                string sXMLFile = "";

                //int nFileSize = ServClass.ReadXMLWrite2File(stmX.SStream, ref sXMLFile);
                stmX.ASReadS.TermDat = AppC.baTermMsg;
                if (stmX.ASReadS.BeginARead(true, 1000 * 60) == SocketStream.ASRWERROR.RET_FULLMSG)
                {
                    sXMLFile = stmX.ASReadS.OutFile;
                }
                else
                {
                    throw new System.Net.Sockets.SocketException(10061);
                }

                sErr = "Ошибка загрузки XML";
                DataSet   dsZ = new DataSet("dsZ");
                DataTable dt  = xNSI.DT[NSI.BD_SOTG].dt;
                dt.BeginInit();
                dt.Rows.Clear();
                System.Xml.XmlReader xmlRd = System.Xml.XmlReader.Create(sXMLFile);
                dt.ReadXml(xmlRd);
                xmlRd.Close();
                System.IO.File.Delete(sXMLFile);
                dt.EndInit();
                sErr = "OK";
            }
            finally
            {
                dgShlyuz.DataSource = xDS;
                bsSh.ResetBindings(false);
                dgShlyuz.ResumeLayout();
            }
        }
Example #29
0
            //private void NsiFromSrv(Stream stmX, Dictionary<string, string> aC, DataSet ds,
            //    ref string sErr, int nRetSrv)
            //{
            //    string sMD5New = aC["MD5"];
            //    string sP = xNSI.sPathNSI + xNSI.DT[sTName].sXML;

            //    DataTable dtAdded = null;
            //    int nAddedCount = 0;

            //    if ((bMD_5 == true) && (sMD5New == sMD5Old))
            //        sErr = "OK-No Load";
            //    else
            //    {
            //        sErr = "Ошибка чтения XML";
            //        string sXMLFile = "";
            //        int nFileSize = ServClass.ReadXMLWrite2File(stmX, ref sXMLFile);
            //        switch (sTName)
            //        {
            //            case NSI.I_TMT:
            //                dtAdded = dt.Clone();
            //                dtAdded.BeginLoadData();

            //                foreach (DataRow dr in dt.Rows)
            //                {
            //                    if ( (System.DBNull.Value != dr["SOURCE"]) &&
            //                         (NSI.DOCSRC_ZVKLOAD == (int)dr["SOURCE"]) )
            //                    {// добавить в буфер для восстановления
            //                        dtAdded.ImportRow(dr);
            //                    }
            //                }
            //                dtAdded.EndLoadData();
            //                nAddedCount = dtAdded.Rows.Count;
            //                break;
            //        }

            //        sErr = "Ошибка загрузки XML";
            //        dt.BeginLoadData();
            //        dt.Clear();
            //        System.Xml.XmlReader xmlRd = System.Xml.XmlReader.Create(sXMLFile);
            //        dt.ReadXml(xmlRd);
            //        xmlRd.Close();
            //        if (nAddedCount > 0)
            //        {
            //            dt.Merge(dtAdded);
            //        }

            //        dt.EndLoadData();

            //        sErr = "Ошибка сохранения XML";
            //        //File.Delete( sP );
            //        //File.Move(sXMLFile, sP);
            //        dt.WriteXml(sP);

            //        xNSI.DT[NSI.BD_TINF].dt.Rows[sTName]["MD5"] = sMD5New;
            //        sErr = "OK";
            //    }
            //}

            private void NsiFromSrv(Stream stmX, Dictionary <string, string> aC, DataSet ds,
                                    ref string sErr, int nRetSrv)
            {
                string sMD5New = aC["MD5"];
                string sP      = xNSI.sPathNSI + xNSI.DT[sTName].sXML;

                //DataTable dtAdded = null;
                //int nAddedCount = 0;

                if ((bMD_5 == true) && (sMD5New == sMD5Old))
                {
                    sErr = "OK-No Load";
                }
                else
                {
                    sErr = "Ошибка чтения XML";
                    string sXMLFile  = "";
                    int    nFileSize = ServClass.ReadXMLWrite2File(stmX, ref sXMLFile);

                    sErr = "Ошибка загрузки XML";
                    dt.BeginLoadData();
                    dt.Clear();
                    System.Xml.XmlReader xmlRd = System.Xml.XmlReader.Create(sXMLFile);
                    dt.ReadXml(xmlRd);
                    xmlRd.Close();
                    //if (nAddedCount > 0)
                    //  dt.Merge(dtAdded);

                    dt.EndLoadData();

                    sErr = "Ошибка сохранения XML";
                    //File.Delete( sP );
                    //File.Move(sXMLFile, sP);
                    dt.WriteXml(sP);

                    if (drMD5 != null)
                    {
                        drMD5["MD5"] = sMD5New;
                    }
                    sErr = "OK";
                }
            }
Example #30
0
        static void Main(string[] args)
        {
            Matrix Key = new Matrix();

            Double[,] BigraphStat = new Double[25, 25];

            // CreateBS(@"H:\BS\BS.txt", @"H:\BS\BS.xml");


            // Read Bigraph Statistic from xml file
            string BsPath = @"H:\BS\BSLog10.xml";

            System.Xml.Serialization.XmlSerializer ReadBS = new System.Xml.Serialization.XmlSerializer(typeof(Double[][]));
            System.Xml.XmlReader XmlReader        = System.Xml.XmlReader.Create(BsPath);
            Double[][]           BigraphStatDummy = (Double[][])ReadBS.Deserialize(XmlReader);
            XmlReader.Close();

            for (int i = 0; i < 25; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    BigraphStat[i, j] = BigraphStatDummy[i][j];
                }
            }

            // Read Key from txt file
            Key.ReadMatrixFile(@"H:\Key.txt");

            // Create Ciphertext from txt file
            string CipherText = PlayFair.Encrypt(Key, PlayFair.Format(System.IO.File.ReadAllText(@"H:\Plaintext.txt")));


            string CrackedCipherText = PlayFair.Attack(CipherText, BigraphStat);


            Console.WriteLine("\nMatch: " + (CrackedCipherText == PlayFair.Format(System.IO.File.ReadAllText(@"H:\Plaintext.txt"))));
            Console.WriteLine("\nCracked Cipher:\n\n" + CrackedCipherText);
            Console.In.ReadLine();
        }