示例#1
0
        public void ExtractFile(RepositoryFileInfo info)
        {
            string str;
            Stream file = info.File.GetFile(info);

            if (info.Name != null)
            {
                str = this.extractBasePath + info.Name;
            }
            else
            {
                str = string.Format("{0}/{1:X}.bin", this.extractBasePath, info.Hash);
            }
            str = str.Replace('/', '\\');
            RepoDirectory rootDirectory = this.rootDirectory;

            string[] strArray = info.Name.Split(new char[] { '/' });
            string   path     = this.extractBasePath + @"\";

            for (int i = 1; i < (strArray.Length - 1); i++)
            {
                if (rootDirectory.SubDirectories.ContainsKey(strArray[i]))
                {
                    rootDirectory = rootDirectory.SubDirectories[strArray[i]];
                }
                else
                {
                    RepoDirectory directory2 = new RepoDirectory {
                        Name = strArray[i]
                    };
                    rootDirectory.SubDirectories[strArray[i]] = directory2;
                    rootDirectory = directory2;
                }
                path = path + strArray[i] + @"\";
            }
            if (!rootDirectory.Files.Contains(strArray[strArray.Length - 1]))
            {
                rootDirectory.Files.Add(strArray[strArray.Length - 1]);
            }
            Directory.CreateDirectory(path);
            Stream stream2 = File.Open(str, FileMode.Create, FileAccess.Write);

            byte[] buffer = new byte[file.Length];
            file.Read(buffer, 0, buffer.Length);
            stream2.Write(buffer, 0, buffer.Length);
            file.Close();
            stream2.Close();
        }
        private static RepoCommit ToRepoCommit(this string svnList, string message, DateTime date, int revNumber)
        {
            string[] splitList = svnList.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);

            Dictionary <string, RepoDirectory> rootDirectories = new Dictionary <string, RepoDirectory>();
            List <string> files = new List <string>();

            RepoDirectory root = new RepoDirectory("root");

            for (int i = 0; i < splitList.Length; i++)
            {
                RepoDirectory current = root;

                bool isFolder = splitList[i].Last() == '/';

                string[] line = splitList[i].Split('/', StringSplitOptions.RemoveEmptyEntries);

                for (int j = 0; j < line.Length; j++)
                {
                    if (j == line.Length - 1)
                    {
                        if (isFolder)
                        {
                            current.AddDirectory(line[j]);
                        }
                        else
                        {
                            current.AddFile(line[j]);
                        }
                    }
                    else
                    {
                        current = current.GetDirectory(line[j]);
                    }
                }
            }

            return(new RepoCommit()
            {
                directories = root.directories,
                files = root.files,
                date = date,
                message = message,
                commitId = revNumber.ToString()
            });
        }
示例#3
0
        private void BuildRepository(TableModel table)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("/*******************************************************   ");
            builder.AppendLine("*    ");
            builder.AppendLine("* 作者:罗敏贵   ");
            builder.AppendLine("* 说明:   ");
            builder.AppendLine("* 运行环境:.NET 4.5.0   ");
            builder.AppendLine("* 版本号:1.0.0   ");
            builder.AppendLine("*    ");
            builder.AppendLine("* 历史记录:   ");
            builder.AppendLine("*    创建文件 罗敏贵 " + DateTime.Now + "  ");
            builder.AppendLine("*    ");
            builder.AppendLine("*******************************************************/   ");
            builder.AppendLine("using LCL;   ");
            builder.AppendLine("using LCL.Repositories;   ");
            builder.AppendLine("using LCL.Repositories.EntityFramework; ");
            builder.AppendLine(" ");
            builder.AppendLine("namespace " + this.DomainName + " ");
            builder.AppendLine("{   ");
            builder.AppendLine("    public interface I" + table.TableName + "Repository : IRepository<" + table.TableName + ">   ");
            builder.AppendLine("    {   ");
            builder.AppendLine("   ");
            builder.AppendLine("    }   ");
            builder.AppendLine("    public class " + table.TableName + "Repository : EntityFrameworkRepository<" + table.TableName + ">, I" + table.TableName + "Repository   ");
            builder.AppendLine("    {   ");
            builder.AppendLine("        public " + table.TableName + "Repository(IRepositoryContext context) : base(context) ");
            builder.AppendLine("        {    ");
            builder.AppendLine("           ");
            builder.AppendLine("        }   ");
            builder.AppendLine("    }   ");
            builder.AppendLine("}   ");

            //写到文件,并加入到项目中。
            var file = Path.Combine(Path.GetDirectoryName(RepoDirectory.get_FileNames(1)), table.TableName) + ".cs";

            if (!File.Exists(file))
            {
                File.WriteAllText(file, builder.ToString());
                RepoDirectory.ProjectItems.AddFromFile(file);
            }
        }
示例#4
0
        public void ExtractFile(RepositoryFileInfo info)
        {
            Stream file  = info.File.GetFile(info);
            string path1 =
                (info.Name == null
                     ? string.Format("{0}/{1:X}.bin", ExtractBasePath, info.Hash)
                     : ExtractBasePath + info.Name).Replace('/', '\\');
            RepoDirectory repoDirectory1 = _rootDirectory;

            string[] strArray = info.Name.Split(new char[1]
            {
                '/'
            });
            string path2 = ExtractBasePath + "\\";

            for (int index = 1; index < strArray.Length - 1; ++index)
            {
                if (repoDirectory1.SubDirectories.ContainsKey(strArray[index]))
                {
                    repoDirectory1 = repoDirectory1.SubDirectories[strArray[index]];
                }
                else
                {
                    var repoDirectory2 = new RepoDirectory();
                    repoDirectory2.Name = strArray[index];
                    repoDirectory1.SubDirectories[strArray[index]] = repoDirectory2;
                    repoDirectory1 = repoDirectory2;
                }
                path2 = path2 + strArray[index] + "\\";
            }
            if (!repoDirectory1.Files.Contains(strArray[strArray.Length - 1]))
            {
                repoDirectory1.Files.Add(strArray[strArray.Length - 1]);
            }
            Directory.CreateDirectory(path2);
            Stream stream = File.Open(path1, FileMode.Create, FileAccess.Write);
            var    buffer = new byte[file.Length];

            file.Read(buffer, 0, buffer.Length);
            stream.Write(buffer, 0, buffer.Length);
            file.Close();
            stream.Close();
        }
示例#5
0
 public Repository()
 {
     _repositoryFiles = new List <RepositoryFile>();
     _rootDirectory   = new RepoDirectory();
 }