예제 #1
0
        public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor)
        {
            object readObject = null;

            ProjectExtensionUtil.BeginLoadOperation();
            try {
                string ext = Path.GetExtension(fileName).ToLower();

                if (ext == ".mdp")
                {
                    object project = ReadProjectFile(fileName, monitor);
                    if (project is DotNetProject)
                    {
                        ((DotNetProject)project).SetItemHandler(new MD1DotNetProjectHandler((DotNetProject)project));
                    }
                    readObject = project;
                }
                else if (ext == ".mds")
                {
                    readObject = ReadCombineFile(fileName, monitor);
                }
                else if (ext == ".mdw")
                {
                    readObject = ReadWorkspaceItemFile(fileName, monitor);
                }
                else
                {
                    XmlTextReader reader = new XmlTextReader(new StreamReader(fileName));
                    try {
                        monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading solution item: {0}"), fileName), 1);
                        reader.MoveToContent();
                        XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext);
                        ser.SerializationContext.BaseFile        = fileName;
                        ser.SerializationContext.ProgressMonitor = monitor;
                        SolutionEntityItem entry = (SolutionEntityItem)ser.Deserialize(reader, typeof(SolutionEntityItem));
                        entry.FileName = fileName;
                        MD1ProjectService.InitializeHandler(entry);
                        readObject = entry;
                    }
                    catch (Exception ex) {
                        monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load solution item: {0}"), fileName), ex);
                        throw;
                    }
                    finally {
                        monitor.EndTask();
                        reader.Close();
                    }
                }
            } finally {
                ProjectExtensionUtil.EndLoadOperation();
            }

            IWorkspaceFileObject fo = readObject as IWorkspaceFileObject;

            if (fo != null)
            {
                fo.ConvertToFormat(MD1ProjectService.FileFormat, false);
            }
            return(readObject);
        }
예제 #2
0
        public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor)
        {
            string ext = Path.GetExtension(fileName).ToLower();

            if (ext != ".mdw")
            {
                throw new ArgumentException();
            }

            object readObject = null;

            ProjectExtensionUtil.BeginLoadOperation();
            try {
                readObject = ReadWorkspaceItemFile(fileName, monitor);
            } finally {
                ProjectExtensionUtil.EndLoadOperation();
            }

            IWorkspaceFileObject fo = readObject as IWorkspaceFileObject;

            if (fo != null)
            {
                fo.ConvertToFormat(MD1ProjectService.FileFormat, false);
            }
            return(readObject);
        }
예제 #3
0
        string Export(IProgressMonitor monitor, IWorkspaceFileObject obj, string[] includedChildIds, string targetPath, FileFormat format)
        {
            string rootSourceFile = obj.FileName;
            string sourcePath     = Path.GetFullPath(Path.GetDirectoryName(rootSourceFile));

            targetPath = Path.GetFullPath(targetPath);

            if (sourcePath != targetPath)
            {
                if (!CopyFiles(monitor, obj, obj.GetItemFiles(true), targetPath, true))
                {
                    return(null);
                }

                string newFile = Path.Combine(targetPath, Path.GetFileName(rootSourceFile));
                if (IsWorkspaceItemFile(rootSourceFile))
                {
                    obj = ReadWorkspaceItem(monitor, newFile);
                }
                else
                {
                    obj = (SolutionEntityItem)ReadSolutionItem(monitor, newFile);
                }

                using (obj)
                {
                    List <FilePath> oldFiles = obj.GetItemFiles(true);
                    ExcludeEntries(obj, includedChildIds);
                    if (format != null)
                    {
                        obj.ConvertToFormat(format, true);
                    }
                    obj.Save(monitor);
                    List <FilePath> newFiles = obj.GetItemFiles(true);

                    foreach (FilePath f in newFiles)
                    {
                        if (!f.IsChildPathOf(targetPath))
                        {
                            if (obj is Solution)
                            {
                                monitor.ReportError("The solution '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the root solution directory.", null);
                            }
                            else
                            {
                                monitor.ReportError("The project '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the project directory.", null);
                            }
                        }
                        oldFiles.Remove(f);
                    }

                    // Remove old files
                    foreach (FilePath file in oldFiles)
                    {
                        if (File.Exists(file))
                        {
                            File.Delete(file);

                            // Exclude empty directories
                            FilePath dir = file.ParentDirectory;
                            if (Directory.GetFiles(dir).Length == 0 && Directory.GetDirectories(dir).Length == 0)
                            {
                                try
                                {
                                    Directory.Delete(dir);
                                }
                                catch (Exception ex)
                                {
                                    monitor.ReportError(null, ex);
                                }
                            }
                        }
                    }
                    return(obj.FileName);
                }
            }
            else
            {
                using (obj)
                {
                    ExcludeEntries(obj, includedChildIds);
                    if (format != null)
                    {
                        obj.ConvertToFormat(format, true);
                    }
                    obj.Save(monitor);
                    return(obj.FileName);
                }
            }
        }
예제 #4
0
		bool SelectValidFileFormat (IWorkspaceFileObject item)
		{
			var dlg = new SelectFileFormatDialog (item);
			try {
				if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok && dlg.Format != null) {
					item.ConvertToFormat (dlg.Format, true);
					return true;
				}
				return false;
			} finally {
				dlg.Destroy ();
			}
		}
예제 #5
0
		string Export (IProgressMonitor monitor, IWorkspaceFileObject obj, string[] includedChildIds, string targetPath, FileFormat format)
		{
			string rootSourceFile = obj.FileName;
			string sourcePath = Path.GetFullPath (Path.GetDirectoryName (rootSourceFile));
			targetPath = Path.GetFullPath (targetPath);
			
			if (sourcePath != targetPath) {
				if (!CopyFiles (monitor, obj, obj.GetItemFiles (true), targetPath, true))
					return null;
				
				string newFile = Path.Combine (targetPath, Path.GetFileName (rootSourceFile));
				if (IsWorkspaceItemFile (rootSourceFile))
					obj = ReadWorkspaceItem (monitor, newFile);
				else
					obj = (SolutionEntityItem) ReadSolutionItem (monitor, newFile);
				
				using (obj) {
					List<FilePath> oldFiles = obj.GetItemFiles (true);
					ExcludeEntries (obj, includedChildIds);
					if (format != null)
						obj.ConvertToFormat (format, true);
					obj.Save (monitor);
					List<FilePath> newFiles = obj.GetItemFiles (true);
					
					foreach (FilePath f in newFiles) {
						if (!f.IsChildPathOf (targetPath)) {
							if (obj is Solution)
								monitor.ReportError ("The solution '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the root solution directory.", null);
							else
								monitor.ReportError ("The project '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the project directory.", null);
						}
						oldFiles.Remove (f);
					}
	
					// Remove old files
					foreach (FilePath file in oldFiles) {
						if (File.Exists (file)) {
							File.Delete (file);
						
							// Exclude empty directories
							FilePath dir = file.ParentDirectory;
							if (Directory.GetFiles (dir).Length == 0 && Directory.GetDirectories (dir).Length == 0) {
								try {
									Directory.Delete (dir);
								} catch (Exception ex) {
									monitor.ReportError (null, ex);
								}
							}
						}
					}
					return obj.FileName;
				}
			}
			else {
				using (obj) {
					ExcludeEntries (obj, includedChildIds);
					if (format != null)
						obj.ConvertToFormat (format, true);
					obj.Save (monitor);
					return obj.FileName;
				}
			}
		}