Пример #1
0
        /// <summary>
        /// Updates the Restore folder location of those db files whose orginal directory location
        /// is not present in the destination computer.
        /// </summary>
        internal void UpdateDBFilesPhysicalRelocate()
        {
            foreach (DbFile item in DbFiles)
            {
                string fileName = this.GetTargetDbFilePhysicalName(item.PhysicalName);
                item.PhysicalNameRelocate = PathWrapper.Combine(PathWrapper.GetDirectoryName(item.PhysicalName),
                                                                fileName);
                Uri  pathUri;
                bool fUriCreated = Uri.TryCreate(item.PhysicalNameRelocate, UriKind.Absolute, out pathUri);
                if ((!fUriCreated || pathUri.Scheme != Uri.UriSchemeHttps) &&
                    !Directory.Exists(Path.GetDirectoryName(item.PhysicalNameRelocate)))
                {
                    string directoryPath = string.Empty;
                    if (string.Compare(item.DbFileType, SR.Log, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        directoryPath = Util.GetDefaultLogFileFolder();
                    }
                    else
                    {
                        directoryPath = Util.GetDefaultDataFileFolder();
                    }

                    item.PhysicalNameRelocate = PathWrapper.Combine(directoryPath, fileName);
                }
            }
        }
Пример #2
0
        internal string GetDefaultStandbyFile(string databaseName)
        {
            if (string.IsNullOrEmpty(databaseName))
            {
                return(string.Empty);
            }
            var folderpath = GetDefaultBackupFolder();
            var filename   = SanitizeFileName(databaseName) + "_RollbackUndo_" + GetServerCurrentDateTime().ToString("yyyy-MM-dd_HH-mm-ss") + ".bak";

            return(PathWrapper.Combine(folderpath, filename));
        }
Пример #3
0
        /// <summary>
        /// Returns a default location for tail log backup
        /// If the first backup media is from Microsoft Azure, a Microsoft Azure url for the Tail log backup file is returned
        /// </summary>
        internal string GetDefaultTailLogbackupFile(string databaseName, RestorePlan restorePlan)
        {
            if (string.IsNullOrEmpty(databaseName) || restorePlan == null)
            {
                return(string.Empty);
            }
            if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
            {
                restorePlan.TailLogBackupOperation.Devices.Clear();
            }
            string      folderpath       = string.Empty;
            BackupMedia firstBackupMedia = this.GetFirstBackupMedia(restorePlan);
            string      filename         = this.SanitizeFileName(databaseName) + "_LogBackup_" + this.GetServerCurrentDateTime().ToString("yyyy-MM-dd_HH-mm-ss") + ".bak";

            if (firstBackupMedia != null && firstBackupMedia.MediaType == DeviceType.Url)
            {
                // the uri will use the same container as the container of the first backup media
                Uri uri;
                if (Uri.TryCreate(firstBackupMedia.MediaName, UriKind.Absolute, out uri))
                {
                    UriBuilder uriBuilder = new UriBuilder();
                    uriBuilder.Scheme = uri.Scheme;
                    uriBuilder.Host   = uri.Host;
                    if (uri.AbsolutePath.Length > 0)
                    {
                        string[] parts   = uri.AbsolutePath.Split('/');
                        string   newPath = string.Join("/", parts, 0, parts.Length - 1);
                        if (newPath.EndsWith("/"))
                        {
                            newPath = newPath.Substring(0, newPath.Length - 1);
                        }
                        uriBuilder.Host = uriBuilder.Host + newPath;
                    }
                    uriBuilder.Path = filename;
                    string urlFilename = uriBuilder.Uri.AbsoluteUri;
                    if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
                    {
                        restorePlan.TailLogBackupOperation.Devices.Add(new BackupDeviceItem(urlFilename, DeviceType.Url));
                    }
                    return(urlFilename);
                }
            }
            folderpath = this.GetDefaultBackupFolder();
            if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
            {
                restorePlan.TailLogBackupOperation.Devices.Add(new BackupDeviceItem(PathWrapper.Combine(folderpath, filename), DeviceType.File));
            }
            return(PathWrapper.Combine(folderpath, filename));
        }
        /// <summary>
        /// Returns the folder where result files should be written
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string GetResultsFolder(this VisualStudio.TestTools.UnitTesting.TestContext context)
        {
            var path = Environment.GetEnvironmentVariable("RESULTS_FOLDER");

            if (string.IsNullOrEmpty(path))
            {
                path = context.Properties.ContainsKey("resultsFolder") ? context.Properties["resultsFolder"].ToString() : null;
            }
            if (string.IsNullOrEmpty(path))
            {
                path = PathWrapper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                path = PathWrapper.Combine(path, "results");
            }
            return(path);
        }
Пример #5
0
        public void CanLoadAndExecute()
        {
            var assemblyFactory = new AssemblyFactory();
            var plugins         = new[] {
                new { Name = "PluginOne", Framework = "netstandard2.0" },
                new{ Name = "PluginTwo", Framework = "net6.0" },
            };
            var pluginPathFiles = plugins.Select(plugin =>
                                                 pathWrapper.Combine(
                                                     PathToPlugins(),
                                                     plugin.Name,
                                                     "bin",
                                                     "Debug",
                                                     plugin.Framework,
                                                     plugin.Name + ".dll")
                                                 );

            var assemblies = pluginPathFiles.Select(pluginPathFile => assemblyFactory.LoadFile(pluginPathFile));

            var sut = PluginHandler.Create();

            //  Act.
            sut.Load(assemblies);
            var res = sut.Execute("a");

            //  Assert.
            res
            .Select(pr => new { pr.Name, Result = pr.Result.ToString() })
            .Should()
            .BeEquivalentTo(
                new[] {
                new { Name = "Plugin one", Result = "<data plugin=\"Plugin one\">a</data>" },
                new { Name = "Plugin two", Result = "<data plugin=\"Plugin two\">a</data>" },
            }
                );
        }
        public IRunnableProcess CreateDownload(IEnumerable <string> links, string location, bool audio, string format = null)
        {
            var program = new CliProgramBuilder();

            return(program.Build(b =>
            {
                b.AddProgram("youtube-dl");
                foreach (var link in links)
                {
                    b.AddArgument(link);
                }

                b.AddFlagArgument("-o", _pathWrapper.Combine(location, "%(title)s.%(ext)s"));
                if (audio)
                {
                    b.AddFlag("-x");
                    b.AddFlagArgument("--audio-format", format ?? "mp3");
                }
                else
                {
                    if (format != null)
                    {
                        b.AddFlagArgument("--merge-output-format", format);
                    }
                }

                if (_errorCallbacks != null)
                {
                    foreach (var errorCallback in _errorCallbacks)
                    {
                        b.AddErrorReceivedCallback(errorCallback);
                    }
                }

                if (_callbacks == null)
                {
                    return;
                }
                foreach (var callback in _callbacks)
                {
                    b.AddDataReceivedCallback(callback);
                }
            }));
        }
Пример #7
0
 private void UpdateDbFiles()
 {
     try
     {
         foreach (DbFile dbFile in this.DbFiles)
         {
             string fileName = this.GetTargetDbFilePhysicalName(dbFile.PhysicalName);
             if (!dbFile.DbFileType.Equals("Log"))
             {
                 if (!string.IsNullOrEmpty(this.DataFilesFolder))
                 {
                     dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.DataFilesFolder, fileName);
                 }
                 else
                 {
                     dbFile.PhysicalNameRelocate = fileName;
                 }
             }
             else
             {
                 if (!string.IsNullOrEmpty(this.LogFilesFolder))
                 {
                     dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.LogFilesFolder, fileName);
                 }
                 else
                 {
                     dbFile.PhysicalNameRelocate = fileName;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.ActiveException = ex;
     }
 }