예제 #1
0
        /// <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)
		{
			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);
		}
예제 #3
0
        public FileProjectItem EnsureOutputFileIsInProject(FileProjectItem baseItem, string outputFileName, bool isPrimaryOutput)
        {
            if (baseItem == null)
            {
                throw new ArgumentNullException("baseItem");
            }
            if (baseItem.Project != project)
            {
                throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to");
            }

            SD.MainThread.VerifyAccess();
            bool saveProject = false;

            if (isPrimaryOutput)
            {
                if (baseItem.GetEvaluatedMetadata("LastGenOutput") != Path.GetFileName(outputFileName))
                {
                    saveProject = true;
                    baseItem.SetEvaluatedMetadata("LastGenOutput", Path.GetFileName(outputFileName));
                }
            }
            FileProjectItem outputItem = project.FindFile(FileName.Create(outputFileName));

            if (outputItem == null)
            {
                outputItem               = new FileProjectItem(project, ItemType.Compile);
                outputItem.FileName      = FileName.Create(outputFileName);
                outputItem.DependentUpon = Path.GetFileName(baseItem.FileName);
                outputItem.SetEvaluatedMetadata("AutoGen", "True");
                ProjectService.AddProjectItem(project, outputItem);
                FileService.FireFileCreated(outputFileName, false);
                saveProject = true;
                ProjectBrowserPad.RefreshViewAsync();
            }
            if (saveProject)
            {
                project.Save();
            }
            return(outputItem);
        }
예제 #4
0
        public string GetOutputFileName(FileProjectItem baseItem, string additionalExtension, bool isPrimaryOutput)
        {
            if (baseItem == null)
            {
                throw new ArgumentNullException("baseItem");
            }
            if (baseItem.Project != project)
            {
                throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to");
            }

            if (isPrimaryOutput)
            {
                string lastGenOutput = baseItem.GetEvaluatedMetadata("LastGenOutput");
                if (!string.IsNullOrEmpty(lastGenOutput))
                {
                    return(Path.Combine(Path.GetDirectoryName(baseItem.FileName), lastGenOutput));
                }
            }

            string newExtension    = null;
            var    codeDomProvider = project.CreateCodeDomProvider();

            if (codeDomProvider != null)
            {
                newExtension = codeDomProvider.FileExtension;
            }
            if (string.IsNullOrEmpty(newExtension))
            {
                if (string.IsNullOrEmpty(additionalExtension))
                {
                    newExtension = ".unknown";
                }
                else
                {
                    newExtension        = additionalExtension;
                    additionalExtension = "";
                }
            }
            if (!newExtension.StartsWith(".", StringComparison.Ordinal))
            {
                newExtension = "." + newExtension;
            }

            string newFileName = Path.ChangeExtension(baseItem.FileName, additionalExtension + newExtension);
            int    retryIndex  = 0;

            while (true)
            {
                FileProjectItem item = project.FindFile(FileName.Create(newFileName));
                // If the file does not exist in the project, we can use that name.
                if (item == null)
                {
                    return(newFileName);
                }
                // If the file already exists in the project, use it only if it belongs to our base item
                if (string.Equals(item.DependentUpon, Path.GetFileName(baseItem.FileName), StringComparison.OrdinalIgnoreCase))
                {
                    return(newFileName);
                }
                // Otherwise, find another free file name
                retryIndex++;
                newFileName = Path.ChangeExtension(baseItem.FileName, additionalExtension + retryIndex + newExtension);
            }
        }
예제 #5
0
		/// <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));
		}
예제 #6
0
파일: CustomTool.cs 프로젝트: Altaxo/Altaxo
		public FileProjectItem EnsureOutputFileIsInProject(FileProjectItem baseItem, string outputFileName, bool isPrimaryOutput)
		{
			if (baseItem == null)
				throw new ArgumentNullException("baseItem");
			if (baseItem.Project != project)
				throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to");
			
			WorkbenchSingleton.AssertMainThread();
			bool saveProject = false;
			if (isPrimaryOutput) {
				if (baseItem.GetEvaluatedMetadata("LastGenOutput") != Path.GetFileName(outputFileName)) {
					saveProject = true;
					baseItem.SetEvaluatedMetadata("LastGenOutput", Path.GetFileName(outputFileName));
				}
			}
			FileProjectItem outputItem = project.FindFile(outputFileName);
			if (outputItem == null) {
				outputItem = new FileProjectItem(project, ItemType.Compile);
				outputItem.FileName = outputFileName;
				outputItem.DependentUpon = Path.GetFileName(baseItem.FileName);
				outputItem.SetEvaluatedMetadata("AutoGen", "True");
				ProjectService.AddProjectItem(project, outputItem);
				FileService.FireFileCreated(outputFileName, false);
				saveProject = true;
				ProjectBrowserPad.RefreshViewAsync();
			}
			if (saveProject)
				project.Save();
			return outputItem;
		}
예제 #7
0
파일: CustomTool.cs 프로젝트: Altaxo/Altaxo
		public string GetOutputFileName(FileProjectItem baseItem, string additionalExtension, bool isPrimaryOutput)
		{
			if (baseItem == null)
				throw new ArgumentNullException("baseItem");
			if (baseItem.Project != project)
				throw new ArgumentException("baseItem is not from project this CustomToolContext belongs to");
			
			if (isPrimaryOutput) {
				string lastGenOutput = baseItem.GetEvaluatedMetadata("LastGenOutput");
				if (!string.IsNullOrEmpty(lastGenOutput)) {
					return Path.Combine(Path.GetDirectoryName(baseItem.FileName), lastGenOutput);
				}
			}
			
			string newExtension = null;
			if (project.LanguageProperties.CodeDomProvider != null) {
				newExtension = project.LanguageProperties.CodeDomProvider.FileExtension;
			}
			if (string.IsNullOrEmpty(newExtension)) {
				if (string.IsNullOrEmpty(additionalExtension)) {
					newExtension = ".unknown";
				} else {
					newExtension = additionalExtension;
					additionalExtension = "";
				}
			}
			if (!newExtension.StartsWith(".")) {
				newExtension = "." + newExtension;
			}
			
			string newFileName = Path.ChangeExtension(baseItem.FileName, additionalExtension + newExtension);
			int retryIndex = 0;
			while (true) {
				FileProjectItem item = project.FindFile(newFileName);
				// If the file does not exist in the project, we can use that name.
				if (item == null)
					return newFileName;
				// If the file already exists in the project, use it only if it belongs to our base item
				if (string.Equals(item.DependentUpon, Path.GetFileName(baseItem.FileName), StringComparison.OrdinalIgnoreCase))
					return newFileName;
				// Otherwise, find another free file name
				retryIndex++;
				newFileName = Path.ChangeExtension(baseItem.FileName, additionalExtension + retryIndex + newExtension);
			}
		}