private MessageFromServerToClient HandleRequestForJob([NotNull] MessageFromClientToServer req)
        {
            if (OpenTasks.IsEmpty)
            {
                return(new MessageFromServerToClient(ServerResponseEnum.NothingToDo, req.TaskGuid));
            }

            bool success = OpenTasks.TryDequeue(out var task);

            if (success)
            {
                SaveExecuteHelper.Get().SaveExecuteWithWait(() => ActiveTasks.Add(task));
                task.Client         = req.ClientName;
                task.ExecutionStart = DateTime.Now;
                var answer = new MessageFromServerToClient(ServerResponseEnum.ServeCalcJob, task.Guid);
                answer.HouseJobStr = File.ReadAllText(task.OriginalJsonFilePath ??
                                                      throw new DistSimException("Jsonpath was not found: " + task.OriginalJsonFilePath));
                FileInfo fi = new FileInfo(task.OriginalJsonFilePath);
                answer.OriginalFileName = fi.Name;
                answer.LpgFiles         = InitalizeLpgFiles(false);
                return(answer);
            }

            return(new MessageFromServerToClient(ServerResponseEnum.NothingToDo, req.TaskGuid));
        }
 public void Enqueue([NotNull] T item)
 {
     SaveExecuteHelper.Get().SaveExecuteWithWait(() => {
         _queue.Enqueue(item);
         CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
         OnPropertyChanged(nameof(Count));
     });
 }
Ejemplo n.º 3
0
        public void TrackLastAnswer([NotNull] string reqClientName, [NotNull] MessageFromServerToClient answer)
        {
            string cleanname = CleanClientName(reqClientName);
            var    client    = ClientStatus.FirstOrDefault(x => x.ClientName == cleanname);

            if (client == null)
            {
                client = new ServerClientStatusTracker(cleanname);
                SaveExecuteHelper.Get().SaveExecuteWithWait(() => ClientStatus.Add(client));
            }

            client.LastRequestTime = DateTime.Now;
            client.LastTask        = answer.ServerResponse.ToString();
        }
        public bool TryDequeue([NotNull] out T item)
        {
            var success = _queue.TryDequeue(out var myItem);

            item = myItem;
            if (CollectionChanged != null)
            {
                SaveExecuteHelper.Get().SaveExecute(() => {
                    CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, myItem, 0));
                    OnPropertyChanged(nameof(Count));
                });
            }

            return(success);
        }
        private MessageFromServerToClient HandleFailureReport([NotNull] MessageFromClientToServer req)
        {
            var task = ActiveTasks.FirstOrDefault(x => x.Guid == req.TaskGuid);

            if (task == null)
            {
                throw new DistSimException("Invalid guid: " + req.TaskGuid);
            }

            task.FinishStatusMessage = req.ClientRequest + " " + req.Message;
            SaveExecuteHelper.Get().SaveExecuteWithWait(() => ActiveTasks.Remove(task));
            SaveExecuteHelper.Get().SaveExecuteWithWait(() => FinishedTasks.Add(task));
            _errorLogger.Error(task.OriginalJsonFilePath + " - no output at all at client " + req.ClientName, _threadId);
            Logger.Error(task.OriginalJsonFilePath + " - no output at all at client " + req.ClientName, _threadId);
            return(new MessageFromServerToClient(ServerResponseEnum.JobFinishAck, req.TaskGuid));
        }
 public MainWindow()
 {
     BindingErrorListener.Listen(m => {
         if (!m.Contains("FindAncestor"))
         {
             var s = m;
             var t = new Thread(() => MessageBox.Show(s));
             Console.WriteLine(m);
             t.Start();
         }
     });
     InitializeComponent();
     SaveExecuteHelper.Get().Dispatcher = Dispatcher;
     _applicationPresenter = new ApplicationPresenter();
     DataContext           = _applicationPresenter;
 }
Ejemplo n.º 7
0
        public void TrackLastRequest([NotNull] MessageFromClientToServer req)
        {
            string cleanname = CleanClientName(req.ClientName);
            var    client    = ClientStatus.FirstOrDefault(x => x.ClientName == cleanname);

            if (client == null)
            {
                client = new ServerClientStatusTracker(cleanname);
                SaveExecuteHelper.Get().SaveExecuteWithWait(() => ClientStatus.Add(client));
            }

            if (req.ClientRequest == ClientRequestEnum.ReportFinish)
            {
                client.CompletedJobs++;
            }

            if (req.ClientRequest == ClientRequestEnum.ReportFailure)
            {
                client.FailedJobs++;
            }
            client.LastRequestTime = DateTime.Now;
            client.LastRequest     = req.ClientRequest + " " + req.Message;
        }
        public MainWindowClient()
        {
            BindingErrorListener.Listen(m => {
                if (!m.Contains("FindAncestor"))
                {
                    var s = m;
                    var t = new Thread(() => MessageBox.Show(s));
                    Console.WriteLine(m);
                    t.Start();
                }
            });
            InitializeComponent();
            _applicationPresenter = new ApplicationPresenter();
            SaveExecuteHelper.Get().Dispatcher = Dispatcher;
            for (int i = 1; i <= _applicationPresenter.Settings.ClientSettings.NumberOfThreads; i++)
            {
                string workingDir = _applicationPresenter.Settings.ClientSettings.WorkingDirectory;
#pragma warning disable CA2000 // Dispose objects before losing scope
                string     logfilename = Path.Combine(workingDir, "DistCalc.Client." + i + ".Log.sqlite");
                DistLogger logger      = new DistLogger(logfilename, "Log", null);
#pragma warning restore CA2000 // Dispose objects before losing scope
                Settings cs = new Settings(_applicationPresenter.Settings);
                cs.ClientSettings.WorkingDirectory = Path.Combine(cs.ClientSettings.WorkingDirectory, "c" + i);
                ClientThread ct = new ClientThread(logger, cs, new ThreadId(Environment.MachineName, i));
                _clientThreads.Add(ct);
                var t = new Thread(() => ct.Run(ShowMessageBox));
                _threads.Add(t);
                t.Start();
                TabItem ti = new TabItem();
                ti.Header = "Client " + i;
                ClientView      cv = new ClientView();
                ClientPresenter cp = new ClientPresenter(ct, this);
                cv.DataContext = cp;
                ti.Content     = cv;
                MyTabControl.Items.Add(ti);
            }
        }
        private MessageFromServerToClient HandleTaskFinishReport([NotNull] MessageFromClientToServer req)
        {
            try {
                _logger.Info("got a finish report from " + req.ClientName + " for " + req.HouseName, _threadId);
                ServerExecutionTask set = ActiveTasks.FirstOrDefault(x => x.Guid == req.TaskGuid);
                if (set == null)
                {
                    return(new MessageFromServerToClient(ServerResponseEnum.JobFinishAck, req.TaskGuid));
                    //if it is an old task guid from previous run, just ignore the finish report
                    //throw new DistSimException("No task found for guid " + req.TaskGuid);
                }

                set.ExecutionEnd = DateTime.Now;
                SaveExecuteHelper.Get().SaveExecuteWithWait(() => ActiveTasks.Remove(set));
                SaveExecuteHelper.Get().SaveExecuteWithWait(() => {
                    FinishedTasks.Add(set);
                    while (FinishedTasks.Count > 20)
                    {
                        FinishedTasks.RemoveAt(0);
                    }
                });
                set.FinishStatusMessage = req.Message;
                var           resultFileArchiveDirectory = MakeResultFileDirectory(req);
                DirectoryInfo di = new DirectoryInfo(resultFileArchiveDirectory);
                if (di.Exists)
                {
                    _logger.Info("deleting previous results from  " + di.FullName, _threadId);
                    SaveDelete(di);
                    Thread.Sleep(250);
                }

                di.Create();
                _logger.Info("created " + di.FullName, _threadId);
                bool isFailure = false;
                if (req.ResultFiles != null)
                {
                    foreach (var jsonfile in req.ResultFiles)
                    {
                        string        directory = Path.Combine(resultFileArchiveDirectory, jsonfile.RelativeDirectory);
                        DirectoryInfo subdir    = new DirectoryInfo(directory);
                        if (!subdir.Exists)
                        {
                            subdir.Create();
                        }

                        string dstPath = Path.Combine(directory, jsonfile.FileName);
                        _logger.Info("writing " + dstPath + "," + "\nresult archive dir: " + resultFileArchiveDirectory + "\n relative dir: " +
                                     jsonfile.RelativeDirectory,
                                     _threadId);
                        jsonfile.WriteBytesFromJson(dstPath, Logger);
                        if (jsonfile.FileName.ToLower(CultureInfo.InvariantCulture) == "calculationexceptions.txt")
                        {
                            string fileContent = File.ReadAllText(dstPath);
                            _errorLogger.Error(set.OriginalJsonFilePath + " - error during calc " + fileContent, _threadId);
                            _logger.Error(set.OriginalJsonFilePath + " - error during calc " + fileContent, _threadId);
                            isFailure = true;
                        }
                    }
                }
                else
                {
                    _logger.Error("No result files were delivered", _threadId);
                }

                ArchiveJsonFile(set, isFailure);
                var answer = new MessageFromServerToClient(ServerResponseEnum.JobFinishAck, req.TaskGuid);
                return(answer);
            }
            catch (Exception ex) {
                _logger.Exception(ex, "Error while handling a finish report  " + ex.Message);
                throw;
            }
        }