Esempio n. 1
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. 2
0
 private string FolderFor(CatalogCode code)
 {
     if (code.Equals(CatalogCode.current))
     {
         return("");
     }
     return("\\" + string.Join("\\", code.CodePattern));
 }
Esempio n. 3
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. 4
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));
        }