public void SaveLoadedData(AccountingDataSync dataSync) { using (DbContextTransaction trans = Database.BeginTransaction()) { try { Database.ExecuteSqlCommand("exec PrepareLoading"); ArticleDatas.AddRange(dataSync.Articles); ArticleItemDatas.AddRange(dataSync.ArticleItems); SaveChanges(); LastUpdate = dataSync.LastUpdate; DbCommand command = Database.Connection.CreateCommand(); command.Transaction = trans.UnderlyingTransaction; command.CommandTimeout = 0; command.CommandText = "exec PostLoadUpdate"; command.ExecuteNonQuery(); trans.Commit(); Logger.Info("Data loaded"); } catch (Exception ex) { Logger.Error(ex); trans.Rollback(); } } }
public void IndexDatabase(bool filePrepared) { AccountingDataSync globalDataSync = ProcessAccountingData(filePrepared, false); using (StoreKeeperDataContext context = new StoreKeeperDataContext()) { SqlParameter userIdParam = new SqlParameter("@UserId", new Guid("F2024637-2251-479A-8ED9-940E4354F37B")); SqlParameter unlockParam = new SqlParameter("@Unlock", SqlDbType.Bit) { Value = 0 }; context.Database.ExecuteSqlCommand("exec LockDatabase @UserId, @Unlock", userIdParam, unlockParam); context.SaveLoadedData(globalDataSync); context.LastUpdate = DateTime.Now; context.ResponsibleUser = "******"; context.SaveChanges(); } }
public void ProcessFile(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException("Source XML file not found!", fileName); } _parsedArticles.Clear(); XmlDocument document = new XmlDocument(); document.Load(fileName); XmlNode articleList = document.SelectSingleNode("//StockList"); ParseArticles(articleList); _dataSync = new AccountingDataSync { Articles = _parsedArticles, ArticleItems = _parsedItems }; }
private bool GetAccountingData(SessionId callerSessionId, bool reloadAll) { try { ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>(); // parse data AccountingDataSync globalDataSync = ProcessAccountingData(false, reloadAll); using (StoreKeeperDataContext context = new StoreKeeperDataContext()) { // save to database context.SaveLoadedData(globalDataSync); } return(true); } catch (Exception ex) { Logger.Error(ex); throw new DataSynchronizationError(GetType(), DataSyncErrorType.Runtime, ex.Message); } }