예제 #1
0
        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));
            });
        }
        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);
        }
예제 #3
0
        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));
            });
        }
        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);
        }
예제 #5
0
        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();
            var             ns  = ccu.AddNamespace(setDoc.GeneratedClassNamespace);

            ns.Types.Add(CreateClass(setDoc));
            if (setDoc.UseMySettingsClassName)
            {
                ns.Types.Add(CreateMySettingsProperty(setDoc));
            }
            context.WriteCodeDomToFile(item, context.GetOutputFileName(item, ".Designer"), ccu);
        }
        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;

            context.WriteCodeDomToFile(
                item,
                context.GetOutputFileName(item, ".Designer"),
                StronglyTypedResourceBuilder.Create(
                    resources,                                          // resourceList
                    Path.GetFileNameWithoutExtension(inputFilePath),    // baseName
                    context.OutputNamespace,                            // 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));
            }
        }