示例#1
0
        private static ReturnValue Upgrade(string appPath, string appName, string version)
        {
            return(ReturnValue.Wrap(() =>
            {
                var sourceFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appName, version);
                if (!Directory.Exists(sourceFolder))
                {
                    throw new DirectoryNotFoundException(string.Format("source app folder '{0}' not found", sourceFolder));
                }

                if (!Directory.Exists(appPath))
                {
                    throw new DirectoryNotFoundException(string.Format("target app folder '{0}' not found", sourceFolder));
                }
                var attempt = 1;
                var success = false;
                while (attempt <= MaxAttempts && (!success))
                {
                    Log(string.Format("Upgrade attempt #{0}..", attempt));
                    success = AttemptUpgrade(sourceFolder, appPath);
                    Thread.Sleep(1000);
                    attempt++;
                }
                if (attempt > MaxAttempts)
                {
                    ReturnValue.Abort(string.Format("Unable to Upgrade after {0} attempts.", MaxAttempts));
                }
                Log("Upgrade sucessful.");
            }, string.Format("Upgrading {0} to {1}, {2}", appPath, appName, version)));
        }