Ejemplo n.º 1
0
        protected ViewstateContext GetFromDatabase(string query, object args)
        {
            SqlConnection conn = new SqlConnection(connectionstringProvider.Connectionstring);

            ViewstateDatabaseRow r;
            try
            {
                conn.Open();
                r = conn.ExecuteMapperQuery<ViewstateDatabaseRow>(query, args).FirstOrDefault();
            }
                catch(Exception ex)
                {
                    AnnotatedException e = new AnnotatedException("Error loading viewstate", ex);
                    e.AddAnnotation("Query", GetByGuidQuery);
                    e.AddAnnotations(args);

                    throw e;

                }
            finally
            {
                conn.Close();
            }

            if (r == null)
            {
                AnnotatedException e = new AnnotatedException("Unloading to load viewstate", new Exception("Empty (no data) in viewstate from database"));
                e.AddAnnotations(args);

                throw e;
            }

            return new ViewstateContext(r.ViewstateID, r.ViewData, r.Reference);
        }
Ejemplo n.º 2
0
        public void SetState(Guid viewStateID, int state)
        {
            SqlConnection conn = new SqlConnection( connectionstringProvider.Connectionstring );
            var args = new
                {
                    ViewStateID = viewStateID,
                    State=state
                };

            try
            {
                conn.Open();
                conn.ExecuteMapperCommand(SetStateQuery, args);
            }
            catch(Exception ex)
            {
                AnnotatedException e = new AnnotatedException("Error saving state for viewstate", ex);
                e.AddAnnotation("Query", SetStateQuery);
                e.AddAnnotations(args);

                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 3
0
        protected void DeleteViewstate(string query, object args)
        {
            SqlConnection conn = new SqlConnection( connectionstringProvider.Connectionstring );

            try
            {
                conn.Open();
                conn.ExecuteMapperCommand(query, args);
            }
            catch(Exception ex)
            {
                AnnotatedException e = new AnnotatedException("Could not delete viewstate from database", ex);
                e.AddAnnotation("Query", query);
                e.AddAnnotations(args);

                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 4
0
        public void SaveState(ViewstateContext ctx, bool useGuid = true)
        {
            if ( !useGuid && string.IsNullOrWhiteSpace( ctx.Reference ) )
                useGuid = true;

            string query = useGuid ? SaveStateByGuidQuery : SaveStateByReferenceQuery;
            var args = ctx.GetDatebaseRow();

            SqlConnection conn = new SqlConnection(connectionstringProvider.Connectionstring);
            try
            {
                conn.Open();
                conn.ExecuteMapperCommand(query, args);
            }
            catch(Exception ex)
            {
                AnnotatedException e = new AnnotatedException("Error saving viewstate", ex);
                e.AddAnnotation("UseGuid", useGuid);
                e.AddAnnotation("Query", query);
                e.AddAnnotations(args);

                throw e;
            }
            finally
            {
                conn.Close();
            }
        }