public void SourceLocationValidateThrowsExceptionWhenInvalidFolderPathIsProvided()
        {
            var loc = new LocalSourceLocation();

            loc.Path = null;
            loc.ValidateParameters();
        }
        public void SourceLocationValidateThrowsExceptionWhenInvalidFileMatchPatternIsProvided2()
        {
            var loc = new LocalSourceLocation();

            loc.Path            = Environment.CurrentDirectory;
            loc.FileMatchFilter = "test.mp3";
            loc.ValidateParameters();
        }
        public void SourceLocationValidateThrowsExceptionWhenInvalidRevisionCountProvided2()
        {
            var loc = new LocalSourceLocation();

            loc.Path          = Environment.CurrentDirectory;
            loc.RevisionCount = -15;
            loc.ValidateParameters();
        }
        public void SourceLocationValidatePassesValidExample3()
        {
            var loc = new LocalSourceLocation();

            loc.Path          = Environment.CurrentDirectory;
            loc.RevisionCount = 12345678;
            loc.ID            = 1;
            loc.ValidateParameters();

            Assert.IsTrue(true);
        }
        public void SourceLocationValidatePassesValidExample14()
        {
            var loc = new LocalSourceLocation();

            loc.Path            = Environment.CurrentDirectory;
            loc.RevisionCount   = 1;
            loc.FileMatchFilter = "t?st.do?";
            loc.ID = 1;
            loc.ValidateParameters();

            Assert.IsTrue(true);
        }
        /// <summary>
        /// Cmdlet invocation.
        /// </summary>
        protected override void ProcessRecord()
        {
            FileBackupPriority priorityEnum;

            if (!Enum.TryParse(Priority, out priorityEnum))
            {
                throw new ArgumentException(nameof(Priority) + " value was not valid.");
            }

            if (MatchFilter == null)
            {
                MatchFilter = ArchivialLibrary.Constants.CommandLine.DefaultSourceMatchFilter;
            }

            var db = GetDatabaseConnection();

            WriteVerbose("Querying for existing scan sources to check for duplicates.");

            var allSources      = db.GetSourceLocationsAsync().GetAwaiter().GetResult();
            var allLocalSources = allSources.Where(x => x is LocalSourceLocation).ToList();

            if (allLocalSources.Any(x => string.Equals(x.Path, FolderPath, StringComparison.CurrentCultureIgnoreCase) &&
                                    string.Equals(x.FileMatchFilter, MatchFilter, StringComparison.CurrentCultureIgnoreCase)))
            {
                // there already exists a source with this folder location and match filter.
                throw new SourceLocationException("Unable to add source: the specified folder and match filter combination is already listed as a source.");
            }
            else
            {
                WriteVerbose("No duplicate sources found.");
            }

            var newSource = new LocalSourceLocation();

            newSource.Path            = FolderPath;
            newSource.FileMatchFilter = MatchFilter;
            newSource.RevisionCount   = Revisions;
            newSource.Priority        = priorityEnum;

            WriteVerbose("Validating the source parameters are acceptable.");
            newSource.ValidateParameters();
            WriteVerbose("The specified scan source has normal parameters.");

            WriteVerbose("Saving the source to the database.");

            db.SetSourceLocationAsync(newSource).GetAwaiter().GetResult();

            WriteVerbose("Successfully saved source to the database.");
        }