Click here to Skip to main content
15,880,796 members
Articles / Programming Languages / C#

SVN Shelve

Rate me:
Please Sign up or sign in to vote.
3.53/5 (9 votes)
23 Sep 2008CPOL5 min read 55.5K   423   25  
A simple utility to shelve your projects under SVN.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SvnShelve.Model
{
    public class FileStatusInfo
    {
        public FileStatusInfo() { }

        public static FileStatusInfo ParseConsoleLine(string path, string consoleLine)
        {
            FileStatusInfo fileStatus = new FileStatusInfo();

            string state = consoleLine.Substring(0, 6);
            char status = state[0];
            fileStatus.FilePath = consoleLine.Remove(0, 6).Trim();
            if (Directory.Exists(fileStatus.FilePath))
            {
                fileStatus.IsFolder = true;
            }

            fileStatus.FilePath = fileStatus.FilePath.Replace(path, string.Empty);

            if (fileStatus.FilePath.StartsWith("\\"))
                fileStatus.FilePath = fileStatus.FilePath.Remove(0, 1);

            if (fileStatus.FilePath.Length == 0)
            {
                fileStatus.FilePath = "(root)";
            }
            fileStatus.State = StatusEnum.None;
            switch (status)
            {
                case 'A':
                    fileStatus.State = StatusEnum.Added;
                    break;
                case 'M':
                    fileStatus.State = StatusEnum.Modified;
                    break;
                case 'D':
                    fileStatus.State = StatusEnum.Deleted;
                    break;
                case 'C':
                    fileStatus.State = StatusEnum.Conflicted;
                    break;
                case '?':
                case '!':
                case ' ':
                case '~':
                case '-':
                    break;
                default:
                    throw new NotSupportedException(string.Format("File status '{0}' is not supported", status));
            }

            return fileStatus;
        }
        public enum StatusEnum
        {
            None,
            Added,
            Deleted,
            Modified,
            Conflicted
        }

        private string _filePath;

        public string FilePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        private bool _isFolder;

        public bool IsFolder
        {
            get { return _isFolder; }
            set { _isFolder = value; }
        }
	
        private StatusEnum _state;

        public StatusEnum State
        {
            get { return _state; }
            set { _state = value; }
        }

        public override string ToString()
        {
            string str = null;
            switch (State)
            {
                case FileStatusInfo.StatusEnum.Added:
                    str = string.Format("(A) - {0}", FilePath);
                    break;
                case FileStatusInfo.StatusEnum.Deleted:
                    str = string.Format("(D) - {0}", FilePath);
                    break;
                case FileStatusInfo.StatusEnum.Modified:
                    str = string.Format("(M) - {0}", FilePath);
                    break;
                case StatusEnum.Conflicted:
                    str = string.Format("(C) - {0}", FilePath);
                    break;
            }

            return str;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) VORLAN Group, Inc.
United States United States
writing code for the past 20 years, and now decided to share some thoughts. Smile | :)
Also known as Oleg Vorkunov.

Comments and Discussions