Ejemplo n.º 1
0
        public override void FinishJob(GridJob job, ILog logger)
        {
            var count = 0;

            foreach (var task in job.JobTasks)
            {
                if (task.OutputFile?.Bytes != null)
                {
                    try {
                        count += int.Parse(Encoding.UTF8.GetString(task.OutputFile.Bytes));
                    } catch {
                        ;
                    }
                }
            }

            logger.Info($"Total count is '{count}'");
            File.WriteAllText(GridIo.ResolveFilePathShared(job, job.JobOutFile.FileName), $"{count}");
        }
Ejemplo n.º 2
0
        public override void ExecuteTask(GridTaskExecutor executor, GridJobTask task, ILog logger)
        {
            var inputFilePath = GridIo.ResolveFilePathShared(task.ParentJob, task.Arguments[0]);

            if (!File.Exists(inputFilePath))
            {
                throw new Exception($"Unable to load task input file '{task.Arguments[0]}', not found by present path '{inputFilePath}'");
            }

            byte[] buffer;
            using (var fs = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read)) {
                var startPos = long.Parse(task.Arguments[1]);
                var endPos   = long.Parse(task.Arguments[2]);

                buffer = new byte[endPos - startPos];
                fs.Seek(startPos, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
            }

            var needleCount  = 0;
            var needleString = task.Arguments[4];

            using (var sr = new StreamReader(new MemoryStream(buffer))) {
                var all = sr.ReadToEnd();

                for (var i = 0; i < all.Length; i++)
                {
                    if (SearchSubstringAt(all, needleString, i))
                    {
                        needleCount++;
                        i += needleString.Length;
                    }
                }
            }

            logger.Info($"Find '{needleCount}' in block");
            executor.WriteFileOutput(task, task.Arguments[3], $"{needleCount}");
        }