Example #1
0
        public string[] GetListOfUserBooks(string user)
        {
            var directoriesPaths = new string[] { };

            try
            {
                directoriesPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books/"));
            }
            catch (FileNotFoundException e)
            {
                directoriesPaths[0] = "No books found for this user";
            }


            return(directoriesPaths);
        }
Example #2
0
        public string[] GetListOfTemplates()
        {
            string[] filesPaths = Directory.GetFiles(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("TemplateDirectory")));

            return(filesPaths);
        }
Example #3
0
        public List <BookModel> GetListOf2DCharacter(string bookName, string user)
        {
            var aListObjects = new List <BookModel>();

            string[] directoryPaths = null;
            directoryPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books/" + bookName + GlobalVariables.ConfigResource("Character2DRes")));

            if (directoryPaths.Length == 0)
            {
                return(aListObjects);
            }

            foreach (var directoryPath in directoryPaths)
            {
                var filesPaths     = Directory.GetFiles(HttpContext.Current.Server.MapPath(directoryPath));
                var lastFolderName = this.GetFolderName(directoryPath);
                var aBookModel     = new BookModel {
                    Target = lastFolderName
                };

                if (filesPaths.Length != 0)
                {
                    foreach (var aFile in filesPaths)
                    {
                        var aObject = new ObjectModel {
                            ImageObj = aFile
                        };

                        aBookModel.Objects.Add(aObject);
                        aListObjects.Add(aBookModel);
                    }
                }
            }
            return(aListObjects);
        }
Example #4
0
        public string AddNewBook(string newFileName, string userName)
        {
            var mssg = string.Empty;

            try
            {
                if ((newFileName != null) || (userName != string.Empty))
                {
                    var actualDirectory = HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + userName + "/Books/");
                    if (!Directory.Exists(actualDirectory + newFileName))
                    {
                        Directory.CreateDirectory(actualDirectory + newFileName);
                    }

                    if (
                        !File.Exists(actualDirectory + newFileName + "/" + newFileName + ".xml"))
                    {
                        File.Copy(
                            HttpContext.Current.Server.MapPath(
                                GlobalVariables.ConfigResource("TemplateDirectory") + "empty.xml"),
                            actualDirectory + newFileName + "/" + newFileName + ".xml");

                        File.Copy(
                            HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("Images") + "noimage.jpg"),
                            actualDirectory + newFileName + "/" + newFileName + ".jpg");

                        Directory.CreateDirectory(
                            actualDirectory + newFileName + "/Generic/background/");

                        foreach (var dirName in GlobalVariables.GenericCharacterDirectory().SelectMany(genericCharDir => genericCharDir))
                        {
                            Directory.CreateDirectory(
                                actualDirectory + newFileName + "/Generic/character/" + dirName);
                        }

                        foreach (KeyValuePair <string, List <string[]> > genericChar2DDir in GlobalVariables.GenericCharacter2Directory())
                        {
                            foreach (var dirName in genericChar2DDir.Value)
                            {
                                var rootDirectory = actualDirectory + newFileName + "/Generic/character2d/"
                                                    + genericChar2DDir.Key + "/";
                                foreach (var subdirectory in dirName)
                                {
                                    Directory.CreateDirectory(rootDirectory + subdirectory);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new IOException("ERROR:This file exist already.Please!! Choose another name. ");
                    }
                }
                else
                {
                    throw new IOException("ERROR:File name cannot be empty ");
                }
            }
            catch (IOException e)
            {
                mssg = e.Message;
            }
            return(mssg);
        }
Example #5
0
        public List <string> GetListOfUserBooksRelativePath(string user)
        {
            var physicalPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books"));

            return(physicalPaths.Select(path => new FileInfo(path)).Select(fileInfo => fileInfo.Name).ToList());
        }