public override void Remove()
        {
            if (TargetFileSystem.FileExists(PathToConfig))
            {
                TargetFileSystem.DeleteFile(PathToConfig);
            }

            if (TargetFileSystem.DirectoryExists(InstallationPath) &&
                !string.Equals(LocalFileSystem.GetFullPath(BaselineSourcePath), TargetFileSystem.GetFullPath(InstallationPath), StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    TargetFileSystem.DeleteDirectory(InstallationPath);
                }
                catch (UnauthorizedAccessException)
                {
                    foreach (System.Diagnostics.Process p in Win32ProcessHelper.GetProcessesLockingFile(GetUnremovedFile(InstallationPath)))
                    {
                        Console.WriteLine("File is locked by Process(ID: {0}, NAME: {1}). Killing the process to unlock files", p.Id, p.ProcessName);
                        if (!p.WaitForExit(1000))
                        {
                            Win32ProcessHelper.TerminateProcess(p);
                            p.WaitForExit(5000);
                        }
                    }

                    TargetFileSystem.DeleteDirectory(InstallationPath);
                }
            }
        }
Example #2
0
        public override void ApplyPackage(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            string pathToAppOfflineHtm = BaseFileSystem.CombinePaths(InstallationPath, "app_offline.htm");

            if (string.IsNullOrEmpty(ManagedRuntimeVersion))
            {
                using (FileStream appOfflineHtm = TargetFileSystem.OpenFile(pathToAppOfflineHtm))
                {
                    StreamWriter appOfflineHtmWriter = new StreamWriter(appOfflineHtm);
                    appOfflineHtmWriter.WriteLine("This is temporary app_offline.htm generated by a deployment script to stop web application.");
                    appOfflineHtmWriter.WriteLine("If you see this - please remove the file");
                }
            }

            package.ApplyToWebComponent(this);

            if (string.IsNullOrEmpty(ManagedRuntimeVersion) && TargetFileSystem.FileExists(pathToAppOfflineHtm))
            {
                TargetFileSystem.DeleteFile(pathToAppOfflineHtm);
            }
        }
        protected void SetupConfigFromTemplate(string pathToConfig, string pathToTemplate)
        {
            if (LocalFileSystem.FileExists(pathToTemplate))
            {
                if (!TargetFileSystem.FileExists(pathToConfig))
                {
                    Logger.Instance.Log(LogLevel.Info, "\tCreating config '{0}' from '{1}' template",
                                        TargetFileSystem.GetFullPath(pathToConfig),
                                        LocalFileSystem.GetFullPath(pathToTemplate));

                    LocalFileSystem.CopyFile(pathToTemplate, TargetFileSystem, pathToConfig, true);
                }

                EnvironmentHelper.ExpandEnvironmentVariablesInConfig(pathToConfig, TargetFileSystem);
            }
        }