示例#1
0
        private void BuildFolderStructure(CustomItemInformation customItemInformation)
        {
            bool baseDirectoryExists = Directory.Exists(customItemInformation.BaseFileRoot);

            if (!baseDirectoryExists)
            {
                throw new DirectoryNotFoundException("Base Directory Not Found: " + customItemInformation.BaseFileRoot);
            }

            string relativeNamespace = customItemInformation.FullNameSpace.Replace(customItemInformation.BaseNamespace, string.Empty);

            string[] dirNames     = relativeNamespace.Split('.');
            string   baseFileRoot = customItemInformation.BaseFileRoot;

            foreach (string dirName in dirNames)
            {
                if (!string.IsNullOrEmpty(dirName))
                {
                    baseFileRoot = baseFileRoot + @"\" + dirName;
                    if (!Directory.Exists(baseFileRoot))
                    {
                        Directory.CreateDirectory(baseFileRoot);
                        if (!Directory.Exists(baseFileRoot))
                        {
                            throw new FileNotFoundException("Could not create directory: " + baseFileRoot);
                        }
                    }
                }
            }
        }
示例#2
0
 public CodeGenerator(CustomItemInformation customItemInformation, bool generateBaseFile,
                      bool generateInstanceFile, bool generateInterfaceFile, bool generateStaticFile)
 {
     CustomItemInformation = customItemInformation;
     GenerateBaseFile      = generateBaseFile;
     GenerateInstanceFile  = generateInstanceFile;
     GenerateInterfaceFile = generateInterfaceFile;
     GenerateStaticFile    = generateStaticFile;
     GenerationMessage     = string.Empty;
     GeneratedFilePaths    = new List <string>();
 }
 public CodeGenerator(CustomItemInformation customItemInformation, bool generateBaseFile,
     bool generateInstanceFile, bool generateInterfaceFile, bool generateStaticFile)
 {
     CustomItemInformation = customItemInformation;
     GenerateBaseFile = generateBaseFile;
     GenerateInstanceFile = generateInstanceFile;
     GenerateInterfaceFile = generateInterfaceFile;
     GenerateStaticFile = generateStaticFile;
     GenerationMessage = string.Empty;
     GeneratedFilePaths = new List<string>();
 }
        public static string GetCodeFileString(HttpServerUtility server, CustomItemInformation info)
        {
            VelocityEngine velocity = new VelocityEngine();

            ExtendedProperties props = new ExtendedProperties();
            props.SetProperty("file.resource.loader.path", server.MapPath(".")); // The base path for Templates

            velocity.Init(props);

            //Template template = velocity.GetTemplate("template.tmp");
            NVelocity.Template template = velocity.GetTemplate("CustomItem.vm");

            VelocityContext context = new VelocityContext();

            context.Put("BaseTemplates", info.BaseTemplates);
            context.Put("CustomItemFields", info.Fields);
            context.Put("CustomItemInformation", info);

            StringWriter writer = new StringWriter();
            template.Merge(context, writer);
            return writer.GetStringBuilder().ToString();
        }
        protected override void OnOK(object sender, EventArgs args)
        {
            CustomItemSettings settings = new CustomItemSettings(HttpContext.Current);

            ICustomItemNamespaceProvider namespaceProvider = AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider);
            ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider);

            CustomItemInformation customItemInformation = new CustomItemInformation(template, CustomItemNamespace.Value,
                                                                                    CustomItemFilePath.Value, filePathProvider, namespaceProvider);

            if (settings.AutoUpdate) {
                new CodeGenerator(customItemInformation, true, false, false, false).GenerateCode();
            }
            else {
                CodeGenerator codeGenerator = new CodeGenerator(customItemInformation,
                            GenerateBaseFile.Checked, GenerateInstanceFile.Checked, GenerateInterfaceFile.Checked, GenerateStaticFile.Checked);
                codeGenerator.GenerateCode();

                SheerResponse.Alert(codeGenerator.GenerationMessage, new string[0]);
            }
            base.OnOK(sender, args);
        }
        private void BuildFolderStructure(CustomItemInformation customItemInformation)
        {
            bool baseDirectoryExists = Directory.Exists(customItemInformation.BaseFileRoot);
            if (!baseDirectoryExists)
            {
                throw new DirectoryNotFoundException("Base Directory Not Found: " + customItemInformation.BaseFileRoot);
            }

            string relativeNamespace = customItemInformation.FullNameSpace.Replace(customItemInformation.BaseNamespace, string.Empty);

            string[] dirNames = relativeNamespace.Split('.');
            string baseFileRoot = customItemInformation.BaseFileRoot;

            foreach (string dirName in dirNames)
            {
                if (!string.IsNullOrEmpty(dirName))
                {
                    baseFileRoot = baseFileRoot + @"\" + dirName;
                    if (!Directory.Exists(baseFileRoot))
                    {
                        Directory.CreateDirectory(baseFileRoot);
                        if (!Directory.Exists(baseFileRoot))
                        {
                            throw new FileNotFoundException("Could not create directory: " + baseFileRoot);
                        }
                    }
                }
            }
        }
        protected override void OnOK(object sender, EventArgs args)
        {
            foreach (ChecklistItem template in TemplateList.Items)
            {
                //Do nothing if the template has not been selected
                if (!template.Checked) continue;

                //Try and get the template
                TemplateItem templateItem = masterDb.GetItem(template.Value);
                if (templateItem == null) continue;

                //Using the settings item get the providers needed for creating both the namespaces for the custom items
                // as well as the file/folder strucutre.
                CustomItemSettings settings = new CustomItemSettings(HttpContext.Current);

                ICustomItemNamespaceProvider namespaceProvider =
                    AssemblyUtil.GetNamespaceProvider(settings.NamespaceProvider);

                ICustomItemFolderPathProvider filePathProvider = AssemblyUtil.GetFilePathProvider(settings.FilepathProvider);

                //Get all the custom item information
                CustomItemInformation customItemInformation = new CustomItemInformation(templateItem, CustomItemNamespace.Value,
                                                                                        CustomItemFilePath.Value,
                                                                                        filePathProvider,
                                                                                        namespaceProvider);
                //Generate the class file(s)
                CodeGenerator codeGenerator =
                    new CodeGenerator(customItemInformation,
                                      GenerateBaseFile.Checked, GenerateInstanceFile.Checked, GenerateInterfaceFile.Checked,
                                      GenerateStaticFile.Checked);

                codeGenerator.GenerateCode();
            }

            SheerResponse.Alert("Custom items sucessfully generated.", new string[0]);

            base.OnOK(sender, args);
        }