public XcodeSyncBackContext GetChanges(IProgressMonitor monitor, NSObjectInfoService infoService, DotNetProject project)
        {
            var ctx        = new XcodeSyncBackContext(projectDir, syncTimeCache, infoService, project);
            var needsSync  = new List <XcodeSyncedItem> (items.Where(i => i.NeedsSyncBack(monitor, ctx)));
            var knownFiles = GetKnownFiles();

            if (Directory.Exists(projectDir))
            {
                monitor.BeginTask("Scanning for newly-added files in the Xcode project...", 0);
                ScanForAddedFiles(monitor, ctx, knownFiles, projectDir, null);
                monitor.EndTask();
            }

            if (needsSync.Count > 0)
            {
                monitor.BeginStepTask(GettextCatalog.GetString("Synchronizing changes made to known files in Xcode back to MonoDevelop..."), needsSync.Count, 1);
                for (int i = 0; i < needsSync.Count; i++)
                {
                    var item = needsSync [i];
                    item.SyncBack(monitor, ctx);
                    monitor.Step(1);
                }
                monitor.EndTask();
            }

            return(ctx);
        }
 public void BeginStepTask(string name, int totalWork, int stepSize)
 {
     lock (monitor.SyncRoot)
     {
         monitor.BeginStepTask(name, totalWork, stepSize);
     }
 }
Example #3
0
        public IAsyncOperation Update(IProgressMonitor monitor)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                string[] statuses;
                if (InitialUpdate)
                {
                    statuses = new string [] { "NEW", "ASSIGNED", "NEEDINFO" }
                }
                ;
                else
                {
                    statuses = new string [] { "NEW", "ASSIGNED", "NEEDINFO", "RESOLVED", "CLOSED", "VERIFIED" }
                };
                string[] severities = new string [] { "Critical", "Major", "Normal", "Minor", "Enhancement" };
                DateTime t          = DateTime.Now;
                monitor.BeginTask("Updating from bugzilla server", 3);
                try {
                    Connect();
                    int nb, mb;

                    // Bugs
                    int lastWork = -1;
                    Bug[] data   = server.GetBugsForProduct(Product, statuses, severities, lastUpdate, delegate(int total, int current) {
                        if (lastWork == -1)
                        {
                            monitor.BeginStepTask("Getting bug data", total, 2);
                            lastWork = 0;
                        }
                        monitor.Step(current - lastWork);
                        lastWork = current;
                    });
                    monitor.EndTask();
                    UpdateBugData(data, out nb, out mb);
                    lastUpdate = t;
                    monitor.Step(1);
                    Save();
                    monitor.Step(1);
                    monitor.ReportSuccess(string.Format("Bug list updated ({0} added, {1} modified)", nb, mb));
                } catch (Exception ex) {
                    monitor.ReportError("Update failed", ex);
                } finally {
                    monitor.Dispose();
                }
            });
Example #4
0
        /// <summary>
        /// Copies resource files from the Xcode project (back) to the MonoDevelop project directory.
        /// </summary>
        /// <param name='monitor'>
        /// A progress monitor.
        /// </param>
        /// <param name='context'>
        /// The sync context.
        /// </param>
        void CopyFilesToMD(IProgressMonitor monitor, XcodeSyncBackContext context)
        {
            if (context.FileSyncJobs.Count == 0)
            {
                return;
            }

            monitor.BeginStepTask("Copying files from Xcode back to MonoDevelop...", context.FileSyncJobs.Count, 1);

            foreach (var file in context.FileSyncJobs)
            {
                monitor.Log.WriteLine("Copying {0} file from Xcode: {1}", file.IsFreshlyAdded ? "new" : "changed", file.SyncedRelative);

                if (!Directory.Exists(file.Original.ParentDirectory))
                {
                    Directory.CreateDirectory(file.Original.ParentDirectory);
                }

                var      tempFile = file.Original.ParentDirectory.Combine(".#" + file.Original.ParentDirectory.FileName);
                FilePath path     = context.ProjectDir.Combine(file.SyncedRelative);

                if (File.Exists(path))
                {
                    File.Copy(path, tempFile);
                    FileService.SystemRename(tempFile, file.Original);

                    DateTime mtime = File.GetLastWriteTime(file.Original);
                    context.SetSyncTime(file.SyncedRelative, mtime);
                }
                else
                {
                    monitor.ReportWarning(string.Format("'{0}' does not exist.", file.SyncedRelative));
                }

                monitor.Step(1);
            }

            monitor.EndTask();
        }
Example #5
0
        public XcodeSyncBackContext GetChanges(IProgressMonitor monitor, NSObjectInfoService infoService, DotNetProject project)
        {
            var ctx        = new XcodeSyncBackContext(projectDir, syncTimeCache, infoService, project);
            var needsSync  = new List <XcodeSyncedItem> (items.Where(i => i.NeedsSyncBack(ctx)));
            var knownFiles = GetKnownFiles();

            ScanForAddedFiles(ctx, knownFiles, projectDir, null);

            if (needsSync.Count > 0)
            {
                monitor.BeginStepTask(GettextCatalog.GetString("Synchronizing Xcode project changes"), needsSync.Count, 1);
                for (int i = 0; i < needsSync.Count; i++)
                {
                    var item = needsSync [i];
                    item.SyncBack(ctx);
                    monitor.Step(1);
                }

                monitor.Log.WriteLine(GettextCatalog.GetPluralString("Synchronized {0} file", "Synchronized {0} files", needsSync.Count), needsSync.Count);
                monitor.EndTask();
            }

            return(ctx);
        }
Example #6
0
		public XcodeSyncBackContext GetChanges (IProgressMonitor monitor, NSObjectInfoService infoService, DotNetProject project)
		{
			var ctx = new XcodeSyncBackContext (projectDir, syncTimeCache, infoService, project);
			var needsSync = new List<XcodeSyncedItem> (items.Where (i => i.NeedsSyncBack (monitor, ctx)));
			var knownFiles = GetKnownFiles ();
			
			if (Directory.Exists (projectDir)) {
				monitor.BeginTask ("Scanning for newly-added files in the Xcode project...", 0);
				ScanForAddedFiles (monitor, ctx, knownFiles, projectDir, null);
				monitor.EndTask ();
			}
			
			if (needsSync.Count > 0) {
				monitor.BeginStepTask (GettextCatalog.GetString ("Synchronizing changes made to known files in Xcode back to MonoDevelop..."), needsSync.Count, 1);
				for (int i = 0; i < needsSync.Count; i++) {
					var item = needsSync [i];
					item.SyncBack (monitor, ctx);
					monitor.Step (1);
				}
				monitor.EndTask ();
			}
			
			return ctx;
		}
Example #7
0
		public override void Revert (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
		{
			foreach (var group in localPaths.GroupBy (f => GetRepository (f))) {
				var repository = group.Key;
				var files = group.ToArray ();

			var c = GetHeadCommit (repository);
			RevTree tree = c != null ? c.Tree : null;
			
			List<FilePath> changedFiles = new List<FilePath> ();
			List<FilePath> removedFiles = new List<FilePath> ();
			
			monitor.BeginTask (GettextCatalog.GetString ("Reverting files"), 3);
			monitor.BeginStepTask (GettextCatalog.GetString ("Reverting files"), files.Length, 2);
			
			DirCache dc = repository.LockDirCache ();
			DirCacheBuilder builder = dc.Builder ();
			
			try {
				HashSet<string> entriesToRemove = new HashSet<string> ();
				HashSet<string> foldersToRemove = new HashSet<string> ();
				
				// Add the new entries
				foreach (FilePath fp in files) {
					string p = repository.ToGitPath (fp);
					
					// Register entries to be removed from the index
					if (Directory.Exists (fp))
						foldersToRemove.Add (p);
					else
						entriesToRemove.Add (p);
					
					TreeWalk tw = tree != null ? TreeWalk.ForPath (repository, p, tree) : null;
					if (tw == null) {
						// Removed from the index
					}
					else {
						// Add new entries
						
						TreeWalk r;
						if (tw.IsSubtree) {
							// It's a directory. Make sure we remove existing index entries of this directory
							foldersToRemove.Add (p);
							
							// We have to iterate through all folder files. We need a new iterator since the
							// existing rw is not recursive
							r = new NGit.Treewalk.TreeWalk(repository);
							r.Reset (tree);
							r.Filter = PathFilterGroup.CreateFromStrings(new string[]{p});
							r.Recursive = true;
							r.Next ();
						} else {
							r = tw;
						}
						
						do {
							// There can be more than one entry if reverting a whole directory
							string rpath = repository.FromGitPath (r.PathString);
							DirCacheEntry e = new DirCacheEntry (r.PathString);
							e.SetObjectId (r.GetObjectId (0));
							e.FileMode = r.GetFileMode (0);
							if (!Directory.Exists (Path.GetDirectoryName (rpath)))
								Directory.CreateDirectory (rpath);
							DirCacheCheckout.CheckoutEntry (repository, rpath, e);
							builder.Add (e);
							changedFiles.Add (rpath);
						} while (r.Next ());
					}
					monitor.Step (1);
				}
				
				// Add entries we want to keep
				int count = dc.GetEntryCount ();
				for (int n=0; n<count; n++) {
					DirCacheEntry e = dc.GetEntry (n);
					string path = e.PathString;
					if (!entriesToRemove.Contains (path) && !foldersToRemove.Any (f => IsSubpath (f,path)))
						builder.Add (e);
				}
				
				builder.Commit ();
			}
			catch {
				dc.Unlock ();
				throw;
			}
			
			monitor.EndTask ();
			monitor.BeginTask (null, files.Length);

			foreach (FilePath p in changedFiles) {
				FileService.NotifyFileChanged (p);
				monitor.Step (1);
			}
			foreach (FilePath p in removedFiles) {
				FileService.NotifyFileRemoved (p);
				monitor.Step (1);
			}
			monitor.EndTask ();
			}
		}
Example #8
0
		public XcodeSyncBackContext GetChanges (IProgressMonitor monitor, NSObjectInfoService infoService, DotNetProject project)
		{
			var ctx = new XcodeSyncBackContext (projectDir, syncTimeCache, infoService, project);
			var needsSync = new List<XcodeSyncedItem> (items.Where (i => i.NeedsSyncBack (ctx)));
			var knownFiles = GetKnownFiles ();
			
			ScanForAddedFiles (ctx, knownFiles, projectDir, null);
			
			if (needsSync.Count > 0) {
				monitor.BeginStepTask (GettextCatalog.GetString ("Synchronizing Xcode project changes"), needsSync.Count, 1);
				for (int i = 0; i < needsSync.Count; i++) {
					var item = needsSync [i];
					item.SyncBack (ctx);
					monitor.Step (1);
				}
				
				monitor.Log.WriteLine (GettextCatalog.GetPluralString ("Synchronized {0} file", "Synchronized {0} files", needsSync.Count), needsSync.Count);
				monitor.EndTask ();
			}
			
			return ctx;
		}
 public override void BeginStepTask(string name, int totalWork, int stepSize)
 {
     base.BeginStepTask(name, totalWork, stepSize);
     statusMonitor.BeginStepTask(name, totalWork, stepSize);
 }
Example #10
0
		void WriteProjects (SolutionFolder folder, string baseDirectory, StreamWriter writer, bool saveProjects, IProgressMonitor monitor)
		{
			monitor.BeginStepTask (GettextCatalog.GetString ("Saving projects"), folder.Items.Count, 1); 
			foreach (SolutionItem ce in folder.Items.ToArray ())
			{
				string[] l = null;
				if (ce is SolutionEntityItem) {
					
					SolutionEntityItem item = (SolutionEntityItem) ce;
					MSBuildHandler handler = MSBuildProjectService.GetItemHandler (item);
					
					if (saveProjects) {
						try {
							handler.SavingSolution = true;
							item.Save (monitor);
						} finally {
							handler.SavingSolution = false;
						}
					}

					l = handler.SlnProjectContent;

					writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""",
					    handler.TypeGuid,
						item.Name, 
						FileService.NormalizeRelativePath (FileService.AbsoluteToRelativePath (
							baseDirectory, item.FileName)).Replace ('/', '\\'),
						ce.ItemId);
					DataItem data = handler.WriteSlnData ();
					if (data != null && data.HasItemData) {
						writer.WriteLine ("\tProjectSection(MonoDevelopProperties) = preProject");
						WriteDataItem (writer, data);
						writer.WriteLine ("\tEndProjectSection");
					}
					if (item.ItemDependencies.Count > 0 || handler.UnresolvedProjectDependencies != null) {
						writer.WriteLine ("\tProjectSection(ProjectDependencies) = postProject");
						foreach (var dep in item.ItemDependencies)
							writer.WriteLine ("\t\t{0} = {0}", dep.ItemId);
						if (handler.UnresolvedProjectDependencies != null) {
							foreach (var dep in handler.UnresolvedProjectDependencies)
								writer.WriteLine ("\t\t{0} = {0}", dep);
						}
						writer.WriteLine ("\tEndProjectSection");
					}
				} else if (ce is SolutionFolder) {
					//Solution
					SlnData slnData = GetSlnData (ce);
					if (slnData == null) {
						// Solution folder
						slnData = new SlnData ();
						ce.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
					}

					l = slnData.Extra;
					
					writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""",
						MSBuildProjectService.FolderTypeGuid,
						ce.Name, 
						ce.Name,
						ce.ItemId);
					
					// Folder files
					WriteFolderFiles (writer, (SolutionFolder) ce);
					
					//Write custom properties
					MSBuildSerializer ser = new MSBuildSerializer (folder.ParentSolution.FileName);
					DataItem data = (DataItem) ser.Serialize (ce, typeof(SolutionFolder));
					if (data.HasItemData) {
						writer.WriteLine ("\tProjectSection(MonoDevelopProperties) = preProject");
						WriteDataItem (writer, data);
						writer.WriteLine ("\tEndProjectSection");
					}
				}

				if (l != null) {
					foreach (string s in l)
						writer.WriteLine (s);
				}

				writer.WriteLine ("EndProject");
				if (ce is SolutionFolder)
					WriteProjects (ce as SolutionFolder, baseDirectory, writer, saveProjects, monitor);
				monitor.Step (1);
			}
			monitor.EndTask ();
		}
Example #11
0
		/// <summary>
		/// Copies resource files from the Xcode project (back) to the MonoDevelop project directory.
		/// </summary>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// The sync context.
		/// </param>
		void CopyFilesToMD (IProgressMonitor monitor, XcodeSyncBackContext context)
		{
			if (context.FileSyncJobs.Count == 0)
				return;
			
			monitor.BeginStepTask ("Copying files from Xcode back to MonoDevelop...", context.FileSyncJobs.Count, 1);
			
			foreach (var file in context.FileSyncJobs) {
				monitor.Log.WriteLine ("Copying {0} file from Xcode: {1}", file.IsFreshlyAdded ? "new" : "changed", file.SyncedRelative);
				
				if (!Directory.Exists (file.Original.ParentDirectory))
					Directory.CreateDirectory (file.Original.ParentDirectory);
				
				var tempFile = file.Original.ParentDirectory.Combine (".#" + file.Original.ParentDirectory.FileName);
				FilePath path = context.ProjectDir.Combine (file.SyncedRelative);
				
				if (File.Exists (path)) {
					File.Copy (path, tempFile);
					FileService.SystemRename (tempFile, file.Original);
					
					DateTime mtime = File.GetLastWriteTime (file.Original);
					context.SetSyncTime (file.SyncedRelative, mtime);
				} else {
					monitor.ReportWarning (string.Format ("'{0}' does not exist.", file.SyncedRelative));
				}
				
				monitor.Step (1);
			}
			
			monitor.EndTask ();
		}
Example #12
0
        internal bool Install(IProgressStatus statusMonitor, PackageCollection packs)
        {
            // Make sure the registry is up to date
            service.Registry.Update(statusMonitor);

            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            PackageCollection    toUninstall;
            DependencyCollection unresolved;

            if (!ResolveDependencies(monitor, packs, out toUninstall, out unresolved))
            {
                monitor.ReportError("Not all dependencies could be resolved.", null);
                return(false);
            }

            ArrayList prepared          = new ArrayList();
            ArrayList uninstallPrepared = new ArrayList();
            bool      rollback          = false;

            monitor.BeginTask("Installing add-ins...", 100);

            // Prepare install

            monitor.BeginStepTask("Initializing installation", toUninstall.Count + packs.Count + 1, 75);

            foreach (Package mpack in toUninstall)
            {
                try
                {
                    mpack.PrepareUninstall(monitor, this);
                    uninstallPrepared.Add(mpack);
                    if (monitor.IsCancelRequested)
                    {
                        throw new InstallException("Installation cancelled.");
                    }
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    ReportException(monitor, ex);
                    rollback = true;
                    break;
                }
            }

            monitor.Step(1);

            foreach (Package mpack in packs)
            {
                try
                {
                    mpack.PrepareInstall(monitor, this);
                    if (monitor.IsCancelRequested)
                    {
                        throw new InstallException("Installation cancelled.");
                    }
                    prepared.Add(mpack);
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    ReportException(monitor, ex);
                    rollback = true;
                    break;
                }
            }

            monitor.EndTask();

            monitor.BeginStepTask("Installing", toUninstall.Count + packs.Count + 1, 20);

            // Commit install

            if (!rollback)
            {
                foreach (Package mpack in toUninstall)
                {
                    try
                    {
                        mpack.CommitUninstall(monitor, this);
                        if (monitor.IsCancelRequested)
                        {
                            throw new InstallException("Installation cancelled.");
                        }
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                        rollback = true;
                        break;
                    }
                }
            }

            monitor.Step(1);

            if (!rollback)
            {
                foreach (Package mpack in packs)
                {
                    try
                    {
                        mpack.CommitInstall(monitor, this);
                        if (monitor.IsCancelRequested)
                        {
                            throw new InstallException("Installation cancelled.");
                        }
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                        rollback = true;
                        break;
                    }
                }
            }

            monitor.EndTask();

            // Rollback if failed

            if (monitor.IsCancelRequested)
            {
                monitor = new NullProgressMonitor();
            }

            if (rollback)
            {
                monitor.BeginStepTask("Finishing installation", (prepared.Count + uninstallPrepared.Count) * 2 + 1, 5);

                foreach (Package mpack in prepared)
                {
                    try
                    {
                        mpack.RollbackInstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                    }
                }

                foreach (Package mpack in uninstallPrepared)
                {
                    try
                    {
                        mpack.RollbackUninstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                    }
                }
            }
            else
            {
                monitor.BeginStepTask("Finishing installation", prepared.Count + uninstallPrepared.Count + 1, 5);
            }

            // Cleanup

            foreach (Package mpack in prepared)
            {
                try
                {
                    mpack.EndInstall(monitor, this);
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    monitor.Log.WriteLine(ex);
                }
            }

            monitor.Step(1);

            foreach (Package mpack in uninstallPrepared)
            {
                try
                {
                    mpack.EndUninstall(monitor, this);
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    monitor.Log.WriteLine(ex);
                }
            }

            // Update the extension maps
            service.Registry.Update(statusMonitor);

            monitor.EndTask();

            monitor.EndTask();

            service.SaveConfiguration();
            ResetCachedData();

            return(!rollback);
        }
		/// <summary>
		/// Removes any deleted files from the DotNetProject.
		/// </summary>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// The sync context.
		/// </param>
		/// <returns>
		/// Returns whether or not any files were removed from the project.
		/// </returns>
		bool RemoveDeletedFilesFromProject (IProgressMonitor monitor, XcodeSyncBackContext context)
		{
			if (context.FileSyncJobs.Count == 0)
				return false;
			
			var removed = new List<XcodeSyncFileBackJob> (context.FileSyncJobs.Where (job => job.Status == XcodeSyncFileStatus.Removed));
			if (removed.Count == 0)
				return false;
			
			monitor.BeginStepTask (string.Format ("Removing deleted files from {0}...", dnp.Name), removed.Count, 1);
			
			foreach (var file in removed) {
				monitor.Log.WriteLine ("Removing '{0}'", file.SyncedRelative);
				context.Project.Files.Remove (file.Original);
				monitor.Step (1);
			}
			
			monitor.EndTask ();
			
			return true;
		}
		/// <summary>
		/// Adds any newly created content files to MonoDevelop's DotNetProject.
		/// </summary>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// The sync context.
		/// </param>
		/// <returns>
		/// Returns whether or not new files were added to the project.
		/// </returns>
		bool AddNewFilesToProject (IProgressMonitor monitor, XcodeSyncBackContext context)
		{
			if (context.FileSyncJobs.Count == 0)
				return false;
			
			var added = new List<XcodeSyncFileBackJob> (context.FileSyncJobs.Where (job => job.Status == XcodeSyncFileStatus.Added));
			if (added.Count == 0)
				return false;
			
			monitor.BeginStepTask (string.Format ("Adding new files to {0}...", dnp.Name), added.Count, 1);
			
			foreach (var file in added) {
				if (File.Exists (file.Original)) {
					monitor.Log.WriteLine ("Adding '{0}'", file.SyncedRelative);
					
					string buildAction = BuildAction.Content;
					
					if (HasInterfaceDefinitionExtension (file.Original))
						buildAction = BuildAction.InterfaceDefinition;
					
					context.Project.AddFile (file.Original, buildAction);
				}
				
				monitor.Step (1);
			}
			
			monitor.EndTask ();
			
			return true;
		}
		/// <summary>
		/// Syncs modified resource files from the Xcode project (back) to the MonoDevelop project directory.
		/// </summary>
		/// <param name='monitor'>
		/// A progress monitor.
		/// </param>
		/// <param name='context'>
		/// The sync context.
		/// </param>
		void CopyNewAndModifiedFiles (IProgressMonitor monitor, XcodeSyncBackContext context)
		{
			if (context.FileSyncJobs.Count == 0)
				return;
			
			var modified = new List<XcodeSyncFileBackJob> (context.FileSyncJobs.Where (job => job.IsNewOrModified));
			if (modified.Count == 0)
				return;
			
			monitor.BeginStepTask (string.Format ("Copying new and modified files from Xcode back to {0}...", dnp.Name), modified.Count, 1);
			
			foreach (var file in modified) {
				if (file.Status == XcodeSyncFileStatus.Modified)
					monitor.Log.WriteLine ("Copying modified file '{0}'", file.SyncedRelative);
				else
					monitor.Log.WriteLine ("Copying new file '{0}'", file.SyncedRelative);
				
				SyncFile (monitor, context, file);
				monitor.Step (1);
			}
			
			monitor.EndTask ();
		}
 public void BeginStepTask(string name, int totalWork, int stepSize)
 {
     statusMonitor.BeginStepTask(name, totalWork, stepSize);
 }