Ejemplo n.º 1
0
        private IConf CreateConfForPackage(string packageName)
        {
            var confSection = DeployerConfigurationSection.Instance;

            var pathToSurvey = Path.Combine(confSection.Settings.Paths.Surveys, _surveyDir);
            var survey       = new Survey(null, _surveyDir, default(DeployMode));
            var surveyPaths  = new SurveyPaths(pathToSurvey, () => Path.Combine(pathToSurvey, "bin"));
            var packagePaths = new PackagePaths(Path.Combine(confSection.Settings.Paths.Uploads, packageName + ".zip"),
                                                Path.Combine(confSection.Settings.Paths.Backups, packageName + ".zip"));
            var commonPaths = new CommonPaths(confSection.Settings.Paths.Surveys, confSection.Settings.Paths.Uploads,
                                              confSection.Settings.Paths.Backups);
            var templates  = new TemplatesPaths(confSection.Settings.Templates.ConnectionStrings, confSection.Settings.Paths.AdditionalResources.Bins);
            var iisManager = new Mock <IIISManager>();

            iisManager.Setup(m => m.SurveyPath).Returns(surveyPaths.Survey);

            var mockedConf = new Mock <IConf>();

            mockedConf.Setup(s => s.Survey).Returns(survey);
            mockedConf.Setup(s => s.SurveyPath).Returns(surveyPaths);
            mockedConf.Setup(s => s.CommonPaths).Returns(commonPaths);
            mockedConf.Setup(s => s.PackagePaths).Returns(packagePaths);
            mockedConf.Setup(s => s.Templates).Returns(templates);
            mockedConf.Setup(s => s.PackageManager).Returns(new PackageManager());
            mockedConf.Setup(s => s.IISManager).Returns(iisManager.Object);
            mockedConf.Setup(s => s.IIS).Returns(new IISInfo(null, null, null, confSection.Settings.IIS.DirsWithIISAccess.Cast <DirElement>()
                                                             .Select(dir => new KeyValuePair <string, string>(dir.Name, dir.User))));

            return(mockedConf.Object);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a path to the collection, if it exists. Returns whether the directory exists and was added.
        /// </summary>
        /// <param name="fullPath"></param>
        public bool AddPackagePath(string fullPath)
        {
            var directoryName = Path.GetDirectoryName(fullPath);

            if (!FileManager.Exists(directoryName))
            {
                return(false);
            }
            fullPath = fullPath.Replace("\\", "/");
            PackagePaths.Add(fullPath);
            return(true);
        }
Ejemplo n.º 3
0
        public IntPtr GetAddress()
        {
            if (address == IntPtr.Zero)
            {
                return(address);
            }

            using (TArrayUnsafe <FName> packageNamesUnsafe = new TArrayUnsafe <FName>())
            {
                packageNamesUnsafe.AddRange(PackageNames.ToArray());
                Native_FARFilter.Set_PackageNames(address, packageNamesUnsafe.Address);
            }

            using (TArrayUnsafe <FName> packagePathsUnsafe = new TArrayUnsafe <FName>())
            {
                packagePathsUnsafe.AddRange(PackagePaths.ToArray());
                Native_FARFilter.Set_PackagePaths(address, packagePathsUnsafe.Address);
            }

            using (TArrayUnsafe <FName> objectPathsUnsafe = new TArrayUnsafe <FName>())
            {
                objectPathsUnsafe.AddRange(ObjectPaths.ToArray());
                Native_FARFilter.Set_ObjectPaths(address, objectPathsUnsafe.Address);
            }

            using (TArrayUnsafe <FName> classNamesUnsafe = new TArrayUnsafe <FName>())
            {
                classNamesUnsafe.AddRange(ClassNames.ToArray());
                Native_FARFilter.Set_ClassNames(address, classNamesUnsafe.Address);
            }

            using (TArrayUnsafe <FName> tagsUnsafe = new TArrayUnsafe <FName>())
                using (TArrayUnsafe <string> valuesUnsafe = new TArrayUnsafe <string>())
                {
                    tagsUnsafe.AddRange(TagsAndValues.Keys.ToArray());
                    valuesUnsafe.AddRange(TagsAndValues.Values.ToArray());
                    Native_FARFilter.Set_TagsAndValues(address, tagsUnsafe.Address, valuesUnsafe.Address);
                }

            using (TArrayUnsafe <FName> recursiveClassesExclusionSet = new TArrayUnsafe <FName>())
            {
                recursiveClassesExclusionSet.AddRange(RecursiveClassesExclusionSet.ToArray());
                Native_FARFilter.Set_RecursiveClassesExclusionSet(address, recursiveClassesExclusionSet.Address);
            }

            Native_FARFilter.Set_bRecursivePaths(address, RecursivePaths);
            Native_FARFilter.Set_bRecursiveClasses(address, RecursiveClasses);
            Native_FARFilter.Set_bIncludeOnlyOnDiskAssets(address, IncludeOnlyOnDiskAssets);

            return(address);
        }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            PackageInfoItems = PackagePaths
                               .Select(p =>
            {
                PackageIdentity identity = ReadIdentity(p);
                return(new TaskItem(
                           p,
                           new Dictionary <string, string>
                {
                    ["PackageId"] = identity.Id,
                    ["PackageVersion"] = identity.Version.OriginalVersion
                }));
            })
                               .ToArray();

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 5
0
        public override bool Execute()
        {
            PackageInfoItems = PackagePaths
                               .Select(p =>
            {
                using (var reader = new PackageArchiveReader(p))
                {
                    PackageIdentity identity = reader.GetIdentity();
                    return(new TaskItem(
                               p,
                               new Dictionary <string, string>
                    {
                        ["PackageId"] = identity.Id,
                        ["PackageVersion"] = identity.Version.OriginalVersion
                    }));
                }
            })
                               .ToArray();

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 6
0
 internal void FinalizeAddPath(SettingsPathViewModel vm)
 {
     if (!string.IsNullOrWhiteSpace(vm.Path))
     {
         if (vm.PathType == SettingsPathType.Components)
         {
             ComponentPaths.Remove(vm);
             m_settings.ComponentPaths.Add(new SettingsPath(false, vm.Path));
         }
         else if (vm.PathType == SettingsPathType.Type)
         {
             TypePaths.Remove(vm);
             m_settings.TypePaths.Add(new SettingsPath(false, vm.Path));
         }
         else if (vm.PathType == SettingsPathType.Package)
         {
             PackagePaths.Remove(vm);
             m_settings.PackagePaths.Add(new SettingsPath(false, vm.Path));
         }
     }
 }
Ejemplo n.º 7
0
        private void InitializeSettings(DeployerConfigurationSection confSection)
        {
            Credentials = new Credentials(
                confSection.Settings.Credentials.Domain,
                confSection.Settings.Credentials.Login,
                confSection.Settings.Credentials.Password);
            Survey = new Survey(_context.UriName, _context.DatabaseName ?? _context.UriName, _context.Mode);
            var surveyDir = Path.Combine(confSection.Settings.Paths.Surveys, _context.DirectoryName ?? _context.UriName);

            SurveyPath   = new SurveyPaths(surveyDir, () => Path.Combine(surveyDir, "bin"));
            PackagePaths = new PackagePaths(
                Path.Combine(confSection.Settings.Paths.Uploads, _context.UriName + ".zip"),
                Path.Combine(confSection.Settings.Paths.Backups, _context.UriName + ".zip"));
            CommonPaths = new CommonPaths(
                confSection.Settings.Paths.Surveys,
                confSection.Settings.Paths.Uploads,
                confSection.Settings.Paths.Backups);
            DbScriptsPaths = new DbScriptsPaths(
                confSection.Settings.ScriptsPaths.DbCreate,
                confSection.Settings.ScriptsPaths.DbValidate,
                confSection.Settings.ScriptsPaths.DbDelete);
            Templates = new TemplatesPaths(
                confSection.Settings.Templates.ConnectionStrings,
                confSection.Settings.Paths.AdditionalResources.Bins);
            ConnectionStrings = new ConnectionStrings(
                ConfigurationManager.ConnectionStrings["master"].ConnectionString,
                ConfigurationManager.ConnectionStrings["deployer"].ConnectionString);
            IIS = new IISInfo(
                confSection.Settings.IIS.Version,
                confSection.Settings.IIS.Address,
                confSection.Settings.IIS.ApplicationPool,
                confSection.Settings.IIS.DirsWithIISAccess == null
                    ? new List <KeyValuePair <string, string> >()
                    : confSection.Settings.IIS.DirsWithIISAccess.Cast <DirElement>()
                .Select(dir => new KeyValuePair <string, string>(dir.Name, dir.User)));
        }
Ejemplo n.º 8
0
        internal void InstallThread()
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            try
            {
                waitForPackageFilesFree(TapDir, PackagePaths);

                int progressPercent = 10;
                OnProgressUpdate(progressPercent, "");
                foreach (string fileName in PackagePaths)
                {
                    try
                    {
                        OnProgressUpdate(progressPercent, "Installing " + Path.GetFileNameWithoutExtension(fileName));
                        Stopwatch  timer = Stopwatch.StartNew();
                        PackageDef pkg   = PluginInstaller.InstallPluginPackage(TapDir, fileName);

                        log.Info(timer, "Installed " + pkg.Name + " version " + pkg.Version);

                        progressPercent += 80 / PackagePaths.Count();

                        if (pkg.Files.Any(s => s.Plugins.Any(p => p.BaseType == nameof(ICustomPackageData))) && PackagePaths.Last() != fileName)
                        {
                            log.Info(timer, $"Package '{pkg.Name}' contains possibly relevant plugins for next package installations. Searching for plugins..");
                            PluginManager.DirectoriesToSearch.Add(TapDir);
                            PluginManager.SearchAsync();
                        }
                    }
                    catch
                    {
                        if (!ForceInstall)
                        {
                            if (PackagePaths.Last() != fileName)
                            {
                                log.Warning("Aborting installation of remaining packages (use --force to override this behavior).");
                            }
                            throw;
                        }
                        else
                        {
                            if (PackagePaths.Last() != fileName)
                            {
                                log.Warning("Continuing installation of remaining packages (--force argument used).");
                            }
                        }
                    }
                }
                OnProgressUpdate(90, "");

                if (DoSleep)
                {
                    Thread.Sleep(100);
                }

                OnProgressUpdate(100, "Plugin installed.");
                Thread.Sleep(50); // Let Eventhandler get the last OnProgressUpdate
            }
            catch (Exception ex)
            {
                OnError(ex);
                return;
            }

            Installation installation = new Installation(TapDir);

            installation.AnnouncePackageChange();
        }
Ejemplo n.º 9
0
        internal bool RunCommand(string command, bool force, bool modifiesPackageFiles)
        {
            var verb = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(command.ToLower()) + "ed";

            try
            {
                if (modifiesPackageFiles)
                {
                    waitForPackageFilesFree(TapDir, PackagePaths);
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    log.Debug("Received abort while waiting for package files to be unlocked.");
                    return(false);
                }

                double progressPercent = 10;
                OnProgressUpdate((int)progressPercent, "");

                PluginInstaller pi = new PluginInstaller();

                foreach (string fileName in PackagePaths)
                {
                    PackageDef pkg = PackageDef.FromXml(fileName);
                    OnProgressUpdate((int)progressPercent, string.Format("Running command '{0}' on '{1}'", command, pkg.Name));
                    Stopwatch timer = Stopwatch.StartNew();
                    var       res   = pi.ExecuteAction(pkg, command, force, TapDir);

                    if (res == ActionResult.Error)
                    {
                        OnProgressUpdate(100, "Done");
                        return(false);
                    }
                    else if (res == ActionResult.NothingToDo)
                    {
                        log.Info(string.Format("Tried to {0} {1}, but there was nothing to do.", command, pkg.Name));
                    }
                    else
                    {
                        log.Info(timer, string.Format("{1} {0} version {2}.", pkg.Name, verb, pkg.Version));
                    }

                    progressPercent += (double)80 / PackagePaths.Count();
                }
                OnProgressUpdate(90, "");

                if (DoSleep)
                {
                    Thread.Sleep(100);
                }

                OnProgressUpdate(100, "Done");
                Thread.Sleep(50); // Let Eventhandler get the last OnProgressUpdate
            }
            catch (Exception ex)
            {
                OnError(ex);
                return(false);
            }

            new Installation(TapDir).AnnouncePackageChange();

            return(true);
        }