public string Execute(TransitionContext context) { string retEvent = Events.Error; try { ActionContract.Requires<NullReferenceException>(context.Request.Items[this.MediaItemNameIn] != null, "Could not retrieve the Media from the request to populate."); ActionContract.Requires<TypeMismatchException>(context.Request.Items[this.MediaItemNameIn] is Model.Media || context.Request.Items[this.MediaItemNameIn] is SearchResult<Model.Media>, "The Media item was not of type SearchResult<Media> or Media."); ActionContract.Requires<ApplicationException>(context.Request.Items[this.MediaItemNameIn] is Model.Media || (context.Request.Items[this.MediaItemNameIn] is SearchResult<Model.Media> && context.Request.GetItem<SearchResult<Model.Media>>(this.MediaItemNameIn).Items.Length > 0), "The Media items collection did not contain any items."); ActionContract.Requires<ApplicationException>(context.Request.Items[this.MediaItemNameIn] is Model.Media || (context.Request.Items[this.MediaItemNameIn] is SearchResult<Model.Media> && context.Request.GetItem<SearchResult<Model.Media>>(this.MediaItemNameIn).Items.Length == 1), "The Media items collection had more then one item, populate only works on one item at a time."); Model.Media media; if (context.Request.Items[this.MediaItemNameIn] is SearchResult<Model.Media>) { media = context.Request.GetItem<SearchResult<Model.Media>>(this.MediaItemNameIn).Items[0]; } else { media = context.Request.GetItem<Model.Media>(this.MediaItemNameIn); } Model.Media toReturn = Deserialize.Populate(context.Request, media); context.Request.Items[this.MediaItemNameOut] = toReturn; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occurred in Execute.", ex); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { if (context.Request.Items[this.RoleItemNameIn] == null || !(context.Request.Items[this.RoleItemNameIn] is SearchResult<Role>) || context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not retrieve an role or the more than one role was returned."); } Role role = context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items[0]; Role toReturn = Deserialize.Populate(context.Request, role); SearchResult<Role> result = new SearchResult<Role>(new Role[] {toReturn}); context.Request.Items[this.RoleItemNameOut] = result; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(AppSettingNameIn), "No app setting name given in the AppSettingNameIn attribute."); ActionContract.Requires<ApplicationException>(!(string.IsNullOrEmpty(ParamNameOut) && string.IsNullOrEmpty(ItemNameOut)), "One of ParamNameOut or ItemNameOut is required."); ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ConfigurationManager.AppSettings[AppSettingNameIn]), string.Format("No config setting found for '{0}'.", AppSettingNameIn)); string val = ConfigurationManager.AppSettings[AppSettingNameIn]; if (!string.IsNullOrEmpty(ParamNameOut)) { request[ParamNameOut] = val; } if (!string.IsNullOrEmpty(ItemNameOut)) { request.Items[ItemNameOut] = val; } retEvent = Events.Ok; } catch (Exception e) { ILog logger = LogManager.GetCurrentClassLogger(); logger.Error(error => error("Error occurred getting app setting."), e); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ObjectItemNameIn), "No item name given in the ObjectItemNameIn attribute."); ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(SessionName), "No name to store the object in given in the SessionName attribute."); object obj = null; if (ExtractFromSearchResult) { obj = request.GetRequestItem<object>(ObjectItemNameIn, true); if (obj.GetType().Name.StartsWith("SearchResult")) { Array list = (Array)ReflectionUtilities.GetPropertyValue(obj, "Items"); obj = list.GetValue(0); } } else { obj = request.Items[ObjectItemNameIn]; } if (obj != null) { SessionStateProvider.GetSessionState()[SessionName] = obj; retEvent = Events.Ok; } else { retEvent = Events.NoValue; } } catch (Exception e) { ILog logger = LogManager.GetCurrentClassLogger(); logger.Error(error => error("Error storing object to session."), e); } return retEvent; }
/// <summary> /// Determines if published content should be used. For <c>DynamicPublisherRule</c> /// checks the dyn parameter and if set directs the publishing system to not /// use existing published content. /// </summary> /// <param name="context">The <c>TransitionContext</c> to determine if /// published content should be used for.</param> /// <returns><c>True</c> if published content should be used, <c>false</c> if not.</returns> public bool UsePublishedContent( TransitionContext context) { string dyn = context.Request[DYNAMIC_PARAM_NAME]; return !((dyn != null) && ((dyn == "1") || (dyn.ToLower() == "true"))); }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { if (context.Request.Items[this.AccountItemNameIn] == null || !(context.Request.Items[this.AccountItemNameIn] is SearchResult<Account>) || context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not find the account item in the request items."); } if (context.Request.Items[this.RoleItemNameIn] == null || !(context.Request.Items[this.RoleItemNameIn] is SearchResult<Role>) || context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not find the role item in the request items."); } Account account = context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items[0]; Role role = context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items[0]; if (account.IsMemberOf(role.Code)) { account.Roles.Remove(role); } context.Request.Items[this.AccountItemNameOut] = new SearchResult<Account>(new Account[] {account}); retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { if (context.Request.Items[this.AttributeTypeItemNameIn] == null && !(context.Request.Items[this.AttributeTypeItemNameIn] is SearchResult<AttributeType>) && context.Request.GetItem<SearchResult<AttributeType>>(this.AttributeTypeItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not retrieve an attribute type or the more than one attribute type was returned."); } AttributeType account = context.Request.GetItem<SearchResult<AttributeType>>(this.AttributeTypeItemNameIn).Items[0]; AttributeType toReturn = Deserialize.Populate(context.Request, account); SearchResult<AttributeType> result = new SearchResult<AttributeType>(new AttributeType[] {toReturn}); context.Request.Items[this.AttributeTypeItemNameOut] = result; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { if (context.Request.Items[this.AccountItemNameIn] == null || !(context.Request.Items[this.AccountItemNameIn] is SearchResult<Account>) || context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not retrieve an account or the more than one account was returned."); } Account account = context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items[0]; /* Hmm whats better... one line or 3... context.Request.Items[this.AccountsItemNameIn] = new SearchResult<Account>( new[] { Deserialize.Populate(context.Request, accounts.Items[0]) }); */ Account toReturn = Deserialize.Populate(context.Request, account); SearchResult<Account> result = new SearchResult<Account>(new Account[] {toReturn}); context.Request.Items[this.AccountItemNameOut] = result; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; try { // make sure we got exactly 1 matching account if (HttpContext.Current.Session[MembershipConstants.SESSION_USER_ACCOUNT] != null) { // TODO: this should not access HttpContext directly! HttpContext.Current.Session[MembershipConstants.SESSION_USER_ACCOUNT] = null; // expire the cookie if it exists if (context.Request.GetCookie(MembershipConstants.COOKIE_USER_ACCOUNT).Value != "") { MvcHttpCookie cookie = (MvcHttpCookie)context.Request.GetCookie(MembershipConstants.COOKIE_USER_ACCOUNT); cookie.Expires = DateTime.Now.AddDays(-1); context.Request.SetResponseCookie(cookie); } retEvent = Events.Ok; } } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error( errorMessage => errorMessage("There was an error while unauthenticating an account."), ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { IMediaDao dao = DaoFactory.GetDao<IMediaDao>(); if (request.Items[MediaItemNameIn] is Model.Media) { dao.Delete(request.GetRequestItem<Model.Media>(MediaItemNameIn, true)); if (DeleteFile) { DeleteMediaFile(request.GetRequestItem<Model.Media>(MediaItemNameIn, true)); } } else if (request.Items[MediaItemNameIn] is SearchResult<Model.Media>) { SearchResult<Model.Media> results = (SearchResult<Model.Media>)request.Items[MediaItemNameIn]; foreach (Model.Media media in results.Items) { dao.Delete(media); if (DeleteFile) { DeleteMediaFile(media); } } } context.Request.Items["result"] = "success"; retEvent = Events.Ok; } catch (Exception e) { LogManager.GetLogger(typeof(UploadMediaAction)).Error( errorMessage => errorMessage("Error occurred in DeleteMediaAction.", e)); context.Request.Items["result"] = "error"; context.Request.Items["error"] = "Internal error occurred when deleting this file."; } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ParamNameIn), "No parameter name given in the ParamNameIn attribute."); // split the input names to get the individual parameter names string[] paramNames = ParamNameIn.Split('|'); if (RequireAll) { retEvent = paramNames.All(name => !IsEmpty(request[name])) ? Events.Yes : Events.No; } else { retEvent = paramNames.Any(name => !IsEmpty(request[name])) ? Events.Yes : Events.No; } } catch (Exception e) { ILog logger = LogManager.GetCurrentClassLogger(); logger.Error(error => error("Error occurred check parameter existence."), e); } return retEvent; }
/// <summary> /// Determines if published content should be used. For <c>RepublishPublisherRule</c> /// checks the repub parameter and if set directs the publishing system to not /// use existing published content. /// </summary> /// <param name="context">The <c>TransitionContext</c> to determine if /// published content should be used for.</param> /// <returns><c>True</c> if published content should be used, <c>false</c> if not.</returns> public bool UsePublishedContent( TransitionContext context) { string repub = context.Request[REPUB_PARAM_NAME]; return !((repub != null) && ((repub == "1") || (repub.ToLower() == "true"))); }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ObjectItemNameOut), "No item name given in the ObjectItemNameOut attribute."); ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(SessionName), "No session name to retrieve the object from given in the SessionName attribute."); if (SessionStateProvider.GetSessionState()[SessionName] != null) { if (SessionStateProvider.GetSessionState()[SessionName] is string && string.IsNullOrEmpty(SessionStateProvider.GetSessionState()[SessionName].ToString())) { retEvent = Events.NoValue; } else { request.Items[ObjectItemNameOut] = SessionStateProvider.GetSessionState()[SessionName]; retEvent = Events.Ok; } } else { retEvent = Events.NoValue; } } catch (Exception e) { ILog logger = LogManager.GetCurrentClassLogger(); logger.Error(error => error("Error getting object property value."), e); } return retEvent; }
/// <summary> /// Gets the published content to fulfill the given context's request. /// </summary> /// <param name="context">The <b>TransitionContext</b> to get the published content for.</param> /// <returns>A <b>string</b> containing the content to be returned to the client.</returns> public virtual string GetPublishedContent( TransitionContext context) { Publisher publisher = GetPublisher(context); if (publisher != null) { PublishRecord pubRec = publisher.GetPublishRecord(context.PublishKey); if (pubRec == null) { throw new PublishException(context, pubRec, string.Format("No PublishRecord found for {0}.", context.PublishKey)); } try { pubRec.HitCount++; context.Request.Transfer(pubRec.PublishedPath); } catch (System.Threading.ThreadAbortException) { // ignore ThreadAbortException, caused by Transfer } catch (Exception e) { LogManager.GetCurrentClassLogger().Error( errorMessage => errorMessage("Could not GetPublishedContent."), e); // rethrow the error so that the application error handler can handle it throw new PublishException(context, pubRec, "Could not transfer the control to the published page.", e); } } return null; }
public override string Execute( TransitionContext context) { string retEvent = EVENT_ERROR; try { request = context.Request; //idk how we got here and no files are in the request, and technically not an error IList<Model.Media> media = new List<Model.Media>(); string[] files = request[MediaRequestName].Split(','); foreach (string file in files) { media.Add(ProcessFile(file)); } request.Items["size"] = "Successfully uploaded: "; foreach (Model.Media m in media) { request.Items["size"] += string.Format("{0}, ", m.Name); } request.Items[this.RequestItemName] = media; request.Items["result"] = "success"; retEvent = EVENT_OK; } catch (Exception ex) { LogManager.GetLogger(typeof(UploadMediaAction)).Error( errorMessage => errorMessage("Error occured in UploadMediaAction.", ex)); context.Request.Items["result"] = "error"; context.Request.Items["error"] = "Internal error occured when uploading this file."; } return retEvent; }
/// <summary> /// Carries out the actions of the Action. /// </summary> /// <param name="context">The <b>TransitionContext</b> the Action is executing in.</param> /// <returns>A string containing the event returned by the action.</returns> public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { if (string.IsNullOrEmpty(RequestItemName)) { throw new ApplicationException("Could not get the RequestItemName to set to the value."); } if (!string.IsNullOrEmpty(Value)) { request.Items[RequestItemName] = Value; } else if (!string.IsNullOrEmpty(ValueParamNameIn)) { request.Items[RequestItemName] = request[ValueParamNameIn]; } else { request.Items[RequestItemName] = null; } retEvent = Events.Ok; } catch(Exception ex) { LogManager.GetCurrentClassLogger().Error(error => error("Could not set the request item to a value.", ex)); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = "error"; try { //for now this just returns all the states List<State> states = new List<State>(DaoFactory.GetDao<IStateDao>().Get(new State{ IsTerritory = false })); SearchResult<State> results = new SearchResult<State>(states.ToArray()); switch (results.Items.Length) { case 0: retEvent = "zero"; break; case 1: retEvent = "one"; break; default: retEvent = "multiple"; break; } context.Request.Items[(this.RequestItemName ?? ADDRESS_STATES)] = results; } catch (Exception ex) { LogManager.GetLogger(typeof (GetStatesAction)).Error( errorMessage => errorMessage("GetPropertyAction: Execute", ex)); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { IAttributeTypeDao dao = DaoFactory.GetDao<IAttributeTypeDao>(); AttributeTypeFilter filter = dao.GetFilter(); //if all is not set, filter results if (!this.All) { filter.Fill(context.Request); } SearchResult<AttributeType> attributeTypes = dao.Find(filter); context.Request.Items[this.AttributeTypeItemNameOut] = attributeTypes; retEvent = EventUtilities.GetSearchResultEventName(attributeTypes.Items.Length); } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.No; try { if(string.IsNullOrEmpty(this.Roles)) { throw new NullReferenceException("Roles action variable was not set."); } // try to get the account ID from the session Account acct = System.Web.HttpContext.Current.Session[MembershipConstants.SESSION_USER_ACCOUNT] as Account; IAccountDao dao = DaoFactory.GetDao<IAccountDao>(); acct = dao.Get(acct.Id.Value); // if we got the account from the session, set the return event accordingly if (acct != null) { // get the list of role to check for string[] roles = this.Roles.ToStringArray(); foreach ( string role in roles ) { if ( acct.IsMemberOf(role) ) { retEvent = Events.Yes; } } } } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(error => error("Error occured."), e); } return retEvent; }
/// <summary> /// Executes the action to perform the validation. /// </summary> /// <param name="context">The <c>TransitionContext</c> in which the action is executing.</param> /// <returns>The event resulting from the action's execution.</returns> public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { string[] validatorNames = ValidatorName.Split(VALIDATOR_NAME_DELIMITER); bool passed = true; foreach (string validatorName in validatorNames) { // get the Validator from the ValidatorManager Model.Rules.Validator validator = ValidatorManager.GetInstance().GetValidator(validatorName); if (validator == null) { throw new MissingMemberException(string.Format( "No validator found for '{0}'.", validatorName)); } // evaluate the validator ValidationResult result = validator.Evaluate(request); // if the validation failed, build an ErrorList and add // it to the request for the page if (!result.Passed && (result.Errors != null)) { ErrorList errors; // if the request contains the error list, append to it, else create a new one if (request.Items[ErrorsItemNameIn] != null && request.Items[ErrorsItemNameIn] is ErrorList && request.GetItem<ErrorList>(ErrorsItemNameIn) != null) { errors = request.GetItem<ErrorList>(ErrorsItemNameIn); } else { errors = new ErrorList(DictionaryManager.GetDictionaryManager().GetDictionary(context.Site)); } foreach (ValidationError err in result.Errors) { errors.Add(err.ErrorId); } // add the errors to the request to propagate back to the page request.Items[ErrorsItemNameOut] = errors; } passed = (passed && result.Passed); } retEvent = passed ? Events.Pass : Events.Fail; } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error(error => error("Error in Execute."), ex); } return retEvent; }
/// <summary> /// Determines if the content generated to fulfill the given request /// should be published for use in fulfilling future requests. /// </summary> /// <param name="context">The <c>TransitionContext</c> to determine if /// content should be published for.</param> /// <returns><c>True</c> if the content should be published, <c>false</c> if not.</returns> public bool ShouldBePublished( TransitionContext context) { bool publish = true; string repub = context.Request[REPUB_PARAM_NAME]; if (repub != null) { publish = ((repub == "1") || (repub.ToLower() == "true")); } return publish; }
/// <summary> /// Determines if the content generated to fulfill the given request /// should be published for use in fulfilling future requests. /// </summary> /// <param name="context">The <c>TransitionContext</c> to determine if /// content should be published for.</param> /// <returns><c>True</c> if the content should be published, <c>false</c> if not.</returns> public bool ShouldBePublished( TransitionContext context) { bool publish = true; string dyn = context.Request[DYNAMIC_PARAM_NAME]; if (dyn != null) { publish = !((dyn == "1") || (dyn.ToLower() == "true")); } return publish; }
private string CheckDao(TransitionContext context) { IAccountDao dao = DaoFactory.GetDao<IAccountDao>(); AccountFilter filter = dao.GetFilter(); filter.Usernames = new[] {context.Request[ParameterNames.Account.USERNAME]}; SearchResult<Account> acc = dao.Find(filter); string retEvent = acc.Items.Length > 0 ? Events.No : Events.Yes; return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; try { if (context.Request.Items[this.AccountItemNameIn] == null || !(((context.Request.Items[this.AccountItemNameIn] is SearchResult<Account> || context.Request.Items[this.AccountItemNameIn] is Account)))) { throw new MissingFieldException("Could not find the account item in the request items."); } if (context.Request.Items[this.RoleItemNameIn] == null || !(context.Request.Items[this.RoleItemNameIn] is SearchResult<Role>) || context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items.Length != 1) { throw new MissingFieldException("Could not find the role item in the request items."); } Account account; if (context.Request.Items[this.AccountItemNameIn] is SearchResult<Account>) { account = context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items[0]; }else { account = context.Request.GetItem<Account>(this.AccountItemNameIn); } Role role = context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items[0]; if (account.Roles == null) { account.Roles = new List<Role>(); } if (!account.IsMemberOf(role.Code)) { if(account.Roles == null) account.Roles = new List<Role>(); account.Roles.Add(role); } context.Request.Items[this.AccountItemNameOut] = new SearchResult<Account>(new Account[] {account}); retEvent = Events.Ok; } catch (Exception e) { LogManager.GetCurrentClassLogger().Error("Error occured while saving role to account.", e); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { context.Request[this.AuthenticatedAccountIdParamNameOut] = ((Account)HttpContext.Current.Session[MembershipConstants.SESSION_USER_ACCOUNT]).Id.ToString(); retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { Model.Media toReturn = Deserialize.CreateMedia(context.Request); context.Request.Items[this.MediaItemNameOut] = toReturn; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occurred in Execute.", ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; MvcRequest request = context.Request; try { ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ObjectItemNameIn), "No item name given in the ObjectItemNameIn attribute."); //ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ObjectPropertyNameIn), // "No object property name given in the ObjectPropertyNameIn attribute."); ActionContract.Requires<ApplicationException>(!string.IsNullOrEmpty(ParameterNameOut), "No parameter name given in the ParameterNameOut attribute."); object obj = request.GetRequestItem<object>(ObjectItemNameIn, true); if (obj.GetType().Name.StartsWith("SearchResult")) { Array list = (Array)ReflectionUtilities.GetPropertyValue(obj, "Items"); obj = list.GetValue(0); } // if no property name given, return the object itself (as string) if (string.IsNullOrEmpty(ObjectPropertyNameIn)) { request[ParameterNameOut] = obj.ToString(); retEvent = Events.Ok; } else { // loop thru the path to the lowest level property string[] path = ObjectPropertyNameIn.Split('.'); for (int k = 0; k < path.Length && obj != null; k++) { obj = ReflectionUtilities.GetPropertyValue(obj, path[k]); } object propVal = obj; if (propVal != null) { request[ParameterNameOut] = propVal.ToString(); retEvent = Events.Ok; } else { retEvent = Events.NoValue; } } } catch (Exception e) { ILog logger = LogManager.GetCurrentClassLogger(); logger.Error(error => error("Error getting object property value."), e); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { AttributeType toReturn = Deserialize.CreateAttributeType(context.Request); SearchResult<AttributeType> result = new SearchResult<AttributeType>(new AttributeType[] {toReturn}); context.Request.Items[this.AttributeTypeItemNameOut] = result; retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error("Error occured in Execute.", ex); } return retEvent; }
public string Execute( TransitionContext context) { string retEvent = Events.Error; try { NameValueCollection paramList = ((ActionState)context.CurrentState).Parameters; MvcRequest req = context.Request; for (int i = 0; i < paramList.Count; i++) { try { // remove the parameter from parameter name value collection string paramName = paramList.GetKey(i); if (req.Params.AllKeys.Contains(paramName)) { req.Params.Remove(paramName); } else { List<String> removalList = new List<String>(); foreach (string param in req.Params) { if (!string.IsNullOrEmpty(param) && Regex.Matches(param, paramName).Count > 0) { removalList.Add(param); } } foreach (string param in removalList) { req.Params.Remove(param.EvaluatePropertyValue()); } } } catch (Exception e) { LogManager.GetCurrentClassLogger().Warn( errorMessage => errorMessage("Could not clear a parameter."), e); } } retEvent = Events.Ok; } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error( errorMessage => errorMessage("ClearParameterAction.Execute:"), ex); } return retEvent; }
public string Execute(TransitionContext context) { string retEvent = Events.Error; try { ActionContract.Requires<NullReferenceException>(context.Request.Items[this.AccountItemNameIn] != null, "Could not retrieve the account from the request to save."); ActionContract.Requires<TypeMismatchException>(context.Request.Items[this.AccountItemNameIn] is SearchResult<Account> || context.Request.Items[this.AccountItemNameIn] is Account, "The account item was not of type SearchResult<Account> or Account."); ActionContract.Requires<ApplicationException>(context.Request.Items[this.AccountItemNameIn] is Account || (context.Request.Items[this.AccountItemNameIn] is SearchResult<Account> && context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items.Length > 0), "The account items collection did not contain any items."); IAccountDao dao = DaoFactory.GetDao<IAccountDao>(); if (context.Request.Items[this.AccountItemNameIn] is SearchResult<Account>) { SearchResult<Account> accounts = context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn); foreach (Account account in accounts.Items) { account.ModifiedDate = DateTime.Now; } dao.Save(accounts.Items); context.Request.Items[this.AccountItemNameOut] = accounts; } else { Account account = context.Request.GetItem<Account>(this.AccountItemNameIn); account.ModifiedDate = DateTime.Now; dao.Save(account); context.Request.Items[this.AccountItemNameOut] = account; } retEvent = Events.Ok; } catch (Exception ex) { this.logger.Error( errorMessage => errorMessage("There was an error while saving an account."), ex); } return retEvent; }