Exemplo n.º 1
0
        public static bool Install(TInstaller manager, IInstallable <TInstaller> install, bool initial)
        {
            try
            {
                IHasDefaultOption defaultOption = install as IHasDefaultOption;
                if (defaultOption != null)
                {
                    defaultOption.InitDefaultValue();
                }

                return(install.Install(manager, initial));
            }
            catch (Exception e)
            {
                string name = null;

                try
                {
                    name = install.Name;
                }
                catch
                {
                    name = install.GetType().ToString();
                }

                Common.Exception(name, e);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copy the entry from the opened zipfile to the path specified.
        /// </summary>
        internal static void CopyZipEntry(string absoluteDirectoryRoot, IInstallable file)
        {
            string absolutePath = Path.Combine(absoluteDirectoryRoot, file.Destination);

            if (file.IsDirectory)
            {
                // Skip if we're not making directories for this install.
                if (!file.makeDirs)
                {
                    log.DebugFormat("Skipping {0}, we don't make directories for this path", absolutePath);
                    return;
                }

                log.DebugFormat("Making directory {0}", absolutePath);
                file_transaction.CreateDirectory(absolutePath);
            }
            else
            {
                log.DebugFormat("Writing file {0}", absolutePath);

                // Sometimes there are zipfiles that don't contain entries for the
                // directories their files are in. No, I understand either, but
                // the result is we have to make sure our directories exist, just in case.
                if (file.makeDirs)
                {
                    string directory = Path.GetDirectoryName(absolutePath);
                    file_transaction.CreateDirectory(directory);
                }

                // We don't allow for the overwriting of files. See #208.
                if (File.Exists(absolutePath))
                {
                    throw new FileExistsKraken(absolutePath, string.Format("Trying to write {0} but it already exists.", absolutePath));
                }

                // Snapshot whatever was there before. If there's nothing, this will just
                // remove our file on rollback. We still need this even thought we won't
                // overwite files, as it ensures deletiion on rollback.
                file_transaction.Snapshot(absolutePath);

                try
                {
                    // It's a file! Prepare the streams
                    using (Stream zipStream = file.stream)
                        using (FileStream writer = File.Create(absolutePath))
                        {
                            // 4k is the block size on practically every disk and OS.
                            byte[] buffer = new byte[4096];
                            StreamUtils.Copy(zipStream, writer, buffer);
                        }
                }
                catch (DirectoryNotFoundException ex)
                {
                    throw new DirectoryNotFoundKraken("", ex.Message, ex);
                }
            }
        }
Exemplo n.º 3
0
        /* ----------------------------------------------------------------- */
        ///
        /// Log
        ///
        /// <summary>
        /// Puts debug information to the log file.
        /// </summary>
        ///
        /// <param name="src">Service object.</param>
        /// <param name="action">User action.</param>
        /// <param name="method">Method name.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Log(this IInstallable src, Action action,
                               [CallerMemberName] string method = null)
        {
            var status = "Success";
            var sw     = Stopwatch.StartNew();

            try { action(); }
            catch { status = "Failed"; throw; }
            finally { src.Put($"[{method}]", $"{status}", $"({sw.Elapsed})"); }
        }
Exemplo n.º 4
0
 /* ----------------------------------------------------------------- */
 ///
 /// GetOrDefault
 ///
 /// <summary>
 /// Gets the first matched element from the specified arguments.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="collection">Collection of elements.</param>
 /// <param name="name">Target name.</param>
 /// <param name="ignoreError">Ignore exceptions or not.</param>
 ///
 /// <returns>First matched element.</returns>
 ///
 /* ----------------------------------------------------------------- */
 public static T GetOrDefault <T>(this IInstallable src, Func <IEnumerable <T> > collection,
                                  string name, bool ignoreError) where T : IInstallable
 {
     try
     {
         var opt = StringComparison.InvariantCultureIgnoreCase;
         return(collection().FirstOrDefault(e => e.Name.Equals(name, opt)));
     }
     catch
     {
         if (ignoreError)
         {
             return(default(T));
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 5
0
 /* ----------------------------------------------------------------- */
 ///
 /// GetEnvironment
 ///
 /// <summary>
 /// Gets the name of current architecture.
 /// </summary>
 ///
 /// <param name="src">IInstaller implementation.</param>
 ///
 /// <returns>Name of architecture.</returns>
 ///
 /* ----------------------------------------------------------------- */
 public static string GetEnvironment(this IInstallable src) =>
 (IntPtr.Size == 4) ? "Windows NT x86" : "Windows x64";
Exemplo n.º 6
0
        private RequestedAction InstallOrUpgradeModule(IInstallable module, ModuleInfo moduleInfo)
        {
            RequestedAction? requestedAction = null;
            var version = module.GetType().GetTypeInfo().Assembly.GetName().Version;
            if (moduleInfo.Config.Version == null)
            {
                var context = new DefaultInstallContext(this);
                module.Install(context);
                requestedAction = context.RequestedAction;
            }
            else if (moduleInfo.Config.Version < version)
            {
                var context = new DefaultUpgradeContext(this, moduleInfo.Config.Version);
                module.Upgrade(context);
                requestedAction = context.RequestedAction;
            }

            if (requestedAction.HasValue)
            {
                moduleInfo.Config.Version = version;
                this.ConfigManager.Save<AppConfig>();
            }

            return requestedAction ?? RequestedAction.None;
        }