Ejemplo n.º 1
0
 /// <summary>
 /// Rollback the transaction then calls Dispose
 /// </summary>
 public void Rollback()
 {
     if (DBTransaction != null)
     {
         DBTransaction.Rollback();
         DBTransaction.Dispose();
         DBTransaction = null;
     }
     Dispose();
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (DBTransaction != null)
     {
         DBTransaction.Commit();
         DBTransaction.Dispose();
         DBTransaction = null;
     }
     if (DBConnection != null)
     {
         DBConnection.Dispose();
         DBConnection = null;
     }
 }
Ejemplo n.º 3
0
        public virtual async Task <ActionResult <Stream> > DownloadLogFile([FromRoute] long logId)
        {
            var transaction = new DBTransaction(table.Connection, CurrentUser);

            try
            {
                var streamResult = await GetLogStream(logId, transaction);

                if (streamResult.Value.Stream == null)
                {
                    transaction.Dispose();
                    return(streamResult.Result);
                }
                return(new TransactFileStreamResult(streamResult.Value.Stream,
                                                    System.Net.Mime.MediaTypeNames.Application.Octet,
                                                    transaction, streamResult.Value.FileName));
            }
            catch (Exception ex)
            {
                transaction.Dispose();
                return(BadRequest(ex));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Stream> > DownloadFile([FromRoute] K id)
        {
            var transaction = new DBTransaction(table.Connection, CurrentUser);

            try
            {
                var item = table.LoadById(id, DBLoadParam.Load | DBLoadParam.Referencing, null, transaction);
                if (item == null)
                {
                    return(NotFound());
                }
                if (!(item.Access?.GetFlag(AccessType.Download, transaction.Caller) ?? true) &&
                    !(item.Access?.GetFlag(AccessType.Update, transaction.Caller) ?? true))
                {
                    return(Forbid());
                }
                if (table.FileNameKey == null)
                {
                    return(BadRequest("No file columns presented!"));
                }
                var fileName = item.GetValue <string>(table.FileNameKey);
                if (string.IsNullOrEmpty(fileName))
                {
                    return(BadRequest("File name was not specified!"));
                }
                var stream = (Stream)null;
                if (table.FileLOBKey != null && item.GetValue(table.FileLOBKey) != null)
                {
                    stream = await item.GetLOB(table.FileLOBKey, transaction);
                }
                else if (table.FileKey != null)
                {
                    stream = item.GetZipMemoryStream(table.FileKey, transaction);
                }
                else
                {
                    return(BadRequest("No file columns presented!"));
                }
                return(new TransactFileStreamResult(stream,
                                                    System.Net.Mime.MediaTypeNames.Application.Octet,
                                                    transaction, fileName));
            }
            catch (Exception ex)
            {
                transaction.Dispose();
                return(BadRequest(ex));
            }
        }
Ejemplo n.º 5
0
            /// <summary>
            /// Close transaction and connection. If transaction has not been rolled back, it is committed
            /// </summary>
            public void Dispose()
            {
                GC.SuppressFinalize(this);

                try
                {
                    if (DBTransaction != null)
                    {
                        DBTransaction.Commit();
                        DBTransaction.Dispose();
                        DBTransaction = null;
                    }
                    if (disposeConnection)
                    {
                        db.CloseConnection(DBConnection);
                    }
                    DBConnection = null;
                }
                catch
                {
                    // don't care
                }
            }
Ejemplo n.º 6
0
        protected virtual void Dispose(bool freeManagedResources)
        {
            if (freeManagedResources)
            {
                // free managed resources

                if (_currentContext != null)
                {
                    _currentContext.SqlContext.Transaction = null;
                    _currentContext.Dispose();
                    _currentContext = null;
                }
                DataContext.Current = _previousContext;

                if (_transaction != null)
                {
                    _transaction.Dispose();
                    _transaction = null;
                }
            }

            // free native resources if there are any.
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Close transaction and connection. If transaction has not been rolled back, it is committed
 /// </summary>
 public void Dispose()
 {
     try
     {
         if (DBTransaction != null)
         {
             DBTransaction.Commit();
             DBTransaction.Dispose();
             DBTransaction = null;
         }
         if (DBConnection != null)
         {
             if (disposeConnection)
             {
                 DBConnection.Dispose();
             }
             DBConnection = null;
         }
     }
     catch
     {
         // don't care
     }
 }