コード例 #1
0
    } // End of the SetItemExpireCallback method

    /// <summary>
    /// Set and realease a session post
    /// </summary>
    public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
    {
        // Serialize the SessionStateItemCollection as a string.
        string sessItems = Serialize((SessionStateItemCollection)item.Items);

        // Create a webshop session
        WebshopSession webshopSession = new WebshopSession();
        webshopSession.id = id;
        webshopSession.application_name = this.applicationName;
        webshopSession.created_date = DateTime.UtcNow;
        webshopSession.expires_date = DateTime.UtcNow.AddMinutes((Double)item.Timeout);
        webshopSession.lock_date = DateTime.UtcNow;
        webshopSession.lock_id = 0;
        webshopSession.timeout_limit = item.Timeout;
        webshopSession.locked = false;
        webshopSession.session_items = sessItems;
        webshopSession.flags = 0;

        if (newItem == true)
        {
            // Delete the session if it exists
            WebshopSession.DeleteOnId(id, this.applicationName);

            // Add the session
            WebshopSession.Add(webshopSession);

        }
        else
        {
            // Update session values
            webshopSession.lock_id = (Int32)lockId;

            // Update the session
            WebshopSession.UpdateWithLockId(webshopSession);
        }

    } // End of the SetAndReleaseItemExclusive method
コード例 #2
0
    } // End of the Deserialize method

    #endregion

    #region Delete methods

    /// <summary>
    /// Remove a session item
    /// </summary>
    public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
    {
        // Delete the session post
        WebshopSession.DeleteOnId(id, this.applicationName, (int)lockId);
        
    } // End of the RemoveItem method
コード例 #3
0
    } // End of the GetItemExclusive method


    /// <summary>
    /// Get a session store item
    /// </summary>
    private SessionStateStoreData GetSessionStoreItem(bool lockRecord, HttpContext context, string id, out bool locked, out TimeSpan lockAge, 
        out object lockId, out SessionStateActions actionFlags)
    {
        // Initial values for return value and out parameters
        SessionStateStoreData item = null;
        lockAge = TimeSpan.Zero;
        lockId = null;
        locked = false;
        actionFlags = 0;

        // String to hold serialized SessionStateItemCollection.
        string serializedItems = "";
        // True if a record is found in the database.
        bool foundRecord = false;
        // True if the returned session item is expired and needs to be deleted.
        bool deleteData = false;
        // Timeout value from the data store.
        int timeout = 0;

        // Create a webshop session
        WebshopSession webshopSession = new WebshopSession();

        if (lockRecord == true)
        {
            // Update the webshop session
            webshopSession.id = id;
            webshopSession.application_name = this.applicationName;
            webshopSession.expires_date = DateTime.UtcNow;
            webshopSession.lock_date = DateTime.UtcNow;
            webshopSession.locked = true;

            // Lock the webshop session
            Int32 postsAffected = WebshopSession.Lock(webshopSession);

            // Set the locked variable
            locked = postsAffected == 0 ? true : false;
        }

        // Get the current session
        webshopSession = WebshopSession.GetOneById(id, this.applicationName);

        if(webshopSession != null)
        {
            if (webshopSession.expires_date < DateTime.UtcNow)
            {
                locked = false;
                deleteData = true;
            }
            else
            {
                foundRecord = true;
            }

            // Set data
            serializedItems = webshopSession.session_items;
            lockId = webshopSession.lock_id;
            lockAge = DateTime.UtcNow.Subtract(webshopSession.lock_date);
            actionFlags = (SessionStateActions)webshopSession.flags;
            timeout = webshopSession.timeout_limit;
        }

       
        // If the returned session item is expired, 
        // delete the record from the data source.
        if (deleteData)
        {
            WebshopSession.DeleteOnId(id, this.applicationName);
        }

        // The record was not found. Ensure that locked is false.
        if (foundRecord == false)
        {
            locked = false;
        }
            
        // If the record was found and you obtained a lock, then set 
        // the lockId, clear the actionFlags,
        // and create the SessionStateStoreItem to return.
        if (foundRecord && !locked)
        {
            lockId = (int)lockId + 1;

            // Update the lock id and flags
            WebshopSession.UpdateLockIdAndFlags(id, this.applicationName, (Int32)lockId);

            // If the actionFlags parameter is not InitializeItem, deserialize the stored SessionStateItemCollection.
            if (actionFlags == SessionStateActions.InitializeItem)
                item = CreateNewStoreData(context, (Int32)this.sessionStateConfiguration.Timeout.TotalMinutes);
            else
                item = Deserialize(context, serializedItems, timeout);
        }

        // Return the session item
        return item;

    } // End of the GetSessionStoreItem method