// dodaje childDir
        public void AddChildToChildrenList(IEditableDirWithChildrenAndParent child)
        {
            if (DirValidate.IsNameExistingInChildrenDirs(this, child.Description.Name))
            {
                throw new InvalidOperationException($"folder named as {child.Description.Name}  exist in structure");
            }
            child.ParentDir = this;
            DirManagement.AutoGenerateDirFullName(child);

            if (DirValidate.IsfolderExisting(child.Description.FullName))
            {
                throw new InvalidOperationException("you can't create folder that exist");
            }
            Children.Add(child);
        }
Ejemplo n.º 2
0
        public void WriteListToFile(string path, List <string> stringToWrite, string fileName = @"/AboutFolders.txt")
        {
            stringToWrite.Sort();

            if (String.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("path is null or whiteSpace");
            }

            if (stringToWrite == null)
            {
                throw new ArgumentNullException("list is null");
            }

            if (!dirValidate.IsfolderExisting(path))
            {
                throw new ArgumentException("folder path isn't valid ");
            }

            string systemUserName = Environment.UserName;

            if (!File.Exists(path + fileName))
            {
                using (StreamWriter writer = new StreamWriter(path + fileName))
                {
                    writer.WriteLine(DateTime.Now + ": created by: " + systemUserName);
                    writer.WriteLine();
                    foreach (var txt in stringToWrite)
                    {
                        writer.WriteLine(txt);
                    }
                }
            }
            else
            {
                using (StreamWriter writer = new StreamWriter(path + fileName, true))
                {
                    writer.WriteLine();
                    writer.WriteLine(DateTime.Now + ": edited by: " + systemUserName);
                    writer.WriteLine();
                    foreach (var txt in stringToWrite)
                    {
                        writer.WriteLine(txt);
                    }
                }
            }
        }