Esempio n. 1
0
        public SVR_ImportFolder SaveImportFolder(ImportFolder folder)
        {
            SVR_ImportFolder ns;

            if (folder.ImportFolderID > 0)
            {
                // update
                ns = GetByID(folder.ImportFolderID);
                if (ns == null)
                {
                    throw new Exception($"Could not find Import Folder ID: {folder.ImportFolderID}");
                }
            }
            else
            {
                // create
                ns = new SVR_ImportFolder();
            }

            if (string.IsNullOrEmpty(folder.ImportFolderName))
            {
                throw new Exception("Must specify an Import Folder name");
            }

            if (string.IsNullOrEmpty(folder.ImportFolderLocation))
            {
                throw new Exception("Must specify an Import Folder location");
            }

            if (!Directory.Exists(folder.ImportFolderLocation))
            {
                throw new Exception("Cannot find Import Folder location");
            }

            if (folder.ImportFolderID == 0)
            {
                SVR_ImportFolder nsTemp =
                    GetByImportLocation(folder.ImportFolderLocation);
                if (nsTemp != null)
                {
                    throw new Exception("Another entry already exists for the specified Import Folder location");
                }
            }

            ns.ImportFolderName     = folder.ImportFolderName;
            ns.ImportFolderLocation = folder.ImportFolderLocation;
            ns.IsDropDestination    = folder.IsDropDestination;
            ns.IsDropSource         = folder.IsDropSource;
            ns.IsWatched            = folder.IsWatched;
            ns.ImportFolderType     = folder.ImportFolderType;

            Save(ns);

            Utils.MainThreadDispatch(() => { ServerInfo.Instance.RefreshImportFolders(); });
            ShokoServer.StopWatchingFiles();
            ShokoServer.StartWatchingFiles();

            return(ns);
        }
Esempio n. 2
0
 private void ShutDown()
 {
     ShokoServer.StopWatchingFiles();
     ShokoServer.AniDBDispose();
     ShokoServer.StopHost();
 }
Esempio n. 3
0
        public SVR_ImportFolder SaveImportFolder(ImportFolder folder)
        {
            SVR_ImportFolder ns;

            if (folder.ImportFolderID > 0)
            {
                // update
                ns = GetByID(folder.ImportFolderID);
                if (ns == null)
                {
                    throw new Exception($"Could not find Import Folder ID: {folder.ImportFolderID}");
                }
            }
            else
            {
                // create
                ns = new SVR_ImportFolder();
            }

            if (string.IsNullOrEmpty(folder.ImportFolderName))
            {
                throw new Exception("Must specify an Import Folder name");
            }

            if (string.IsNullOrEmpty(folder.ImportFolderLocation))
            {
                throw new Exception("Must specify an Import Folder location");
            }

            if (folder.CloudID == 0)
            {
                folder.CloudID = null;
            }

            if (folder.CloudID == null && !Directory.Exists(folder.ImportFolderLocation))
            {
                throw new Exception("Cannot find Import Folder location");
            }

            if (folder.ImportFolderID == 0)
            {
                SVR_ImportFolder nsTemp =
                    GetByImportLocation(folder.ImportFolderLocation);
                if (nsTemp != null)
                {
                    throw new Exception("Another entry already exists for the specified Import Folder location");
                }
            }

            if (folder.IsDropDestination == 1 && folder.IsDropSource == 1)
            {
                throw new Exception("A folder cannot be a drop source and a drop destination at the same time");
            }

            // check to make sure we don't have multiple drop folders
            IReadOnlyList <SVR_ImportFolder> allFolders = GetAll();

            if (folder.IsDropDestination == 1)
            {
                foreach (SVR_ImportFolder imf in allFolders)
                {
                    if (folder.CloudID == imf.CloudID && imf.IsDropDestination == 1 &&
                        (folder.ImportFolderID == 0 || folder.ImportFolderID != imf.ImportFolderID))
                    {
                        imf.IsDropDestination = 0;
                        Save(imf);
                    }
                    else if (imf.CloudID != folder.CloudID)
                    {
                        if (folder.IsDropSource == 1 && (imf.FolderIsDropDestination || imf.FolderIsDropSource))
                        {
                            throw new Exception("A drop folders cannot have different file systems");
                        }

                        if (folder.IsDropDestination == 1 && (imf.FolderIsDropDestination || imf.FolderIsDropSource))
                        {
                            throw new Exception("A drop folders cannot have different file systems");
                        }
                    }
                }
            }

            ns.ImportFolderName     = folder.ImportFolderName;
            ns.ImportFolderLocation = folder.ImportFolderLocation;
            ns.IsDropDestination    = folder.IsDropDestination;
            ns.IsDropSource         = folder.IsDropSource;
            ns.IsWatched            = folder.IsWatched;
            ns.ImportFolderType     = folder.ImportFolderType;
            ns.CloudID = folder.CloudID;

            Save(ns);

            Utils.MainThreadDispatch(() => { ServerInfo.Instance.RefreshImportFolders(); });
            ShokoServer.StopWatchingFiles();
            ShokoServer.StartWatchingFiles();

            return(ns);
        }