public void FatalError(string message) { GUIDispatcher.Invoke(new Action(() => { AllertWindow win = new AllertWindow(message); win.ShowWindowOnCenter(); // } )); }
private void TaskBindAlarm() { while (IsRunning) { if (_alarmer != null && _alarmer.AlarmList != null) { GUIDispatcher.Invoke(new Action(() => BindAlarm())); return; } Thread.Sleep(100); } }
private void TaskConnectToDatabase() { try { //TODO if not connected ???????????? _dataSource.ConnectToDatabase(); GUIDispatcher.Invoke(new Action(() => _mainWindow.BindDBDataSource())); } catch (Exception e) { Error("App.TaskConnectToDatabase", e); } }
private void TaskCreateInstrumentsTable() { //changed 2017-05-02 while (DealingServer == null || DealingServer.GlobalConfig == null || DealingServer.Instruments == null || !DealingServer.IsGlobalConfigAvail) { Thread.Sleep(100); } DealingServer.Instruments.WaitInstrumentsLoaded(); try { int ii = 1; /*foreach (var r in Plaza2Connector.GlobalConfig.ListIsins) * GUIDispatcher.Invoke(new Action ( ()=> * CreateOneIstrumentsRecord(r, ii++, firstCol)) * );*/ foreach (var dbInstrument in DealingServer.Instruments) { if (dbInstrument.Is_GUI_monitoring == 1) { GUIDispatcher.Invoke(new Action(() => CreateOneIstrumentsLine(dbInstrument.instrument, dbInstrument.RoundTo, ii++, firstCol))); } } } catch (Exception e) { DealingServer.Error("TaskCreateInstrumentsTable", e); } // CreateOneIstrumentsRecord("RTS-12.15", 1, firstCol); // CreateOneIstrumentsRecord("Si-12.15", 2, firstCol); // CreateOneIstrumentsRecord("SBRF-12.15", 3, firstCol); IsButtonsLoaded = true; }
private void TaskConnectToDealingServers() { try { GUIDispatcher.Invoke(new Action(() => _mainWindow.BindTCPDataSource())); _dataSource.ConnectToDealingServers(); } catch (Exception e) { Error("App.TaskConnectToDealingServers", e); } }
/// <summary> /// Wait till it it possible to bind (using specifig delegate) than call BindTextPath /// Call from CreateControlTextBlock /// </summary> /// <param name="textBlock"></param> /// <param name="path"></param> /// <param name="delToWait">Delegate for wait till it will be possible to binf</param> /// <param name="delToWaitPar">Parameter for delToWait</param> /// <param name="delBindSourse">Delegate retrieves Bind data source</param> /// <param name="delBindSourcePar">Parameter for delBindSourse</param> /// <param name="format">String format for output</param> private void TaskBindControlTextBlock(TextBlock textBlock, string path, DelegateWait delToWait, object delPar, DeleagateBindingSource delBindSource, object delBindSourcePar, string format) { try { while (delToWait(delPar)) { System.Threading.Thread.Sleep(1000); } GUIDispatcher.Invoke(new Action(() => BindTextPath(textBlock, path, delBindSource, delBindSourcePar, format))); } catch (Exception e) {// TODO throw exception ! string st = ""; if (e != null) { Thread.Sleep(0); } } }
public static TaskCompletionSource <Tuple <XElement, string> > ConvertInput(Input input) { var promise = new TaskCompletionSource <Tuple <XElement, string> >(); var tempDirectory = NewTempDirectory; var outputFileName = input.PartName + ".xml"; var process = new Process() { StartInfo = new ProcessStartInfo() { FileName = ApplicationData.ConverterExeName, Arguments = string.Format("\"{0}\" -TxJT2cojt -extIdMod 3 {1} -dest \"{2}\" -output \"{3}\"", new object[] { input.JTPath, input.PartClass ? "" : "-emsClass defaultResource", tempDirectory, outputFileName }), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }, EnableRaisingEvents = true }; if (process.Start()) { void processOutputDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs) => Console.WriteLine(dataReceivedEventArgs.Data); void processErrorDataReceived(object processObject, DataReceivedEventArgs dataReceivedEventArgs) => Console.Error.WriteLine(dataReceivedEventArgs.Data); void processExited(object processObject, EventArgs exitedEventArguments) { try { process.OutputDataReceived -= processOutputDataReceived; process.ErrorDataReceived -= processErrorDataReceived; process.Exited -= processExited; var pathToXMLDocument = Path.Combine(tempDirectory, outputFileName); if (File.Exists(pathToXMLDocument)) { var xmlDocument = XElement.Load(pathToXMLDocument); var fileNameElements = xmlDocument.Descendants("fileName").ToArray(); for (int i = 0, c = fileNameElements.Length; i < c; ++i) { var fileNameElement = fileNameElements[i]; var existingPath = fileNameElement.Value.TrimStart(new char[] { '#' }); var existingFileName = Path.GetFileNameWithoutExtension(existingPath); var newFileName = i.ToString() + ".cojt"; var newPath = Path.Combine(GetPathRelativeTo(input.OutputDirectory, ApplicationData.Service.SysRootPath).TrimStart(new char[] { Path.DirectorySeparatorChar }), newFileName); fileNameElement.SetValue("#" + newPath); var outputCOJTDirectory = Path.Combine(input.OutputDirectory, newFileName); try { Directory.CreateDirectory(outputCOJTDirectory); } catch (Exception e) { GUIDispatcher.Invoke(() => { ApplicationData.Service.Errors.Add(new TranslationError() { Timestamp = DateTime.Now, JTPath = outputCOJTDirectory, Description = e.Message }); }); throw new Exception(); } var existingJTFilePath = Path.Combine(existingPath, existingFileName + ".jt"); if (!File.Exists(existingJTFilePath)) { var existingJTFilePathTmp = Path.Combine(existingPath + ".tmp", existingFileName + ".jt"); if (!File.Exists(existingJTFilePathTmp)) { GUIDispatcher.Invoke(() => { ApplicationData.Service.Errors.Add(new TranslationError() { Timestamp = DateTime.Now, JTPath = input.JTPath, Description = String.Format("Conversion error: '{0}' not found.", existingJTFilePath) }); }); continue; } else { existingJTFilePath = existingJTFilePathTmp; } } var newJTFilePath = Path.Combine(outputCOJTDirectory, i.ToString() + ".jt"); try { File.Copy(existingJTFilePath, newJTFilePath, true); } catch (Exception e) { GUIDispatcher.Invoke(() => { ApplicationData.Service.Errors.Add(new TranslationError() { Timestamp = DateTime.Now, JTPath = existingJTFilePath, Description = e.Message }); }); } } promise.TrySetResult(new Tuple <XElement, string>(xmlDocument, outputFileName)); } else { GUIDispatcher.Invoke(() => { ApplicationData.Service.Errors.Add(new TranslationError() { Timestamp = DateTime.Now, JTPath = input.JTPath, Description = "Conversion failed: XML file was not created." }); }); throw new Exception(); } } catch (Exception) { /*GUIDispatcher.Invoke(() => * { * ApplicationData.Service.Errors.Add(new TranslationError() * { * Timestamp = DateTime.Now, * Description = exception.Message * }); * });*/ promise.TrySetResult(null); } finally { if (Directory.Exists(tempDirectory)) { try { Directory.Delete(tempDirectory, true); } catch (Exception) { } } } } process.OutputDataReceived += processOutputDataReceived; process.ErrorDataReceived += processErrorDataReceived; process.Exited += processExited; process.BeginOutputReadLine(); process.BeginErrorReadLine(); } return(promise); }