Пример #1
0
        //TODO: find solution that contains the project if possible
        public Solution GetWrapperSolution(IProgressMonitor monitor, string filename)
        {
            // First of all, check if a solution with the same name already exists

            FileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormats(filename, typeof(SolutionEntityItem));
            if (formats.Length == 0)
            {
                formats = new  [] { DefaultFileFormat }
            }
            ;

            Solution tempSolution = new Solution();

            FileFormat solutionFileFormat = formats.FirstOrDefault(f => f.CanWrite(tempSolution)) ?? DefaultFileFormat;

            string solFileName = solutionFileFormat.GetValidFileName(tempSolution, filename);

            if (File.Exists(solFileName))
            {
                return((Solution)Services.ProjectService.ReadWorkspaceItem(monitor, solFileName));
            }
            else
            {
                // Create a temporary solution and add the project to the solution
                tempSolution.SetLocation(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));
                SolutionEntityItem sitem = Services.ProjectService.ReadSolutionItem(monitor, filename);
                tempSolution.ConvertToFormat(solutionFileFormat, false);
                tempSolution.RootFolder.Items.Add(sitem);
                tempSolution.CreateDefaultConfigurations();
                tempSolution.Save(monitor);
                return(tempSolution);
            }
        }
Пример #2
0
        string WriteFile(IProgressMonitor monitor, string file, object item, FileFormat format)
        {
            if (format == null)
            {
                if (defaultFormat.CanWrite(item))
                {
                    format = defaultFormat;
                }
                else
                {
                    FileFormat[] formats = formatManager.GetFileFormatsForObject(item);
                    format = formats.Length > 0 ? formats [0] : null;
                }

                if (format == null)
                {
                    return(null);
                }
                file = format.GetValidFileName(item, file);
            }

            if (!FileService.RequestFileEdit(file))
            {
                throw new UserException(GettextCatalog.GetString("The project could not be saved"), GettextCatalog.GetString("Write permission has not been granted for file '{0}'", file));
            }

            format.Format.WriteFile(file, item, monitor);
            return(file);
        }
Пример #3
0
        FilePath WriteFile(IProgressMonitor monitor, FilePath file, object item, FileFormat format)
        {
            if (format == null)
            {
                if (defaultFormat.CanWrite(item))
                {
                    format = defaultFormat;
                }
                else
                {
                    FileFormat[] formats = formatManager.GetFileFormatsForObject(item);
                    format = formats.Length > 0 ? formats [0] : null;
                }

                if (format == null)
                {
                    return(null);
                }

                file = format.GetValidFileName(item, file);
            }

            FileService.RequestFileEdit(file);

            format.Format.WriteFile(file, item, monitor);
            return(file);
        }
 internal void InstallFormat(FileFormat format)
 {
     fileFormat = format;
     if (fileName != FilePath.Null)
     {
         fileName = fileFormat.GetValidFileName(this, fileName);
     }
 }
Пример #5
0
 public virtual void ConvertToFormat(FileFormat format, bool convertChildren)
 {
     FormatSet   = true;
     this.format = format;
     if (!string.IsNullOrEmpty(FileName))
     {
         FileName = format.GetValidFileName(this, FileName);
     }
 }
Пример #6
0
		string WriteFile (IProgressMonitor monitor, string file, object item, FileFormat format)
		{
			if (format == null) {
				if (defaultFormat.CanWrite (item))
					format = defaultFormat;
				else {
					FileFormat[] formats = formatManager.GetFileFormatsForObject (item);
					format = formats.Length > 0 ? formats [0] : null;
				}
				
				if (format == null)
					return null;
				file = format.GetValidFileName (item, file);
			}
			
			if (!FileService.RequestFileEdit (file))
				throw new UserException (GettextCatalog.GetString ("The project could not be saved"), GettextCatalog.GetString ("Write permission has not been granted for file '{0}'", file));
			
			format.Format.WriteFile (file, item, monitor);
			return file;
		}
Пример #7
0
		FilePath WriteFile (IProgressMonitor monitor, FilePath file, object item, FileFormat format)
		{
			if (format == null) {
				if (defaultFormat.CanWrite (item))
					format = defaultFormat;
				else {
					FileFormat[] formats = formatManager.GetFileFormatsForObject (item);
					format = formats.Length > 0 ? formats [0] : null;
				}
				
				if (format == null)
					return null;

				file = format.GetValidFileName (item, file);
			}
			
			FileService.RequestFileEdit (file);

			format.Format.WriteFile (file, item, monitor);
			return file;
		}