public void GenerateCode(FileProjectItem item, CustomToolContext context) { LanguageOption languageToGenerateCode = LanguageOption.GenerateCSharpCode; if (item.Project.Language != "C#") languageToGenerateCode = LanguageOption.GenerateVBCode; XDocument edmxDocument = XDocument.Load(item.FileName); XElement conceptualModelsElement = EDMXIO.ReadSection(edmxDocument, EDMXIO.EDMXSection.CSDL); if (conceptualModelsElement == null) throw new ArgumentException("Input file is not a valid EDMX file."); XDocument csdlDocument = new XDocument(new XDeclaration("1.0", "utf-8", null), conceptualModelsElement.Element(XName.Get("Schema", csdlNamespace.NamespaceName))); string tempFileName = IO.GetTempFilenameWithExtension("csdl"); csdlDocument.Save(tempFileName); string outputFileName = context.GetOutputFileName(item, "Designer"); EntityCodeGenerator entityCodeGenerator = new EntityCodeGenerator(languageToGenerateCode); IList<EdmSchemaError> edmSchemaErrors = entityCodeGenerator.GenerateCode(tempFileName, outputFileName); File.Delete(tempFileName); context.EnsureOutputFileIsInProject(item, outputFileName); }
/// <summary> /// Runs the specified custom tool on the base item. /// </summary> public static void RunCustomTool(FileProjectItem baseItem, ICustomTool customTool, bool showMessageBoxOnErrors) { if (baseItem == null) { throw new ArgumentNullException("baseItem"); } if (customTool == null) { throw new ArgumentNullException("customTool"); } WorkbenchSingleton.AssertMainThread(); string fileName = baseItem.FileName; if (toolRuns.Exists(delegate(CustomToolRun run) { return(FileUtility.IsEqualFileName(run.file, fileName)); })) { // file already in queue, do not enqueue it again return; } CustomToolContext context = new CustomToolContext(baseItem.Project); if (string.IsNullOrEmpty(baseItem.CustomToolNamespace)) { context.OutputNamespace = GetDefaultNamespace(baseItem.Project, baseItem.FileName); } else { context.OutputNamespace = baseItem.CustomToolNamespace; } RunCustomTool(new CustomToolRun(context, fileName, baseItem, customTool, showMessageBoxOnErrors)); }
/// <summary> /// Runs the specified custom tool on the base item. /// </summary> public static void RunCustomTool(FileProjectItem baseItem, ICustomTool customTool, bool showMessageBoxOnErrors) { if (baseItem == null) { throw new ArgumentNullException("baseItem"); } if (customTool == null) { throw new ArgumentNullException("customTool"); } SD.MainThread.VerifyAccess(); string fileName = baseItem.FileName; if (toolRuns.Any(run => FileUtility.IsEqualFileName(run.file, fileName))) { // file already in queue, do not enqueue it again return; } CustomToolContext context = new CustomToolContext(baseItem.Project); context.OutputNamespace = baseItem.GetEvaluatedMetadata("CustomToolNamespace"); if (string.IsNullOrEmpty(context.OutputNamespace)) { context.OutputNamespace = GetDefaultNamespace(baseItem.Project, baseItem.FileName); } RunCustomTool(new CustomToolRun(context, fileName, baseItem, customTool, showMessageBoxOnErrors)); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { context.RunAsync( ()=> { string fileName = item.FileName; var projectNode = item.Project; SpecFlowProject specFlowProject = CreateSpecFlowProjectFrom(projectNode); var specFlowGenerator = new SpecFlowGenerator(specFlowProject); string outputFile = context.GetOutputFileName(item, ".feature"); var specFlowFeatureFile = specFlowProject.GetOrCreateFeatureFile(fileName); var fileContents = File.ReadAllText(fileName); string outputFileContents; using(var reader = new StringReader(fileContents)) { using (var writer = new StringWriter(new StringBuilder())) { specFlowGenerator.GenerateTestFile(specFlowFeatureFile, projectNode.LanguageProperties.CodeDomProvider, reader, writer); outputFileContents = writer.ToString(); } } File.WriteAllText(outputFile, outputFileContents); WorkbenchSingleton.SafeThreadCall( () => context.EnsureOutputFileIsInProject(item, outputFile)); }); }
protected virtual ITextTemplatingFilePreprocessor CreateTextTemplatingFilePreprocessor( FileProjectItem templateFile, CustomToolContext context) { var host = CreateTextTemplatingHost(context.Project); var textTemplatingCustomToolContext = new TextTemplatingCustomToolContext(context); return new TextTemplatingFilePreprocessor(host, templateFile, textTemplatingCustomToolContext); }
public CustomToolRun(CustomToolContext context, string file, FileProjectItem baseItem, ICustomTool customTool, bool showMessageBoxOnErrors) { this.context = context; this.file = file; this.baseItem = baseItem; this.customTool = customTool; this.showMessageBoxOnErrors = showMessageBoxOnErrors; }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { /*context.GenerateCodeDomAsync(item, context.GetOutputFileName(item, ".Designer"), delegate { return GenerateCodeDom(); });*/ string inputFilePath = item.FileName; // Ensure that the generated code will not conflict with an // existing class. if (context.Project != null) { IProjectContent pc = ParserService.GetProjectContent(context.Project); if (pc != null) { IClass existingClass = pc.GetClass(context.OutputNamespace + "." + StronglyTypedResourceBuilder.VerifyResourceName(Path.GetFileNameWithoutExtension(inputFilePath), pc.Language.CodeDomProvider), 0); if (existingClass != null) { if (!IsGeneratedResourceClass(existingClass)) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.ClassConflict"), inputFilePath, existingClass.FullyQualifiedName)); return; } } } } IResourceReader reader; if (string.Equals(Path.GetExtension(inputFilePath), ".resx", StringComparison.OrdinalIgnoreCase)) { reader = new ResXResourceReader(inputFilePath); ((ResXResourceReader)reader).BasePath = Path.GetDirectoryName(inputFilePath); } else { reader = new ResourceReader(inputFilePath); } Hashtable resources = new Hashtable(); foreach (DictionaryEntry de in reader) { resources.Add(de.Key, de.Value); } string[] unmatchable = null; string generatedCodeNamespace = context.OutputNamespace; context.WriteCodeDomToFile( item, context.GetOutputFileName(item, ".Designer"), StronglyTypedResourceBuilder.Create( resources, // resourceList Path.GetFileNameWithoutExtension(inputFilePath), // baseName generatedCodeNamespace, // generatedCodeNamespace context.OutputNamespace, // resourcesNamespace context.Project.LanguageProperties.CodeDomProvider, // codeProvider createInternalClass, // internal class out unmatchable )); foreach (string s in unmatchable) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.CouldNotGenerateResourceProperty"), s)); } }
protected override ITextTemplatingFileGenerator CreateTextTemplatingFileGenerator( FileProjectItem projectFile, CustomToolContext context) { ProjectFilePassedToCreateTextTemplatingFileGenerator = projectFile; ContextPassedToCreateTextTemplatingFileGenerator = context; return FakeTextTemplatingFileGenerator; }
protected override ITextTemplatingFilePreprocessor CreateTextTemplatingFilePreprocessor( FileProjectItem templateFile, CustomToolContext context) { TemplateFilePassedToCreateTextTemplatingFilePreprocessor = templateFile; ContextPassedToCreateTextTemplatingFilePreprocessor = context; return FakeTextTemplatingFilePreprocessor; }
protected virtual ITextTemplatingFileGenerator CreateTextTemplatingFileGenerator( IFileProjectItem templateFile, CustomToolContext context) { TextTemplatingHost host = CreateTextTemplatingHost(context.Project); var textTemplatingCustomToolContext = new TextTemplatingCustomToolContext(context); return new TextTemplatingFileGenerator(host, templateFile, textTemplatingCustomToolContext); }
public void GenerateCode_CustomToolContextPassed_CustomToolContextUsedToCreateTextTemplatingFileGenerator() { CreateCustomTool(); IProject project = ProjectHelper.CreateProject(); var context = new CustomToolContext(project); customTool.GenerateCode(null, context); Assert.AreEqual(context, customTool.ContextPassedToCreateTextTemplatingFileGenerator); }
internal static void NotifyAsyncFinish(CustomToolContext context) { WorkbenchSingleton.SafeThreadAsyncCall( delegate { activeToolRun = null; CustomToolRun nextRun = toolRuns[0]; toolRuns.RemoveAt(0); RunCustomTool(nextRun); }); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { context.RunAsync(() => { var ideSingleFileGenerator = new IdeSingleFileGenerator(); string outputFilePath = context.GetOutputFileName(item, ".feature"); ideSingleFileGenerator.GenerateFile(item.FileName, outputFilePath, () => new SharpDevelop4GeneratorServices(item.Project)); WorkbenchSingleton.SafeThreadCall( () => context.EnsureOutputFileIsInProject(item, outputFilePath)); }); }
internal static void NotifyAsyncFinish(CustomToolContext context) { SD.MainThread.InvokeAsyncAndForget(delegate { activeToolRun = null; if (toolRuns.Count > 0) { CustomToolRun nextRun = toolRuns.Dequeue(); if (nextRun != null) { RunCustomTool(nextRun); } } }); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { XmlDocument doc = new XmlDocument(); doc.Load(item.FileName); SettingsDocument setDoc = new SettingsDocument(doc.DocumentElement, DummySettingsEntryHost.Instance); string customToolNamespace = item.GetEvaluatedMetadata("CustomToolNamespace"); if (!string.IsNullOrEmpty(customToolNamespace)) { setDoc.GeneratedClassNamespace = customToolNamespace; } CodeCompileUnit ccu = new CodeCompileUnit(); ccu.AddNamespace(setDoc.GeneratedClassNamespace).Types.Add(CreateClass(setDoc)); context.WriteCodeDomToFile(item, context.GetOutputFileName(item, ".Designer"), ccu); }
internal static void NotifyAsyncFinish(CustomToolContext context) { WorkbenchSingleton.SafeThreadAsyncCall( delegate { activeToolRun = null; if (toolRuns.Count > 0) { CustomToolRun nextRun = toolRuns.Dequeue(); if (nextRun != null) { RunCustomTool(nextRun); } } }); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { XElement schema = GetModelSchema(item); XDocument csdlDocument = CreateCsdlDocument(schema); string tempFileName = IO.GetTempFilenameWithExtension("csdl"); csdlDocument.Save(tempFileName); LanguageOption languageToGenerateCode = GetLanguageOption(item); string outputFileName = context.GetOutputFileName(item, "Designer"); EntityCodeGenerator entityCodeGenerator = new EntityCodeGenerator(languageToGenerateCode); AddNamespaceMapping(entityCodeGenerator, schema, context.OutputNamespace); IList<EdmSchemaError> edmSchemaErrors = entityCodeGenerator.GenerateCode(tempFileName, outputFileName); File.Delete(tempFileName); context.EnsureOutputFileIsInProject(item, outputFileName); }
/// <summary> /// Called by SharpDevelop when your tool has to generate code. /// </summary> /// <param name="item"> /// The file for which your tool should generate code. /// </param> public void GenerateCode(FileProjectItem item, CustomToolContext context) { string dir = Path.GetDirectoryName(item.FileName); string traceFile = Path.Combine(dir, "trace.txt"); string parserOutFile = Path.Combine(dir, "Parser.cs"); string scannerOutFile = Path.Combine(dir, "Scanner.cs"); ErrorsInTaskService.ClearAllErrors(); CocoCategory.ClearText(); CocoCategory.AppendLine("Generating " + Path.GetFileName(item.FileName) + "..."); using (FileStream inputStream = File.OpenRead(item.FileName)) { Scanner scanner = new Scanner(inputStream); Parser parser = new Parser(scanner); parser.errors = new ErrorsInTaskService(item.FileName); parser.errors.errorStream = new MessageViewCategoryWriter(CocoCategory); parser.tab = new Tab(parser); parser.tab.trace = new LazyTextWriter(delegate { return new StreamWriter(traceFile); } ); parser.dfa = new DFA(parser); parser.pgen = new ParserGen(parser); parser.tab.srcName = item.FileName; parser.tab.srcDir = Path.GetDirectoryName(item.FileName); parser.tab.nsName = context.OutputNamespace; parser.tab.frameDir = parser.tab.srcDir; parser.tab.outDir = parser.tab.srcDir; try { parser.Parse(); } catch (FatalError err) { CocoCategory.AppendLine("Fatal error: " + err.Message); return; } finally { parser.tab.trace.Close(); } CocoCategory.AppendLine("Done. " + parser.errors.count + " error(s)."); } if (File.Exists(parserOutFile)) { context.EnsureOutputFileIsInProject(item, parserOutFile); } if (File.Exists(scannerOutFile)) { context.EnsureOutputFileIsInProject(item, scannerOutFile); } }
public override void GenerateCode(FileProjectItem item, CustomToolContext context) { using (var generator = CreateTextTemplatingFileGenerator(item, context)) { generator.ProcessTemplate(); } }
public abstract void GenerateCode(FileProjectItem item, CustomToolContext context);
internal static void NotifyAsyncFinish(CustomToolContext context) { WorkbenchSingleton.SafeThreadAsyncCall( delegate { activeToolRun = null; if(toolRuns.Count > 0) { CustomToolRun nextRun = toolRuns.Dequeue(); if(nextRun != null) { RunCustomTool(nextRun); } } }); }
/// <summary> /// Runs the specified custom tool on the base item. /// </summary> public static void RunCustomTool(FileProjectItem baseItem, ICustomTool customTool, bool showMessageBoxOnErrors) { if (baseItem == null) throw new ArgumentNullException("baseItem"); if (customTool == null) throw new ArgumentNullException("customTool"); WorkbenchSingleton.AssertMainThread(); string fileName = baseItem.FileName; if (toolRuns.Any(run => FileUtility.IsEqualFileName(run.file, fileName))) { // file already in queue, do not enqueue it again return; } CustomToolContext context = new CustomToolContext(baseItem.Project); context.OutputNamespace = baseItem.GetEvaluatedMetadata("CustomToolNamespace"); if (string.IsNullOrEmpty(context.OutputNamespace)) { context.OutputNamespace = GetDefaultNamespace(baseItem.Project, baseItem.FileName); } RunCustomTool(new CustomToolRun(context, fileName, baseItem, customTool, showMessageBoxOnErrors)); }
public override void GenerateCode(FileProjectItem item, CustomToolContext context) { var processor = CreateTextTemplatingFilePreprocessor(item, context); processor.PreprocessTemplate(); }
public TextTemplatingCustomToolContext(CustomToolContext context) { this.context = context; }