Esempio n. 1
0
        /// <summary>
        /// Recursive function
        /// </summary>
        /// <param name="docPath"></param>
        /// <returns></returns>
        public JsonDirectory getDirectoryWithChildren(string docPath)
        {
            var children = new Dictionary <string, JsonDirectory>();

            try
            {
                List <string> dirs = new List <string>(Directory.EnumerateDirectories(docPath));

                foreach (var dir in dirs)
                {
                    var directoryName = dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                    Console.WriteLine($"{directoryName}");

                    var child = getDirectoryWithChildren(dir);
                    children.Add(directoryName, child);
                }
                Console.WriteLine($"{dirs.Count} directories found.");
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (PathTooLongException ex)
            {
                Console.WriteLine(ex.Message);
            }
            var directory = new JsonDirectory
            {
                Path     = docPath.Replace(Constants.rootDocPath + "\\", ""),
                Children = children
            };

            return(directory);
        }
        /// <summary>
        /// File handling switcher.
        /// </summary>
        /// <param name="paths"></param>
        private void Store(object paths)
        {
            string path = paths as string;

            if (Path.GetExtension(path) == ".csv")
            {
                storeData = new ReadFromCsv(path, JsonDirectory.ToString());
            }
            else if (Path.GetExtension(path) == ".xml")
            {
                storeData = new ReadFromXml(path, JsonDirectory.ToString());
            }

            BusinessDataModel.TablesData store = new BusinessDataModel.TablesData(storeData);

            collection.Remove(path);
        }
Esempio n. 3
0
 public DynamicTypeManager(DynamicTypeDataRepository descriptorRepository, DataSettings settings)
 {
     DataSettings  = settings;
     JsonDirectory = settings.GetRootDataDirectory(nameof(DynamicTypeManager));
     if (!JsonDirectory.Exists)
     {
         JsonDirectory.Create();
     }
     descriptorRepository.EnsureDaoAssemblyAndSchema();
     DynamicTypeDataRepository = descriptorRepository;
     JsonFileProcessor         = new BackgroundThreadQueue <DataFile>()
     {
         Process = (df) =>
         {
             ProcessJsonFile(df.TypeName, df.FileInfo);
         }
     };
 }
Esempio n. 4
0
        public string GetDirectories(string path)
        {
            DebugHandler.TraceMessage("GetDirectories Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Directory Path: " + path, DebugSource.TASK, DebugType.PARAMETERS);


            try
            {
                string[] dirs = Directory.GetDirectories(path);

                JsonDirectories      tosendover          = new JsonDirectories();
                List <JsonDirectory> directorieswithpath = new List <JsonDirectory>();
                foreach (string directory in dirs)
                {
                    JsonDirectory directorywithpath = new JsonDirectory
                    {
                        dirname = directory.Replace(Path.GetDirectoryName(directory) + Path.DirectorySeparatorChar, ""),
                        path    = directory
                    };
                    tosendover.directories.Add(directorywithpath);
                }
                return(tosendover.ToJson());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Failed getting directories: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError jsonError = new JsonError
                {
                    type         = "get_drives_error",
                    errortype    = "exception",
                    errormessage = "Could not get drives, see log.",
                    exception    = e.ToString()
                };

                return(jsonError.ToJson());
            }
        }
Esempio n. 5
0
        public string GetDrives()
        {
            DebugHandler.TraceMessage("GetDrives Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            try
            {
                JsonDirectories directories = new JsonDirectories();

#if __ANDROID__
#if DEBUG
#warning Compiling android code!
#endif

                DebugHandler.TraceMessage("Running Android Code!", DebugSource.TASK, DebugType.INFO);


                string onlyAvailablePath = "/storage/";
                if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
                {
                    string[] dirs = Directory.GetDirectories("/storage/");

                    foreach (string dir in dirs)
                    {
                        if (dir.Contains("-"))
                        {
                            onlyAvailablePath = Path.Combine(dir, "/Android/data/LittleWeeb.LittleWeeb/files");
                            break;
                        }
                    }
                }


                JsonDirectory directory = new JsonDirectory();
                directory.path    = onlyAvailablePath;
                directory.dirname = "External Storage if Present.";

                directories.directories.Add(directory);

                directory         = new JsonDirectory();
                directory.path    = Android.OS.Environment.RootDirectory.AbsolutePath;
                directory.dirname = "Internal Root Directory";

                directories.directories.Add(directory);


                return(directories.ToJson());
#else
                DebugHandler.TraceMessage("Running Windows Code!", DebugSource.TASK, DebugType.INFO);
                DriveInfo[] allDrives = DriveInfo.GetDrives();
                foreach (DriveInfo drive in allDrives)
                {
                    JsonDirectory directorywithpath = new JsonDirectory
                    {
                        dirname = drive.Name,
                        path    = drive.Name
                    };
                    directories.directories.Add(directorywithpath);
                }
                return(directories.ToJson());
#endif
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Failed to get drives: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError error = new JsonError
                {
                    type         = "get_drives_error",
                    errortype    = "exception",
                    errormessage = "Could not get drives, see log.",
                    exception    = e.ToString()
                };

                return(error.ToJson());
            }
        }