public void RollbackTransaction() { if (m_NeedCommit) { m_Manager.RollbackTransaction(); m_NeedCommit = false; } }
public bool PostHalf(DbManagerProxy manager, IObject obj, bool bMyPref) { bool bTransactionStarted = false; bool bSuccess; try { LaboratorySectionMaster bo = obj as LaboratorySectionMaster; if (!manager.IsTransactionStarted) { bTransactionStarted = true; manager.BeginTransaction(); } bSuccess = _PostNonTransactionHalf(manager, obj as LaboratorySectionMaster, false); if (bTransactionStarted) { if (bSuccess) { bo.DeepAcceptChanges(bMyPref); manager.CommitTransaction(); } else { manager.RollbackTransaction(); } } if (bSuccess && bo.IsNew && !bo.IsMarkedToDelete) // insert { bo.m_IsNew = false; } if (bSuccess && bTransactionStarted) { bo.OnAfterPost(); } } catch (Exception e) { if (bTransactionStarted) { manager.RollbackTransaction(); } if (e is DataException) { throw DbModelException.Create(obj, e as DataException); } else { throw; } } return(bSuccess); }
public static T GetInnerQueryResult <T>(DbManagerProxy manager, string queryString, string lang, Func <DbManager, T> commandExecutor) { Utils.CheckNotNull(manager, "manager"); Utils.CheckNotNull(lang, "lang"); Utils.CheckNotNullOrEmpty(queryString, "queryString"); Utils.CheckNotNull(commandExecutor, "commandExecutor"); int oldTimeout = manager.CommandTimeout; try { manager.CommandTimeout = m_CommandTimeout; manager.BeginTransaction(IsolationLevel.ReadUncommitted); DbManager command = manager.SetCommand(queryString, manager.Parameter("LangID", lang)); T result = commandExecutor(command); manager.CommitTransaction(); return(result); } catch (Exception) { manager.RollbackTransaction(); throw; } finally { manager.CommandTimeout = oldTimeout; } }
public void AvrSearchObjectCheckTest() { using (DbManagerProxy manager = DbManagerFactory.Factory.Create()) { try { manager.BeginTransaction(); manager.CommandTimeout = 120; string scriptPath = PathToTestFolder.Get(TestFolders.Db) + @"..\..\Sources\EIDSS\eidss.db\Scripts\AVR Check script\Search objects check script.sql"; if (!File.Exists(scriptPath)) { scriptPath = PathToTestFolder.Get(TestFolders.Db) + @"..\..\eidss.db\Scripts\AVR Check script\Search objects check script.sql"; } IEnumerable <string> scripts = ScriptLoader.LoadScript(scriptPath); foreach (string script in scripts) { if (String.IsNullOrWhiteSpace(script)) { continue; } manager.SetCommand(script.Trim()).ExecuteNonQuery(); } } finally { manager.RollbackTransaction(); } } }
public ActionResult QueryLayoutTreeUpdatePartial(AvrTreeElement treeElement) { //TODO выводим ошибки ввода куда? if (ModelState.IsValid) { //проверим, были ли изменения if (treeElement.ID > 0) { List <AvrTreeElement> tree = GetQueryTree(); AvrTreeElement elem = tree.FirstOrDefault(c => c.ID == treeElement.ID); if ((elem != null) && treeElement.IsEqual(elem)) { //TODO в противном случае надо показать диалог подтверждения сохранения return(PartialView("QueryLayoutTreePartial", GetQueryTree())); } } long id = 0; using (DbManagerProxy manager = DbManagerFactory.Factory.Create()) { try { manager.BeginTransaction(); if (treeElement.IsLayout) { AvrQueryLayoutTreeDbHelper.SaveLayoutMetadata( ModelUserContext.CurrentLanguage , treeElement.ID , treeElement.DefaultName , treeElement.NationalName , (long)DBGroupInterval.gitDateYear , treeElement.QueryID , treeElement.DescriptionID , treeElement.Description , treeElement.DescriptionEnglish , treeElement.ReadOnly , treeElement.IsShared ); AvrQueryLayoutTreeDbHelper.SaveLayoutLocation(treeElement.ID, treeElement.ParentID != treeElement.QueryID ? treeElement.ParentID : null); id = treeElement.ID; } else if (treeElement.IsFolder) { if (treeElement.ParentID == treeElement.QueryID) { treeElement.ParentID = null; } AvrQueryLayoutTreeDbHelper.SaveFolder(treeElement.ID, treeElement.ParentID, treeElement.QueryID, treeElement.DefaultName, treeElement.NationalName); id = treeElement.ID; } //long publishedId = 0; //var eventType = EventType.AVRLayoutFolderPublishedLocal; //только для инициализации //if (id > 0) //{ // if (treeElement.IsPublished && !treeElement.ReadOnly) // { // PublishRoutines(treeElement.ID, manager, treeElement.ElementType, true, out publishedId, out eventType); // } // else if (!treeElement.IsPublished && treeElement.ReadOnly && treeElement.GlobalID.HasValue) // { // PublishRoutines(treeElement.GlobalID.Value, manager, treeElement.ElementType, false, out publishedId, // out eventType); // } //} manager.CommitTransaction(); if (id > 0) { if (treeElement.IsPublished && !treeElement.ReadOnly) { PublishUnpublish(treeElement.ID, treeElement.ElementType, true); } else if (!treeElement.IsPublished && treeElement.ReadOnly && treeElement.GlobalID.HasValue) { PublishUnpublish(treeElement.ID, treeElement.ElementType, false); } } //if (publishedId > 0) //{ // EidssEventLog.Instance.CreateProcessedEvent(eventType, // publishedId > 0 ? publishedId : 0, 0, // EidssUserContext.User.ID, // manager.Transaction); //} } catch (Exception) { manager.RollbackTransaction(); throw; } } /* TODO вызов обрушивает систему * LookupManager.ClearByTable("Layout"); * LookupManager.ClearByTable("LayoutFolder"); * LookupManager.ClearByTable("Query"); * LookupManager.ClearAndReloadOnIdle();*/ } RefreshTree(); return(PartialView("QueryLayoutTreePartial", GetQueryTree())); }
public ActionResult QueryLayoutTreeAddPartial(AvrTreeElement newNode) { //делаем дочерний элемент HttpCookie cc = Request.Cookies["newElementType"]; string errStr = String.Empty; if ((cc != null) && AvrPermissions.InsertPermission && !IsFolderDepthTooBig(newNode)) { bool createFolder = (newNode.IsFolder || (newNode.IsQuery && cc.Value == "folder")); bool createLayout = (newNode.IsLayout || (newNode.IsQuery && cc.Value == "layout")); if (createFolder || createLayout) { newNode.ElementType = createFolder ? AvrTreeElementType.Folder : AvrTreeElementType.Layout; using (DbManagerProxy manager = DbManagerFactory.Factory.Create()) { try { manager.BeginTransaction(); long nodeId = NewId(); long?parentId = newNode.ParentID != newNode.QueryID ? newNode.ParentID : null; if (createFolder) { AvrQueryLayoutTreeDbHelper.SaveFolder( nodeId , parentId , newNode.QueryID , newNode.DefaultName , newNode.NationalName); } else { AvrQueryLayoutTreeDbHelper.SaveLayoutMetadata( ModelUserContext.CurrentLanguage , nodeId , newNode.DefaultName , newNode.NationalName , (long)DBGroupInterval.gitDateYear , newNode.QueryID , NewId() , newNode.Description , newNode.DescriptionEnglish , false , newNode.IsShared ); AvrQueryLayoutTreeDbHelper.SaveLayoutLocation(nodeId, parentId); } //long publishedId = 0; //var eventType = EventType.AVRLayoutFolderPublishedLocal; //только для инициализации //if (newNode.IsPublished) //{ // PublishRoutines(nodeId, manager, // createFolder ? AvrTreeElementType.Folder : AvrTreeElementType.Layout, // true, out publishedId, out eventType); //} manager.CommitTransaction(); if (newNode.IsPublished) { PublishUnpublish(nodeId, createFolder ? AvrTreeElementType.Folder : AvrTreeElementType.Layout, true); } //if (publishedId > 0) //{ // EidssEventLog.Instance.CreateProcessedEvent(eventType, // publishedId > 0 ? publishedId : 0, 0, // EidssUserContext.User.ID, // manager.Transaction); //} } catch (Exception exc) { errStr = exc.Message; //TODO куда писать ошибки? manager.RollbackTransaction(); throw; } } } } else { errStr = "error"; } if (errStr.Length == 0) { RefreshTree(); } return(PartialView("QueryLayoutTreePartial", GetQueryTree())); }
public int Import(string fileName, bool forcePost) { if (m_Errors != null) { m_Errors.Clear(); } else { m_Errors = new List <CsvError>(); } m_Lines = null; InitSettings(); m_BreakImport = false; using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite)) { using (var csv = new CsvReader( new StreamReader(fs), true, ';')) { csv.DefaultParseErrorAction = ParseErrorAction.RaiseEvent; int fieldCount = csv.FieldCount; if (fieldCount != 9) { m_Errors.Add(new CsvError(csv.CurrentRecordIndex, 0, 0, "errStatisticImportFieldsQty", null, null, false)); return(-1); } csv.ParseError += new EventHandler <ParseErrorEventArgs>(csv_ParseError); string[] headers = csv.GetFieldHeaders(); m_PostedRowsQty = 0; m_TotalRowsQty = 0; using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance)) { manager.AuditParams = new object[] { AuditEventType.daeCreate, EIDSSAuditObject.daoStatistic, AuditTable.tlbStatistic, null }; manager.BeginTransaction(); try { while (csv.ReadNextRecord()) { m_TotalRowsQty++; if (!ValidateRecord(csv)) { continue; } if (!PostRecord(csv, manager)) { continue; } if (m_BreakImport || m_Errors.Count >= MaxErrorsQty) { manager.RollbackTransaction(); return(1); } } if (m_Errors.Count == 0 || forcePost) { //manager.SetEventParams("StatisticImport", new object[] { EventType.StatisticImport, null, string.Format("{0} of {1} records were imported", m_PostedRowsQty, m_TotalRowsQty) }); manager.CommitTransaction(); } else { manager.RollbackTransaction(); } } catch { manager.RollbackTransaction(); throw; } } } } return(0); }