public void UpdateContracts(DateTime now, string[] lritids) { logInfo("Entro en UpdateContracts"); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(10))) { DBDataContext ctx = null; try { context = ctx = new DBDataContext(cstring); logInfo("Contexto creado"); IQueryable <Contract> contracts = ctx.Contracts; if (lritids.Length != 0) { contracts = ctx.Contracts.Where(c => lritids.Contains(c.lritid)); } foreach (var contract in contracts) { //Lo que me deben, se calcula desde la ultima fecha que facture contract.credit_balance = CreditBalanceFor(contract.lritid, (DateTime)contract.lastInvoice, now); //Lo que debeo, se calcula desde la ultima fecha que me facturaron contract.debit_balance = DebitBalanceFor(contract.lritid, (DateTime)contract.lastInvoiceRecv, now); } logInfo("Intentando enviar cambios.."); ctx.SubmitChanges(); logInfo("Cerrando scope de transaccion.."); scope.Complete(); logInfo("TERMINADO!"); if (lritids.Length == 0) { logInfo(string.Format("PriceUpdater: Actualizado todo a fecha {0:yyyy-MM-dd}", now)); } else { logInfo(string.Format("PriceUpdater: Actualizado {0} a fecha {1:yyyy-MM-dd}", String.Join(",", lritids), now)); } } catch (Exception ex) { logError(string.Format("PriceUpdater Error: {0}", ex.Message), ex); if (ctx != null) { ctx.Dispose(); } } finally { if (ctx != null) { ctx.Dispose(); } } } }
protected override void OnResultExecuted(ResultExecutedContext filterContext) { if (_context != null) { _context.Dispose(); } }
private void btnImport_Click(object sender, EventArgs e) { //try //{ // DDPImportHelper ddpImport = new DDPImportHelper(); // DataCenterDataAccess.DDPVersion v = new DataCenterDataAccess.DDPVersion(); // ddpImport.Import(txtDDPFile.Text, v ); //} //catch(Exception ex) //{ // MessageBox.Show( ex.ToString() ); //} //PricingManager pm = new PricingManager(); //var p = pm.GetMyCurrentPriceFor(DataCenterDataAccess.PricesDataAccess.PriceType.PositionReport); //p = p; DBDataContext c = new DBDataContext(DataCenterDataAccess.Config.ConnectionString); var m = new MsgInOut(); m.MsgType = 9999; m.MsgId = "ASPReprog"; m.TimeStamp = DateTime.UtcNow; m.Source = ""; m.RefId = ""; m.InOut = 1; m.Price = (decimal)44.4; m.Destination = ""; m.DDPVersion = ""; c.MsgInOuts.InsertOnSubmit(m); c.SubmitChanges(); c.Dispose(); }
public void Dispose() { if (DB != null) { DB.Dispose(); } }
public void Dispose() { if (context == null) { context.Dispose(); } }
public void Dispose() { Contexto.Dispose(); }
/// <summary> /// Importa un archivo DDP en formato XML a la base de datos /// </summary> /// <param name="stream">Stream de memoria del archivo</param> public DateTime Import(XmlDocument ddpxml, DDPVersion ddpVersion) { DateTime pubDate = DateTime.UtcNow; DBDataContext context = null; try { context = new DBDataContext(Config.ConnectionString); //--------------------------------------------------- XmlNamespaceManager nsmanager = new XmlNamespaceManager(ddpxml.NameTable); nsmanager.AddNamespace("lr", "http://gisis.imo.org/XML/LRIT/ddp/2008"); //--------------------------------------------------- //Hack-o-mati: Asociation of contracting goverment Dictionary <ContractingGoverment, ContractingConfig> goverments = new Dictionary <ContractingGoverment, ContractingConfig>(); //Just for return, do not use here. pubDate = DateTime.Parse(ddpxml.SelectSingleNode("/lr:DataDistributionPlan", nsmanager).Attributes["regularVersionImplementationAt"].Value); readCGS("/lr:DataDistributionPlan/lr:ContractingGovernment", ref goverments, ref ddpxml, ref nsmanager); readCGS("/lr:DataDistributionPlan/lr:Territory", ref goverments, ref ddpxml, ref nsmanager); var cgda = new ContractingGovermentDataAccess(context); var pda = new PlaceDataAccess(context); var soda = new StandingOrderDataAccess(context); var ssda = new SARServiceDataAccess(context); //var exda = new ExclusionDataAccess(context); //cgda.DropAll(); foreach (KeyValuePair <ContractingGoverment, ContractingConfig> kv in goverments) { kv.Key.DDPVersionId = ddpVersion.Id; int gId = cgda.Create(kv.Key); foreach (Place p in kv.Value.places) { p.ContractingGovermentId = gId; } foreach (SARService ss in kv.Value.sarservice) { ss.ContractingGovermentId = gId; } //foreach (Exclusion excl in kv.Value.exclusions) // excl.ContractingGoverment = gId; log.Debug(string.Format("{2}: Key:{0}, Value{1}", kv.Key.Name, kv.Value.places.Count, kv.Key.Id)); pda.Create(kv.Value.places.ToArray()); //exda.Create(kv.Value.exclusions.ToArray()); ssda.Create(kv.Value.sarservice.ToArray()); //Places with ids List <Place> places = pda.GetAll(ddpVersion.regularVer + ":" + ddpVersion.inmediateVer); //Standing orders string path = string.Format("/lr:DataDistributionPlan/lr:CoastalStateStandingOrders/lr:StandingOrder[@contractingGovernmentID='{0}']", kv.Key.LRITId); XmlNode standingOrder = ddpxml.SelectSingleNode(path, nsmanager); if (standingOrder != null && !String.IsNullOrEmpty(standingOrder.InnerText)) { foreach (string area in standingOrder.InnerText.Split(' ')) { int id = getPlaceId(places, area); if (id == -1) { continue; } StandingOrder so = new StandingOrder(); so.PlaceId = id; kv.Value.standingOrders.Add(so); } } //ES ACA soda.Create(kv.Value.standingOrders.ToArray()); } } catch (Exception ex) { if (context != null) { context.Dispose(); } throw new Exception("Unable to Import DDP File", ex); } finally { if (context != null) { context.Dispose(); } } return(pubDate); }
internal void Import(MemoryStream s) { var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(s); Stream stream = zipFile.GetInputStream(0); DBDataContext context = null; try { XmlDocument ddpxml = new XmlDocument(); ddpxml.Load(stream); context = new DBDataContext(Config.ConnectionString); //--------------------------------------------------- XmlNamespaceManager nsmanager = new XmlNamespaceManager(ddpxml.NameTable); nsmanager.AddNamespace("pr", "http://gisis.imo.org/XML/LRIT/pricingFile/2008"); //--------------------------------------------------- var prices = new List <Price>(); foreach (XmlNode price in ddpxml.SelectNodes("/pr:PricingFile/pr:PriceList", nsmanager)) { var p = new Price(); //Effective date p.effectiveDate = DateTime.Parse(price.Attributes["effectiveDate"].Value, CultureInfo.InvariantCulture); //Issue date p.issueDate = null; if (price.Attributes["issueDate"] != null) { p.issueDate = DateTime.Parse(price.Attributes["issueDate"].Value, CultureInfo.InvariantCulture); } //Datacenter ID p.dataCentreID = price.Attributes["dataCentreID"].Value; //Data Providers (list) if (price["dataProviderID"] != null) { foreach (string dataProvider in price["dataProviderID"].InnerText.Split(' ')) { var pup = new PriceUserProvider(); pup.dataProviderID = dataProvider; p.PriceUserProviders.Add(pup); } } var bd = price["BreakDown"]; p.currency = bd.Attributes["currency"].Value; p.ArchivePositionReport = decimal.Parse(bd["ArchivePositionReport"].InnerText, CultureInfo.InvariantCulture); p.PeriodicRateChange = decimal.Parse(bd["PeriodicRateChange"].InnerText, CultureInfo.InvariantCulture); p.Poll = decimal.Parse(bd["Poll"].InnerText, CultureInfo.InvariantCulture); p.PositionReport = decimal.Parse(bd["PositionReport"].InnerText, CultureInfo.InvariantCulture); prices.Add(p); } var pdao = new PricesDataAccess(context); pdao.Create(prices.ToArray()); } catch (Exception ex) { if (context != null) { context.Dispose(); } throw new Exception("Unable to Import Pricing File", ex); } finally { if (context != null) { context.Dispose(); } } }