public ActionResult Export() {
            var content = _contentManager
                .Query(VersionOptions.Published)
                .List();

            XDocument export = new XDocument();
            export.Add(new XElement("Orchard"));
            export.Element("Orchard").Add(new XElement("Data"));
            foreach(var contentItem in content) {
                export.Element("Orchard").Element("Data").Add(_contentManager.Export(contentItem));
            }

            StringBuilder xml = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings()
                {Encoding = Encoding.UTF8, Indent = true, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true};
            using (XmlWriter w = XmlWriter.Create(xml, settings)) {
                export.WriteTo(w);
                w.Flush();
            }

            return new ContentResult() {
                Content = xml.ToString(),
                ContentType = "text/xml",
                ContentEncoding = Encoding.UTF8
            };
        }
예제 #2
0
 public void WriteCodebook(string path, StudyUnitVM studyUnit)
 {
     Debug.Assert(!string.IsNullOrEmpty(path));
     this.studyUnit = studyUnit;
     ClearError();
     CreateConvertIds();
     XmlWriterSettings xws = new XmlWriterSettings();
     xws.Indent = true;
     xws.Encoding = Encoding.UTF8;
     using (XmlWriter xw = XmlWriter.Create(path, xws))
     {
         XDocument doc = new XDocument(
             DECLARATION,
             new XElement(cb + TAG_CODEBOOK,
                 CreateSafeIDAttribute(studyUnit.Id),
                 CreateVersionAttribute(),
                 new XAttribute("xmlns", cb),
                 new XAttribute(XNamespace.Xmlns + "xsi", xsi),
                 new XAttribute(XNamespace.Xmlns + "dc", dc),
                 new XAttribute(XNamespace.Xmlns + "terms", terms),
                 new XAttribute(XNamespace.Xmlns + "schemaLocation", schemaLocation),
                 CreateStdyDscr(),
                 CreateFileDscrs(),
                 CreateDataDscr()
                 )
         );
         CheckError();
         doc.WriteTo(xw);
     }
 }
예제 #3
0
 private static void WriteXml(XDocument xml)
 {
     using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }))
     {
         xml.WriteTo(writer);
     }
 }
        public static void WriteTo(BundleEntry entry, XmlWriter writer, bool summary = false)
        {
            if (entry == null) throw new ArgumentException("Entry cannot be null");

            var result = createEntry(entry,summary);

            var doc = new XDocument(result);
            doc.WriteTo(writer);
        }
예제 #5
0
 public void Write(Stream s)
 {
     var metaDataDocument = new XDocument();
     FillMetaDataDocument(metaDataDocument);
     var settings = new XmlWriterSettings {CloseOutput = false, Encoding = Encoding.UTF8, Indent = true};
     using (var writer = XmlWriter.Create(s, settings))
     {
         metaDataDocument.WriteTo(writer);
     }
 }
예제 #6
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/rss+xml";
            XNamespace media = "http://search.yahoo.com/mrss";

            using (var quran = new QuranObjects.QuranContext())
            {
                var translations = (from translation in quran.MyTranslations
                                    orderby translation.LastUpdateDate descending
                                    select translation).Take(25).ToList();

                XDocument rss = new XDocument(
                    new XElement("rss", new XAttribute("version", "2.0"),
                        new XElement("channel",
                            new XElement("title", "Quran Modern Bangla Translation Updates"),
                            new XElement("link", "http://quran.omaralzabir.com"),
                            new XElement("description", ""),
                            new XElement("language", ""),
                            new XElement("pubDate", DateTime.Now.ToString("r")),
                            new XElement("generator", "XLinq"),

                            from mytranslation in translations
                            select new XElement("item",
                                       new XElement("title", (mytranslation.CreatedDate == mytranslation.LastUpdateDate ? "Add: " : "Update: ") + mytranslation.SurahNo + ":" + mytranslation.AyahNo),
                                       new XElement("link", "http://quran.omaralzabir.com/" + mytranslation.SurahNo + "/" + mytranslation.AyahNo,
                                           new XAttribute("rel", "alternate"),
                                           new XAttribute("type", "text/html"),
                                           new XAttribute("href", "http://quran.omaralzabir.com/" + mytranslation.SurahNo + "/" + mytranslation.AyahNo)),
                                       new XElement("id", mytranslation.ID.ToString() + mytranslation.LastUpdateDate.Ticks.ToString()),
                                       new XElement("pubDate", mytranslation.LastUpdateDate.ToLongDateString()),
                                       new XElement("description",
                                           new XCData(
                                               string.Format("<h2>{0}</h2><p style=\"font-size: 16pt\">{1}</p><p style=\"font-size: 14pt\">{2}</p><p><hr /></p>", mytranslation.Heading, mytranslation.Translation, mytranslation.Footnote) +
                                               string.Join("",
                                                   (from translation in quran.Ayahs
                                                    where translation.SurahNo == mytranslation.SurahNo &&
                                                    translation.AyahNo == mytranslation.AyahNo && translation.Translator.ShowDefault == true
                                                    orderby translation.Translator.Order
                                                    select ("<p style=\"margin:0; padding:0; font: italic 16px/18px georgia;color: #6798BF;display: block;font-size: 10pt;line-height: 18px;margin-left: 10px;\">" + translation.Translator.Name + "</p>" +
                                                    "<p style=\"margin:0; padding:0; font-size: 14pt;font-family: Georgia;text-align: left;line-height: 24px;margin-left: 10px;\">" + translation.Content + "</p>")))
                                           )
                                       ),
                                       new XElement("author", "Omar AL Zabir")
                                  )
                             )
                        )
                    );
                using (XmlWriter writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
                {
                    rss.WriteTo(writer);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Writes content to stream
        /// </summary>
        /// <param name="s"></param>
        public void Write(Stream s)
        {
            var contentDocument = new XDocument();
            CreateNAVDocument(contentDocument);
            var settings = new XmlWriterSettings {CloseOutput = false, Encoding = Encoding.UTF8, Indent = true};
            using (var writer = XmlWriter.Create(s, settings))
            {
                contentDocument.WriteTo(writer);
            }


        }
예제 #8
0
 /// <summary>
 /// Extends IHTMLItem class to evaluate the size of generated output
 /// </summary>
 /// <param name="item">item to evaluate</param>
 /// <returns></returns>
 public static ulong EstimateSize(this IHTMLItem item)
 {
     var stream = new MemoryStream();
     var node = item.Generate();
     var doc = new XDocument();
     doc.Add(node);
     using (var writer = XmlWriter.Create(stream))
     {
         doc.WriteTo(writer);
     }
     return (ulong)stream.Length;
 }
예제 #9
0
        public object Xml(XDocument document)
        {
            // This is a JSON based web service, ya jerk!
            MemoryStream ms = new MemoryStream();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using(XmlWriter writer = XmlWriter.Create(ms, settings))
            {
                document.WriteTo(writer);
            }
            return Resource(ms, "text/xml");
        }
 public void Write(Stream s)
 {
     XDocument contentDocument = new XDocument();
     CreateContentDocument(contentDocument);
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.CloseOutput = false;
     settings.Encoding = Encoding.Unicode;
     settings.Indent = true;
     using (var writer = XmlWriter.Create(s, settings))
     {
         contentDocument.WriteTo(writer);
     }
 }
        /// <summary>
        /// Creates the configuration XML stream.
        /// </summary>
        /// <param name="configurationXml">The configuration XML.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static MemoryStream CreateConfigurationXmlStream(XDocument configurationXml)
        {
            MemoryStream ms = new MemoryStream();
            XmlWriterSettings xws = new XmlWriterSettings {OmitXmlDeclaration = true, Indent = true};

            using (XmlWriter xw = XmlWriter.Create(ms, xws))
            {
                configurationXml.WriteTo(xw);
            }

            ms.Position = 0;
            return ms;
        }
예제 #12
0
파일: Response.cs 프로젝트: mausch/MiniMVC
 public static void XDocument(this HttpResponseBase response, XDocument doc, string contentType)
 {
     if (response == null)
         throw new ArgumentNullException("response");
     if (doc == null)
         throw new ArgumentNullException("doc");
     if (contentType != null)
         response.ContentType = contentType;
     using (var xmlwriter = XmlWriter.Create(response.Output, new XmlWriterSettings { Indent = true })) {
         doc.WriteTo(xmlwriter);
         xmlwriter.Flush();
     }
 }
 private static void CreateFileIfNotExist()
 {
     lock (_lockObject)
     {
         if (File.Exists(_path)) return;
         var name = XName.Get("announcements");
         var doc = new XDocument(new XElement(name));
         using (var xmlWriter = XmlWriter.Create(File.CreateText(_path)))
         {
             doc.WriteTo(xmlWriter);
         }
     }
 }
예제 #14
0
        public void Serialize()
        {
            var doc = new XDocument(new XDeclaration("1.0", null, null));

            var elementName = messageType.SerializationFriendlyName();
            doc.Add(new XElement(elementName));
            WriteObject(doc.Root, elementName, messageType, message, true);

            SetDefaultNamespace(doc.Root, $"{@namespace}/{messageType.Namespace}");
            ForceEmptyTagsWithNewlines(doc);

            doc.WriteTo(writer);
            writer.Flush();
        }
        public void Serialize(System.IO.Stream Stream, ISerializableObject SerializableObject)
        {
            XDocument xdoc = new XDocument();

            xdoc.Add(new XElement("Root"));

            Serialize(xdoc.Root, SerializableObject);

            System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(Stream, new System.Xml.XmlWriterSettings() { Indent = true });

            xdoc.WriteTo(xmlWriter);

            xmlWriter.Close();
        }
예제 #16
0
        /// <summary>
        /// Set the encoding of this XML document to the encoding given, if not set (null) default encoding is UTF8.
        /// Returns this XML document converted to it's string representation.
        /// </summary>

        public static string AsString(this XDocument xmlDoc, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            using (var sw = new ExtentedStringWriter(new StringBuilder(), encoding))
            {
                using (var tx = new XmlTextWriter(sw))
                {
                    xmlDoc.WriteTo(tx);
                    return(sw.ToString());
                }
            }
        }
예제 #17
0
 public static void TestXmlLoadingAndSaving()
 {
     var test = Program.GetTest();
     var testToXmlConverter = new TestToXmlConverter<string>(new StringToStringConverter());
     var xTest = new XDocument(testToXmlConverter.ConvertTo(test));
     using (var fileStream = File.Create(Path.Combine("save", "test.xml")))
     {
         using (var xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings{Indent = true, IndentChars = "    "}))
         {
             xTest.WriteTo(xmlWriter);
         }
     }
     var testFromXml = testToXmlConverter.ConvertFrom(xTest.Root);
     Debug.Assert(test.SequenceEqual(testFromXml));
 }
예제 #18
0
        public string WriteExportFile(XDocument recipeDocument) {
            var exportFile = String.Format("Export-{0}-{1}.xml", _orchardServices.WorkContext.CurrentUser.UserName, _clock.UtcNow.Ticks);
            if (!_appDataFolder.DirectoryExists(ExportsDirectory)) {
                _appDataFolder.CreateDirectory(ExportsDirectory);
            }

            var path = _appDataFolder.Combine(ExportsDirectory, exportFile);
            
            using (var writer = new XmlTextWriter(_appDataFolder.CreateFile(path), Encoding.UTF8)) {
                writer.Formatting = Formatting.Indented;
                recipeDocument.WriteTo(writer);
            }

            return _appDataFolder.MapPath(path);
        }
예제 #19
0
        /// <summary>
        /// Return formatted XML string from current XDocument
        /// </summary>
        /// <param name="settings">Optional Settings</param>
        public static string ToFormattedXmlString(this XDocument value, XmlWriterSettings settings = null)
        {
            if (settings == null)
            {
                settings = GetDefaultSettings();
            }

            using (var sw = new StringWriterEncoded(settings.Encoding ?? Encoding.UTF8))
                using (var xw = XmlWriter.Create(sw, settings))
                {
                    value.WriteTo(xw);
                    xw.Flush();
                    return(sw.ToString());
                }
        }
        public void Setup()
        {
            MemoryStream ms = new MemoryStream();
            var doc = new XDocument(
                        new XElement("Customer",
                            new XElement("Name", "Chris")));

            var writer = XmlWriter.Create(ms);
            doc.WriteTo(writer);
            writer.Flush();
            ms.Position = 0;

            inputStream = ms;

            attr = new XmlBindAttribute();
        }
예제 #21
0
        /// <summary>
        /// Save the given document to the given stream.
        /// </summary>
        public static void WriteTo(XDocument document, Stream stream, Encoding encoding)
        {
            // Write to memory
            var memStream = new MemoryStream();
            using (var writer = XmlWriter.Create(memStream, new XmlWriterSettings { Encoding = encoding }))
            {
                document.WriteTo(writer);
            }
            memStream.Position = 0;

            // Compress
            var compressed = Compress(memStream);

            // Write to target stream
            compressed.CopyTo(stream);
        }
예제 #22
0
        public void WriteTo(XmlWriter writer)
        {
            var document = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var root = new XElement(Name("DirectedGraph"), new XAttribute("Title", "ReteNetwork"));
            var nodes = new XElement(Name("Nodes"));
            var links = new XElement(Name("Links"));
            var categories = new XElement(Name("Categories"));

            WriteNodes(nodes);
            WriteLinks(links);
            WriteCategories(categories);

            root.Add(nodes, links, categories);
            document.Add(root);

            document.WriteTo(writer);
        }
예제 #23
0
        public void WriteGroup(string path, GroupVM group, List<StudyUnitVM> studyUnits)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));

            ClearError();
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.Indent = true;
            xws.Encoding = Encoding.UTF8;
            using (XmlWriter xw = XmlWriter.Create(path, xws))
            {
                XElement gr = CreateGroup(group, studyUnits);
                foreach (StudyUnitVM studyUnit in studyUnits)
                {
                    XElement su = new XElement(g + TAG_STUDY_UNIT);
                    gr.Add(su);
                    this.studyUnit = studyUnit;
                    su.Add(CreateStudyUnit());
                }
                gr.Add(CreateComparison(group, studyUnits));

                XDocument doc = new XDocument(
                    DECLARATION,
                    new XElement(ddi + TAG_DDI_INSTANCE,
                        CreateIDAttribute(group.GroupModel.InstanceId),
                        CreateVersionAttribute(),
                        CreateAgencyAttribute(),
                        new XAttribute(XNamespace.Xmlns + "ddi", ddi),
                        new XAttribute(XNamespace.Xmlns + "s", s),
                        new XAttribute(XNamespace.Xmlns + "r", r),
                        new XAttribute(XNamespace.Xmlns + "a", a),
                        new XAttribute(XNamespace.Xmlns + "c", c),
                        new XAttribute(XNamespace.Xmlns + "d", d),
                        new XAttribute(XNamespace.Xmlns + "l", l),
                        new XAttribute(XNamespace.Xmlns + "p", p),
                        new XAttribute(XNamespace.Xmlns + "pi", pi),
                        new XAttribute(XNamespace.Xmlns + "g", g),
                        new XAttribute(XNamespace.Xmlns + "cm", cm),
                        new XAttribute(XNamespace.Xmlns + "dce", dce),
                        new XAttribute(XNamespace.Xmlns + "dc", dc),
                        gr
                        ));
                CheckError();
                doc.WriteTo(xw);
            }
        }
예제 #24
0
        private void WriteToFile(FileInfo file, XElement xml)
        {
            XDocument charDoc;
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.OmitXmlDeclaration = true;
            xws.Indent = true;

            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }

            using (XmlWriter writer = XmlWriter.Create(file.FullName, xws))
            {
                charDoc = new XDocument(xml);
                charDoc.WriteTo(writer);
            }
        }
예제 #25
0
        public void Serialize(object[] messages, Stream messageStream)
        {
            if(messages.Length> MaxNumberOfAllowedItemsInCollection)
                throw new UnboundedResultSetException("A message batch is limited to 256 messages");

            var namespaces = GetNamespaces(messages);
            var messagesElement = new XElement(namespaces["esb"] + "messages");
            var xml = new XDocument(messagesElement);

            foreach (var m in messages)
            {
                if (m == null)
                    continue;

                try
                {
                    WriteObject(reflection.GetNameForXml(m.GetType()), m, messagesElement, namespaces);
                }
                catch (Exception e)
                {
                    throw new SerializationException("Could not serialize " + m.GetType() + ".", e);
                }
            }

            messagesElement.Add(
                namespaces.Select(x => new XAttribute(XNamespace.Xmlns + x.Key, x.Value))
                );

            var streamWriter = new StreamWriter(messageStream);
            var writer = XmlWriter.Create(streamWriter, new XmlWriterSettings
            {
                Indent = true,
                Encoding = Encoding.UTF8
            });
            if (writer == null)
                throw new InvalidOperationException("Could not create xml writer from stream");

            xml.WriteTo(writer);
            writer.Flush();
            streamWriter.Flush();
        }
예제 #26
0
		public string CreateText(XDocument document) {
			if (options == null)
				throw new InvalidOperationException();
			if (document == null)
				throw new ArgumentNullException(nameof(document));

			var settings = new XmlWriterSettings {
				Indent = true,
				IndentChars = options.IndentChars ?? "\t",
				NewLineChars = options.NewLineChars ?? Environment.NewLine,
				NewLineOnAttributes = options.NewLineOnAttributes,
				OmitXmlDeclaration = true,
			};
			using (var writer = new StringWriter(CultureInfo.InvariantCulture)) {
				using (var xmlWriter = XmlWriter.Create(writer, settings))
					document.WriteTo(xmlWriter);
				// WriteTo() doesn't add a final newline
				writer.WriteLine();
				return writer.ToString();
			}
		}
예제 #27
0
        public static bool SendEmail(MailAddress receiveEmail, string subject, XDocument xml, string xmlName)
        {
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SmtpSenderEmail"]))
                throw new Exception("SmtpSenderEmail must be defined");
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SmtpSenderName"]))
                throw new Exception("SmtpSenderName must be defined");

            MemoryStream ms = new MemoryStream();
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.OmitXmlDeclaration = true;
            xws.Indent = true;
            using (XmlWriter xw = XmlWriter.Create(ms, xws))
            {
                xml.WriteTo(xw);

                MailMessage message = new MailMessage();
                message.From = new MailAddress(ConfigurationManager.AppSettings["SmtpSenderEmail"], ConfigurationManager.AppSettings["SmtpSenderName"]);
                message.To.Add(receiveEmail);
                message.Subject = subject;
                message.Body = xml.ToString();
                message.Attachments.Add(new Attachment(ms, xmlName + ".xml"));

                SmtpClient smtpClient = new SmtpClient();
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.Host = ConfigurationManager.AppSettings["SmtpHost"];
                if (ConfigurationManager.AppSettings["SmtpPort"] != null &&
                    !string.IsNullOrEmpty(ConfigurationManager.AppSettings["SmtpPort"]))
                    smtpClient.Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]);

                try
                {
                    smtpClient.Send(message);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
예제 #28
0
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            response.ContentEncoding = Encoding.UTF8;
            response.ContentType = "application/rss+xml";

            var dc = XNamespace.Get("http://purl.org/dc/elements/1.1/");
            var slash = XNamespace.Get("http://purl.org/rss/1.0/modules/slash/");
            var wfw = XNamespace.Get("http://wellformedweb.org/CommentAPI/");

            var xdoc = new XDocument(
                new XElement("rss",
                    new XAttribute("version", "2.0"),
                    new XAttribute(XNamespace.Xmlns + "dc", dc),
                    new XAttribute(XNamespace.Xmlns + "slash", slash),
                    new XAttribute(XNamespace.Xmlns + "wfw", wfw),
                    new XElement("channel",
                        new XElement("title", "The Daily WTF"),
                        new XElement("link", "http://thedailywtf.com/"),
                        new XElement("description", "Curious Perversions in Information Technology"),
                        this.articles.Select(a => new XElement("item",
                            new XElement("author", a.Author.Name),
                            new XElement("title", a.RssTitle),
                            new XElement("link", a.Url),
                            new XElement("category", a.Series.Title),
                            new XElement("pubDate", a.PublishedDate.Value.ToUniversalTime().ToString("r")),
                            new XElement("guid", a.Id),
                            new XElement("description", a.BodyAndAdHtml),
                            new XElement(slash + "comments", a.CoalescedCommentCount),
                            new XElement("comments", a.CommentsUrl)
                        ))
                    )
                )
            );

            using (var writer = XmlWriter.Create(response.OutputStream, new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = false }))
            {
                xdoc.WriteTo(writer);
            }
        }
예제 #29
0
        public void GenerateRss(List<RssEpisodeItems> items)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");

            Response.Clear();
            Response.ContentType = "application/rss+xml";
            Response.ContentEncoding = Encoding.UTF8;

            var document = new XDocument(
                new XElement("rss", new XAttribute("version", "2.0"),
                    new XElement("channel",
                        new XElement("title", "MUMS RssEpisodeFilter"),
                        new XElement("link", Request.Url.ToString()),
                        new XElement("pubDate", DateTime.Now.ToString("r")),
                        new XElement("generator", "MUMS.RssEpisodeFilter"),

                        from item in items
                        select new XElement("item",
                            new XElement("title", new XCData(string.Format("{0}, S{1:00}E{2:00}", item.ShowName, item.Season, item.Episode))),
                            new XElement("description", GetContent(item)),
                            new XElement("id", item.EnclosureUrl),
                            new XElement("pubDate", item.PubDate.ToString("r")),
                            new XElement("link", new XCData(item.SourceUrl ?? item.EnclosureUrl)),
                            new XElement("enclosure",
                                new XAttribute("url", item.EnclosureUrl),
                                new XAttribute("length", item.EnclosureLength),
                                new XAttribute("type", "application/x-bittorrent")
                            )
                        )
                    )
                )
            );

            using (var writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
            {
                writer.Indentation = 4;
                writer.Formatting = Formatting.Indented;
                document.WriteTo(writer);
            }
        }
예제 #30
0
        public string Write(CaseCollection caseCollection)
        {
            var stringBuilder = new StringBuilder();
            using (var stringWriter = new Utf8StringWriter(stringBuilder))
            {
                var settings = new XmlWriterSettings
                {
                    IndentChars = "\t",
                    Indent = true
                };

                using (XmlWriter xmlWriter = XmlTextWriter.Create(stringWriter, settings))
                {

                    XElement testCasesElement = new XElement("testcases");
                    testCasesElement.Add(new XAttribute("repeat", caseCollection.Repeat.ToString()));

                    foreach (Case testCase in caseCollection.TestCases)
                    {
                        XElement headersElement = GetHeadersElement(testCase);
                        XElement postbodyElement = GetPostBodyElement(testCase);
                        XElement parseResponsesElement = GetParseResponsesElement(testCase);
                        XElement verificationElement = GetVerificationElement(testCase);

                        XElement caseElement = GetCaseElement(testCase);
                        caseElement.Add(headersElement);
                        caseElement.Add(postbodyElement);
                        caseElement.Add(parseResponsesElement);
                        caseElement.Add(verificationElement);

                        testCasesElement.Add(caseElement);
                    }

                    XDocument doc = new XDocument(testCasesElement);
                    doc.WriteTo(xmlWriter);
                }

                return stringBuilder.ToString();
            }
        }
예제 #31
0
 public static string SendOpenPayuDocumentAuth(XDocument doc, string merchantPostId, string secretKey, string openPayuEndPointUrl)
 {
     if (string.IsNullOrEmpty(merchantPostId))
     {
         return ErrorContent.MerchantPostId;
     }
     if (string.IsNullOrEmpty(secretKey))
     {
         return ErrorContent.SecretKey;
     }
     if (string.IsNullOrEmpty(openPayuEndPointUrl))
     {
         return ErrorContent.OpenPayuEndPointUrl;
     }
     //doc , converting to the string type
     StringWriter sw = new Utf8StringWriter();
     XmlTextWriter tx = new XmlTextWriter(sw);
     doc.WriteTo(tx);
     string signature = ComputeHash(sw.ToString() + StaticString.SignatureKey, new SHA256CryptoServiceProvider());
     string authData = "sender=" + merchantPostId + ";signature=" + signature + ";algorithm=SHA256;content=DOCUMENT";
     return SendDataAuth(openPayuEndPointUrl, "DOCUMENT=" + HttpContext.Current.Server.UrlEncode(sw.ToString()), authData);
 }
        public ActionResult Flicker()
        {
            var files = new DirectoryInfo(System.Web.Hosting.HostingEnvironment.MapPath("~/videos")).GetFiles("flicker_*.mp4");

            var xml = new XDocument(
                new XElement("videos",
                    files.Select(f => new XElement("video", "/videos/" + f.Name)).ToArray()));

            var output = new StringBuilder();
            using (var writer = XmlWriter.Create(output))
            {
                xml.WriteTo(writer);
                writer.Flush();
            }

            return new ContentResult()
            {
                Content = output.ToString(),
                ContentEncoding = Encoding.UTF8,
                ContentType = "text/xml"
            };
        }