private void _setContractValue(ISessionModel session, string propertyName, Type type) { var sessionValue = session[propertyName]; object value = null; if (type == typeof(Int16) || type == typeof(Int32)) { value = Converts.ToTryInt(sessionValue); } else if (type == typeof(Int64)) { var l = 0L; if (sessionValue != null && Int64.TryParse(sessionValue.ToString(), out l)) { value = l; } else { value = 0; } } else if (type == typeof(String)) { value = Converts.ToTryString(sessionValue); } else if (type == typeof(Boolean)) { value = Converts.ToTryBool(sessionValue); } else if (type == typeof(Decimal) || type == typeof(Decimal?)) { value = Converts.ToTryDecimal(sessionValue); } else if (type == typeof(Double) || type == typeof(Double?)) { value = Converts.ToTryDouble(sessionValue, 0); } else if (type == typeof(DateTime) || type == typeof(DateTime?)) { value = Converts.ToTryDateTimeNullable(sessionValue, null); } else if (type.IsEnum) { if (sessionValue != null && Enum.IsDefined(type, Converts.ToTryString(sessionValue))) { value = Enum.Parse(type, Converts.ToTryString(sessionValue));// Enum.GetValues(type).GetValue(Converts.ToTryString(sessionValue)); } else { value = Enum.GetValues(type).GetValue(0); } } else { _throwPropertyExceptoin(propertyName); } GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, this, new[] { value }); }
/// <summary> /// Initializes a new instance of the SessionHolder. /// </summary> /// <param name="model"> /// The session model. /// </param> /// <param name="lockId"> /// The lock ID. /// </param> /// <param name="initialized"> /// A flag to indicated whether the session is initialized. /// </param> /// <param name="timeout"> /// The session timeout value. /// </param> public SessionHolder(ISessionModel model, long lockId, bool initialized, TimeSpan timeout) { m_model = model; m_lockId = lockId; m_initialized = initialized; m_timeout = timeout; }
/// <summary> /// Deserialize specified Binary into a <b>ISessionModel</b>. /// </summary> /// <param name="binModel"> /// A Binary containing the serialized form of a <b>ISessionModel</b>. /// </param> /// <returns> /// The deserialized <b>ISessionModel</b>. /// </returns> public virtual ISessionModel Deserialize(Binary binModel) { using (DataReader reader = binModel.GetReader()) { ISessionModel model = CreateSessionModel(); model.ReadExternal(reader); return(model); } }
/// <summary> /// Serialize specified <b>ISessionModel</b>. /// </summary> /// <param name="model"> /// The <b>ISessionModel</b> to serialize. /// </param> /// <returns> /// The serialized form of the given <b>ISessionModel</b>. /// </returns> protected virtual Binary Serialize(ISessionModel model) { BinaryMemoryStream stream = new BinaryMemoryStream(4 * 1024); using (DataWriter writer = new DataWriter(stream)) { model.WriteExternal(writer); return(stream.ToBinary()); } }
/// <summary> /// Update session items in the cache and release the exclusive lock. /// </summary> /// <param name="sessionId">Session key.</param> /// <param name="holder">Session holder.</param> /// <param name="newSession"> /// Flag specifying whether this is a new session. /// </param> public virtual void SaveSession(SessionKey sessionId, SessionHolder holder, bool newSession) { long lockId = holder.LockId; bool initialized = holder.Initialized; long timeout = (long)holder.Timeout.TotalMilliseconds; ISessionModel model = holder.Model; Binary binModel = newSession || model.Dirty ? Serialize(model) : null; IDictionary extAttr = model.Dirty ? GetExternalAttributes(model) : null; IList obsExtAttr = model.Dirty ? GetObsoleteExternalAttributes(model) : null; SessionCache.Invoke(sessionId, new SaveSessionProcessor(lockId, newSession, initialized, timeout, binModel, extAttr, obsExtAttr)); if (newSession && m_sessionEndCallback != null) { SessionEndListener listener = new SessionEndListener(this, sessionId); SessionCache.AddCacheListener(listener, listener.EventFilter, false); } }
private static ISessionModel SetupSession(IComponentContext context) { context.TryResolve <ISessionStore>(out var store); ISessionModel session = null; var cookie = HttpContext.Current.Request.Cookies["iocHUB"]?.Value; if (!System.Guid.TryParse(cookie, out var sessionID)) { session = CreateSession(store); } else { session = store.Contains(sessionID) ? store.Get(sessionID) : CreateSession(store); } return(session); }
public CustomerController(IAccountManager accountManager, ISessionModel sessionModel, IHttpContextAccessor httpContextAccessor) { _accountManager = accountManager; _sessionModel = sessionModel; _httpContextAccessor = httpContextAccessor; }
public CategoryProductsController(IProductManager productManager, ISessionModel sessionModel) { _productManager = productManager; _sessionModel = sessionModel; }
public LegendService(ISessionModel session) { Session = session; }
public ValuesController(ISessionModel session, ISessionStore store) { _session = session; _store = store; }
public SessionBasesClass(ISessionModel session) { Session = session; }
/// <summary> /// Get obsolete external attributes. /// </summary> /// <param name="model"> /// Model to get the obsolete external attributes from. /// </param> /// <returns>External attributes dictionary.</returns> protected override IList GetObsoleteExternalAttributes(ISessionModel model) { IList obsoleteExtAttrs = ((SplitSessionModel)model).GetObsoleteExternalAttributes(); return(obsoleteExtAttrs.Count > 0 ? obsoleteExtAttrs : null); }
/// <summary> /// Get external attributes. /// </summary> /// <param name="model"> /// Model to get the external attributes from. /// </param> /// <returns>External attributes dictionary.</returns> protected virtual IDictionary GetExternalAttributes(ISessionModel model) { return(null); }
public ApplicationController(IApplicationManager applicationManager, ISessionModel sessionModel) { _applicationManager = applicationManager; _sessionModel = sessionModel; }
public BasketController(ISessionModel sessionModel, IBasketManager basketManager, ICheckoutManager checkoutManager) { _basketManager = basketManager; _sessionModel = sessionModel; _checkoutManager = checkoutManager; }
/// <summary> /// Get obsolete external attributes. /// </summary> /// <param name="model"> /// Model to get the obsolete external attributes from. /// </param> /// <returns>External attributes dictionary.</returns> protected virtual IList GetObsoleteExternalAttributes(ISessionModel model) { return(null); }
public BaseSessionModel(ISessionModel sessionBase) { _sessionBase = sessionBase; }
public void Set(ISessionModel session) { this.Cache.Add(session.Id.ToString(), session, new CacheItemPolicy { SlidingExpiration = new TimeSpan(1, 0, 0) }); }
public CategoryController(ICategoryManager categoryManager, ISessionModel sessionModel) { _categoryManager = categoryManager; _sessionModel = sessionModel; }
/// <summary> /// Get external attributes. /// </summary> /// <param name="model"> /// Model to get the external attributes from. /// </param> /// <returns>External attributes dictionary.</returns> protected override IDictionary GetExternalAttributes(ISessionModel model) { IDictionary extAttrs = ((SplitSessionModel)model).GetExternalAttributes(); return(extAttrs.Count > 0 ? extAttrs : null); }
public ProductController(IProductManager productManager, ISessionModel sessionModel) { _productManager = productManager; _sessionModel = sessionModel; }