Ejemplo n.º 1
0
 protected virtual void FireBeforeUpdate(FileUpdateEventArgs e)
 {
     _events.FireCancelableEvent(BeforeUpdate, this, e);
 }
Ejemplo n.º 2
0
        public override void Add(FilePath[] paths, bool recurse, IProgressMonitor monitor)
        {
            foreach (FilePath path in paths)
            {
                if (IsVersioned(path) && File.Exists(path) && !Directory.Exists(path))
                {
                    if (rootPath == null)
                    {
                        throw new UserException(GettextCatalog.GetString("Project publishing failed. There is a stale .svn folder in the path '{0}'", path.ParentDirectory));
                    }
                    VersionInfo srcInfo = GetVersionInfo(path, false);
                    if (srcInfo.HasLocalChange(VersionStatus.ScheduledDelete))
                    {
                        // It is a file that was deleted. It can be restored now since it's going
                        // to be added again.
                        // First of all, make a copy of the file
                        string tmp = Path.GetTempFileName();
                        File.Copy(path, tmp, true);

                        // Now revert the status of the file
                        Revert(path, false, monitor);

                        // Copy the file over the old one and clean up
                        File.Copy(tmp, path, true);
                        File.Delete(tmp);
                    }
                }
                else
                {
                    if (File.Exists(path) && !IsVersioned(path.ParentDirectory))
                    {
                        // The file belongs to an unversioned folder. We can add it by versioning the parent
                        // folders up to the root of the repository

                        if (!path.IsChildPathOf(rootPath))
                        {
                            throw new InvalidOperationException("File outside the repository directory");
                        }

                        List <FilePath> dirChain  = new List <FilePath> ();
                        FilePath        parentDir = path.CanonicalPath;
                        do
                        {
                            parentDir = parentDir.ParentDirectory;
                            if (Directory.Exists(SubversionVersionControl.GetDirectoryDotSvn(parentDir)))
                            {
                                break;
                            }
                            dirChain.Add(parentDir);
                        }while (parentDir != rootPath);

                        // Found all parent unversioned dirs. Versin them now.
                        dirChain.Reverse();
                        FileUpdateEventArgs args = new FileUpdateEventArgs();
                        foreach (var d in dirChain)
                        {
                            Svn.Add(d, false, monitor);
                            args.Add(new FileUpdateEventInfo(this, dirChain [0], true));
                        }
                        VersionControlService.NotifyFileStatusChanged(args);
                    }
                    Svn.Add(path, recurse, monitor);
                }
            }
        }
Ejemplo n.º 3
0
        public void Save()
        {
            if (Id == 0)
            {
                var e = new FileCreateEventArgs();
                FireBeforeCreate(e);
                if (e.Cancel)
                    return;

                Application.SqlHelper.ExecuteNonQuery(
                    "INSERT INTO wikiFiles (path, name, createdBy, nodeId, version, type, downloads, archived, umbracoVersion, verified, dotNetVersion) VALUES(@path, @name, @createdBy, @nodeId, @nodeVersion, @type, @downloads, @archived, @umbracoVersion, @verified, @dotNetVersion)",
                    Application.SqlHelper.CreateParameter("@path", Path),
                    Application.SqlHelper.CreateParameter("@name", Name),
                    Application.SqlHelper.CreateParameter("@createdBy", CreatedBy),
                    Application.SqlHelper.CreateParameter("@nodeId", NodeId),
                    Application.SqlHelper.CreateParameter("@type", FileType),
                    Application.SqlHelper.CreateParameter("@nodeVersion", NodeVersion),
                    Application.SqlHelper.CreateParameter("@downloads", Downloads),
                    Application.SqlHelper.CreateParameter("@archived", Archived),
                    Application.SqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                    Application.SqlHelper.CreateParameter("@verified", Verified),
                    Application.SqlHelper.CreateParameter("@dotNetVersion", DotNetVersion)
                    );

                CreateDate = DateTime.Now;

                Id = Application.SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM wikiFiles WHERE createdBy = @createdBy", Application.SqlHelper.CreateParameter("@createdBy", CreatedBy));

                FireAfterCreate(e);
            }
            else
            {
                var e = new FileUpdateEventArgs();
                FireBeforeUpdate(e);

                if (e.Cancel)
                    return;

                Application.SqlHelper.ExecuteNonQuery(
                    "UPDATE wikiFiles SET path = @path, name = @name, type = @type, [current] = @current, removedBy = @removedBy, version = @version, downloads = @downloads, archived = @archived, umbracoVersion = @umbracoVersion, verified = @verified, dotNetVersion = @dotNetVersion WHERE id = @id",
                    Application.SqlHelper.CreateParameter("@path", Path),
                    Application.SqlHelper.CreateParameter("@name", Name),
                    Application.SqlHelper.CreateParameter("@type", FileType),
                    Application.SqlHelper.CreateParameter("@current", Current),
                    Application.SqlHelper.CreateParameter("@removedBy", RemovedBy),
                    Application.SqlHelper.CreateParameter("@version", NodeVersion),
                    Application.SqlHelper.CreateParameter("@id", Id),
                    Application.SqlHelper.CreateParameter("@downloads", Downloads),
                    Application.SqlHelper.CreateParameter("@archived", Archived),
                    Application.SqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                    Application.SqlHelper.CreateParameter("@verified", Verified),
                    Application.SqlHelper.CreateParameter("@dotNetVersion", DotNetVersion)
                    );

                FireAfterUpdate(e);
            }
        }
Ejemplo n.º 4
0
 protected virtual void FireAfterUpdate(FileUpdateEventArgs e)
 {
     if (AfterUpdate != null)
         AfterUpdate(this, e);
 }
Ejemplo n.º 5
0
 protected virtual void FireBeforeUpdate(FileUpdateEventArgs e)
 {
     _events.FireCancelableEvent(BeforeUpdate, this, e);
 }
Ejemplo n.º 6
0
		void OnFileStatusChanged (object s, FileUpdateEventArgs args)
		{
			if (args.Any (f => f.FilePath == filepath || (f.FilePath.IsChildPathOf (filepath) && f.IsDirectory))) {
				StartUpdate ();
				return;
			}
			foreach (FileUpdateEventInfo f in args) {
				if (!OnFileStatusChanged (f))
					break;
			}
			UpdateControlStatus ();
Ejemplo n.º 7
0
        void OnFileStatusChanged(object s, FileUpdateEventArgs args)
        {
            if (!args.FilePath.IsChildPathOf(filepath) && args.FilePath != filepath)
            {
                return;
            }

            if (args.IsDirectory)
            {
                StartUpdate();
                return;
            }

            bool     found = false;
            int      oldStatusIndex;
            TreeIter oldStatusIter = TreeIter.Zero;

            // Locate the file in the status object list
            for (oldStatusIndex = 0; oldStatusIndex < statuses.Count; oldStatusIndex++)
            {
                if (statuses [oldStatusIndex].LocalPath == args.FilePath)
                {
                    found = true;
                    break;
                }
            }

            // Locate the file in the treeview
            if (found)
            {
                found = false;
                if (filestore.GetIterFirst(out oldStatusIter))
                {
                    do
                    {
                        if (args.FilePath == (string)filestore.GetValue(oldStatusIter, ColFullPath))
                        {
                            found = true;
                            break;
                        }
                    } while (filestore.IterNext(ref oldStatusIter));
                }
            }

            VersionInfo newInfo;

            try {
                // Reuse remote status from old version info
                newInfo = vc.GetVersionInfo(args.FilePath, false);
                if (found && newInfo != null)
                {
                    VersionInfo oldInfo = statuses [oldStatusIndex];
                    if (oldInfo != null)
                    {
                        newInfo.RemoteStatus   = oldInfo.RemoteStatus;
                        newInfo.RemoteRevision = oldInfo.RemoteRevision;
                    }
                }
            }
            catch (Exception ex) {
                LoggingService.LogError(ex.ToString());
                return;
            }

            if (found)
            {
                if (!FileVisible(newInfo))
                {
                    // Just remove the file from the change set
                    changeSet.RemoveFile(args.FilePath);
                    statuses.RemoveAt(oldStatusIndex);
                    filestore.Remove(ref oldStatusIter);
                    UpdateControlStatus();
                    return;
                }

                statuses [oldStatusIndex] = newInfo;

                // Update the tree
                AppendFileInfo(newInfo);
                filestore.Remove(ref oldStatusIter);
            }
            else
            {
                if (FileVisible(newInfo))
                {
                    statuses.Add(newInfo);
                    changeSet.AddFile(newInfo);
                    AppendFileInfo(newInfo);
                }
            }
            UpdateControlStatus();
        }
Ejemplo n.º 8
0
        public void Save()
        {
            if (Id == 0)
            {
                var e = new FileCreateEventArgs();
                FireBeforeCreate(e);
                if (e.Cancel)
                {
                    return;
                }

                using (var sqlHelper = Application.SqlHelper)
                {
                    sqlHelper.ExecuteNonQuery(
                        "INSERT INTO wikiFiles (path, name, createdBy, nodeId, version, type, downloads, archived, umbracoVersion, verified, dotNetVersion, minimumVersionStrict) VALUES(@path, @name, @createdBy, @nodeId, @nodeVersion, @type, @downloads, @archived, @umbracoVersion, @verified, @dotNetVersion, @minimumVersionStrict)",
                        sqlHelper.CreateParameter("@path", Path),
                        sqlHelper.CreateParameter("@name", Name),
                        sqlHelper.CreateParameter("@createdBy", CreatedBy),
                        sqlHelper.CreateParameter("@nodeId", NodeId),
                        sqlHelper.CreateParameter("@type", FileType),
                        sqlHelper.CreateParameter("@nodeVersion", NodeVersion),
                        sqlHelper.CreateParameter("@downloads", Downloads),
                        sqlHelper.CreateParameter("@archived", Archived),
                        sqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                        sqlHelper.CreateParameter("@verified", Verified),
                        sqlHelper.CreateParameter("@dotNetVersion",
                                                  string.IsNullOrWhiteSpace(DotNetVersion) ? "" : DotNetVersion),
                        sqlHelper.CreateParameter("@minimumVersionStrict",
                                                  string.IsNullOrWhiteSpace(MinimumVersionStrict) ? "" : MinimumVersionStrict)
                        );

                    CreateDate = DateTime.Now;

                    Id = sqlHelper.ExecuteScalar <int>(
                        "SELECT MAX(id) FROM wikiFiles WHERE createdBy = @createdBy",
                        sqlHelper.CreateParameter("@createdBy", CreatedBy));
                }
                FireAfterCreate(e);
            }
            else
            {
                var e = new FileUpdateEventArgs();
                FireBeforeUpdate(e);

                if (e.Cancel)
                {
                    return;
                }

                using (var sqlHelper = Application.SqlHelper)
                {
                    sqlHelper.ExecuteNonQuery(
                        "UPDATE wikiFiles SET path = @path, name = @name, type = @type, [current] = @current, removedBy = @removedBy, version = @version, downloads = @downloads, archived = @archived, umbracoVersion = @umbracoVersion, verified = @verified, dotNetVersion = @dotNetVersion, minimumVersionStrict = @minimumVersionStrict WHERE id = @id",
                        sqlHelper.CreateParameter("@path", Path),
                        sqlHelper.CreateParameter("@name", Name),
                        sqlHelper.CreateParameter("@type", FileType),
                        sqlHelper.CreateParameter("@current", Current),
                        sqlHelper.CreateParameter("@removedBy", RemovedBy),
                        sqlHelper.CreateParameter("@version", NodeVersion),
                        sqlHelper.CreateParameter("@id", Id),
                        sqlHelper.CreateParameter("@downloads", Downloads),
                        sqlHelper.CreateParameter("@archived", Archived),
                        sqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                        sqlHelper.CreateParameter("@verified", Verified),
                        sqlHelper.CreateParameter("@dotNetVersion",
                                                  string.IsNullOrWhiteSpace(DotNetVersion) ? "" : DotNetVersion),
                        sqlHelper.CreateParameter("@minimumVersionStrict",
                                                  string.IsNullOrWhiteSpace(MinimumVersionStrict) ? "" : MinimumVersionStrict)
                        );
                }
                FireAfterUpdate(e);
            }
        }
Ejemplo n.º 9
0
		protected override void OnAdd (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
		{
			foreach (FilePath path in localPaths) {
				if (IsVersioned (path) && File.Exists (path) && !Directory.Exists (path)) {
					if (RootPath.IsNull)
						throw new UserException (GettextCatalog.GetString ("Project publishing failed. There is a stale .svn folder in the path '{0}'", path.ParentDirectory));
					VersionInfo srcInfo = GetVersionInfo (path, VersionInfoQueryFlags.IgnoreCache);
					if (srcInfo.HasLocalChange (VersionStatus.ScheduledDelete)) {
						// It is a file that was deleted. It can be restored now since it's going
						// to be added again.
						// First of all, make a copy of the file
						string tmp = Path.GetTempFileName ();
						File.Copy (path, tmp, true);
						
						// Now revert the status of the file
						Revert (path, false, monitor);
						
						// Copy the file over the old one and clean up
						File.Copy (tmp, path, true);
						File.Delete (tmp);
						continue;
					}
				}
				else {
					if (!IsVersioned (path.ParentDirectory)) {
						// The file/folder belongs to an unversioned folder. We can add it by versioning the parent
						// folders up to the root of the repository
						
						if (!path.IsChildPathOf (RootPath))
							throw new InvalidOperationException ("File outside the repository directory");

						List<FilePath> dirChain = new List<FilePath> ();
						FilePath parentDir = path.CanonicalPath;
						do {
							parentDir = parentDir.ParentDirectory;
							if (IsVersioned (parentDir))
								break;
							dirChain.Add (parentDir);
						}
						while (parentDir != RootPath);

						// Found all parent unversioned dirs. Versin them now.
						dirChain.Reverse ();
						FileUpdateEventArgs args = new FileUpdateEventArgs ();
						foreach (var d in dirChain) {
							Svn.Add (d, false, monitor);
							args.Add (new FileUpdateEventInfo (this, d, true));
						}
						VersionControlService.NotifyFileStatusChanged (args);
					}
				}
				Svn.Add (path, recurse, monitor);
			}
		}
Ejemplo n.º 10
0
        protected override async Task OnAddAsync(FilePath[] localPaths, bool recurse, ProgressMonitor monitor)
        {
            foreach (FilePath path in localPaths)
            {
                if (await IsVersionedAsync(path, monitor.CancellationToken).ConfigureAwait(false) && File.Exists(path) && !Directory.Exists(path))
                {
                    if (RootPath.IsNull)
                    {
                        throw new UserException(GettextCatalog.GetString("Project publishing failed. There is a stale .svn folder in the path '{0}'", path.ParentDirectory));
                    }
                    VersionInfo srcInfo = await GetVersionInfoAsync(path, VersionInfoQueryFlags.IgnoreCache).ConfigureAwait(false);

                    if (srcInfo.HasLocalChange(VersionStatus.ScheduledDelete))
                    {
                        // It is a file that was deleted. It can be restored now since it's going
                        // to be added again.
                        // First of all, make a copy of the file
                        string tmp = Path.GetTempFileName();
                        File.Copy(path, tmp, true);

                        // Now revert the status of the file
                        await RevertAsync(path, false, monitor).ConfigureAwait(false);

                        // Copy the file over the old one and clean up
                        File.Copy(tmp, path, true);
                        File.Delete(tmp);
                        continue;
                    }
                }
                else
                {
                    if (!await IsVersionedAsync(path.ParentDirectory, monitor.CancellationToken).ConfigureAwait(false))
                    {
                        // The file/folder belongs to an unversioned folder. We can add it by versioning the parent
                        // folders up to the root of the repository

                        if (!path.IsChildPathOf(RootPath))
                        {
                            throw new InvalidOperationException("File outside the repository directory");
                        }

                        List <FilePath> dirChain  = new List <FilePath> ();
                        FilePath        parentDir = path.CanonicalPath;
                        do
                        {
                            parentDir = parentDir.ParentDirectory;
                            if (await IsVersionedAsync(parentDir, monitor.CancellationToken).ConfigureAwait(false))
                            {
                                break;
                            }
                            dirChain.Add(parentDir);
                        }while (parentDir != RootPath);

                        // Found all parent unversioned dirs. Versin them now.
                        dirChain.Reverse();
                        FileUpdateEventArgs args = new FileUpdateEventArgs();
                        foreach (var d in dirChain)
                        {
                            Svn.Add(d, false, monitor);
                            args.Add(new FileUpdateEventInfo(this, d, true));
                        }
                        VersionControlService.NotifyFileStatusChanged(args);
                    }
                }
                Svn.Add(path, recurse, monitor);
            }
        }
Ejemplo n.º 11
0
        public void Save()
        {
            if (Id == 0)
            {
                var e = new FileCreateEventArgs();
                FireBeforeCreate(e);
                if (e.Cancel)
                {
                    return;
                }

                using (var sqlHelper = Application.SqlHelper)
                {
                    sqlHelper.ExecuteNonQuery(
                        "INSERT INTO wikiFiles (path, name, createdBy, createDate, [current], nodeId, version, type, downloads, archived, umbracoVersion, verified, dotNetVersion, minimumVersionStrict) VALUES(@path, @name, @createdBy, @createDate, @current, @nodeId, @nodeVersion, @type, @downloads, @archived, @umbracoVersion, @verified, @dotNetVersion, @minimumVersionStrict)",
                        sqlHelper.CreateParameter("@path", Path),
                        sqlHelper.CreateParameter("@name", Name),
                        sqlHelper.CreateParameter("@createdBy", CreatedBy),
                        sqlHelper.CreateParameter("@createDate", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")),

                        // Note: for some reason this has to be set to 1 else package uploads will fail
                        // Interestingly, this property is never actually used, we use the currentFile
                        // Note2: HACK! This is stored as a type `bit` and you need to pass "1" instead of a boolean 🤷‍♂️
                        sqlHelper.CreateParameter("@current", "1"),

                        sqlHelper.CreateParameter("@nodeId", NodeId),
                        sqlHelper.CreateParameter("@type", FileType),
                        sqlHelper.CreateParameter("@nodeVersion", NodeVersion),
                        sqlHelper.CreateParameter("@downloads", Downloads),
                        sqlHelper.CreateParameter("@archived", Archived),
                        sqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                        sqlHelper.CreateParameter("@verified", Verified),
                        sqlHelper.CreateParameter("@dotNetVersion",
                                                  string.IsNullOrWhiteSpace(DotNetVersion) ? "" : DotNetVersion),
                        sqlHelper.CreateParameter("@minimumVersionStrict",
                                                  string.IsNullOrWhiteSpace(MinimumVersionStrict) ? "" : MinimumVersionStrict)
                        );

                    Id = sqlHelper.ExecuteScalar <int>(
                        "SELECT MAX(id) FROM wikiFiles WHERE createdBy = @createdBy",
                        sqlHelper.CreateParameter("@createdBy", CreatedBy));
                }
                FireAfterCreate(e);
            }
            else
            {
                var e = new FileUpdateEventArgs();
                FireBeforeUpdate(e);

                if (e.Cancel)
                {
                    return;
                }

                using (var sqlHelper = Application.SqlHelper)
                {
                    sqlHelper.ExecuteNonQuery(
                        "UPDATE wikiFiles SET path = @path, name = @name, type = @type, [current] = @current, removedBy = @removedBy, version = @version, downloads = @downloads, archived = @archived, umbracoVersion = @umbracoVersion, verified = @verified, dotNetVersion = @dotNetVersion, minimumVersionStrict = @minimumVersionStrict WHERE id = @id",
                        sqlHelper.CreateParameter("@path", Path),
                        sqlHelper.CreateParameter("@name", Name),
                        sqlHelper.CreateParameter("@type", FileType),
                        sqlHelper.CreateParameter("@current", Current),
                        sqlHelper.CreateParameter("@removedBy", RemovedBy),
                        sqlHelper.CreateParameter("@version", NodeVersion),
                        sqlHelper.CreateParameter("@id", Id),
                        sqlHelper.CreateParameter("@downloads", Downloads),
                        sqlHelper.CreateParameter("@archived", Archived),
                        sqlHelper.CreateParameter("@umbracoVersion", ToVersionString(Versions)),
                        sqlHelper.CreateParameter("@verified", Verified),
                        sqlHelper.CreateParameter("@dotNetVersion",
                                                  string.IsNullOrWhiteSpace(DotNetVersion) ? "" : DotNetVersion),
                        sqlHelper.CreateParameter("@minimumVersionStrict",
                                                  string.IsNullOrWhiteSpace(MinimumVersionStrict) ? "" : MinimumVersionStrict)
                        );
                }
                FireAfterUpdate(e);
            }
        }
		void OnFileStatusChanged (object s, FileUpdateEventArgs args)
		{
			if (!args.FilePath.IsChildPathOf (filepath) && args.FilePath != filepath)
				return;
				
			if (args.IsDirectory) {
				StartUpdate ();
				return;
			}
			
			bool found = false;
			int oldStatusIndex;
			TreeIter oldStatusIter = TreeIter.Zero;
			
			// Locate the file in the status object list
			for (oldStatusIndex=0; oldStatusIndex<statuses.Count; oldStatusIndex++) {
				if (statuses [oldStatusIndex].LocalPath == args.FilePath) {
					found = true;
					break;
				}
			}

			// Locate the file in the treeview
			if (found) {
				found = false;
				if (filestore.GetIterFirst (out oldStatusIter)) {
					do {
						if (args.FilePath == (string) filestore.GetValue (oldStatusIter, ColFullPath)) {
							found = true;
							break;
						}
					} while (filestore.IterNext (ref oldStatusIter));
				}
			}

			VersionInfo newInfo;
			try {
				// Reuse remote status from old version info
				newInfo = vc.GetVersionInfo (args.FilePath, false);
				if (found && newInfo != null) {
					VersionInfo oldInfo = statuses [oldStatusIndex];
					if (oldInfo != null) {
						newInfo.RemoteStatus = oldInfo.RemoteStatus;
						newInfo.RemoteRevision = oldInfo.RemoteRevision;
					}
				}
			}
			catch (Exception ex) {
				LoggingService.LogError (ex.ToString ());
				return;
			}
			
			if (found) {
				if (!FileVisible (newInfo)) {
					// Just remove the file from the change set
					changeSet.RemoveFile (args.FilePath);
					statuses.RemoveAt (oldStatusIndex);
					filestore.Remove (ref oldStatusIter);
					UpdateControlStatus ();
					return;
				}
				
				statuses [oldStatusIndex] = newInfo;
				
				// Update the tree
				AppendFileInfo (newInfo);
				filestore.Remove (ref oldStatusIter);
			}
			else {
				if (FileVisible (newInfo)) {
					statuses.Add (newInfo);
					changeSet.AddFile (newInfo);
					AppendFileInfo (newInfo);
				}
			}
			UpdateControlStatus ();
		}
Ejemplo n.º 13
0
		public void Resolve (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
		{
			Svn.Resolve (localPaths, recurse, monitor);
			FileUpdateEventArgs args = new FileUpdateEventArgs ();
			foreach (var path in localPaths)
				args.Add (new FileUpdateEventInfo (this, path, Directory.Exists (path)));
			VersionControlService.NotifyFileStatusChanged (args);
		}