public static List <SeedItem> BuildTargetSeeds(ITargetBuilderOptions options, Func <SeedItem, bool> acceptSeed, IProgressCallback progress) { List <SeedItem> seeds = new List <SeedItem>(); var mapped = GetTargetCoverageRegion(options, progress); progress.SetMessage("Building seeds ..."); progress.SetRange(0, mapped.Count); progress.SetPosition(0); foreach (var l in mapped) { progress.Increment(1); for (int i = 0; i < l.Sequence.Length - options.MinimumSeedLength; i++) { SeedItem si = GetSeed(l, i, options.MinimumSeedLength, options.MinimumCoverage); if (si != null && acceptSeed(si)) { seeds.Add(si); } } } progress.End(); progress.SetMessage("Total {0} {1}mers seeds were built.", seeds.Count, options.MinimumSeedLength); return(seeds); }
private void IncrementProgress(IProgressCallback progressCallback) { if (progressCallback != null) { progressCallback.Increment(1); } }
public static List <PeakList <T> > GetPeakListFromDtaDirectory <T>(string dtaDirectory, IProgressCallback progress) where T : IPeak, new() { var result = new List <PeakList <T> >(); var ddi = new DtaDirectoryIterator <T>(dtaDirectory); progress.SetMessage("Reading peak list from dta files of directory " + new DirectoryInfo(dtaDirectory).Name + ", total " + ddi.Count + " files ..."); progress.SetRange(0, ddi.Count); progress.SetPosition(0); while (ddi.HasNext()) { progress.Increment(1); if (progress.IsCancellationPending()) { throw new UserTerminatedException(); } result.Add(ddi.Next()); } return(result); }
public static void Increment(int val) { if (callback != null) { callback.Increment(val); } }
public static List <SeedItem> BuildTargetSeeds(ITargetBuilderOptions options, List <string> seeds, IProgressCallback progress) { List <SeedItem> result = new List <SeedItem>(); var mapped = GetTargetCoverageRegion(options, progress); progress.SetMessage("Building seeds ..."); progress.SetRange(0, mapped.Count); progress.SetPosition(0); foreach (var l in mapped) { progress.Increment(1); foreach (var seed in seeds) { var curseq = l.Strand == '+' ? l.ReverseComplementedSequence : l.Sequence; int lastpos = -1; while (true) { int pos = curseq.IndexOf(seed, lastpos + 1); if (pos == -1) { break; } if (l.Strand == '+') { result.Add(GetSeed(l, curseq.Length - pos - options.MinimumSeedLength, options.MinimumSeedLength, options.MinimumCoverage)); } else { result.Add(GetSeed(l, pos, options.MinimumSeedLength, options.MinimumCoverage)); } lastpos = pos; } } } progress.End(); progress.SetMessage("Total {0} {1}mers seeds were built.", result.Count, options.MinimumSeedLength); return(result); }
public bool GenerateSortedSolutionList(IProgressCallback callback, out List <ImpositionSolution> solutions) { // get applicable pattern list List <ImpositionPattern> patternList = GetPatternList(); // need to compute orthogonal positions ? bool processOrthogonalImposition = AllowOrthogonalImposition; /*_allowOrthogonalImposition && (_cardboardFormat.Width != _cardboardFormat.Height);*/ // compute number of expected solutions if (null != callback) { callback.Begin(0, patternList.Count * (processOrthogonalImposition ? 4 : 2)); } // instantiate solution list solutions = new List <ImpositionSolution>(); // process pattern list foreach (ImpositionPattern pattern in patternList) { // generate pattern try { pattern.GeneratePattern(InitialEntities, SpaceBetween, ImpositionOffset, false); } catch (Exception ex) { _log.Error(ex.Message); continue; } // default orientation ImpositionSolution solution = GenerateSolution(pattern); if (null != solution && solution.IsValid) { solution.UnitLengthCut = _unitLengthCut; solution.UnitLengthFold = _unitLengthFold; solution.UnitArea = _unitArea; solutions.Add(solution); } // increment progress dialog? if (null != callback) { callback.Increment(solutions.Count); } // orthogonal direction if (processOrthogonalImposition) { // generate pattern try { pattern.GeneratePattern(InitialEntities, SpaceBetween, ImpositionOffset, true); } catch (Exception ex) { _log.Error(ex.Message); continue; } solution = GenerateSolution(pattern); if (null != solution && solution.IsValid) { solution.UnitLengthCut = _unitLengthCut; solution.UnitLengthFold = _unitLengthFold; solution.UnitArea = _unitArea; solutions.Add(solution); } } // increment progress dialog? if (null != callback) { callback.Increment(solutions.Count); } } // generate thumbnails foreach (ImpositionSolution sol in solutions) { sol.GenerateThumbnail(); // increment progress dialog? if (null != callback) { callback.Increment(solutions.Count); } } // sort solution list solutions.Sort(new SolutionComparerFormat()); if (null != callback) { callback.End(); } return(solutions.Count > 0); }
private void DoSomeWork(object status) { errorList = new StringBuilder(); errorMail = false; string sSource = "MultiMail"; string sLog = "Application"; errorList.AppendLine("Email not sent to:"); IProgressCallback callback = status as IProgressCallback; try { callback.Begin(0, clbLeden.CheckedItems.Count + clbExtraEmail.CheckedItems.Count); SmtpClientExt client = new SmtpClientExt(param.STMPserver, param.STMPport, param.EmailUserId, param.EmailPassword, EmailLogFile, chkLogEmail.Checked, ckbDoNotSendEmail.Checked, callback.SetText); MailMessage message = new MailMessage(); message.Subject = txtSubject.Text; message.From = new MailAddress(param.EmailReturnAdress); message.ReplyToList.Add(param.EmailReturnAdress); message.IsBodyHtml = ckbHtml.Checked; string messid = string.Format("<{0}@{1}>", Guid.NewGuid().ToString(), "wwww.ttvn.nl"); message.Headers.Add("Message-Id", messid); string strBody = string.Empty; if (ckbHtml.Checked) { strBody = string.Format(@"<html><head><meta http-equiv=Content-Type content=""text/html; charset=us-ascii""></head>{0}</html>", htmlTextbox1.Text); } else { strBody = htmlTextbox1.PlainText; } if (txtBijlage1.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage1.Text)); message.Attachments.Add(new Attachment(txtBijlage1.Text)); } if (txtBijlage2.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage2.Text)); message.Attachments.Add(new Attachment(txtBijlage2.Text)); } if (txtBijlage3.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage3.Text)); message.Attachments.Add(new Attachment(txtBijlage3.Text)); } for (int i = 0; i < clbLeden.Items.Count; i++) { if (!clbLeden.GetItemChecked(i)) { continue; } message.To.Clear(); message.To.Add(clbLeden.Items[i].ToString()); message.Body = MailRoutines.ReplaceKeyWords(strBody, ledenSchaduwlijst[i], param); //emailer.To.Clear(); //emailer.To.Add(clbLeden.Items[i].ToString()); //emailer.Body = MailRoutines.ReplaceKeyWords(strBody, ledenSchaduwlijst[i], param); try { //emailer.SendMessage(); client.Send(message); } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message + @"/n" + message.Body, EventLogEntryType.Warning, 001); } catch (Exception ex2) { GuiRoutines.ExceptionMessageBox(this, ex); Console.WriteLine(ex2.ToString()); } errorMail = true; errorList.AppendLine(clbLeden.Items[i].ToString()); } callback.Increment(1); callback.SetText(clbLeden.Items[i].ToString()); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } for (int i = 0; i < clbExtraEmail.Items.Count; i++) { if (!clbExtraEmail.GetItemChecked(i)) { continue; } message.To.Clear(); message.To.Add(clbExtraEmail.Items[i].ToString()); message.Body = MailRoutines.ReplaceKeyWords(strBody, new tblLid(), param); try { client.Send(message); } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } errorMail = true; errorList.AppendLine(clbExtraEmail.Items[i].ToString()); } callback.Increment(1); callback.SetText(clbExtraEmail.Items[i].ToString()); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } callback.WaitOK(); } catch (System.Threading.ThreadAbortException ex) { // We want to exit gracefully here (if we're lucky) try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } } catch (System.Threading.ThreadInterruptedException ex) { // And here, if we can try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } GuiRoutines.ExceptionMessageBox(this, ex); } finally { if (callback != null) { callback.End(); } } }
private void SendContributieIncassoAankondiging() { string fileName = param.LocationTemplates + @"\Template_ContributieIncasso.htm";; if (!File.Exists(fileName)) { MessageBox.Show("Template voor incasso mail " + fileName + " bestaat niet", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SmtpClientExt client = new SmtpClientExt(param.STMPserver, param.STMPport, param.EmailUserId, param.EmailPassword, EmailLogFile, chkLogEmail.Checked, ckbDoNotSendEmail.Checked, callback.SetText); //SmtpEmailer emailer = new SmtpEmailer(); //emailer.Host = param.STMPserver; //emailer.From = param.EmailReturnAdress; //emailer.AuthenticationMode = AuthenticationType.Base64; //emailer.User = param.EmailUserId; //emailer.Password = param.EmailPassword; //emailer.SendAsHtml = true; //emailer.LogFile = EmailLogFile; //emailer.DoNotSendMail = ckbDoNotSendEmail.Checked; //emailer.LogMail = chkLogEmail.Checked; StreamReader sr = File.OpenText(fileName); StringReader str = new StringReader(sr.ReadToEnd()); string template = str.ReadToEnd(); foreach (Leden.Net.tblRekening rekening in selectedInc) { MailMessage message = new MailMessage(); message.From = new MailAddress(param.EmailReturnAdress); //emailer.ClearMessage(); if (rekening.TypeRekening != 0 || rekening.MailOnderdrukken) { continue; // Alleen contributie incasso's } string sbr = template; // vervangen keywords sbr = MailRoutines.ReplaceKeyWords(sbr, rekening.Lid, param); sbr = ReplaceRekeningItems(sbr, rekening); message.IsBodyHtml = true; message.Body = sbr; //emailer.Body = sbr; if (rekening.Lid.MainEmailAdress != string.Empty) { message.Subject = "Aankondiging contributie incasso TTVN"; //emailer.Subject = "Aankondiging contributie incasso TTVN"; message.To.Add(rekening.Lid.MainEmailAdress); //emailer.To.Add(rekening.Lid.MainEmailAdress); } else { message.Subject = "Geen email adres bij Aankondiging contributie incasso TTVN"; //emailer.Subject = "Geen email adres bij Aankondiging contributie incasso TTVN"; //emailer.To.Add(param.EmailReturnAdress); message.To.Add(param.EmailReturnAdress); } try { client.Send(message); //emailer.SendMessage(); } catch { errorMail = true; errorList.AppendLine(rekening.Lid.MainEmailAdress); } callback.Increment(1); callback.SetText(rekening.Lid.MainEmailAdress); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } }
/// <summary> /// The do export database. /// </summary> /// <param name="exportPath"> /// The export path. /// </param> /// <param name="format"> /// The format. /// </param> /// <param name="batchSize"> /// The batch size. /// </param> /// <param name="callback"> /// The callback. /// </param> private void DoExportDatabase(string exportPath, DataFormat format, int batchSize, IProgressCallback callback) { var routes = this.ResultEnvironment.FareDatabase.GetRoutes(true, false, false, false, callback); var journeyBatch = new List<Journey>(); var routesBatch = new List<TravelRoute>(); var jCount = routes.Sum(r => r.Journeys.Count); int stackCount = 0; callback.Begin(0, jCount); callback.Title = string.Format("Processing {0} journeys...", jCount); int routesCount = routes.Count; int lastRoutesIdx = routesCount - 1; for (int i = 0; i < routesCount; i++) { if (callback.IsAborting) { return; } TravelRoute route = routes[i]; callback.Text = string.Format("{0} - {1}", route.Departure, route.Destination); var journeys = route.Journeys; int journeysCount = journeys.Count; int lastJourneyIdx = journeysCount - 1; if (journeysCount > 0) { for (int j = 0; j < journeysCount; j++) { var journey = journeys[j]; journeyBatch.Add(journey); if (journeyBatch.Count >= batchSize || j == lastJourneyIdx) { // Batch is full or this is the last item var expRoute = new TravelRoute(route); // Gather journeys into 1 exported route expRoute.AddJourney(journeyBatch, false); this.ResultEnvironment.FareDatabase.LoadData(journeyBatch, true, AppContext.ProgressCallback); routesBatch.Add(expRoute); stackCount += journeyBatch.Count; journeyBatch.Clear(); } if (stackCount >= batchSize || i == lastRoutesIdx) { if (routesBatch.Count > 0) { this.ResultEnvironment.ArchiveManager.ExportData(routesBatch, exportPath, format, AppContext.ProgressCallback); routesBatch.Clear(); } callback.Increment(stackCount); stackCount = 0; } } } callback.Increment(1); } }
public static List<SeedItem> BuildTargetSeeds(ITargetBuilderOptions options, Func<SeedItem, bool> acceptSeed, IProgressCallback progress) { List<SeedItem> seeds = new List<SeedItem>(); var mapped = GetTargetCoverageRegion(options, progress); progress.SetMessage("Building seeds ..."); progress.SetRange(0, mapped.Count); progress.SetPosition(0); foreach (var l in mapped) { progress.Increment(1); for (int i = 0; i < l.Sequence.Length - options.MinimumSeedLength; i++) { SeedItem si = GetSeed(l, i, options.MinimumSeedLength, options.MinimumCoverage); if (si != null && acceptSeed(si)) { seeds.Add(si); } } } progress.End(); progress.SetMessage("Total {0} {1}mers seeds were built.", seeds.Count, options.MinimumSeedLength); return seeds; }
public static List<SeedItem> BuildTargetSeeds(ITargetBuilderOptions options, List<string> seeds, IProgressCallback progress) { List<SeedItem> result = new List<SeedItem>(); var mapped = GetTargetCoverageRegion(options, progress); progress.SetMessage("Building seeds ..."); progress.SetRange(0, mapped.Count); progress.SetPosition(0); foreach (var l in mapped) { progress.Increment(1); foreach (var seed in seeds) { var curseq = l.Strand == '+' ? l.ReverseComplementedSequence : l.Sequence; int lastpos = -1; while (true) { int pos = curseq.IndexOf(seed, lastpos + 1); if (pos == -1) { break; } if (l.Strand == '+') { result.Add(GetSeed(l, curseq.Length - pos - options.MinimumSeedLength, options.MinimumSeedLength, options.MinimumCoverage)); } else { result.Add(GetSeed(l, pos, options.MinimumSeedLength, options.MinimumCoverage)); } lastpos = pos; } } } progress.End(); progress.SetMessage("Total {0} {1}mers seeds were built.", result.Count, options.MinimumSeedLength); return result; }
/// <summary> /// The import data. /// </summary> /// <param name="path"> /// The path. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="IList"/>. /// </returns> /// <exception cref="ArgumentException"> /// </exception> public IList<TravelRoute> ImportData(string path, DataOptions options, IProgressCallback callback) { if (string.IsNullOrEmpty(path)) { path = ".\\"; } if (!Directory.Exists(path)) { throw new ArgumentException("Target path does not exist: " + path); } var result = new List<TravelRoute>(); callback.Begin(); callback.Text = "Getting file list..."; string[] fileList = Directory.GetFiles(path, "*"); var acceptedFiles = new List<string>(); foreach (var file in fileList) { string fileExt = Path.GetExtension(file); foreach (var ext in this.AcceptedExtensions) { if (string.Equals(fileExt, ext, StringComparison.OrdinalIgnoreCase)) { acceptedFiles.Add(file); break; } } } callback.Title = string.Format(CultureInfo.InvariantCulture, "Importing {0} files...", acceptedFiles.Count); callback.SetRange(0, acceptedFiles.Count); int stackCount = 0, maxStack = this._config.ProcessBatchSize; long stackSizeBytes = 0, maxStackSizeBytes = 1024 * 1024 * 20; // If data size reaches the limit: Start processing file content var processRoutes = new List<TravelRoute>(); var formatter = new ProtoBufTransfer(this.Logger); var processFiles = new List<string>(); for (int i = 0; i < acceptedFiles.Count; i++) { if (callback.IsAborting) { return result; } string file = acceptedFiles[i]; string fileName = Path.GetFileName(file); string ext = Path.GetExtension(fileName); // Get file extension in order to determine the data type this.Logger.InfoFormat("Importing file [{0}]", fileName); callback.Text = fileName; var fileSize = new FileInfo(file).Length; stackSizeBytes += fileSize; // Handle Binary data if (string.Equals(ext, BIN_EXTENSION, StringComparison.OrdinalIgnoreCase)) { var newRoutes = formatter.FromRaw<List<TravelRoute>>(file); if (newRoutes == null) { var singleRoute = formatter.FromRaw<TravelRoute>(file); if (singleRoute != null && singleRoute.Journeys.Count > 0) { processRoutes.Add(singleRoute); stackCount += singleRoute.Journeys.Count; } } else if (newRoutes.Count > 0) { foreach (var r in newRoutes) { if (r.Journeys.Count > 0) { processRoutes.AddRange(newRoutes); stackCount += r.Journeys.Count; } } } } else { // Handle the old data using the Fare Provider var newRoute = this.FareDataProvider.ReadData(File.ReadAllText(file, Encoding.Default)); if (newRoute != null && newRoute.Journeys.Count > 0) { var existRoute = processRoutes.FirstOrDefault(r => r.IsSameRoute(newRoute)); if (existRoute == null) { processRoutes.Add(newRoute); } else { existRoute.AddJourney(newRoute.Journeys, true); // Merge the journeys into the same Route } foreach (var j in newRoute.Journeys) { foreach (var d in j.Data) { if (d.DataDate.IsUndefined()) { d.DataDate = DateTime.Now; } } } stackCount += newRoute.Journeys.Count; stackSizeBytes += 20 * fileSize; // XML file needs much more resource for processing: Add "padding" to the file size boundary } } processFiles.Add(file); if (stackCount >= maxStack || stackSizeBytes >= maxStackSizeBytes || i == acceptedFiles.Count - 1) { this.FareDatabase.AddData(processRoutes, callback); result.AddRange(processRoutes); if (options.ArchiveDataFiles) { callback.Text = string.Format("Archiving {0} data entries...", processFiles.Count); this.ExportData(processRoutes, this._config.ArchivePath, DataFormat.Binary, callback); foreach (var f in processFiles) { File.Delete(f); } } processRoutes.Clear(); stackCount = 0; stackSizeBytes = 0; } callback.Increment(1); } return result; }
private void ProcessAddOrder(object objCallback) { IProgressCallback callback = (IProgressCallback)objCallback; ExecutionEngine.EventLogger.Write("FileOrderStorage:AddOrder"); if (callback != null) { if (callback.IsAborted) { return; } callback.SetRange(0, _order.OrderItems.Count); } CreateStoreFolder(); if (!string.IsNullOrEmpty(_currentOrderPath)) { LockOrderFolder(_currentOrderPath); try { foreach (OrderItem item in _order.OrderItems) { if (callback != null) { if (callback.IsAborted) { throw new InvalidOperationException(); } callback.Increment(); } try { item.OrderStoreFileName = VerifyFileName(_currentOrderPath, item.SourcePhotoItem.SourceFileNameWithoutPath); ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "Copying file from: {0} to: {1}", item.SourcePhotoItem.ActualFileName, _currentOrderPath + "\\" + item.OrderStoreFileName)); File.Copy(item.SourcePhotoItem.ActualFileName, _currentOrderPath + "\\" + item.OrderStoreFileName); } catch (Exception e) { ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "File copy error {0}. Message: {1}", item.SourcePhotoItem.ActualFileName, e.Message)); ExecutionEngine.EventLogger.WriteExceptionInfo(e); } } SaveOrderInfoToFile(_order, _currentOrderPath + "\\" + Constants.OrderInfoXmlFileName); UnlockOrderFolder(_currentOrderPath); IncreaseOrderId(); if (callback != null) { callback.IsComplete = true; } } catch (InvalidOperationException) { callback.IsComplete = false; ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "Order process was cancelled")); ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "Remove Folder: {0}", _currentOrderPath)); try { Directory.Delete(_currentOrderPath, true); ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "Folder {0} removed succesfully", _currentOrderPath)); } catch (Exception e) { ExecutionEngine.EventLogger.Write(string.Format(CultureInfo.InvariantCulture, "Uneble to remove folder {0}. {1}", _currentOrderPath, e.Message)); } } callback.End(); } }