/// <summary>
        ///   Adds the file from template.
        /// </summary>
        /// <param name = "source">The source template.</param>
        /// <param name = "target">The target file.</param>
        public override void AddFileFromTemplate(string source, string target)
        {
            if (!File.Exists(source))
            {
                throw new FileNotFoundException(string.Format("Template file not found: {0}", source));
            }

            string projectPath  = Path.GetDirectoryName(GetMkDocument());
            string relativePath = Path.GetDirectoryName(target).Substring(projectPath.Length);

            string fileNamespace = relativePath.Replace("\\", ".");

            fileNamespace = fileNamespace.TrimStart(new[] { '.' });
            if (!string.IsNullOrEmpty(fileNamespace))
            {
                fileNamespace += ".";
            }
            fileNamespace += Path.GetFileNameWithoutExtension(target);

            FileTemplateProcessor.AddReplace("%namespace%", fileNamespace);

            try
            {
                FileTemplateProcessor.UntokenFile(source, target);
                FileTemplateProcessor.Reset();
            }
            catch (Exception e)
            {
                throw new FileLoadException("Failed to add template file to project", target, e);
            }
        }
Exemple #2
0
        public override void AddFileFromTemplate(
            string source, string target)
        {
            string nameSpace = FileTemplateProcessor.GetFileNamespace(target, this);
            string className = Path.GetFileNameWithoutExtension(target);

            FileTemplateProcessor.AddReplace("$nameSpace$", nameSpace);
            FileTemplateProcessor.AddReplace("$className$", className);

            FileTemplateProcessor.UntokenFile(source, target);
            FileTemplateProcessor.Reset();
        }
        /// <summary>
        /// Called to add a file to the project from a template.
        /// Override to do it yourself if you want to customize the file
        /// </summary>
        /// <param name="source">Full path of template file</param>
        /// <param name="target">Full path of file once added to the project</param>
        public override void AddFileFromTemplate(string source, string target)
        {
            if (!File.Exists(source))
            {
                throw new FileNotFoundException(string.Format("Template file not found: {0}", source));
            }

            // The class name is based on the new file name
            string scriptName = Path.GetFileNameWithoutExtension(target);

            FileTemplateProcessor.AddReplace("%scriptName%", scriptName);
            FileTemplateProcessor.AddReplace("%author%", WindowsIdentity.GetCurrent().Name);

            try
            {
                FileTemplateProcessor.UntokenFile(source, target);

                FileTemplateProcessor.Reset();
            }
            catch (Exception e)
            {
                throw new FileLoadException("Failed to add template file to project", target, e);
            }
        }