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


C# TempFileCollection.AddExtension方法代码示例

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


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

示例1: FileLoggerTest

 public void FileLoggerTest()
 {
     var tfc = new TempFileCollection();
     var fileName = tfc.AddExtension("txt");
     var logger = LoggerFactory.Instance.GetLogger(LogType.File, fileName);
     logger.Log(TEST_LOG);
 }
开发者ID:solarplexus6,项目名称:Oop,代码行数:7,代码来源:Zad1Test.cs

示例2: ViewLog

 public void ViewLog()
 {
     TempFileCollection tempFiles = new TempFileCollection();
     FileInfo msgFile = new FileInfo(tempFiles.AddExtension("txt"));
     File.WriteAllText(msgFile.FullName, Session.Log, Encoding.ASCII);
     Process.Start(msgFile.FullName);
 }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:7,代码来源:SessionViewModel.cs

示例3: FileSerializeMatchesLength

		public void FileSerializeMatchesLength() {
			using (TempFileCollection tfc = new TempFileCollection()) {
				string file = tfc.AddExtension(".txt");
				File.WriteAllText(file, "sometext");
				var part = MultipartPostPart.CreateFormFilePart("someformname", file, "text/plain");
				VerifyLength(part);
			}
		}
开发者ID:SachiraChin,项目名称:dotnetopenid,代码行数:8,代码来源:MultipartPostPartTests.cs

示例4: MetaData

 public void MetaData()
 {
     string SAVfilename;
     using (System.CodeDom.Compiler.TempFileCollection tfc = new System.CodeDom.Compiler.TempFileCollection())
     {
         SAVfilename = tfc.AddExtension("sav", true);
         SpssConvert.ToFile(tblTest, tblTest.Select(), SAVfilename, FillInMetaData);
         Console.WriteLine("The file with metadata is stored at: " + SAVfilename);
     }
 }
开发者ID:WMichta,项目名称:SPSS.NET,代码行数:10,代码来源:SpssConvertTest.cs

示例5: MultiPartPostMultiByteCharacters

		public void MultiPartPostMultiByteCharacters() {
			using (TempFileCollection tfc = new TempFileCollection()) {
				string file = tfc.AddExtension("txt");
				File.WriteAllText(file, "\x1020\x818");
				this.VerifyFullPost(new List<MultipartPostPart> {
					MultipartPostPart.CreateFormPart("a", "\x987"),
					MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
				});
			}
		}
开发者ID:SachiraChin,项目名称:dotnetopenid,代码行数:10,代码来源:MultipartPostPartTests.cs

示例6: MultiPartPostAscii

		public void MultiPartPostAscii() {
			using (TempFileCollection tfc = new TempFileCollection()) {
				string file = tfc.AddExtension("txt");
				File.WriteAllText(file, "sometext");
				this.VerifyFullPost(new List<MultipartPostPart> {
					MultipartPostPart.CreateFormPart("a", "b"),
					MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
				});
			}
		}
开发者ID:SachiraChin,项目名称:dotnetopenid,代码行数:10,代码来源:MultipartPostPartTests.cs

示例7: WriteFileContext

        internal WriteFileContext(string filename, string templateFilename) {
            string directoryname = UrlPath.GetDirectoryOrRootName(filename);

            _templateFilename = templateFilename;
            _tempFiles = new TempFileCollection(directoryname);
            try {
                _tempNewFilename = _tempFiles.AddExtension("newcfg");
            }
            catch {
                ((IDisposable)_tempFiles).Dispose();
                _tempFiles = null;
                throw;
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:14,代码来源:writefilecontext.cs

示例8: CompileAssemblyFromReader

        CompilerResults CompileAssemblyFromReader(CompilerParameters options, params TextReader[] readers)
        {
            var tempFiles = new TempFileCollection(Path.GetTempPath(), false);

            for (int i = 0; i < readers.Length; i++)
            {
                string file = tempFiles.AddExtension(FileExtension, false);
                File.WriteAllText(file, readers[i].ReadToEnd());
            }

            var fileNames = new string[tempFiles.Count];
            tempFiles.CopyTo(fileNames, 0);
            var results = CompileAssemblyFromFile(options, fileNames);
            tempFiles.Delete();
            return results;
        }
开发者ID:lnsoso,项目名称:IronAHK,代码行数:16,代码来源:IACodeProvider.cs

示例9: CreateTemporaryFile

        public static string CreateTemporaryFile()
        {
            TempFileCollection tfc = new TempFileCollection();
            string fileName = tfc.AddExtension("txt");

            // Create and use the tmp file
            using (FileStream fs1 = File.OpenWrite(fileName))
            {
                using (StreamWriter sw1 = new StreamWriter(fs1))
                {
                    sw1.WriteLine("Test string " +DateTime.Now);
                }
            }
            
            return fileName;
        }
开发者ID:m4rwin,项目名称:BestPractices,代码行数:16,代码来源:Program.cs

示例10: AddAddressNoteWithFile

        public void AddAddressNoteWithFile(string routeId, int addressId)
        {
            // Create the manager with the api key
              Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

              NoteParameters noteParameters = new NoteParameters()
              {
            RouteId = routeId,
            AddressId = addressId,
            Latitude = 33.132675170898,
            Longitude = -83.244743347168,
            DeviceType = DeviceType.Web.Description(),
            ActivityType = StatusUpdateType.DropOff.Description()
              };

              string tempFilePath = null;
              using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Route4MeSDKTest.Resources.test.png"))
              {
            var tempFiles = new TempFileCollection();
            {
              tempFilePath = tempFiles.AddExtension("png");
              System.Console.WriteLine(tempFilePath);
              using (Stream fileStream = File.OpenWrite(tempFilePath))
              {
            stream.CopyTo(fileStream);
              }
            }
              }

              // Run the query
              string errorString;
              string contents = "Test Note Contents with Attachment " + DateTime.Now.ToString();
              AddressNote note = route4Me.AddAddressNote(noteParameters, contents, tempFilePath, out errorString);

              Console.WriteLine("");

              if (note != null)
              {
            Console.WriteLine("AddAddressNoteWithFile executed successfully");

            Console.WriteLine("Note ID: {0}", note.NoteId);
              }
              else
              {
            Console.WriteLine("AddAddressNoteWithFile error: {0}", errorString);
              }
        }
开发者ID:route4me,项目名称:route4me-csharp-sdk,代码行数:47,代码来源:AddAddressNoteWithFile.cs

示例11: AddFileExtension

 public void AddFileExtension()
 {
     string tempDirectory = TempDirectory();
     using (var collection = new TempFileCollection(tempDirectory))
     {
         string file = collection.AddExtension("txt");
         Assert.False(File.Exists(file));
         Assert.Equal(collection.BasePath + "." + "txt", file);
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:TempFileCollectionTests.cs

示例12: Execute


//.........这里部分代码省略.........
            compilerParameters.LanguageToUse = this.ProjectType.ToString();
            compilerParameters.TempFiles.KeepFiles = ShouldKeepTempFiles();

            compilerParameters.OutputAssembly = AssemblyName;
            if (!string.IsNullOrEmpty(assemblyName))
            {
                // Normalizing the assembly name. 
                // The codeDomProvider expects the proper extension to be set.
                string extension = (compilerParameters.GenerateExecutable) ? ".exe" : ".dll";
                compilerParameters.OutputAssembly += extension;
            }

            CodeDomProvider codeProvider = null;
            if (this.ProjectType == SupportedLanguages.VB)
                codeProvider = CompilerHelpers.CreateCodeProviderInstance(typeof(VBCodeProvider), compilerParameters.CompilerVersion);
            else
                codeProvider = CompilerHelpers.CreateCodeProviderInstance(typeof(CSharpCodeProvider), compilerParameters.CompilerVersion);

            using (TempFileCollection tempFileCollection = new TempFileCollection(Environment.GetEnvironmentVariable("temp", EnvironmentVariableTarget.User), true))
            {
                this.outputFiles = new TaskItem[1];

                // Compile and generate a temporary code file for each xoml file.
                string[] xomlFilesPaths;
                if (this.WorkflowMarkupFiles != null)
                {
                    xomlFilesPaths = new string[WorkflowMarkupFiles.GetLength(0) + userCodeFiles.Length];
                    int index = 0;
                    for (; index < this.WorkflowMarkupFiles.GetLength(0); index++)
                        xomlFilesPaths[index] = Path.Combine(ProjectDirectory, this.WorkflowMarkupFiles[index].ItemSpec);

                    userCodeFiles.CopyTo(xomlFilesPaths, index);
                }
                else
                {
                    xomlFilesPaths = new string[userCodeFiles.Length];
                    userCodeFiles.CopyTo(xomlFilesPaths, 0);
                }

                WorkflowCompilerResults compilerResults = new CompilerWrapper().Compile(compilerParameters, xomlFilesPaths);

                foreach (WorkflowCompilerError error in compilerResults.Errors)
                {
                    if (error.IsWarning)
                    {
                        warningCount++;
                        if (workflowErrorLogger != null)
                        {
                            error.FileName = Path.Combine(this.ProjectDirectory, error.FileName);
                            workflowErrorLogger.LogError(error);
                            workflowErrorLogger.LogMessage(error.ToString() + "\n");
                        }
                        else
                            this.Log.LogWarning(error.ErrorText, error.ErrorNumber, error.FileName, error.Line, error.Column);
                    }
                    else
                    {
                        errorCount++;
                        if (workflowErrorLogger != null)
                        {
                            error.FileName = Path.Combine(this.ProjectDirectory, error.FileName);
                            workflowErrorLogger.LogError(error);
                            workflowErrorLogger.LogMessage(error.ToString() + "\n");
                        }
                        else
                            this.Log.LogError(error.ErrorText, error.ErrorNumber, error.FileName, error.Line, error.Column);
                    }
                }

                if (!compilerResults.Errors.HasErrors)
                {
                    CodeCompileUnit ccu = compilerResults.CompiledUnit;
                    if (ccu != null)
                    {
                        // Fix standard namespaces and root namespace.
                        WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(ccu.Namespaces, this.RootNamespace, CompilerHelpers.GetSupportedLanguage(this.ProjectType.ToString())); //just add the standard namespaces

                        string tempFile = tempFileCollection.AddExtension(codeProvider.FileExtension);
                        using (StreamWriter fileStream = new StreamWriter(new FileStream(tempFile, FileMode.Create, FileAccess.Write), Encoding.UTF8))
                        {
                            CodeGeneratorOptions options = new CodeGeneratorOptions();
                            options.BracingStyle = "C";
                            codeProvider.GenerateCodeFromCompileUnit(ccu, fileStream, options);
                        }

                        this.outputFiles[0] = new TaskItem(tempFile);
                        this.temporaryFiles.Add(tempFile);
                        this.Log.LogMessageFromResources(MessageImportance.Normal, "TempCodeFile", tempFile);
                    }
                }
            }
            if ((errorCount > 0 || warningCount > 0) && workflowErrorLogger != null)
                workflowErrorLogger.LogMessage(string.Format(CultureInfo.CurrentCulture, "\nCompile complete -- {0} errors, {1} warnings \n", new object[] { errorCount, warningCount }));

#if DEBUG
            DumpOutputParameters();
#endif
            this.Log.LogMessageFromResources(MessageImportance.Normal, "XomlValidationCompleted", errorCount, warningCount);
            return (errorCount == 0);
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:101,代码来源:CompileXomlTask.cs

示例13: Load

        /// <summary>
        /// Loads an output from a path on disk.
        /// </summary>
        /// <param name="stream">Stream containing the output file.</param>
        /// <param name="uri">Uri for finding this stream.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
        /// <returns>Returns the loaded output.</returns>
        /// <remarks>This method will set the Path and SourcePath properties to the appropriate values on successful load.</remarks>
        internal static Output Load(Stream stream, Uri uri, bool suppressVersionCheck, bool suppressSchema)
        {
            XmlReader reader = null;
            TempFileCollection tempFileCollection = null;
            string cabPath = null;

            // look for the Microsoft cabinet file header and save the cabinet data if found
            if ('M' == stream.ReadByte() && 'S' == stream.ReadByte() && 'C' == stream.ReadByte() && 'F' == stream.ReadByte())
            {
                long cabFileSize = 0;
                byte[] offsetBuffer = new byte[4];
                tempFileCollection = new TempFileCollection();
                cabPath = tempFileCollection.AddExtension("cab", false);

                // skip the header checksum
                stream.Seek(4, SeekOrigin.Current);

                // get the cabinet file size
                stream.Read(offsetBuffer, 0, 4);
                cabFileSize = BitConverter.ToInt32(offsetBuffer, 0);

                stream.Seek(0, SeekOrigin.Begin);

                // Create the cab file from stream
                using (FileStream fs = File.Create(cabPath))
                {
                    for (int i = 0; i < cabFileSize; i++)
                    {
                        fs.WriteByte((byte)stream.ReadByte());
                    }
                }
            }
            else // plain xml file - start reading xml at the beginning of the stream
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            // read the xml
            try
            {
                reader = new XmlTextReader(uri.AbsoluteUri, stream);

                if (!suppressSchema)
                {
                    reader = new XmlValidatingReader(reader);
                    ((XmlValidatingReader)reader).Schemas.Add(GetSchemas());
                }

                reader.MoveToContent();

                if ("wixOutput" != reader.LocalName)
                {
                    throw new WixNotOutputException(WixErrors.InvalidDocumentElement(SourceLineNumberCollection.FromUri(reader.BaseURI), reader.Name, "output", "wixOutput"));
                }

                Output output = Parse(reader, suppressVersionCheck);
                output.tempFileCollection = tempFileCollection;
                output.cabPath = cabPath;

                return output;
            }
            catch (XmlException xe)
            {
                throw new WixException(WixErrors.InvalidXml(SourceLineNumberCollection.FromUri(reader.BaseURI), "output", xe.Message));
            }
            catch (XmlSchemaException xse)
            {
                throw new WixException(WixErrors.SchemaValidationFailed(SourceLineNumberCollection.FromUri(reader.BaseURI), xse.Message, xse.LineNumber, xse.LinePosition));
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
            }
        }
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:86,代码来源:Output.cs

示例14: Compile

		public static CompilerResults Compile (string language, string key, string file, ArrayList assemblies, bool debug)
		{
			Cache cache = HttpRuntime.InternalCache;
			CompilerResults results = (CompilerResults) cache [cachePrefix + key];
			if (results != null)
				return results;

			if (!Directory.Exists (dynamicBase))
				Directory.CreateDirectory (dynamicBase);

			object ticket;
			bool acquired = AcquireCompilationTicket (cachePrefix + key, out ticket);

			try {
				Monitor.Enter (ticket);
				results = (CompilerResults) cache [cachePrefix + key];
				if (results != null)
					return results;

				CodeDomProvider provider = null;
				int warningLevel;
				string compilerOptions;
				string tempdir;

				provider = BaseCompiler.CreateProvider (language, out compilerOptions, out warningLevel, out tempdir);
				if (provider == null)
					throw new HttpException ("Configuration error. Language not supported: " +
								  language, 500);
				CodeDomProvider compiler = provider;
				CompilerParameters options = GetOptions (assemblies);
				options.IncludeDebugInformation = debug;
				options.WarningLevel = warningLevel;
				options.CompilerOptions = compilerOptions;
				
				TempFileCollection tempcoll = new TempFileCollection (tempdir, true);
				string dllfilename = Path.GetFileName (tempcoll.AddExtension ("dll", true));
				options.OutputAssembly = Path.Combine (dynamicBase, dllfilename);
				results = compiler.CompileAssemblyFromFile (options, file);
				ArrayList realdeps = new ArrayList (assemblies.Count + 1);
				realdeps.Add (file);
				for (int i = assemblies.Count - 1; i >= 0; i--) {
					string current = (string) assemblies [i];
					if (Path.IsPathRooted (current))
						realdeps.Add (current);
				}

				string [] deps = (string []) realdeps.ToArray (typeof (string));
				cache.Insert (cachePrefix + key, results, new CacheDependency (deps));
			} finally {
				Monitor.Exit (ticket);
				if (acquired)
					ReleaseCompilationTicket (cachePrefix + key);
			}

			return results;
		}
开发者ID:kumpera,项目名称:mono,代码行数:56,代码来源:CachingCompiler.cs

示例15: Execute


//.........这里部分代码省略.........
     }
 Label_01BE:
     parameters.CompilerOptions = this.PrepareCompilerOptions(builder);
     parameters.GenerateCodeCompileUnitOnly = true;
     parameters.LanguageToUse = this.ProjectType.ToString();
     parameters.TempFiles.KeepFiles = this.ShouldKeepTempFiles();
     parameters.OutputAssembly = this.AssemblyName;
     if (!string.IsNullOrEmpty(this.assemblyName))
     {
         string str = parameters.GenerateExecutable ? ".exe" : ".dll";
         parameters.OutputAssembly = parameters.OutputAssembly + str;
     }
     CodeDomProvider provider2 = null;
     if (this.ProjectType == SupportedLanguages.VB)
     {
         provider2 = CompilerHelpers.CreateCodeProviderInstance(typeof(VBCodeProvider), parameters.CompilerVersion);
     }
     else
     {
         provider2 = CompilerHelpers.CreateCodeProviderInstance(typeof(CSharpCodeProvider), parameters.CompilerVersion);
     }
     using (TempFileCollection files = new TempFileCollection(Environment.GetEnvironmentVariable("temp", EnvironmentVariableTarget.User), true))
     {
         string[] strArray2;
         this.outputFiles = new TaskItem[1];
         if (this.WorkflowMarkupFiles != null)
         {
             strArray2 = new string[this.WorkflowMarkupFiles.GetLength(0) + strArray.Length];
             int index = 0;
             while (index < this.WorkflowMarkupFiles.GetLength(0))
             {
                 strArray2[index] = Path.Combine(this.ProjectDirectory, this.WorkflowMarkupFiles[index].ItemSpec);
                 index++;
             }
             strArray.CopyTo(strArray2, index);
         }
         else
         {
             strArray2 = new string[strArray.Length];
             strArray.CopyTo(strArray2, 0);
         }
         WorkflowCompilerResults results = new CompilerWrapper().Compile(parameters, strArray2);
         foreach (WorkflowCompilerError error in results.Errors)
         {
             if (error.IsWarning)
             {
                 num2++;
                 if (service != null)
                 {
                     error.FileName = Path.Combine(this.ProjectDirectory, error.FileName);
                     service.LogError(error);
                     service.LogMessage(error.ToString() + "\n");
                 }
                 else
                 {
                     base.Log.LogWarning(error.ErrorText, new object[] { error.ErrorNumber, error.FileName, error.Line, error.Column });
                 }
             }
             else
             {
                 num++;
                 if (service != null)
                 {
                     error.FileName = Path.Combine(this.ProjectDirectory, error.FileName);
                     service.LogError(error);
                     service.LogMessage(error.ToString() + "\n");
                 }
                 else
                 {
                     base.Log.LogError(error.ErrorText, new object[] { error.ErrorNumber, error.FileName, error.Line, error.Column });
                 }
             }
         }
         if (!results.Errors.HasErrors)
         {
             CodeCompileUnit compiledUnit = results.CompiledUnit;
             if (compiledUnit != null)
             {
                 WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(compiledUnit.Namespaces, this.RootNamespace, CompilerHelpers.GetSupportedLanguage(this.ProjectType.ToString()));
                 string path = files.AddExtension(provider2.FileExtension);
                 using (StreamWriter writer = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write), Encoding.UTF8))
                 {
                     CodeGeneratorOptions options = new CodeGeneratorOptions {
                         BracingStyle = "C"
                     };
                     provider2.GenerateCodeFromCompileUnit(compiledUnit, writer, options);
                 }
                 this.outputFiles[0] = new TaskItem(path);
                 this.temporaryFiles.Add(path);
                 base.Log.LogMessageFromResources(MessageImportance.Normal, "TempCodeFile", new object[] { path });
             }
         }
     }
     if (((num > 0) || (num2 > 0)) && (service != null))
     {
         service.LogMessage(string.Format(CultureInfo.CurrentCulture, "\nCompile complete -- {0} errors, {1} warnings \n", new object[] { num, num2 }));
     }
     base.Log.LogMessageFromResources(MessageImportance.Normal, "XomlValidationCompleted", new object[] { num, num2 });
     return (num == 0);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:CompileWorkflowTask.cs


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