protected override void OnOk(CancelEventArgs e) { Settings = new DumpLoadSettings() { Context = SelectedContext, UseTransaction = UseTransaction, TransactionSize = TransactionSize.HasValue ? TransactionSize.Value : 100 }; }
private async Task LoadDumpAsync(string filename, DumpLoadSettings settings) { bool reload = false; await ExecuteAsync((ct) => { var loadDone = false; var countMsgLoaded = 0; var dumpIsInvalid = false; string error; using (var ps = Progress.Start(ct, LongRunningState.Yes)) { ps.SetTitle("Checking dump..."); int previewCount = 0; if (Queue.QueueSource.DumpEngine.CheckDumpIsValid(filename, ps.CancellationToken, out previewCount, out error)) { ps.SetTitle("Loading dump..."); ps.SetRange(0, previewCount); using (var context = new DumpLoadContext(filename, settings)) { countMsgLoaded = Queue.QueueSource.DumpEngine.LoadDump(context, ps.CancellationToken, ps.Progress); } loadDone = true; } else { if (!ps.CancellationToken.IsCancellationRequested) { dumpIsInvalid = true; } } } if (loadDone) { App.MessageService.ShowMessage(App.ShellService.ShellView, Invariant($"{countMsgLoaded} message(s) loaded.")); reload = true; } else { if (dumpIsInvalid) { ShowErrorMessage($"Invalid dump file!\n{error}"); } } }); if (reload) { await RefreshAsync(false); } }
public DumpLoadContext(string filename, DumpLoadSettings settings) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException(nameof(filename)); } Settings = settings ?? throw new ArgumentNullException(nameof(settings)); Input = new StreamReader(filename); }
public int LoadDump(DumpLoadSettings settings, CancellationToken ct, IProgress <int> progress = null) { MQQueue ibmQ = null; var mqPutMsgOpts = new MQPutMessageOptions { Options = MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQPMO_ASYNC_RESPONSE }; if (settings.UseTransaction) { mqPutMsgOpts.Options |= MQC.MQPMO_SYNCPOINT; } else { mqPutMsgOpts.Options |= MQC.MQPMO_NO_SYNCPOINT; } switch (settings.Context) { case DumpLoadSettings.ContextMode.SetAll: mqPutMsgOpts.Options |= MQC.MQPMO_SET_ALL_CONTEXT; break; case DumpLoadSettings.ContextMode.SetIdentity: mqPutMsgOpts.Options |= MQC.MQPMO_SET_IDENTITY_CONTEXT; break; case DumpLoadSettings.ContextMode.NoContext: mqPutMsgOpts.Options |= MQC.MQPMO_NO_CONTEXT; break; case DumpLoadSettings.ContextMode.Default: break; } try { ibmQ = _qSource.NewConnectionCore().OpenQueueCore(OpenQueueMode.ForWrite); using (var sr = File.OpenText(settings.FileName)) { MQMessage msg = null; MQMessageDescriptor md = null; var counter = 0; while (!sr.EndOfStream) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) // a blank line between each message { if (msg != null) { if (progress != null && ct.IsCancellationRequested) { break; } ibmQ.Put(msg, mqPutMsgOpts); counter++; if (counter % 100 == 0) { progress?.Report(counter); } } msg = new MQMessage(); md = GetDescriptor(msg); } else { switch (line[0]) { case 'A': LoadMessageAttribute(line, md); break; case 'X': LoadMessageContent(line, msg); break; } } } progress?.Report(counter); return(counter); } } catch (MQException ibmEx) { throw ibmEx.ToMqException(AddExtraInfoToError); } finally { ibmQ?.Close(); } }