コード例 #1
0
        public bool IsWorkingDirFull()
        {
            var di      = new DriveInfo(_mySettings.ClientSettings.WorkingDirectory.Substring(0, 1));
            var spaceGb = di.AvailableFreeSpace / 1024.0 / 1024 / 1024;

            _logger.Info(": Free Space on drive " + di.RootDirectory + ": " + spaceGb.ToString("N1", CultureInfo.CurrentCulture) + " GB", _threadId);
            if (spaceGb > 5)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
 public ClientThread([NotNull] DistLogger logger, [NotNull] Settings mySettings, [NotNull] ThreadId threadId)
 {
     _logger     = logger;
     _mySettings = mySettings;
     _threadId   = threadId;
     logger.Info("initalizing logger", threadId);
 }
コード例 #3
0
        public void Run()
        {
            DirectoryInfo lpgRawDir  = new DirectoryInfo(_settings.ClientSettings.LPGRawDirectory);
            DirectoryInfo workingDir = new DirectoryInfo(_settings.ClientSettings.LPGCalcDirectory);

            if (workingDir.Exists)
            {
                try {
                    workingDir.Delete(true);
                }
                catch (Exception ex) {
                    _logger.Error(ex.Message, _threadId);
                }

                Thread.Sleep(250);
            }

            workingDir.Create();
            FileInfo[] fis = lpgRawDir.GetFiles();
            foreach (FileInfo fi in fis)
            {
                string dstFullName = Path.Combine(workingDir.FullName, fi.Name);
                _logger.Info("DirectoryPreparer: Copying to " + dstFullName, _threadId);
                fi.CopyTo(dstFullName, true);
            }
        }
コード例 #4
0
        public static List <MsgFile> ReadMsgFiles(bool addFullFiles,
                                                  [NotNull][ItemNotNull] List <FileInfo> filteredFiles,
                                                  [NotNull] DirectoryInfo baseDir, [NotNull] DistLogger logger, [NotNull] ThreadId threadId)
        {
            var  lpgFiles  = new List <MsgFile>();
            long totalSize = 0;

            foreach (var fi in filteredFiles)
            {
                var relativeDirectory = "";
                if (fi.DirectoryName?.Length > baseDir.FullName.Length)
                {
                    relativeDirectory = fi.DirectoryName.Substring(baseDir.FullName.Length).Trim().Trim('\\');
                }

                MsgFile jf = new MsgFile(fi, relativeDirectory);
                if (addFullFiles)
                {
                    jf.FileContent = File.ReadAllBytes(fi.FullName);
                }

                totalSize += fi.Length;
                lpgFiles.Add(jf);
            }

            string prettySize = AutomationUtili.MakePrettySize(totalSize);

            logger.Info("Collected files with " + prettySize, threadId);
            return(lpgFiles);
        }
コード例 #5
0
 public ServerThread([NotNull] Settings settings, [NotNull] ThreadId threadId, [NotNull] DistLogger logger, [NotNull] DistLogger errorLogger)
 {
     _settings    = settings;
     _threadId    = threadId;
     _logger      = logger;
     _errorLogger = errorLogger;
     logger.Info("Initializing Server", _threadId);
 }
コード例 #6
0
        public void ExecuteCalcJob([NotNull] MessageFromServerToClient job, [NotNull] CalcExecutor calcExecutor, [NotNull] RequestSocket client)
        {
            var cdp = new CalcDirectoryPreparer(_mySettings, _logger, _threadId);

            cdp.Run();
            HouseCreationAndCalculationJob hcj = null;

            if (!string.IsNullOrWhiteSpace(job.HouseJobStr))
            {
                hcj = JsonConvert.DeserializeObject <HouseCreationAndCalculationJob>(job.HouseJobStr);
                if (hcj.CalcSpec == null)
                {
                    hcj.CalcSpec = JsonCalcSpecification.MakeDefaultsForProduction();
                }

                hcj.CalcSpec.OutputDirectory = "Results";
                string jsonFileName = Path.Combine(_mySettings.ClientSettings.LPGCalcDirectory, "calcjob.json");
                string correctedJob = JsonConvert.SerializeObject(hcj, Formatting.Indented);
                File.WriteAllText(jsonFileName, correctedJob);
                calcExecutor.Run(hcj);
            }
            else
            {
                _logger.Info("Client #" + _threadId + ": Got a task with an exe, not real, waiting 5s", _threadId);
                Thread.Sleep(5000);
            }

            ReportFinishedCalcJob(job, client, hcj);
        }
コード例 #7
0
        public void RefreshOpenTasks()
        {
            if (_settings.ServerSettings.JsonDirectory == null)
            {
                throw new DistSimException("Jsondirectory was null");
            }

            if (_settings.ServerSettings.JsonDirectory.Count == 0)
            {
                throw new DistSimException("Jsondirectory was empty");
            }

            foreach (string singledir in _settings.ServerSettings.JsonDirectory)
            {
                if (OpenTasks.Count > 1000)
                {
                    break;
                }

                DirectoryInfo di = new DirectoryInfo(singledir);
                if (!di.Exists)
                {
                    di.Create();
                    Thread.Sleep(100);
                }
                var files         = di.GetFiles("*.json");
                var activeFiles   = ActiveTasks.Select(x => x.OriginalJsonFilePath).ToList();
                var openTaskFiles = OpenTasks.Select(x => x.OriginalJsonFilePath).ToList();
                foreach (var fileInfo in files)
                {
                    if (activeFiles.Contains(fileInfo.FullName))
                    {
                        _logger.Info("Currently processing " + fileInfo.Name, _threadId);
                        continue;
                    }

                    if (openTaskFiles.Contains(fileInfo.FullName))
                    {
                        _logger.Info("Currently in queue " + fileInfo.Name, _threadId);
                        continue;
                    }

                    ServerExecutionTask set = new ServerExecutionTask(fileInfo.FullName, fileInfo.Name, Guid.NewGuid().ToString());
                    OpenTasks.Enqueue(set);
                    _logger.Info("Created a job for " + fileInfo.Name, _threadId);
                    if (OpenTasks.Count > 1000)
                    {
                        break;
                    }
                }
            }
        }