当前位置: 首页>>代码示例>>C#>>正文


C# StringWriter.Flush方法代码示例

本文整理汇总了C#中System.IO.StringWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.Flush方法的具体用法?C# StringWriter.Flush怎么用?C# StringWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringWriter的用法示例。


在下文中一共展示了StringWriter.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseHtml

        // Creates XmlDocument from html content and return it with rootitem "<root>".
        public static XmlDocument ParseHtml(string sContent)
        {
            StringReader sr = new StringReader("<root>" + sContent + "</root>");
            SgmlReader reader = new SgmlReader();
            reader.WhitespaceHandling = WhitespaceHandling.All;
            reader.CaseFolding = Sgml.CaseFolding.ToLower;
            reader.InputStream = sr;

            StringWriter sw = new StringWriter();
            XmlTextWriter w = new XmlTextWriter(sw);
            w.Formatting = Formatting.Indented;
            w.WriteStartDocument();
            reader.Read();
            while (!reader.EOF)
            {
                w.WriteNode(reader, true);
            }
            w.Flush();
            w.Close();

            sw.Flush();

            // create document
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.XmlResolver = null;
            doc.LoadXml(sw.ToString());

            reader.Close();

            return doc;
        }
开发者ID:Cabana,项目名称:CMSConverter,代码行数:33,代码来源:SgmlUtil.cs

示例2: SessionInfoToString

        /// <summary>
        /// Sessions the info to string.
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <returns></returns>
        public static string SessionInfoToString(SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
                return null;

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            XmlSerializer xml = new XmlSerializer(typeof(SessionInfo));
            xml.Serialize(sw, sessionInfo);
            sw.Flush();

            CryptoString cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
            string ret = cry.Execute();
            sb.Remove(0, sb.Length);
            if (Regex.IsMatch(ret, @".*[Oo][Nn][a-zA-Z]*=*$"))
            {
                sessionInfo.ConnectionString += ';';
                xml.Serialize(sw, sessionInfo);
                sw.Flush();
                cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
                ret = cry.Execute();
            }

            sw.Close();
            return ret;
        }
开发者ID:Theeranit,项目名称:DealMarker,代码行数:32,代码来源:SessionInfoSerializer.cs

示例3: UrlRequestCall_ShouldBe_Profiled

        public void UrlRequestCall_ShouldBe_Profiled()
        {
            // Arrange
            var originalConsoleOut = Console.Out;
            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                try
                {
                    IUrlRequest profilerUrlRequest = new ProfilerUrlRequest();

                    // Act
                    var content = profilerUrlRequest.GetUrlContent("http://www.google.de");
                    writer.Flush();
                    var consoleOutput = writer.GetStringBuilder().ToString();

                    // Assert
                    Assert.IsNotNull(content);
                    Assert.IsNotNull(consoleOutput);
                    Assert.IsTrue(consoleOutput.StartsWith("Method 'string GetUrlContent(string url)', Duration (ms):"));
                }
                finally
                {
                    Console.SetOut(originalConsoleOut);
                }
            }
        }
开发者ID:tstune,项目名称:designpattern,代码行数:27,代码来源:ProxyTest.cs

示例4: TestBuildCode

        protected void TestBuildCode(string classFileName, string xmlFileName, string contentTypeName)
        {
            ContentType contentType;
            var expectedOutput = "";
            using (var inputReader = File.OpenText(@"..\..\TestFiles\" + xmlFileName + ".xml"))
            {
                contentType = new ContentTypeSerializer().Deserialize(inputReader);
            }
            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs"))
            {
                expectedOutput = goldReader.ReadToEnd();
            }

            var configuration = CodeGeneratorConfiguration.Create();
            var typeConfig = configuration.Get(contentTypeName);
            typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";
            typeConfig.Namespace = "Umbraco.CodeGen.Models";

            configuration.TypeMappings.Add(new TypeMapping("Umbraco.Integer", "Int32"));

            OnConfiguring(configuration, contentTypeName);

            var sb = new StringBuilder();
            var writer = new StringWriter(sb);

            var dataTypeProvider = new TestDataTypeProvider();
            var generator = new CodeGenerator(typeConfig, dataTypeProvider, CreateGeneratorFactory());

            generator.Generate(contentType, writer);

            writer.Flush();
            Console.WriteLine(sb.ToString());

            Assert.AreEqual(expectedOutput, sb.ToString());
        }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:35,代码来源:CodeGeneratorAcceptanceTestBase.cs

示例5: ToJsonString

        public static string ToJsonString(this JToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            // The following code is different from token.ToString(), which special-cases null to return "" instead of
            // "null".
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            try
            {
                using (JsonWriter jsonWriter = JsonSerialization.CreateJsonTextWriter(stringWriter))
                {
                    token.WriteTo(jsonWriter);
                    jsonWriter.Flush();
                    stringWriter.Flush();

                    string result = stringWriter.ToString();
                    stringWriter = null;

                    return result;
                }
            }
            finally
            {
                if (stringWriter != null)
                {
                    stringWriter.Dispose();
                }
            }
        }
开发者ID:ConnorMcMahon,项目名称:azure-webjobs-sdk,代码行数:32,代码来源:JTokenExtensions.cs

示例6: GetGenerateProjectXSLT

        public static StringReader GetGenerateProjectXSLT(string path)
        {
            Stream generateProjectStream;
            var generateProjectXSLT = Path.Combine(path, "Build", "GenerateProject.xslt");
            if (File.Exists(generateProjectXSLT))
                generateProjectStream = File.Open(generateProjectXSLT, FileMode.Open);
            else
                generateProjectStream = GetTransparentDecompressionStream(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "Protobuild.BuildResources.GenerateProject.xslt.gz"));

            using (var stream = generateProjectStream)
            {
                using (var writer = new StringWriter())
                {
                    var additional = "";
                    var additionalPath = Path.Combine(path, "Build", "AdditionalProjectTransforms.xslt");
                    if (File.Exists(additionalPath))
                    {
                        using (var reader = new StreamReader(additionalPath))
                        {
                            additional = reader.ReadToEnd();
                        }
                    }
                    using (var reader = new StreamReader(stream))
                    {
                        var text = reader.ReadToEnd();
                        text = text.Replace("{ADDITIONAL_TRANSFORMS}", additional);
                        writer.Write(text);
                        writer.Flush();
                    }
                    return new StringReader(writer.GetStringBuilder().ToString());
                }
            }
        }
开发者ID:kolupaev,项目名称:Protobuild,代码行数:35,代码来源:ResourceExtractor.cs

示例7: ExportToExcel

        private static byte[] ExportToExcel(Dictionary<string, object> model, string templatePath)
        {
            TemplateManager template = TemplateManager.FromFile(templatePath);
            if (model != null)
            {
                foreach (string key in model.Keys)
                {
                    template.SetValue(key, model[key]);
                }
            }
            template.Functions.Add("DateToString", new TemplateFunction(DateToString));
            template.Functions.Add("GetDate", new TemplateFunction(GetDate));
            template.Functions.Add("GetMarket", new TemplateFunction(GetMarket));
            template.Functions.Add("GetSumBuyCount", new TemplateFunction(GetSumBuyCount));
            template.Functions.Add("GetSumBuyQuatity", new TemplateFunction(GetSumBuyQuatity));
            template.Functions.Add("GetSumSellCount", new TemplateFunction(GetSumSellCount));
            template.Functions.Add("GetSumSellQuatity", new TemplateFunction(GetSumSellQuatity));
            template.Functions.Add("GetSumChange", new TemplateFunction(GetSumChange));
            template.Functions.Add("GetSumDVDMTrungBinhTrenLenh", new TemplateFunction(GetSumDVDMTrungBinhTrenLenh));
            template.Functions.Add("GetSumDVDBTrungBinhTrenLenh", new TemplateFunction(GetSumDVDBTrungBinhTrenLenh));
            template.Functions.Add("GetSumVolume", new TemplateFunction(GetSumVolume));
            template.Functions.Add("GetSumTotalValue", new TemplateFunction(GetSumTotalValue));          
                        
            StringWriter writer = new StringWriter();
            template.Process(writer);
            writer.Flush();

            byte[] data = Encoding.UTF8.GetBytes(writer.GetStringBuilder().ToString());

            return data;
        }
开发者ID:Soucre,项目名称:Working_git_vfs,代码行数:31,代码来源:ExportService.cs

示例8: Decode

 public static string Decode(string contents)
 {
     if (contents == null)
     {
         throw new ArgumentNullException("contents");
     }
     using (StringWriter writer = new StringWriter())
     {
         using (StringReader reader = new StringReader(contents))
         {
             string str;
             while ((str = reader.ReadLine()) != null)
             {
                 str.TrimEnd(new char[0]);
                 if (str.EndsWith("="))
                 {
                     writer.Write(DecodeLine(str));
                 }
                 else
                 {
                     writer.WriteLine(DecodeLine(str));
                 }
             }
         }
         writer.Flush();
         return writer.ToString();
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:28,代码来源:QuotedPrintableEncoding.cs

示例9: RunScript

        string RunScript(string source, bool execute)
        {
            CompilerResults results;

            using (var provider = new IACodeProvider())
            {
                var options = new IACompilerParameters { GenerateExecutable = false, GenerateInMemory = true, Merge = true, MergeFallbackToLink = true };
                results = provider.CompileAssemblyFromFile(options, source);
            }

            var buffer = new StringBuilder();

            using (var writer = new StringWriter(buffer))
            {
                Console.SetOut(writer);

                if (execute)
                    results.CompiledAssembly.EntryPoint.Invoke(null, null);

                writer.Flush();
            }

            string output = buffer.ToString();

            using (var console = Console.OpenStandardOutput())
            {
                var stdout = new StreamWriter(console);
                stdout.AutoFlush = true;
                Console.SetOut(stdout);
            }

            return output;
        }
开发者ID:lnsoso,项目名称:IronAHK,代码行数:33,代码来源:Scripting.cs

示例10: ExecuteHandler

 public virtual string ExecuteHandler(IHttpHandler handler)
 {
     var writer = new StringWriter();
     HttpContext.Current.Server.Execute(handler, writer, true);
     writer.Flush();
     return writer.GetStringBuilder().ToString();
 }
开发者ID:agross,项目名称:FubuMVC-old,代码行数:7,代码来源:IWebFormsControlBuilder.cs

示例11: RenderActionResultToString

        /// <summary>
        /// Renders an action result to a string. This is done by creating a fake http context
        /// and response objects and have that response send the data to a string builder
        /// instead of the browser.
        /// </summary>
        /// <param name="result">The action result to be rendered to string.</param>
        /// <returns>The data rendered by the given action result.</returns>
        protected string RenderActionResultToString(ActionResult result)
        {
            // Create memory writer.
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            // Create fake http context to render the view.
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(System.Web.HttpContext.Current.Request, fakeResponse);
            var fakeControllerContext = new ControllerContext(
                new HttpContextWrapper(fakeContext),
                this.ControllerContext.RouteData,
                this.ControllerContext.Controller);
            var oldContext = System.Web.HttpContext.Current;
            System.Web.HttpContext.Current = fakeContext;

            // Render the view.
            result.ExecuteResult(fakeControllerContext);

            // Restore data.
            System.Web.HttpContext.Current = oldContext;

            // Flush memory and return output.
            memWriter.Flush();
            return sb.ToString();
        }
开发者ID:ganeshkumar-m,项目名称:PaulSchool,代码行数:33,代码来源:PdfController.cs

示例12: createContent

        private void createContent(String varName, Object objectToPass, StringReader reader, String outputFileName)
        {
            Dictionary<String, Object> map = new Dictionary<String, Object>();
            map.Add(varName, objectToPass);

            String outputContent = null;
            StringTemplateGroup group = new StringTemplateGroup(reader);
            var contentTemplate = group.GetInstanceOf("Content");
            contentTemplate.Attributes = map;
            outputContent = contentTemplate.ToString();
            //StringBuilder sb = new StringBuilder(outputContent);
            StringWriter writer = new StringWriter(new StringBuilder(outputContent));
            writer.Flush();
            StreamWriter fileWriter = null;
            try
            {
                fileWriter = new StreamWriter(outputFileName + "/report.html.data");
                fileWriter.Write(writer.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            writer.Close();
            fileWriter.Close();
        }
开发者ID:VTAF,项目名称:VirtusaCodedUIRuntime,代码行数:27,代码来源:Generator.cs

示例13: PrintToString

        public static string PrintToString(this ImmutableEnvelope envelope, Func<object, string> serializer)
        {
            using (var writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                writer.WriteLine("{0,12}: {1}", "EnvelopeId", envelope.EnvelopeId);

                foreach (var attribute in envelope.Attributes)
                {
                    writer.WriteLine("{0,12}: {1}", attribute.Key, attribute.Value);
                }

                writer.WriteLine(envelope.Message.GetType().Name);
                try
                {
                    var buffer = serializer(envelope.Message);
                    writer.WriteLine(buffer);
                }
                catch (Exception ex)
                {
                    writer.WriteLine("Rendering failure");
                    writer.WriteLine(ex);
                }

                writer.WriteLine();
                writer.Flush();
                return writer.GetStringBuilder().ToString();
            }
        }
开发者ID:mojamcpds,项目名称:lokad-cqrs-1,代码行数:28,代码来源:EnvelopePrinter.cs

示例14: RenderActionToString

        public static string RenderActionToString(this HtmlHelper helper, HttpRequest request, string controller, string action)
        {
            //Create memory writer
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            //Create fake http context to render the view
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(request, fakeResponse);
            var fakeControllerContext = new ControllerContext(
                new HttpContextWrapper(fakeContext),
                helper.ViewContext.RouteData,
                helper.ViewContext.Controller);

            var oldContext = HttpContext.Current;
            HttpContext.Current = fakeContext;

            //Use HtmlHelper to render partial view to fake context
            var html = new HtmlHelper(new ViewContext(fakeControllerContext,
                new FakeView(), new ViewDataDictionary(), new TempDataDictionary(), memWriter),
                new ViewPage());
            html.RenderAction(action, controller);

            //Restore context
            HttpContext.Current = oldContext;

            //Flush memory and return output
            memWriter.Flush();
            return sb.ToString();
        }
开发者ID:priceLiu,项目名称:bigpipe,代码行数:30,代码来源:RendererHelper.cs

示例15: Minify

		/// <summary>
		/// Removes a comments and unnecessary whitespace from JavaScript code
		/// </summary>
		/// <param name="content">JavaScript content</param>
		/// <returns>Minified JavaScript content</returns>
		public String Minify(string content)
		{
			string minifiedContent;

			lock (_minificationSynchronizer)
			{
				_theA = 0;
				_theB = 0;
				_theLookahead = EOF;
				_theX = EOF;
				_theY = EOF;

				using (_reader = new StringReader(content))
				using (_writer = new StringWriter())
				{
					InnerMinify();
					_writer.Flush();

					minifiedContent = _writer.ToString().TrimStart();
				}

				_reader = null;
				_writer = null;
			}

			return minifiedContent;
		}
开发者ID:akushnikov,项目名称:bundletransformer,代码行数:32,代码来源:JsMinifier.cs


注:本文中的System.IO.StringWriter.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。