Exemplo n.º 1
0
 /// <summary>
 /// 回滚
 /// </summary>
 public void RollBack()
 {
     if (!transaction.WasCommitted && !transaction.WasRolledBack)
     {
         transaction.Rollback();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns>true or false</returns>
        public bool SaveList(List <D_Board_User_Role_Model> models)
        {
            NHibernate.ITransaction tran = NhSession.BeginTransaction();
            try
            {
                foreach (var item in models)
                {
                    NhSession.SaveOrUpdate(item);
                }

                tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (!tran.WasCommitted && !tran.WasRolledBack)
                {
                    tran.Rollback();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Rollback this instance.
 /// </summary>
 public void Rollback()
 {
     if (transaction.WasRolledBack || IsFinal || disposedValue)
     {
         IsFinal = true;
         return;
     }
     transaction.Rollback();
     IsFinal = true;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Rollbacks transaction and closes database connection.
 /// </summary>
 public void Rollback()
 {
     try
     {
         _transaction.Rollback();
     }
     finally
     {
         Session.Close();
     }
 }
Exemplo n.º 5
0
        public bool SaveWorkFlowLog(D_Report_Model model, D_WorkFlowLog_Model logModel)
        {
            NHibernate.ITransaction tran = NhSession.BeginTransaction();
            try
            {
                logModel.ReportGuid = model;

                NhSession.SaveOrUpdate(model.ReportD2);
                NhSession.SaveOrUpdate(model);
                if (model.ReportD8DataModels.Count > 0)
                {
                    foreach (var item in model.ReportD8DataModels)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }
                if (model.WorkFlow_Models.Count > 0)
                {
                    foreach (var item in model.WorkFlow_Models)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }
                if (model.WorkFlowLog_Models.Count > 0)
                {
                    foreach (var item in model.WorkFlowLog_Models)
                    {
                        NhSession.SaveOrUpdate(item);
                    }
                }

                NhSession.SaveOrUpdate(model);

                tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (!tran.WasCommitted && !tran.WasRolledBack)
                {
                    tran.Rollback();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>Rollsbacks the transaction</summary>
        public void Rollback()
        {
            if (!transaction.WasCommitted && !transaction.WasRolledBack)
            {
                logger.WarnFormat("Rollback {0}", transaction.GetHashCode());
                transaction.Rollback();
                IsRollbacked = true;
                RemoveFromContext();

                OnRollback();
            }
            else if (!transaction.WasCommitted)
            {
                logger.WarnFormat("Not rollbacking {0}, wasCommitted:{1}, wasRolledBack:{2}", transaction.GetHashCode(), transaction.WasCommitted, transaction.WasRolledBack);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 删除数据字典
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Delete(D_Dictionary_Model model)
 {
     NHibernate.ITransaction tran = NhSession.BeginTransaction();
     try
     {
         NhSession.Delete(model);
         tran.Commit();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (!tran.WasCommitted && !tran.WasRolledBack)
         {
             tran.Rollback();
         }
     }
 }
Exemplo n.º 8
0
 public void Excluir(T entidade)
 {
     using (NHibernate.ISession session = SessionFactory.AbrirSession())
     {
         using (NHibernate.ITransaction transacao = session.BeginTransaction())
         {
             try
             {
                 session.Delete(entidade);
                 transacao.Commit();
             }
             catch (Exception ex)
             {
                 if (!transacao.WasCommitted)
                 {
                     transacao.Rollback();
                 }
                 throw new Exception("Erro ao excluir Forma de Pagamento : " + ex.Message);
             }
         }
     }
 }
Exemplo n.º 9
0
        public ActionResult Role_Permission_Edit()
        {
            bool   success     = false;
            string roleGuid    = Request.Form["RoleGuid"];
            string permissions = Request.Form[2].ToString();

            string[] permission = permissions.Split(',');
            using (NHibernate.ITransaction tran = NhSession.BeginTransaction())
            {
                try
                {
                    Guid RoleGuid           = new Guid(roleGuid);
                    Model.D_Role_Model role = NhSession.Get <Model.D_Role_Model>(RoleGuid);
                    ICriteria          ic   = NhSession.CreateCriteria(typeof(Model.D_Role_Permissions_Model));
                    ic.Add(Restrictions.Eq("RoleGuid", role));
                    IList <Model.D_Role_Permissions_Model> rolePermissionList = ic.List <Model.D_Role_Permissions_Model>();

                    foreach (var item in rolePermissionList)
                    {
                        item.DataStatus     = true;
                        item.ModifyDateTime = DateTime.Now;
                        item.ModifyUserGuid = UserView.UserGuid;
                        item.ModifyUserName = UserView.UserName;
                        NhSession.Update(item);
                    }

                    foreach (var item in permission)
                    {
                        Model.D_Role_Permissions_Model rolePermission = rolePermissionList.SingleOrDefault(m => m.Permissions == item);
                        if (rolePermission == null)
                        {
                            rolePermission = new Model.D_Role_Permissions_Model();
                            rolePermission.CreateDateTime = DateTime.Now;
                            rolePermission.CreateUserGuid = UserView.UserGuid;
                            rolePermission.CreateUserName = UserView.UserName;
                            rolePermission.RoleGuid       = role;
                            rolePermission.Permissions    = item;
                        }

                        rolePermission.DataStatus     = false;
                        rolePermission.ModifyDateTime = DateTime.Now;
                        rolePermission.ModifyUserGuid = UserView.UserGuid;
                        rolePermission.ModifyUserName = UserView.UserName;

                        NhSession.SaveOrUpdate(rolePermission);
                    }
                    tran.Commit();
                    return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = success, message = ex.Message }));
                }
                finally
                {
                    if (!tran.WasCommitted && !tran.WasRolledBack)
                    {
                        tran.Rollback();
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void Rollback()
 {
     _transaction.Rollback();
 }
Exemplo n.º 11
0
 public void Rollback()
 {
     innerTran.Rollback();
 }
Exemplo n.º 12
0
        private bool InsertResolution(JsonResolutionModel jsonModel)
        {
            FileLogger.Info(this.Name, "Inizio inserimento Atto");
            Guid       mainChainId              = Guid.Empty;
            Guid       attachmentsChainId       = Guid.Empty;
            Resolution resolution               = new Resolution();
            string     typeDescription          = string.Empty;
            string     typeContainerDescription = string.Empty;

            resolution.Id                = Facade.ParameterFacade.GetIdresolution();
            resolution.Status.Id         = (short)ResolutionStatusId.Attivo;
            resolution.Year              = jsonModel.Anno;
            resolution.ProposeDate       = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.ProposeUser       = DocSuiteContext.Current.User.FullUserName;
            resolution.AdoptionDate      = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.AdoptionUser      = DocSuiteContext.Current.User.FullUserName;
            resolution.Number            = jsonModel.Numero;
            resolution.PublishingDate    = jsonModel.DataAdozione.ToLocalTime().Date;
            resolution.PublishingUser    = DocSuiteContext.Current.User.FullUserName;
            resolution.EffectivenessDate = jsonModel.DataEsecutiva.ToLocalTime().Date;
            resolution.EffectivenessUser = DocSuiteContext.Current.User.FullUserName;
            resolution.InclusiveNumber   = jsonModel.Segnatura;
            resolution.ResolutionObject  = jsonModel.Oggetto;
            resolution.Type.Id           = jsonModel.DelDet;
            string[] splitted = jsonModel.Segnatura.Split('/');
            if (splitted.Length > 1 && splitted[1] != null)
            {
                resolution.ServiceNumber = (splitted.Length > 2 && splitted[2] != null) ? string.Concat(splitted[1], "/", splitted[2]) : splitted[1];
            }
            else
            {
                HandleFailure("InsertResolution - La segnatura dell'atto indicata nel file Json non è valida");
                return(false);
            }
            if (jsonModel.DelDet == 1)
            {
                typeDescription          = "Delibera";
                typeContainerDescription = "Delibere";
            }
            else
            {
                if (jsonModel.DelDet == 0)
                {
                    typeDescription          = "Determina";
                    typeContainerDescription = "Determine";
                }
                else
                {
                    HandleFailure("InsertResolution - Errore in elaborazione: la tipologia di atto selezionata non esiste");
                    return(false);
                }
            }
            IList <Container>      containers      = Facade.ContainerFacade.GetContainerByName(string.Concat(typeContainerDescription, " ", jsonModel.Proponente));
            IList <ResolutionKind> resolutionsKind = new ResolutionKindFacade(DocSuiteContext.Current.User.FullUserName).GetByName(jsonModel.TipologiaAtto);
            IList <Contact>        contacts        = GetProposerContacts(jsonModel.Proponente);
            IList <Role>           roles           = Facade.RoleFacade.GetByName(jsonModel.Proponente);
            Category category = Facade.CategoryFacade.GetById(Parameters.ImportResolutionCategoryId);

            if (containers != null && containers.Count() == 1)
            {
                resolution.Container = containers.First();
                resolution.Location  = resolution.Container.ReslLocation;
            }
            else
            {
                HandleFailure(string.Concat("InsertResolution - Errore in elaborazione del contenitore: il contenitore ", typeContainerDescription, " ", jsonModel.Proponente, " non esiste o non è univoco."));
                return(false);
            }
            if (contacts != null && contacts.Count() == 1)
            {
                resolution.AddProposer(contacts.First());
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione del contatto selezionato: il contatto selezionato non esiste o non è univoco");
                return(false);
            }
            if (category != null)
            {
                resolution.Category = category;
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione del classificatore: classificatore non trovato.");
                return(false);
            }

            if (resolutionsKind != null && resolutionsKind.Any() && resolutionsKind.Count() == 1)
            {
                resolution.ResolutionKind = resolutionsKind.First();
            }
            else
            {
                HandleFailure("InsertResolution - Errore in elaborazione della tipologia di atto: la tipologia di atto non esiste o non è univoca.");
                return(false);
            }

            resolution.WorkflowType = Facade.TabMasterFacade.GetFieldValue("WorkflowType", DocSuiteContext.Current.ResolutionEnv.Configuration, jsonModel.DelDet);
            string SignatureDocument   = String.Concat(DocSuiteContext.Current.ResolutionEnv.CorporateAcronym, " ", typeDescription, " ", jsonModel.Segnatura, " del ", jsonModel.DataAdozione.ToLocalTime().ToString("d"));
            string SignatureAttachment = String.Concat(SignatureDocument, " (Allegato)");

            try
            {
                FileLogger.Info(this.Name, "InsertResolution - Inizio caricamento documenti in Biblos.");
                string           mainDocumentPath = string.Concat(Parameters.ImportResolutionSourceFolder, jsonModel.MaindocumentPath);
                FileDocumentInfo fileDocumentInfo = new FileDocumentInfo(new FileInfo(mainDocumentPath));
                fileDocumentInfo.Signature = SignatureDocument;
                BiblosDocumentInfo storedDocumentInfo = fileDocumentInfo.ArchiveInBiblos(resolution.Location.DocumentServer, resolution.Location.ReslBiblosDSDB, Guid.Empty);
                mainChainId = storedDocumentInfo.ChainId;
                FileLogger.Info(this.Name, "InsertResolution - Documento principale salvato correttamente in Biblos.");

                int integerMainChainId       = storedDocumentInfo.BiblosChainId;
                int integerAttachmentChainId = -1;
                FileDocumentInfo attachment;

                string attachmentDocumentPath;
                foreach (string attachmentRelativePath in jsonModel.AttachmentsDocumentPath)
                {
                    attachmentDocumentPath = string.Concat(Parameters.ImportResolutionSourceFolder, attachmentRelativePath);
                    attachment             = new FileDocumentInfo(new FileInfo(attachmentDocumentPath));
                    attachment.Signature   = SignatureAttachment;
                    BiblosDocumentInfo attachmentDocumentInfo = attachment.ArchiveInBiblos(resolution.Location.DocumentServer, resolution.Location.ReslBiblosDSDB, attachmentsChainId);
                    attachmentsChainId       = attachmentDocumentInfo.ChainId;
                    integerAttachmentChainId = attachmentDocumentInfo.BiblosChainId;
                    FileLogger.Info(this.Name, "InsertResolution - Allegato salvato correttamente in Biblos.");
                }

                FileResolution fileResolution = new FileResolution();
                fileResolution.Id = resolution.Id;
                fileResolution.IdResolutionFile  = integerMainChainId;
                fileResolution.IdProposalFile    = integerMainChainId;
                fileResolution.IdAssumedProposal = integerMainChainId;
                if (integerAttachmentChainId > 0)
                {
                    fileResolution.IdAttachements = integerAttachmentChainId;
                }
                resolution.File = fileResolution;
                FileLogger.Info(this.Name, "InsertResolution - Fine caricamento documenti in Biblos.");
            }
            catch (Exception ex)
            {
                HandleFailure(string.Concat("InsertResolution - Errore in elaborazione del salvataggio dell'atto in Biblos: ", ex.Message));
                return(false);
            }

            resolution.ResolutionWorkflows = new List <ResolutionWorkflow>();
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 1, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 2, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 3, 0));
            resolution.ResolutionWorkflows.Add(CreateResolutionWorkflow(resolution, 4, 1));

            IEnumerable <ResolutionKindDocumentSeries> resolutionDocumentSeries = resolution.ResolutionKind.ResolutionKindDocumentSeries;
            IList <BiblosChainInfo>      documents;
            DocumentSeriesItem           documentSeriesItem;
            ResolutionDocumentSeriesItem resolutionDocumentSeriesItem;

            using (NHibernate.ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    FileLogger.Info(this.Name, "InsertResolution - Inizio transaction.");
                    Facade.ResolutionFacade.SaveWithoutTransaction(ref resolution);
                    FileLogger.Info(this.Name, "InsertResolution - Inserimento autorizzazioni atto.");
                    if (contacts.First().Role != null)
                    {
                        Facade.ResolutionRoleFacade.AddRole(resolution, contacts.First().Role.Id, DocSuiteContext.Current.ResolutionEnv.AuthorizInsertType, false);
                    }
                    foreach (ResolutionKindDocumentSeries item in resolutionDocumentSeries)
                    {
                        documents                         = new List <BiblosChainInfo>();
                        documentSeriesItem                = new DocumentSeriesItem();
                        resolutionDocumentSeriesItem      = new ResolutionDocumentSeriesItem();
                        documentSeriesItem.Status         = DocumentSeriesItemStatus.Draft;
                        documentSeriesItem.DocumentSeries = Facade.DocumentSeriesFacade.GetById(item.DocumentSeries.Id);
                        documentSeriesItem.Subject        = resolution.ResolutionObject;
                        documentSeriesItem.Category       = resolution.Category;
                        documentSeriesItem.IdMain         = mainChainId;

                        Facade.DocumentSeriesItemFacade.SaveDocumentSeriesItem(documentSeriesItem, resolution.Year.Value,
                                                                               new BiblosChainInfo(new List <DocumentInfo>()), null, null, DocSuiteContext.Current.User.FullUserName,
                                                                               DocumentSeriesItemStatus.Draft, string.Concat("Inserimento bozza di ", item.DocumentSeries.Name), false);

                        if (roles != null && roles.Any() && roles.Count() == 1)
                        {
                            Facade.DocumentSeriesItemRoleFacade.AddOwnerRole(documentSeriesItem, roles.First(), false);
                        }
                        else
                        {
                            HandleFailure("InsertResolution - Errore in elaborazione della tipologia di atto: la tipologia di atto non esiste o non è univoca.");
                            return(false);
                        }

                        resolutionDocumentSeriesItem.IdDocumentSeriesItem = documentSeriesItem.Id;
                        resolutionDocumentSeriesItem.Resolution           = resolution;
                        Facade.ResolutionDocumentSeriesItemFacade.SaveWithoutTransaction(ref resolutionDocumentSeriesItem);
                    }
                    transaction.Commit();

                    //TODO:Invio comando di creazione Resolution alle WebApi
                    // facadeFactory.ResolutionFacade.SendCreateResolutionCommand(resolution);

                    FileLogger.Info(this.Name, "InsertResolution - Transaction completata con successo.");
                }
                catch (Exception ex)
                {
                    FileLogger.Error(this.Name, String.Format("InsertResolution - Errore in salvataggio di atto: Message: {0} - StackTrace: {1}", ex.Message, ex.StackTrace));
                    transaction.Rollback();
                }
            }
            Facade.ResolutionLogFacade.Log(resolution, ResolutionLogType.RI, string.Concat("Inserimento atto n.", resolution.InclusiveNumber));
            return(true);
        }