Beispiel #1
0
 public static void ReadingListToXml(string fileName)
 {
     DataTable readData = DatabaseWrapper.GetCompleteReadingData();
     XDocument xDocument = new XDocument(
         new XDeclaration("1.0", "utf-8", "yes"),
         new XComment("Reading List Xml file"));
     XElement rootElement = new XElement("mangaReadingList");
     xDocument.AddFirst(rootElement);
     for (int i = 0; i < readData.Rows.Count; i++)
     {
         Debug.WriteLine(readData.Rows[i][1].ToString());
         XElement readElement = new XElement("manga",
                                             new XElement("Title",
                                                          DatabaseWrapper.GetMangaTitle(
                                                              int.Parse(readData.Rows[i][1].ToString()))),
                                             new XElement("startingChapter", readData.Rows[i][2].ToString()),
                                             new XElement("currentChapter", readData.Rows[i][3].ToString()),
                                             new XElement("onlineURL", readData.Rows[i][4].ToString()),
                                             new XElement("finishedReading",
                                                          bool.Parse(readData.Rows[i][5].ToString())),
                                             new XElement("dateRead", readData.Rows[i][6].ToString()),
                                             new XElement("mangaNote", readData.Rows[i][7].ToString())
             );
         rootElement.Add(readElement);
     }
     xDocument.Save(fileName);
 }
Beispiel #2
0
 /// <summary>
 /// Создание объекта формирования xml файла
 /// </summary>
 /// <param name="workSheetName">Имя листа</param>
 public XMLExcel( string workSheetName )
 {
     _data = new XDocument( new XDeclaration( "1.0", "", "" ) );
     _data.AddAnnotation( "mso-application progid=\"Excel.Sheet\"" );
     _rootEX = new XElement( _ss + "Workbook",
         new XAttribute( "xmlns", _ss.NamespaceName ),
         new XAttribute( XNamespace.Xmlns + "o", _o.NamespaceName ),
         new XAttribute( XNamespace.Xmlns + "x", _x.NamespaceName ),
         new XAttribute( XNamespace.Xmlns + "ss", _ss.NamespaceName ),
         new XAttribute( XNamespace.Xmlns + "html", _html.NamespaceName ),
         new XElement( _o + "DocumentProperties",
             new XAttribute( "xmlns", _o.NamespaceName ),
             new XElement( _o + "Author", " " ),
             new XElement( _o + "Version", "12.00" ) ),
         new XElement( _x + "ExcelWorkbook",
             new XAttribute( "xmlns", _x.NamespaceName ),
             new XElement( _x + "ProtectStructure", "False" ),
             new XElement( _x + "ProtectWindows", "False" ) ),
         XElement.Parse( Resources.XMLExcelStyle ).FirstNode,
         new XElement( _ss + "Worksheet", new XAttribute( _ss + "Name", workSheetName ),
         _workTable = new XElement( _ss + "Table",
             new XAttribute( _x + "FullColumns", "1" ),
             new XAttribute( _x + "FullRows", "1" ),
             new XAttribute( _ss + "DefaultRowHeight", "15" ) ) ) );
     _data.AddFirst( _rootEX );
 }
Beispiel #3
0
        public override string ToString()
        {
            var xml = new XDocument();
            var methodCall = new XElement("methodCall");
            methodCall.Add(new XElement("methodName", Method));
            xml.AddFirst(methodCall);

            if (Parameters.Count > 0)
            {
                var structi = new XElement("struct");
                var paramss = new XElement("params",
                                           new XElement("param",
                                                        new XElement("value", structi)));

                foreach (var xmlParameter in Parameters)
                {
                    var member = new XElement("member", new XElement("name", xmlParameter.Name), GetParameterValue(xmlParameter.Value));
                    structi.Add(member);
                }

                methodCall.Add(paramss);
            }

            return xml.ToString();
        }
Beispiel #4
0
 /// <summary>
 /// Creates the XML contents of an eagle board file
 /// </summary>
 /// <returns></returns>
 public XDocument ToXml()
 {
     var doc= new XDocument()
     {
         Declaration = new       XDeclaration("1.0","utf-8",null)
     };
     var rootNode = new XElement("eagle",
         new XAttribute("version", this.Version),
         new XElement("drawing",
             GetLayers(),
             new XElement("board",
                 GetDimension(),
                 new XElement("libraries",
                     new XElement("library", new XAttribute("name", "default"),
                         GetPackages()
                         )
                     ),
                 new DefaultDesignRules().RulesXml,
                 GetElements(),
                 GetSignals())));
     doc.AddFirst(new XDocumentType("eagle", null, "eagle.dtd", null));
     doc.Add(rootNode);
     var x = new XElement("test");
     return doc;
 }
Beispiel #5
0
        /// <summary>
        /// Create html file with information about timetable and save it
        /// </summary>
        /// <param name="Path">Where html file should be saved</param>
        /// <param name="station">Station</param>
        public void SaveTimetables(string Path, Station station)
        {
            FileStream fs = new FileStream(Path, FileMode.Create);

            XDocument document = new XDocument();
            document.AddFirst(new XElement("html"));

            document.Root.Add(new XElement("head",
                new XElement("title", station.Name)));

            XElement body = new XElement("body");
            XElement div = new XElement("div");
            foreach (Timetable tt in station)
            {
                XElement inner = new XElement("div", new XAttribute("style", "width:800px;"));
                inner.Add(new XElement("div", tt.FirstStation + " - " + tt.LastStation, new XAttribute("style", "border:solid; float:left; width:400px; heigth:20px;"), new XAttribute("align", "center")),
                    new XElement("div", tt.TimeOfArrival.ToString() + " - " + tt.TimeOfDeparture.ToString(), new XAttribute("style", "border:solid; float:left; width:150px; heigth:20px;"), new XAttribute("align", "center")),
                    new XElement("div", tt.FreqType, new XAttribute("style", "border:solid; float:left; width:150px; heigth:20px;"), new XAttribute("align", "center")),
                    new XElement("br"));
                div.Add(inner);
            }
            body.Add(div);
            document.Root.Add(body);

            document.Save(fs);
            fs.Close();
        }
Beispiel #6
0
 static UserDal()
 {
     if (File.Exists(UserDal.fileName) == false)
     {
         XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
         doc.AddFirst(new XElement("users"));
         doc.Save(UserDal.fileName);
     }
 }
        public void CreateHtmlFromVideoCollection(IEnumerable<Video> videos)
        {
            var document = new XDocument();
            document.AddFirst(new XDocumentType("html", null, null, null));

            var html = new XElement("html");
            var head = new XElement("head");
            var meta = new XElement("meta");

            meta.SetAttributeValue("charset", "UTF - 8");
            head.Add(meta);

            var title = new XElement("title", "Telerik Academy Video Archive");
            head.Add(title);

            var styles = new XElement("link");
            styles.SetAttributeValue("rel", "stylesheet");
            styles.SetAttributeValue("href", "styles/video-archive-styles.css");
            head.Add(styles);

            html.Add(head);

            var body = new XElement("body");
            var pageTitle = new XElement("h1", "Telerik Academy Videos");
            body.Add(pageTitle);

            foreach (var video in videos)
            {
                var div = new XElement("div", new XElement("h3", video.Title));
                div.SetAttributeValue("class", "container");

                var videoFrame = new XElement("iframe", string.Empty);
                videoFrame.SetAttributeValue("frameborder", "0");
                videoFrame.SetAttributeValue("src", "https://www.youtube.com/embed/" + video.VideoId);
                div.Add(videoFrame);

                var youtubeLink = new XElement("a", "Youtube");
                youtubeLink.SetAttributeValue("href", video.Link);

                div.Add(youtubeLink);
                body.Add(div);
            }

            html.Add(body);
            document.Add(html);
            var writerSettings = new XmlWriterSettings();
            writerSettings.OmitXmlDeclaration = true;
            writerSettings.NewLineOnAttributes = true;
            writerSettings.Indent = true;

            var writer = XmlWriter.Create("../../index.html", writerSettings);
            document.Save(writer);
            writer.Close();

            Console.WriteLine("index.html generated");
        }
        private static void GenerateHtml(IEnumerable<Video> videos)
        {
            var doc = new XDocument();
            doc.AddFirst(new XDocumentType("html", null, null, null));

            var html = new XElement("html");
            var head = new XElement("head");

            var meta = new XElement("meta");
            meta.SetAttributeValue("charset", "UTF - 8");
            head.Add(meta);

            var title = new XElement("title", "Teleik Academy Videos");
            head.Add(title);

            var styles = new XElement("link");
            styles.SetAttributeValue("rel", "stylesheet");
            styles.SetAttributeValue("href", "stylesheet.css");
            head.Add(styles);

            html.Add(head);

            var body = new XElement("body");

            foreach (var video in videos)
            {
                var videoDiv = new XElement("div", new XElement("p", video.Title));
                videoDiv.SetAttributeValue("class", "container");

                var iframe = new XElement("iframe", string.Empty);
                iframe.SetAttributeValue("frameborder", "0");
                iframe.SetAttributeValue("src", @"https://www.youtube.com/embed/" + video.Id);
                videoDiv.Add(iframe);

                var link = new XElement("a", "Watch in YouTube");
                link.SetAttributeValue("href", video.Link);

                videoDiv.Add(link);
                body.Add(videoDiv);
            }

            html.Add(body);
            doc.Add(html);
            var settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            settings.NewLineOnAttributes = true;
            settings.Indent = true;

            var writter = XmlWriter.Create("../../index.html", settings);
            doc.Save(writter);
            writter.Close();

            //Console.WriteLine("You can find the generated index.html in the main directory");
        }
Beispiel #9
0
 public void SaveComputer(string Path, PC computer)
 {
     XDocument doc = new XDocument();
     XElement root = new XElement("Computer");
     root.Add(new XElement("ID", computer.ID));
     root.Add(new XElement("VideoCount", computer.VideoCount));
     root.Add(new XElement("RAMCount", computer.RAMCount));
     root.Add(new XElement("HDDCapacity", computer.HDDCapacity));
     doc.AddFirst(root);
     doc.Save(Path);
 }
        public static XDocument ConvertToCobertura(XDocument openCoverReport, string sourcesDirectory)
        {
            if (openCoverReport == null)
            {
                throw new ArgumentNullException("openCoverReport");
            }

            XDocument result = new XDocument(new XDeclaration("1.0", null, null), CreateRootElement(openCoverReport, sourcesDirectory));
            result.AddFirst(new XDocumentType("coverage", null, "http://cobertura.sourceforge.net/xml/coverage-04.dtd", null));

            return result;
        }
Beispiel #11
0
 public static void SaveChannels(IEnumerable<RSSChannel> channels,string fileName)
 {
     var document = new XDocument();;
     document.AddFirst(new XElement("channels"));
     foreach (var channel in channels)
     {
         var title = new XElement("title", channel.Title);
         var link = new XElement("link", channel.Link);
         document.Root.Add(new XElement("channel", title, link));
     }
     document.Save(fileName, SaveOptions.None);
 }
Beispiel #12
0
        public ViolationList()
        {
            _document = new XDocument();

            var header = new XElement("Modules");
            _document.AddFirst(header);

            var module = new XElement("Module");
            module.SetAttributeValue(XName.Get("Name"), "FluentValidation.Mvc3");

            _document.Descendants().First().Add(module);
        }
Beispiel #13
0
        public XDocument CreateReport(TestItem testItem, TestEnvironmentInfo testEnvironmentInfo)
        {
            XDocument report = new XDocument();
            report.AddFirst(new XDocumentType("html", null, null, null));

            var html = new XElement("html");
            html.Add(GetHead());
            html.Add(GetBody(testItem, testEnvironmentInfo));

            report.Add(html);

            return report;
        }
        public string ToPapXml()
        {
            var doc = new XDocument ();

            var docType = new XDocumentType("pap", "-//WAPFORUM//DTD PAP 2.1//EN", "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd", "<?wap-pap-ver supported-versions=\"2.0\"?>");

            doc.AddFirst (docType);

            var pap = new XElement ("pap");

            var pushMsg = new XElement ("push-message");

            pushMsg.Add (new XAttribute ("push-id", this.PushId));
            pushMsg.Add(new XAttribute("source-reference", this.SourceReference));

            if (!string.IsNullOrEmpty (this.PpgNotifyRequestedTo))
                pushMsg.Add(new XAttribute("ppg-notify-requested-to", this.PpgNotifyRequestedTo));

            if (this.DeliverAfterTimestamp.HasValue)
                pushMsg.Add (new XAttribute ("deliver-after-timestamp", this.DeliverAfterTimestamp.Value.ToUniversalTime ().ToString("s", CultureInfo.InvariantCulture) + "Z"));
            if (this.DeliverBeforeTimestamp.HasValue)
                pushMsg.Add (new XAttribute ("deliver-before-timestamp", this.DeliverBeforeTimestamp.Value.ToUniversalTime ().ToString("s", CultureInfo.InvariantCulture) + "Z"));

            //Add all the recipients
            foreach (var r in Recipients)
            {
                var address = new XElement("address");

                var addrValue = r.Recipient;

                if (!string.IsNullOrEmpty(r.RecipientType))
                {
                    addrValue = string.Format("WAPPUSH={0}%3A{1}/TYPE={2}", System.Web.HttpUtility.UrlEncode(r.Recipient),
                        r.Port, r.RecipientType);
                }

                address.Add(new XAttribute("address-value", addrValue));
                pushMsg.Add (address);
            }

            pushMsg.Add (new XElement ("quality-of-service", new XAttribute ("delivery-method", this.QualityOfService.ToString ().ToLowerInvariant ())));

            pap.Add(pushMsg);
            doc.Add (pap);

            return "<?xml version=\"1.0\"?>" + Environment.NewLine + doc.ToString (SaveOptions.None);
        }
        public static XDocument ConvertToCobertura(XDocument openCoverReport, string sourcesDirectory, bool includeGettersSetters)
        {
            if (openCoverReport == null)
            {
                throw new ArgumentNullException(nameof(openCoverReport));
            }

            if (sourcesDirectory != null)
            {
                sourcesDirectory = sourcesDirectory.Replace("/", "\\");
            }

            XDocument result = new XDocument(new XDeclaration("1.0", null, null), CreateRootElement(openCoverReport, sourcesDirectory, includeGettersSetters));
            result.AddFirst(new XDocumentType("coverage", null, "http://cobertura.sourceforge.net/xml/coverage-04.dtd", null));

            return result;
        }
Beispiel #16
0
        /// <summary>
        /// Сохраняет данные об играх в БД
        /// </summary>
        /// <param name="Path">Путь к БД</param>
        public static void Create(List<Game> games, string path)
        {
            XDocument doc = new XDocument();
            XElement root = new XElement("Games");
            doc.AddFirst(root);

            foreach (Game game in games)
            {
                root.Add(new XElement("Game", new XAttribute("Title", game.Title),
                    new XAttribute("ID", game.ID),
                    new XAttribute("Genre", game.Genre.ToString()),
                    new XElement("Logo", game.Logo),
                    new XElement("Description", game.Description),
                    new XElement("Path", game.Exe)));
            }

            doc.Save(path);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            XDocument _doc = XDocument.Load(@"C:\Users\Milad\Documents\Jobs\Codiato\Codiato.Khayyam\Codiato.Khayyam.WPUI\Data\KhayyamPoem - old.xml");
            var poems = _doc.Descendants("poems").First()
                .Descendants("poem").Select(p => new { Content = p.Attribute("content").Value });

            string[] seperator = { "\r\n" };
            var quadrants = new List<quadrant>();
            foreach (var poem in poems)
            {
                var q = new quadrant();
                string[] temp = poem.Content.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
                q.first.firstMesra = temp[0].Split('\t')[0];
                q.first.secondMesra = temp[0].Split('\t')[1];

                q.second.firstMesra = temp[1].Split('\t')[0];
                q.second.secondMesra = temp[1].Split('\t')[1];

                quadrants.Add(q);
            }

            List<XNode> _el = new List<XNode>();
            int i = 1;
            foreach (var q in quadrants)
            {
                XNode quadrant = new XElement("poem",
                    new XAttribute("title", q.first.firstMesra),
                    new XElement("id", i++),
                    new XElement("first", q.first.firstMesra),
                    new XElement("second", q.first.secondMesra),
                    new XElement("third", q.second.firstMesra),
                    new XElement("fourth", q.second.secondMesra)
                    );

                _el.Add(quadrant);
            }

            var _newDoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));
            _newDoc.AddFirst(new XElement("poems", _el.ToArray()));

            _newDoc.Save(@"C:\Users\Milad\Documents\Jobs\Codiato\Codiato.Khayyam\Codiato.Khayyam.WPUI\Data\KhayyamPoem - new.xml");

            Console.Read();
        }
 public void InvalidAddIntoXDocument3()
 {
     _runWithEvents = (bool)Params[0];
     try
     {
         var doc = new XDocument(new XProcessingInstruction("pi", "halala"), new XElement("A"));
         var o = new XElement("C");
         if (_runWithEvents)
         {
             _eHelper = new EventsHelper(doc);
         }
         doc.AddFirst(o);
         if (_runWithEvents)
         {
             _eHelper.Verify(XObjectChange.Add, o);
         }
         TestLog.Compare(false, "Exception expected");
     }
     catch (InvalidOperationException)
     {
     }
 }
 public void InvalidAddIntoXDocument1()
 {
     _runWithEvents = (bool)Params[0];
     try
     {
         var doc = new XDocument(new XDocumentType("root", null, null, null), new XElement("A"));
         var o = new XDocumentType("D", null, null, null);
         if (_runWithEvents)
         {
             _eHelper = new EventsHelper(doc);
         }
         doc.AddFirst(o);
         if (_runWithEvents)
         {
             _eHelper.Verify(XObjectChange.Add, o);
         }
         TestLog.Compare(false, "Exception expected");
     }
     catch (InvalidOperationException)
     {
     }
 }
 public void InvalidAddIntoXDocument5()
 {
     _runWithEvents = (bool)Params[0];
     foreach (object o in new object[] { new XCData("CD"), new XAttribute("a1", "avalue"), "text1", new XText("text2"), new XDocument() })
     {
         try
         {
             var doc = new XDocument(new XElement("A"));
             if (_runWithEvents)
             {
                 _eHelper = new EventsHelper(doc);
             }
             doc.AddFirst(o);
             if (_runWithEvents)
             {
                 _eHelper.Verify(XObjectChange.Add, o);
             }
             TestLog.Compare(false, "Exception expected");
         }
         catch (ArgumentException)
         {
         }
     }
 }
Beispiel #21
0
        /// <summary>
        /// Saves this library info to the specified file.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        public void Save(string fileName)
        {
            var doc = new XDocument();
            doc.AddFirst(new XComment("This file is needed to correctly identify xap version. Remove it to rebuild libraries"));

            doc.Add(
                new XElement(
                    VersionInfoElementName,
                    new XElement(VersionElementName, new XAttribute(ValueAttributeName, Version)),
                    new XElement(VeyronMetaElementName, new XAttribute(ValueAttributeName, MetaDatabaseConnectionString)),
                    new XElement(VeyronRuntimeElementName, new XAttribute(ValueAttributeName, RuntimeDatabaseConnectionString)),
                    new XElement(VersionProcessLibInCloudElementName, new XAttribute(ValueAttributeName, VersionInCloud)),
                    new XElement(FullTextSearchEnabledElementName, new XAttribute(ValueAttributeName, FullTextSearchEnabled))));

            doc.Save(fileName, SaveOptions.None);
        }
Beispiel #22
0
        /// <summary>
        /// Сохранить проект
        /// </summary>
        public void Save()
        {
            CheckObjects();

            XDocument xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            XElement xEl = new XElement("TalesGeneratorProject");
            xDoc.AddFirst(xEl);
            xEl.Add(_network.SaveToXml());
            DiagramSerializer diagSr = new DiagramSerializer(Diagram);
            diagSr.SaveToXDocument(xDoc);
            xDoc.Save(_path);
        }
Beispiel #23
0
        private string GetEmtpyFeed( string trackerForeignId )
        {
            XDocument doc = new XDocument( this.emptySource.Declaration );

              doc.AddFirst( this.emptySource.Root );

              // ReSharper disable PossibleNullReferenceException
              doc
            .Element( "response" )
            .Element( "errors" )
            .Element( "error" )
            .Element( "description" )
            .Value += trackerForeignId;
              // ReSharper restore PossibleNullReferenceException

              return doc.ToString( );
        }
Beispiel #24
0
        internal string GetFeed( string trackerForeignId )
        {
            lock ( Sync )
              {
            int positionNumber = PositionNumber;

            if ( positionNumber <= 0 )
              return GetEmtpyFeed( trackerForeignId );

            string name = trackerForeignId.Substring( TestIdPrefix.Length );

            /*  Take from each source one after another.
             *  Say PositionNumber=9 and source is S1, what would be a max number of
             *  elements (N) to take from the source?
             *
             *  N   S1  S2  S3  S4
             *  1   .   .   .   .
             *  2   .   .   .   .
             *  3   .
             *
             *  For S1 it will be 3. Calc as: at least 9/4=2. And if 17%4 > (index of the
             *  source, for S1 it's 0) then add 1. 17%4=1 > 0, so result is 2+1=3
             *
             */

            XDocument source = this.sourceData[name];

            int nMaxFromThisSource =
              positionNumber / this.sourceData.Count;

            int nameIndex = this.sourceData.Keys.IndexOf( name );

            if ( positionNumber % this.sourceData.Count > nameIndex )
              nMaxFromThisSource += 1;

            if ( nMaxFromThisSource == 0 )
              return GetEmtpyFeed( trackerForeignId );

            XDocument doc = new XDocument( source.Declaration );

            doc.AddFirst( source.Root );

            // ReSharper disable PossibleNullReferenceException
            IEnumerable<XElement> messages =
              doc.Root
            .Element( "feedMessageResponse" )
            .Element( "messages" )
            .Elements( "message" );
            // ReSharper restore PossibleNullReferenceException

            var messagesArray = messages as XElement[] ?? messages.ToArray( );
            int sourceMessagesCount = messagesArray.Count( );

            if ( nMaxFromThisSource < sourceMessagesCount )
            {
              XElement[] elementsToRemove =
            messagesArray
            .Take( sourceMessagesCount - nMaxFromThisSource )
            .ToArray( );

              elementsToRemove.Remove( );
            }

            return doc.ToString( );
              }
        }
Beispiel #25
0
        protected override void ExecuteTask()
        {
            FileSet filesToCheck = this.FilesToCheck;
            if ( filesToCheck == null || filesToCheck.FileNames.Count == 0 ) {
                throw new BuildException( "Can't cssvalidator an empty set of files" );
            }

            int warning = this.Warning;
            string profile = this.Profile;
            if ( string.IsNullOrEmpty( profile ) ) {
                profile = "css21";
            }
            string prop = this.ErrorCountProperty;

            string exe = this.JavaExe;
            if ( string.IsNullOrEmpty( exe ) || !File.Exists( exe ) ) {
                exe = "java.exe"; // If java isn't in your path, this will blow a rubber ball
            }

            string jar = Path.Combine( BasePath, "css-validator.jar" );
            if ( !File.Exists( jar ) ) {
                throw new BuildException( "Can't find css-validator.jar at " + BasePath );
            }

            int waitSeconds = this.WaitSeconds;
            if ( waitSeconds < 1 ) {
                waitSeconds = 10;
            }

            int errorCount = 0;
            int warningCount = 0;

            XDocument doc = null;
            XElement root = null;
            if ( !string.IsNullOrEmpty( this.XmlOutputFile ) ) {
                doc = new XDocument();
                root = new XElement( "css-validator" );
                doc.AddFirst( root );
            }

            foreach ( string fileToCheck in filesToCheck.FileNames ) {
                if ( !File.Exists( fileToCheck ) ) {
                    throw new BuildException( fileToCheck + " doesn't exist" );
                }
                Results results = CssValidatorHelper.ValidateFile( exe, jar, fileToCheck, profile, warning, waitSeconds );

                if ( this.Verbose ) {
                    if ( !string.IsNullOrEmpty( results.Cmd ) ) {
                        Log( Level.Verbose, results.Cmd );
                    }
                    if ( !string.IsNullOrEmpty( results.StdOut ) ) {
                        // This is just too verbose: Log( Level.Debug, results.StdOut );
                    }
                }
                if ( this.Verbose || string.IsNullOrEmpty( this.XmlOutputFile ) ) {
                    if ( results.Errors != null && results.Errors.Count > 0 ) {
                        foreach ( Error error in results.Errors ) {
                            Log( Level.Error, string.Format( "{0}: {1} ({2}): {3}, {4}", error.ErrorType, fileToCheck, error.Line, error.ErrorDesc, error.Message ) );
                        }
                    }
                }
                if ( doc != null ) {
                    XElement element = new XElement(
                        "file",
                        new XAttribute( "name", fileToCheck ),
                        new XAttribute( "errors", results.ErrorCount ),
                        new XAttribute( "warnings", results.WarningCount )
                        );
                    root.Add( element );
                    if ( results.Errors != null && results.Errors.Count > 0 ) {
                        foreach ( Error error in results.Errors ) {
                            element.Add(
                                new XElement(
                                    "error",
                                    new XAttribute( "line", error.Line ),
                                    new XAttribute( "type", error.ErrorType ),
                                    new XElement( "description", error.ErrorDesc ),
                                    new XElement( "message", error.Message )
                                ) );
                        }
                    }
                    if ( this.Verbose ) {
                        element.Add( new XElement( "command", results.Cmd ) );
                        element.Add( new XElement( "stdout", results.StdOut ) );
                    }
                }

                errorCount += results.ErrorCount;
                warningCount += results.WarningCount;
                if ( !results.Success && results.ErrorCount < 1 ) {
                    errorCount++; // To insure the build fails correctly
                }

            }

            if ( doc != null ) {
                root.Add( new XAttribute( "success", ( errorCount == 0 ) ) );
                root.Add( new XAttribute( "totalErrors", errorCount ) );
                root.Add( new XAttribute( "totalWarnings", warningCount ) );
                doc.Save( this.XmlOutputFile );
            }

            if ( this.FailOnError && errorCount > 0 ) {
                throw new BuildException( "Errors found in css files: " + errorCount );
            }

            if ( Project.Properties.Contains( prop ) ) {
                Project.Properties[prop] = errorCount.ToString();
            } else {
                Project.Properties.Add( prop, errorCount.ToString() );
            }
        }
        private void createDatabaseConfigurationFile(List<string> resources)
        {
            ArgumentValidationHelper.AssertNotNull(resources, "resources");

             var doc = new XDocument();
             doc.AddFirst(new XElement(XName.Get("PathfinderConfiguration")));
             if (doc.Root == null)
             {
            throw new InvalidOperationException();
             }

             resources.ForEach(x => doc.Root.Add(new XElement(XName.Get("DbFile"), x)));
             doc.Save(Path.Combine(_path, "Pathfinder.tdb"));
        }
Beispiel #27
0
        /// <summary>
        /// Serialize the rules to an XML document.
        /// </summary>
        /// <returns>
        /// The XML document of the rules.
        /// </returns>
        public XDocument Serialize()
        {
            var doc = new XDocument();
            var rulesNode = new XElement("rules");
            doc.AddFirst(rulesNode);
            foreach (var rule in this.Rules)
            {
                rulesNode.Add(rule.Serialize());
            }

            return doc;
        }
 private XDocument PrepareXDocument()
 {
     XDocument savedSurveys = new XDocument();
     XElement root = new XElement("results");
     foreach (ResultBasicInfo result in _list)
     {
         XElement resultElement = new XElement("result", new XAttribute("id", result.Id), new XAttribute("title", result.Title), new XAttribute("isCompleted", result.IsResultCompleted), new XAttribute("isSent", result.IsResultSent));
         resultElement.Add(new XElement("time", result.Time));
         if (result.Latitude != null)
         {
             resultElement.Add(new XElement("latitude", result.Latitude));
         }
         if (result.Latitude != null)
         {
             resultElement.Add(new XElement("longitude", result.Longitude));
         }
         resultElement.Add(new XElement("parentId", result.ParentId));
         root.Add(resultElement);
     }
     savedSurveys.AddFirst(root);
     return savedSurveys;
 }
        //public string ReleaseAction { get { return "ALL"; } } //不支持啊

        internal XDocument ReturnTransactionRoot()
        {
            string xmlns = "http://www.w3.org/2000/xmlns/";
            string wfs = "http://www.opengis.net/wfs";
            string ogc = "http://www.opengis.net/ogc";
            string xsi = "http://www.w3.org/2001/XMLSchema-instance";

            if (string.IsNullOrEmpty(this.FeatureNS))
            {
                throw new ArgumentNullException("缺少参数");
            }
            XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

            XElement root = new XElement("{" + wfs + "}Transaction",
                new XAttribute("{" + xmlns + "}wfs", wfs),
                new XAttribute("{" + xmlns + "}ogc", ogc),
                new XAttribute("{" + xmlns + "}xsi", xsi));

            root.SetAttributeValue(XName.Get("{" + xsi + "}schemaLocation"), this.SchemaLocation);

            //添加默认的命名空间
            root.SetAttributeValue(XName.Get("xmlns"), this.FeatureNS);

            doc.AddFirst(root);
            return doc;
        }
Beispiel #30
0
        /// <summary>
        /// Create xml document from information about railroad
        /// </summary>
        /// <param name="railroad">Railroad</param>
        /// <returns>XML Document</returns>
        public XDocument SaveRailroad(Railroad railroad)
        {
            XDocument doc = new XDocument();
            XElement root = new XElement("Railroad");
            doc.AddFirst(root);

            root.Add(new XAttribute("Name", railroad.Name));
            root.Add(new XAttribute("FirstStation", railroad.FirstStation.Name));
            root.Add(new XAttribute("LastStation", railroad.LastStation.Name));

            foreach (Station st in railroad)
                root.Add(SaveStation(st));

            return doc;
        }