示例#1
0
        /// <summary>
        /// Add document to system. If db is set to true, only create file.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="title"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public override Document AddDocument(IItemContainer parent, string title, string revision = "", int id = 0, bool db = false)
        {
            if (!db)
            {
                title = GetAvailableName(title, id, parent.GetPath(), ".txt");
            }
            string documentPath = Path.Combine(parent.GetPath(), Helper.GenerateName(id, title));

            documentPath += ".txt";
            try {
                FileStream   fileStream   = File.Create(documentPath);
                StreamWriter streamWriter = new StreamWriter(fileStream);
                string[]     lines        = revision.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                foreach (string line in lines)
                {
                    streamWriter.WriteLine(line);
                }
                streamWriter.Flush();
                streamWriter.Close();
                fileStream.Close();
            } catch (IOException e) {
                // Should not be accesible
                Console.WriteLine(e.Message);
            }
            if (db)
            {
                return(null);
            }
            Document document = new Document();

            document.Title  = title;
            document.Parent = parent;
            parent.Documents.Add(document);
            return(document);
        }
示例#2
0
 /// <summary>
 /// Add document to system. If db is set to true, only create file.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public override Document AddDocument(IItemContainer parent, string title, string revision = "", int id = 0, bool db = false)
 {
     if (!db) title = GetAvailableName(title, id, parent.GetPath(), ".txt");
     string documentPath = Path.Combine(parent.GetPath(), Helper.GenerateName(id, title));
     documentPath += ".txt";
     try {
         FileStream fileStream = File.Create(documentPath);
         StreamWriter streamWriter = new StreamWriter(fileStream);
         string[] lines = revision.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
         foreach (string line in lines) {
             streamWriter.WriteLine(line);
         }
         streamWriter.Flush();
         streamWriter.Close();
         fileStream.Close();
     } catch (IOException e) {
         // Should not be accesible
         Console.WriteLine(e.Message);
     }
     if (db) return null;
     Document document = new Document();
     document.Title = title;
     document.Parent = parent;
     parent.Documents.Add(document);
     return document;
 }
示例#3
0
        /// <summary>
        /// Add folder to system. If db is set to true, only create folder.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="title"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public override Folder AddFolder(IItemContainer parent, string title, int id = 0, bool db = false)
        {
            if (!db)
            {
                title = GetAvailableName(title, id, parent.GetPath());
            }
            string folderPath = Path.Combine(parent.GetPath(), Helper.GenerateName(id, title));

            try {
                Directory.CreateDirectory(folderPath);
            } catch (IOException e) {
                // Should not be accesible
                Console.WriteLine(e.Message);
            }
            if (db)
            {
                return(null);
            }
            Folder folder = new Folder();

            folder.Title  = title;
            folder.Parent = parent;
            parent.Folders.Add(folder);
            return(folder);
        }
示例#4
0
 /// <summary>
 /// Add folder to system. If db is set to true, only create folder.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public override Folder AddFolder(IItemContainer parent, string title, int id = 0, bool db = false)
 {
     if (!db) title = GetAvailableName(title, id, parent.GetPath());
     string folderPath = Path.Combine(parent.GetPath(), Helper.GenerateName(id, title));
     try {
         Directory.CreateDirectory(folderPath);
     } catch (IOException e) {
         // Should not be accesible
         Console.WriteLine(e.Message);
     }
     if (db) return null;
     Folder folder = new Folder();
     folder.Title = title;
     folder.Parent = parent;
     parent.Folders.Add(folder);
     return folder;
 }
示例#5
0
 /// <summary>
 /// Find all documents in project/folder in file system and create them in internal system.
 /// </summary>
 /// <param name="parent"></param>
 public void FindDocuments(IItemContainer parent)
 {
     string[] documentPaths = Directory.GetFiles(parent.GetPath());
     foreach (string documentName in documentPaths)
     {
         string       pathName     = Path.GetFileName(documentName);
         string[]     parts        = pathName.Split('-');
         int          id           = int.Parse(parts[0]);
         bool         isRevision   = false;
         int          hash         = "".GetHashCode();
         string       revision     = "";
         FileStream   fileStream   = new FileStream(documentName, FileMode.Open, FileAccess.Read);
         StreamReader streamReader = new StreamReader(fileStream);
         string       line;
         int          i = 0;
         while ((line = streamReader.ReadLine()) != null)
         {
             if (i == 0)
             {
                 if (line.Length > 0)
                 {
                     if (line.Substring(0, 3).Equals("rev"))
                     {
                         isRevision = true;
                         line       = line.Substring(3);
                     }
                     hash = int.Parse(line);
                 }
             }
             else
             {
                 revision += line + "\n";
             }
             i++;
         }
         streamReader.Close();
         fileStream.Close();
         Document document = new Document {
             Id              = id,
             Title           = pathName.Replace(parts[0] + "-", "").Replace(".txt", ""),
             Parent          = parent,
             CurrentRevision = revision,
             CurrentHash     = (id == 0 ? revision.GetHashCode() : hash),
             IsMerged        = isRevision
         };
         parent.Documents.Add(document);
     }
 }
示例#6
0
        /// <summary>
        /// Find all folders in project folder and subfolders in file system and create them in internal system.
        /// </summary>
        /// <param name="parent"></param>
        public void FindFolders(IItemContainer parent)
        {
            string[] folders = Directory.GetDirectories(parent.GetPath());
            foreach (string folderName in folders)
            {
                string   pathName = Path.GetFileName(folderName);
                string[] parts    = pathName.Split('-');
                Folder   folder   = new Folder {
                    Id     = int.Parse(parts[0]),
                    Title  = pathName.Replace(parts[0] + "-", ""),
                    Parent = parent
                };
                parent.Folders.Add(folder);

                FindFolders(folder);
                FindDocuments(folder);
            }
        }
示例#7
0
        /// <summary>
        /// Find all folders in project folder and subfolders in file system and create them in internal system.
        /// </summary>
        /// <param name="parent"></param>
        public void FindFolders(IItemContainer parent)
        {
            string[] folders = Directory.GetDirectories(parent.GetPath());
            foreach (string folderName in folders) {
                string pathName = Path.GetFileName(folderName);
                string[] parts = pathName.Split('-');
                Folder folder = new Folder {
                    Id = int.Parse(parts[0]),
                    Title = pathName.Replace(parts[0] + "-", ""),
                    Parent = parent
                };
                parent.Folders.Add(folder);

                FindFolders(folder);
                FindDocuments(folder);
            }
        }
示例#8
0
 /// <summary>
 /// Find all documents in project/folder in file system and create them in internal system.
 /// </summary>
 /// <param name="parent"></param>
 public void FindDocuments(IItemContainer parent)
 {
     string[] documentPaths = Directory.GetFiles(parent.GetPath());
     foreach (string documentName in documentPaths) {
         string pathName = Path.GetFileName(documentName);
         string[] parts = pathName.Split('-');
         int id = int.Parse(parts[0]);
         bool isRevision = false;
         int hash = "".GetHashCode();
         string revision = "";
         FileStream fileStream = new FileStream(documentName, FileMode.Open, FileAccess.Read);
         StreamReader streamReader = new StreamReader(fileStream);
         string line;
         int i = 0;
         while ((line = streamReader.ReadLine()) != null) {
             if (i == 0) {
                 if (line.Length > 0) {
                     if (line.Substring(0, 3).Equals("rev")) {
                         isRevision = true;
                         line = line.Substring(3);
                     }
                     hash = int.Parse(line);
                 }
             } else {
                 revision += line + "\n";
             }
             i++;
         }
         streamReader.Close();
         fileStream.Close();
         Document document = new Document {
             Id = id,
             Title = pathName.Replace(parts[0] + "-", "").Replace(".txt", ""),
             Parent = parent,
             CurrentRevision = revision,
             CurrentHash = (id == 0 ? revision.GetHashCode() : hash),
             IsMerged = isRevision
         };
         parent.Documents.Add(document);
     }
 }