Esempio n. 1
0
        private List <CatalogCode> CardsInRange(List <CodeRange> codeRanges)
        {
            List <CatalogCode> output = new List <CatalogCode>();

            foreach (CodeRange codeRange in codeRanges)
            {
                foreach (CatalogEntry child in catalog.Get(codeRange.fromCode.parent).children)
                {
                    CatalogCode temp = child.codePrefix;
                    if (child.codePrefix.CompareTo(codeRange.fromCode) >= 0 &&
                        child.codePrefix.CompareTo(codeRange.toCode) <= 0)
                    {
                        IsFile(temp, out string p, out bool isImage);
                        if (isImage)
                        {
                            output.Add(temp);
                        }
                        if (codeRange.childrenAsWell)
                        {
                            output.AddRange(CardsOf(catalog.Get(temp)));
                        }
                    }
                }
            }

            return(output);
        }
Esempio n. 2
0
        public CodeRange(string range)
        {
            string[] codes = range.Split('-');
            int      l1    = codes[0].Length;

            if (l1 >= 2 && codes[0][l1 - 1] == '.')
            {
                childrenAsWell = false;
                codes[0]       = codes[0].RemoveLast(1);
            }

            fromCode = new CatalogCode(codes[0]);
            if (codes.Length == 1)
            {
                toCode = fromCode;
            }
            else
            {
                toCode = new CatalogCode(childrenAsWell ? codes[1] : codes[1].RemoveLast(1));
                if (!CatalogCode.SameFolder(fromCode, toCode) || fromCode.CompareTo(toCode) > 0)
                {
                    throw new CatalogError("Invalid code range.");
                }
            }
        }
Esempio n. 3
0
        private string CardPath(CatalogCode code)
        {
            string testFolder = folder + storage + FolderFor(code);

            return(Directory.EnumerateFiles(testFolder)
                   .FirstOrDefault(p => Path.GetFileNameWithoutExtension(p).Contains(code.ToString())));
        }
Esempio n. 4
0
        private void PromptUpdateCatalogFromInput()
        {
            string[] pictures = Directory.GetFiles(folder + inputFolder);
            if (pictures.Length != 0)
            {
                foreach (string pic in Directory.GetFiles(folder + inputFolder))
                {
                    Console.Clear();
                    Console.WriteLine(TreePrint(catalog.root));
                    Process     p     = PromptOpening(pic);
                    CatalogCode code  = PromptCodeOrNewChild("Set the code for this file");
                    string      title = PromptNewOrOldTitleToEdit(code);

                    CreateFolderFor(code);
                    SetFileCode(pic, code, title);
                    catalog.Update(code, title);
                    p?.Kill();
                    Save(folder + fileLoc);
                }
            }
            else
            {
                PC.WriteLine("No files to upload\n");
            }
        }
Esempio n. 5
0
 private void GenerateCatalog(Dictionary <string, string> dict)
 {
     foreach (string key in dict.Keys)
     {
         CatalogCode code = new CatalogCode(key);
         Add(code, dict[key]);
     }
 }
Esempio n. 6
0
 private string FolderFor(CatalogCode code)
 {
     if (code.Equals(CatalogCode.current))
     {
         return("");
     }
     return("\\" + string.Join("\\", code.CodePattern));
 }
Esempio n. 7
0
 private void MoveAndSave(CatalogCode a, CatalogCode b)
 {
     if (!catalog.Contains(a))
     {
         return;
     }
     Move(a, b);
     catalog.Delete(a);
     DeleteFolderOfCode(a);
     Save(folder + fileLoc);
 }
Esempio n. 8
0
        private void PromptOpenFolder()
        {
            PC.WriteLine("Insert the code of the folder to open:");
            CatalogCode code = new CatalogCode(ReadAnswer());

            if (!catalog.Contains(code))
            {
                throw new CatalogError($"{code} does not exist");
            }
            OpenFileProcess(folder + storage + FolderFor(code));
        }
Esempio n. 9
0
 public void Update(CatalogCode code, string title)
 {
     if (Contains(code))
     {
         Set(code, title);
     }
     else
     {
         Add(code, title);
     }
 }
Esempio n. 10
0
        private void PromptAddUpdateRecord(CatalogCode from = null)
        {
            CatalogCode code  = from ?? CatalogCode.current + PromptCodeOrNewChild("Insert the new code to add");
            string      title = PromptNewOrOldTitleToEdit(code);

            if (!catalog.Contains(code))
            {
                CreateFolderFor(code);
            }
            catalog.Update(code, title);
            Save(folder + fileLoc);
        }
Esempio n. 11
0
        public CatalogEntry GetChild(int ID)
        {
            foreach (CatalogEntry ce in children)
            {
                CatalogCode c = ce.codePrefix;
                if (c.CodePattern[c.Depth - 1] == ID)
                {
                    return(ce);
                }
            }

            return(null);
        }
Esempio n. 12
0
        private void SetFileCode(string originalFile, CatalogCode code, string title)
        {
            string name     = $"{code.ToString()} {title}";
            string path     = folder + storage + FolderFor(code) + "\\" + name + Path.GetExtension(originalFile);
            string temppath = Directory.EnumerateFiles(Path.GetDirectoryName(path))
                              .FirstOrDefault(o => Path.GetFileNameWithoutExtension(o) == name);

            if (temppath != null)
            {
                File.Delete(temppath);
            }
            File.Move(originalFile, path);
        }
Esempio n. 13
0
        public CatalogEntry Get(CatalogCode code)
        {
            if (codePrefix.Equals(code))
            {
                return(this);
            }

            CatalogCode  rel   = CatalogCode.Relative(codePrefix, code);
            int          ID    = rel.CodePattern[0];
            CatalogEntry child = GetChild(ID);

            return(child != null?child.Get(code) : null);
        }
Esempio n. 14
0
 public void Delete(CatalogCode code)
 {
     if (Contains(code))
     {
         if (code.Depth == 1)
         {
             root.children.RemoveAll(e => e.codePrefix.Equals(code));
         }
         else
         {
             Get(code.parent).children.RemoveAll(e => e.codePrefix.Equals(code));
         }
     }
 }
Esempio n. 15
0
        private void PromptDeleteFolder()
        {
            PC.FormatWriteLine("Insert the code to {-3}", "delete");
            CatalogCode code     = new CatalogCode(ReadAnswer());
            YNAnswer    response =
                AskYNQuestion($"Are you sure you want to delete the folder {catalog.Get(code).FancifyEntry()}?");

            if (response == YNAnswer.Yes)
            {
                catalog.Delete(code);
                DeleteFolderOfCode(code);
                Save(folder + fileLoc);
            }
        }
Esempio n. 16
0
        private void PromptMove()
        {
            CatalogCode from = PromptCodeOrNewChild("Please insert the original code");
            CatalogCode to   = PromptCodeOrNewChild("Please insert the new code");

            if (!IsMoveConflict(from, to))
            {
                MoveAndSave(from, to);
            }
            else
            {
                PC.FormatWriteLine("Unable to rename {-3} to {-3}", from, to);
            }
        }
Esempio n. 17
0
        private bool IsFile(CatalogCode code, out string path, out bool b)
        {
            path = null;
            b    = false;
            string testFolder = folder + storage + FolderFor(code);

            if (Directory.Exists(testFolder))
            {
                path = CardPath(code);
                b    = imageFormats.Contains(Path.GetExtension(path));
                return(path != default);
            }

            return(false);
        }
Esempio n. 18
0
        private void PromptViewDocument()
        {
            PC.WriteLine("Insert the code of the file to view:");
            CatalogCode code = new CatalogCode(ReadAnswer());

            if (code.Equals(CatalogCode.current))
            {
                throw new CatalogError("Cannot open root");
            }
            if (!IsFile(code, out string path))
            {
                throw new CatalogError($"{code} is not a file");
            }
            OpenFileProcess(path);
        }
Esempio n. 19
0
        public CatalogCode NewChild(CatalogCode code)
        {
            CatalogEntry ce = Get(code);

            if (ce == null || ce.children.Count == 0)
            {
                return(new CatalogCode(code + (code.Equals(CatalogCode.current) ? "" : ".") + "0"));
            }

            int max      = ce.children.Max(c => c.codePrefix.Youngest());
            int addition = 0;

            if (max + 1 == ce.children.Count)
            {
                addition = max + 1;
            }
            else
            {
                List <CatalogEntry> children = ce.children;
                if (children[0].codePrefix.Youngest() != 0)
                {
                    addition = 0;
                }
                else
                {
                    CatalogCode prev = children[0].codePrefix;
                    int         pos  = 1;
                    while (pos < children.Count)
                    {
                        CatalogCode comp = children[pos].codePrefix;
                        if (comp.Youngest() - prev.Youngest() != 1)
                        {
                            addition = prev.Youngest() + 1;
                            break;
                        }

                        prev = comp;
                        pos++;
                    }
                }
            }

            if (code.Equals(CatalogCode.current))
            {
                return(new CatalogCode(addition.ToString()));
            }
            return(new CatalogCode(code + $".{addition}"));
        }
Esempio n. 20
0
        public void Add(CatalogCode code, string s)
        {
            CatalogCode parent = code.parent;

            if (parent.Depth == 0)
            {
                root.Add(code, s);
                return;
            }

            if (!Contains(parent))
            {
                Add(parent, "");
            }
            Get(parent).Add(code, s);
        }
Esempio n. 21
0
        private void PrintCatalog()
        {
            PC.WriteLine("Insert the code you want to display (. for all):");
            string      response = ReadAnswer();
            CatalogCode code     = new CatalogCode(response);

            PC.WriteLine("And to what depth (-1 for all)?");
            if (!int.TryParse(ReadAnswer(), out int depth))
            {
                depth = -1;
            }
            if (code.Equals(CatalogCode.current) && depth >= 1)
            {
                depth++;
            }
            Console.WriteLine(TreePrint(catalog.Get(code), depth));
        }
Esempio n. 22
0
        private CatalogCode PromptCodeOrNewChild(string promptMessage)
        {
            PC.WriteLine(promptMessage);
            string input = ReadAnswer();

            if (input == "")
            {
                throw new CatalogError("Cannot alter the Root");
            }

            if (input.EndsWith("."))
            {
                CatalogCode code = new CatalogCode(input.RemoveLast(1));
                return(catalog.NewChild(code));
            }

            return(new CatalogCode(input));
        }
Esempio n. 23
0
        public bool Contains(CodeRange range)
        {
            if (range == null)
            {
                return(false);
            }

            CatalogCode counter = range.fromCode;

            while (counter.Youngest() <= range.toCode.Youngest())
            {
                if (Get(counter) != null)
                {
                    return(true);
                }
                counter = counter.Increment();
            }

            return(false);
        }
Esempio n. 24
0
        private void PromptDeleteFile()
        {
            PC.FormatWriteLine("Insert the code to {-3}", "delete");
            CatalogCode code = new CatalogCode(ReadAnswer());

            if (IsFile(code))
            {
                YNAnswer response =
                    AskYNQuestion($"Are you sure you want to delete {catalog.Get(code).FancifyEntry()}?");
                if (response == YNAnswer.Yes)
                {
                    string path = Directory.EnumerateFiles(folder + storage + FolderFor(code))
                                  .FirstOrDefault(s => s.Contains(code.ToString()));
                    if (path != default)
                    {
                        File.Delete(path);
                    }
                }
            }
        }
Esempio n. 25
0
        public bool Contains(CodeRange range, CodeRange usingCodeRange, int offset)
        {
            if (range == null)
            {
                return(false);
            }

            CatalogCode counter1 = range.fromCode;
            CatalogCode counter2 = usingCodeRange.fromCode + offset;

            while (counter1.Youngest() <= range.toCode.Youngest())
            {
                if (Contains(counter2) && Contains(counter1))
                {
                    return(true);
                }
                counter1 = counter1.Increment();
                counter2 = counter2.Increment();
            }

            return(false);
        }
Esempio n. 26
0
        private string PromptNewOrOldTitleToEdit(CatalogCode code)
        {
            YNAnswer response = YNAnswer.No;
            string   title    = "";

            if (catalog.Contains(code))
            {
                title = catalog.Get(code).name;
                if (title != "")
                {
                    response = AskYNQuestion($"Would you like to keep the title {PC.Format("{0}",title)}? (Y/N)");
                }
            }

            if (response == YNAnswer.No)
            {
                PC.FormatWriteLine("Insert the title of {0}", code);
                title = ReadAnswer();
            }

            return(title);
        }
Esempio n. 27
0
        private void Move(CatalogCode a, CatalogCode b)
        {
            if (!catalog.Contains(a))
            {
                return;
            }
            CatalogEntry entry = catalog.Get(a);
            string       title = entry.name;

            foreach (CatalogEntry child in entry.children)
            {
                Move(child.codePrefix, b + CatalogCode.Relative(a, child.codePrefix));
            }
            if (!Directory.Exists(folder + storage + FolderFor(b)))
            {
                Directory.CreateDirectory(folder + storage + FolderFor(b));
            }
            if (IsFile(a, out string oldPath, out bool x))
            {
                SetFileCode(oldPath, b, title);
            }
            catalog.Update(b, title);
        }
Esempio n. 28
0
 public CodeRange(CatalogCode f, CatalogCode t, bool caw = true)
 {
     fromCode       = f;
     toCode         = t;
     childrenAsWell = caw;
 }
Esempio n. 29
0
 private void CreateFolderFor(CatalogCode code)
 {
     Directory.CreateDirectory(folder + storage + FolderFor(code));
 }
Esempio n. 30
0
 private void DeleteFolderOfCode(CatalogCode code)
 {
     Directory.Delete(folder + storage + FolderFor(code), true);
 }