Exemplo n.º 1
0
        static void AddTemplateFileToProject(IProject project, FileDescriptionTemplate newFile, FileName fileName)
        {
            ItemType        type    = project.GetDefaultItemType(fileName);
            FileProjectItem newItem = new FileProjectItem(project, type);

            newItem.FileName = fileName;
            newFile.SetProjectItemProperties(newItem);
            project.Items.Add(newItem);
        }
Exemplo n.º 2
0
		public string CompileScript(FileTemplateImpl item, FileDescriptionTemplate file)
		{
			if (file.Content == null)
				throw new ArgumentException("file must have textual content");
			Match m = scriptRegex.Match(file.Content);
			// A file must have at least two "<% %>" segments to be recognized as script.
			// I consider this a bug, but we'll keep it for backwards compatibility;
			// at least until the ScriptRunner gets replaced by something more sane.
			m = m.NextMatch();
			if (m.Success) {
				this.item = item;
				this.file = file;
				return CompileAndGetOutput(GenerateCode());
			}
			return file.Content;
		}
        public string CompileScript(FileTemplateImpl item, FileDescriptionTemplate file)
        {
            if (file.Content == null)
            {
                throw new ArgumentException("file must have textual content");
            }
            Match m = scriptRegex.Match(file.Content);

            // A file must have at least two "<% %>" segments to be recognized as script.
            // I consider this a bug, but we'll keep it for backwards compatibility;
            // at least until the ScriptRunner gets replaced by something more sane.
            m = m.NextMatch();
            if (m.Success)
            {
                this.item = item;
                this.file = file;
                return(CompileAndGetOutput(GenerateCode()));
            }
            return(file.Content);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an OpenedFile for the new file, fills it with the file content, and saves it to disk.
        /// </summary>
        OpenedFile SaveFile(FileDescriptionTemplate newFile, string content, string binaryFileName, FileTemplateOptions options, out bool shouldOpen)
        {
            shouldOpen = false;
            string unresolvedFileName = StringParser.Parse(newFile.Name);
            // Parse twice so that tags used in included standard header are parsed
            string parsedContent = StringParser.Parse(StringParser.Parse(content));

            if (parsedContent != null)
            {
                if (SD.EditorControlService.GlobalOptions.IndentationString != "\t")
                {
                    parsedContent = parsedContent.Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString);
                }
            }


            // when newFile.Name is "${Path}/${FileName}", there might be a useless '/' in front of the file name
            // if the file is created when no project is opened. So we remove single '/' or '\', but not double
            // '\\' (project is saved on network share).
            if (unresolvedFileName.StartsWith("/", StringComparison.Ordinal) && !unresolvedFileName.StartsWith("//", StringComparison.Ordinal) ||
                unresolvedFileName.StartsWith("\\", StringComparison.Ordinal) && !unresolvedFileName.StartsWith("\\\\", StringComparison.Ordinal))
            {
                unresolvedFileName = unresolvedFileName.Substring(1);
            }

            var project  = options.Project;
            var fileName = FileName.Create(unresolvedFileName);

            if (newFile.IsDependentFile && Path.IsPathRooted(fileName))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                if (!String.IsNullOrEmpty(binaryFileName))
                {
                    File.Copy(binaryFileName, fileName);
                }
                else
                {
                    File.WriteAllText(fileName, parsedContent, SD.FileService.DefaultFileEncoding);
                }
                if (project != null)
                {
                    AddTemplateFileToProject(project, newFile, fileName);
                }
                return(SD.FileService.GetOrCreateOpenedFile(fileName));
            }
            else
            {
                if (!String.IsNullOrEmpty(binaryFileName))
                {
                    LoggingService.Warn("binary file was skipped");
                    return(null);
                }
                var        data = SD.FileService.DefaultFileEncoding.GetBytesWithPreamble(parsedContent);
                OpenedFile file = null;
                try {
                    if (Path.IsPathRooted(fileName))
                    {
                        file = SD.FileService.GetOrCreateOpenedFile(fileName);
                        file.SetData(data);

                        Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                        file.SaveToDisk();

                        if (project != null)
                        {
                            AddTemplateFileToProject(project, newFile, fileName);
                        }
                    }
                    else
                    {
                        file = SD.FileService.CreateUntitledOpenedFile(Path.GetFileName(fileName), data);
                    }
                    shouldOpen = true;
                    OpenedFile retVal = file;
                    file = null;                     // don't close file when there was no exception and we're returning it
                    return(retVal);
                } finally {
                    if (file != null)
                    {
                        file.CloseIfAllViewsClosed();
                    }
                }
            }
        }
Exemplo n.º 5
0
		static void AddTemplateFileToProject(IProject project, FileDescriptionTemplate newFile, FileName fileName)
		{
			ItemType type = project.GetDefaultItemType(fileName);
			FileProjectItem newItem = new FileProjectItem(project, type);
			newItem.FileName = fileName;
			newFile.SetProjectItemProperties(newItem);
			project.Items.Add(newItem);
		}
Exemplo n.º 6
0
		string SaveFile(FileDescriptionTemplate newFile, string content, string binaryFileName, FileTemplateOptions options)
		{
			string unresolvedFileName = StringParser.Parse(newFile.Name);
			// Parse twice so that tags used in included standard header are parsed
			string parsedContent = StringParser.Parse(StringParser.Parse(content));
			
			if (parsedContent != null) {
				if (SD.EditorControlService.GlobalOptions.IndentationString != "\t") {
					parsedContent = parsedContent.Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString);
				}
			}
			
			
			// when newFile.Name is "${Path}/${FileName}", there might be a useless '/' in front of the file name
			// if the file is created when no project is opened. So we remove single '/' or '\', but not double
			// '\\' (project is saved on network share).
			if (unresolvedFileName.StartsWith("/") && !unresolvedFileName.StartsWith("//")
			    || unresolvedFileName.StartsWith("\\") && !unresolvedFileName.StartsWith("\\\\"))
			{
				unresolvedFileName = unresolvedFileName.Substring(1);
			}
			
			var project = options.Project;
			var fileName = FileName.Create(unresolvedFileName);
			
			if (newFile.IsDependentFile && Path.IsPathRooted(fileName)) {
				Directory.CreateDirectory(Path.GetDirectoryName(fileName));
				if (!String.IsNullOrEmpty(binaryFileName))
					File.Copy(binaryFileName, fileName);
				else
					File.WriteAllText(fileName, parsedContent, SD.FileService.DefaultFileEncoding);
				if (project != null)
					AddTemplateFileToProject(project, newFile, fileName);
			} else {
				if (!String.IsNullOrEmpty(binaryFileName)) {
					LoggingService.Warn("binary file was skipped");
					return null;
				}
				var data = SD.FileService.DefaultFileEncoding.GetBytesWithPreamble(parsedContent);
				OpenedFile file = null;
				try {
					if (Path.IsPathRooted(fileName)) {
						file = SD.FileService.GetOrCreateOpenedFile(fileName);
						file.SetData(data);
						
						Directory.CreateDirectory(Path.GetDirectoryName(fileName));
						file.SaveToDisk();
						
						if (project != null)
							AddTemplateFileToProject(project, newFile, fileName);
					} else {
						file = SD.FileService.CreateUntitledOpenedFile(Path.GetFileName(fileName), data);
					}
					
					SD.FileService.OpenFile(file.FileName);
				} finally {
					if (file != null)
						file.CloseIfAllViewsClosed();
				}
			}
			
			return fileName;
		}