Ejemplo n.º 1
0
        public override void InsertFile(UploadedFile file)
        {
            UploadStorageDataContext db = new UploadStorageDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqUploadedFile> files = db.GetTable<LinqUploadedFile>();

            file.ApplicationName = this.ApplicationName;

            files.InsertOnSubmit(new LinqUploadedFile(file));

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceError(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public override void UpdateFile(UploadedFile file)
        {
            if (file == null)
                throw new ArgumentNullException("file");

            UploadStorageDataContext db = new UploadStorageDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqUploadedFile> files = db.GetTable<LinqUploadedFile>();

            // BusinessBase inherited clases will have a downside effect with a ChangeConflictException 
            // as it has changed LastUpdated row version in the call stack.
            UploadedFile f = SelectFile(file.ID, false);

            if (f != null)
                file.LastUpdated = f.LastUpdated;

            // Assume that "file" has been sent by client.
            // Attach with "true" to the change tracker to consider the entity modified
            // and it can be checked for optimistic concurrency because
            // it has a column that is marked with "RowVersion" attribute
            files.Attach(new LinqUploadedFile(file), true);

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException)
            {
                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public override void DeleteFile(UploadedFile file)
        {
            if (file == null)
                throw new ArgumentNullException("file");

            LinqUploadedFile f = new LinqUploadedFile(file);

            UploadStorageDataContext db = new UploadStorageDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqUploadedFile> files = db.GetTable<LinqUploadedFile>();

            files.Attach(f);

            files.DeleteOnSubmit(f);

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceError(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
            }
        }