public void Deploy(DeployContext context, byte[] filesHash) { if (!_accessIsGranted) throw new AuthenticationException("Session should be terminated because access wasn't granted"); if (_filesBuffer == null || _filesBuffer.Length == 0) throw new InvalidOperationException("Files was not transfered before deployment"); if (!FileHashIsEqual(filesHash, MD5.Create().ComputeHash(_filesBuffer))) throw new ArgumentException("File sending was failed because it's hash is wrong"); var callback = _dsFactory.CreateCallbackObj(); try { _accessIsGranted = false; var conf = _dsFactory.CreateConfObj(_sessionKey, context, _cFactory); if (!GetDirectoryName(conf.SurveyPath.Survey).Equals(_updatedForlder, StringComparison.InvariantCultureIgnoreCase)) throw new ArgumentException("Current session allows deploy only to '" + _updatedForlder + "' folder"); _logger.Info(string.Format("Starting deploy process for folder '{0}'", _updatedForlder)); RunDeployment(conf, callback, context, _filesBuffer); _logger.Info("Deploy completed successfully"); } catch (Exception ex) { callback.OnFault(UnhandledException.CreateFromEx(ex)); throw; } finally { callback.OnClose(); Dispose(); } }
public Conf(string sessionKey, DeployContext context, IConfFactory factory) { if (sessionKey == null || sessionKey.Length >= 50) throw new ArgumentException("Session key should be no more than 50 characters", "sessionKey"); var confSection = DeployerConfigurationSection.Instance; SessionKey = sessionKey; _context = context; _updateRules = new UpdateRulesBuilder(confSection); InitializeSettings(confSection); PackageManager = factory.CreatePackageManager(); IISManager = factory.CreateIISManager(IIS, _context.UriName); }
public IConf CreateConfObj(string sessionKey, DeployContext deployContext, IConfFactory confFactory) { return _confFactory(sessionKey, deployContext, confFactory); }
private void RunDeployment(IConf conf, IDeployEvents callback, DeployContext context, byte[] files) { using (var session = _dsFactory.CreateSessionObj(conf, _user)) { _logger.Info(string.Format("Session for '{0}' is opened", _sessionKey)); var deploySteps = new List<IDeployer>(); var failedValidators = new List<IValidator>(); var exceptionHandler = _dsFactory.CreateDeployExHandlerObj(callback, conf, _logger, session); try { conf.PackageManager.BytesToZip(files, conf.PackagePaths.Survey); _logger.Info(string.Format("Zip files was unpacked to '{0}'", conf.PackagePaths.Survey)); DeployExecutor.Validate(_dsFactory.CreateValidatorsList(conf), failedValidators, callback, conf.Survey.DeployMode); _logger.Info(string.Format("Validation process is complete. Found '{0}' error(s)", failedValidators.Count)); if (failedValidators.Any()) throw new ValidationException("Validation at " + String.Join(", ", failedValidators.Select(v => v.Name).ToArray()) + " failed."); DeployExecutor.Deploy(_dsFactory.CreateDeployersList(conf), deploySteps, callback, conf.Survey.DeployMode); _logger.Info(string.Format("Deploy is finished for '{0}'", _sessionKey)); session.Commit(); _logger.Info(string.Format("Session for '{0}' is commited successfully", _sessionKey)); } catch (ValidationException exception) { exceptionHandler.HandleValidation(exception, callback); } catch (DeployException exception) { exceptionHandler.HandleDeploy(exception, callback, deploySteps, GetRollbackAction(context)); } catch (Exception exception) { exceptionHandler.HandleUnknown(exception, callback); } } }
private static Action<IDeployer> GetRollbackAction(DeployContext context) { if (context.Mode == DeployMode.Install) return d => d.InstallRollback(); return d => d.UpdateRollback(); }