Example #1
0
        public int PendAdd(string[] paths, bool isRecursive)
        {
            List <ChangeRequest> changes = new List <ChangeRequest>();

            foreach (string path in paths)
            {
                ItemType itemType = ItemType.File;
                if (Directory.Exists(path))
                {
                    itemType = ItemType.Folder;
                }
                changes.Add(new ChangeRequest(path, RequestType.Add, itemType));

                if (!isRecursive || itemType != ItemType.Folder)
                {
                    continue;
                }

                DirectoryInfo dir        = new DirectoryInfo(path);
                FileInfo[]    localFiles = dir.GetFiles("*", SearchOption.AllDirectories);

                foreach (FileInfo file in localFiles)
                {
                    changes.Add(new ChangeRequest(file.FullName, RequestType.Add, ItemType.File));
                }
            }

            if (changes.Count == 0)
            {
                return(0);
            }

            GetOperation[] operations = Repository.PendChanges(this, changes.ToArray());
            return(operations.Length);
        }
Example #2
0
        public int PendRename(string oldPath, string newPath)
        {
            string newServerPath;

            if (VersionControlPath.IsServerItem(newPath))
            {
                newServerPath = GetServerItemForLocalItem(newPath);
            }
            else
            {
                newServerPath = newPath;
            }

            ItemType itemType = ItemType.File;

            if (Directory.Exists(oldPath))
            {
                itemType = ItemType.Folder;
            }

            List <ChangeRequest> changes = new List <ChangeRequest>();

            changes.Add(new ChangeRequest(oldPath, newServerPath, RequestType.Rename, itemType));

            GetOperation[] getOperations = Repository.PendChanges(this, changes.ToArray());

            if (itemType == ItemType.File)
            {
                File.Move(oldPath, newPath);
            }
            else
            {
                Directory.Move(oldPath, newPath);
            }

            UpdateLocalVersionQueue updates = new UpdateLocalVersionQueue(this);

            foreach (GetOperation getOperation in getOperations)
            {
                updates.QueueUpdate(getOperation.ItemId, getOperation.TargetLocalItem, getOperation.VersionServer);
            }

            updates.Flush();
            return(1);
        }
Example #3
0
        public int SetLock(string[] paths, LockLevel lockLevel, RecursionType recursion)
        {
            List <ChangeRequest> changes = new List <ChangeRequest>();

            foreach (string path in paths)
            {
                ItemType itemType = ItemType.File;
                if (Directory.Exists(path))
                {
                    itemType = ItemType.Folder;
                }
                changes.Add(new ChangeRequest(path, RequestType.Lock, itemType, recursion, lockLevel));
            }

            if (changes.Count == 0)
            {
                return(0);
            }

            GetOperation[] operations = Repository.PendChanges(this, changes.ToArray());
            return(operations.Length);
        }
Example #4
0
        public int PendEdit(string[] paths, RecursionType recursionType)
        {
            List <ChangeRequest> changes = new List <ChangeRequest>();

            foreach (string path in paths)
            {
                changes.Add(new ChangeRequest(path, RequestType.Edit, ItemType.File));
            }

            if (changes.Count == 0)
            {
                return(0);
            }

            GetOperation[] getOperations = Repository.PendChanges(this, changes.ToArray());
            foreach (GetOperation getOperation in getOperations)
            {
                UnsetFileAttributes(getOperation.TargetLocalItem);
            }

            return(getOperations.Length);
        }
Example #5
0
        public int PendDelete(string[] paths, RecursionType recursionType)
        {
            List <ChangeRequest> changes = new List <ChangeRequest>();

            foreach (string path in paths)
            {
                ItemType itemType = ItemType.File;
                if (Directory.Exists(path))
                {
                    itemType = ItemType.Folder;
                }
                changes.Add(new ChangeRequest(path, RequestType.Delete, itemType));
            }

            if (changes.Count == 0)
            {
                return(0);
            }

            GetOperation[]          operations = Repository.PendChanges(this, changes.ToArray());
            UpdateLocalVersionQueue updates    = new UpdateLocalVersionQueue(this);

            // first delete all files
            foreach (GetOperation operation in operations)
            {
                if (operation.ItemType != ItemType.File)
                {
                    continue;
                }
                if (!File.Exists(operation.SourceLocalItem))
                {
                    continue;
                }

                UnsetFileAttributes(operation.SourceLocalItem);
                File.Delete(operation.SourceLocalItem);
                updates.QueueUpdate(operation.ItemId, null, operation.VersionServer);
            }

            // then any directories
            foreach (GetOperation operation in operations)
            {
                if (operation.ItemType != ItemType.Folder)
                {
                    continue;
                }
                if (!Directory.Exists(operation.SourceLocalItem))
                {
                    continue;
                }

                //DirectoryInfo dir = new DirectoryInfo(operation.SourceLocalItem);
                //FileInfo[] localFiles = dir.GetFiles("*", SearchOption.AllDirectories);
                //foreach (FileInfo file in localFiles)
                //	UnsetFileAttributes(file.FullName);

                Directory.Delete(operation.SourceLocalItem, true);
                updates.QueueUpdate(operation.ItemId, null, operation.VersionServer);
            }

            updates.Flush();
            return(operations.Length);
        }