コード例 #1
0
        private void btnAddTemplate_Click(object sender, System.EventArgs e)
        {
            var     microwave = Wrap(() => _service.GetMicroWave());
            Int16   timeleft  = microwave.TimeLeft;
            Potency potency   = microwave.Potency;

            if (microwave.CurrentJob != null)
            {
                timeleft = microwave.CurrentJob.Template.TimeLeft;
                potency  = microwave.CurrentJob.Template.Potency;
            }

            var newJobTemplate = new JobTemplate(timeleft, potency)
            {
                CanDelete    = true,
                Default      = false,
                Instructions = txtOutput.Text,
                Name         = txtSearchTemplate.Text,
                MealKind     = GetSelectedMealKind(),
                Dot          = txtSearchTemplate.Text[0]
            };

            var ds = Wrap(() => _service.SaveTemplate(newJobTemplate));

            if (ds != null)
            {
                txtSearchTemplate.Text = String.Empty;
                lbxTemplate.DataSource = ds;
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a job template.
        /// </summary>
        /// <returns></returns>
        public static JobTemplate CreateJobTemplate()
        {
            JobTemplate jobTemplate = JobTemplate.NewWorkerJobTemplate(Assembly.GetExecutingAssembly());
            // add job-specific input files to the template.  These will get streamed to the Server and downloaded to the Agents.
            // tree file
            FileDef fd = jobTemplate.FileDefs.Add();

            fd.Name         = Constants.TreeFileDefName;
            fd.TransferType = TransferType.Streamed;
            fd.Relevance    = Relevance.JobPlaceholder;
            fd.LocalName    = "tree$(JobId).txt";
            // predictor file
            fd              = jobTemplate.FileDefs.Add();
            fd.Name         = Constants.PredictorFileDefName;
            fd.TransferType = TransferType.Streamed;
            fd.Relevance    = Relevance.JobPlaceholder;
            fd.LocalName    = "predictor$(JobId).txt";
            // target file (not an output file!)
            fd              = jobTemplate.FileDefs.Add();
            fd.Name         = Constants.TargetFileDefName;
            fd.TransferType = TransferType.Streamed;
            fd.Relevance    = Relevance.JobPlaceholder;
            fd.LocalName    = "target$(JobId).txt";
            // skip row index file (this requires special handling below because it may be null)
            fd              = jobTemplate.FileDefs.Add();
            fd.Name         = Constants.SkipRowIndexFileDefName;
            fd.TransferType = TransferType.Streamed;
            fd.Relevance    = Relevance.JobPlaceholder;
            fd.LocalName    = "skipRowIndex$(JobId).txt";

            return(jobTemplate);
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,DateAssigned,DateCompleted,Points,CategoryId")] JobTemplate jobTemplate)
        {
            if (id != jobTemplate.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _jobTemplateService.UpdateAsync(jobTemplate);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await JobTemplateExists(jobTemplate.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(await _jobCategoryService.GetAllAsync(), "Id", "Name", jobTemplate.CategoryId);
            return(View(jobTemplate));
        }
コード例 #4
0
        public static JobTemplate CreateJobTemplate(string jobTemplate1)
        {
            JobTemplate jobTemplate = new JobTemplate();

            jobTemplate.JobTemplate1 = jobTemplate1;
            return(jobTemplate);
        }
コード例 #5
0
        public void TestAddCustomTemplate()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.SaveTemplate(newTemplate);
            var actual = _service.GetTemplateByNameKind(newTemplate.Name, newTemplate.MealKind).First();

            Assert.AreEqual(newTemplate, actual);
        }
コード例 #6
0
        public IList <JobTemplate> SaveTemplate(JobTemplate newTemplate)
        {
            if (String.IsNullOrEmpty(newTemplate.Name?.Trim()))
            {
                throw new Exception("Please give a name for the new template.");
            }

            _microwave.SaveTemplate(newTemplate);
            return(_microwave.GetTemplateByNameKind(String.Empty, newTemplate.MealKind));
        }
コード例 #7
0
        private void ValidateInput(JobTemplate template)
        {
            if (template == null)
            {
                throw new Exception("Por favor informe um aquecimento válido.");
            }

            ValidateTimeleft(template.TimeLeft);
            ValidatePotency((Int32)template.Potency);
        }
コード例 #8
0
        public IList <JobTemplate> DeleteTemplate(JobTemplate template, MealKind?mealkind)
        {
            if (!template.CanDelete)
            {
                throw new Exception("Cannot delete a pre-made template.");
            }

            _microwave.DeleteTemplate(template);
            return(_microwave.GetTemplateByNameKind(String.Empty, mealkind));
        }
コード例 #9
0
        public void TestResetPotency()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.Cancel();
            _service.SetJobTemplate(newTemplate);
            Assert.AreEqual(Potency.Eight, _service.GetMicroWave().Potency);

            _service.ResetPotency(10);
            Assert.AreEqual(Potency.Ten, _service.GetMicroWave().CurrentJob.Potency);
        }
コード例 #10
0
        public void TestResetTimleft()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.Cancel();
            _service.SetJobTemplate(newTemplate);
            Assert.AreEqual(30, _service.GetMicroWave().TimeLeft);

            _service.ResetTimeleft(DateTime.MinValue.AddSeconds(1));
            Assert.AreEqual(1, _service.GetMicroWave().CurrentJob.TimeLeft);
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("Id,Name,DateAssigned,DateCompleted,Points,CategoryId")] JobTemplate jobTemplate)
        {
            if (ModelState.IsValid)
            {
                await _jobTemplateService.AddAsync(jobTemplate);

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["CategoryId"] = new SelectList(await _jobCategoryService.GetAllAsync(), "Id", "Name", jobTemplate.CategoryId);
            return(View(jobTemplate));
        }
コード例 #12
0
ファイル: Job.cs プロジェクト: Mixi59/Stump
        /// <summary>
        /// Instantiate a job without record, experience equals zero
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="template"></param>
        public Job(Character owner, JobTemplate template)
        {
            Owner    = owner;
            Record   = null;
            Template = template;

            var level = ExperienceManager.Instance.GetJobLevel(Experience);

            LowerBoundExperience = ExperienceManager.Instance.GetJobLevelExperience(level);
            UpperBoundExperience = ExperienceManager.Instance.GetJobNextLevelExperience(level);
            Level = level;
        }
コード例 #13
0
    public JobTemplate GetJobTemplate(string projectId, string location, string templateId)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the job template name.
        JobTemplateName name = JobTemplateName.FromProjectLocationJobTemplate(projectId, location, templateId);

        // Call the API.
        JobTemplate jobTemplate = client.GetJobTemplate(name);

        // Return the result.
        return(jobTemplate);
    }
コード例 #14
0
ファイル: JobManager.cs プロジェクト: Mixi59/Stump
        public Pair <int, int> GetHarvestItemMinMax(JobTemplate job, int jobLevel, InteractiveSkillTemplate skillTemplate)
        {
            if (skillTemplate.LevelMin > jobLevel)
            {
                return(new Pair <int, int>(0, 0));
            }

            if (skillTemplate.LevelMin == 200 || job.HarvestedCountMax == 0)
            {
                return(new Pair <int, int>(1, 1));
            }

            return(new Pair <int, int>(Math.Max(1, jobLevel / 20),
                                       (int)(job.HarvestedCountMax + ((jobLevel - skillTemplate.LevelMin) / 10))));
        }
コード例 #15
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (JobTemplate == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "JobTemplate");
     }
     if (Schedule == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "Schedule");
     }
     if (JobTemplate != null)
     {
         JobTemplate.Validate();
     }
 }
コード例 #16
0
        public void TestJobTemplate()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.SetJobTemplate(newTemplate);
            var expected = _service.SerializeCurrentJobTemplateToJson();

            var options = new JsonSerializerOptions
            {
                WriteIndented = true
            };

            var actual = JsonSerializer.Serialize(_service.GetMicroWave().CurrentJob.Template, options);

            Assert.AreEqual(expected, actual);
        }
コード例 #17
0
        public void TestFailResetPotency()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.Cancel();
            _service.SetJobTemplate(newTemplate);
            Assert.AreEqual(Potency.Eight, _service.GetMicroWave().Potency);

            var ex1 = Assert.Throws <Exception>(() => _service.ResetPotency(11));

            Assert.That(ex1.Message, Is.EqualTo("A potência máxima é Dez."));

            var ex2 = Assert.Throws <Exception>(() => _service.ResetPotency(0));

            Assert.That(ex2.Message, Is.EqualTo("Por favor informe uma potência entre Um e Dez.."));
        }
コード例 #18
0
        public void TestFailResetTimeleft()
        {
            JobTemplate newTemplate = GetNewTemplate();

            _service.Cancel();
            _service.SetJobTemplate(newTemplate);
            Assert.AreEqual(30, _service.GetMicroWave().TimeLeft);

            var ex1 = Assert.Throws <Exception>(() => _service.ResetTimeleft(DateTime.MinValue));

            Assert.That(ex1.Message, Is.EqualTo("Por favor informe um tempo entre um segundo e dois minutos."));

            var ex2 = Assert.Throws <Exception>(() => _service.ResetTimeleft(DateTime.MinValue.AddSeconds(121)));

            Assert.That(ex2.Message, Is.EqualTo("O tempo de aquecimento não pode ser superior a dois minutos."));
        }
コード例 #19
0
ファイル: JobIndexDialog.cs プロジェクト: Mixi59/Stump
        public void RequestAvailableCrafters(JobTemplate job)
        {
            if (m_lastRequestedJob != null)
            {
                m_lastRequestedJob.CrafterUnSubscribed -= LastRequestedJobOnCrafterUnSubscribed;
                m_lastRequestedJob.CrafterSubscribed   -= LastRequestedJobOnCrafterSubscribed;
                m_lastRequestedJob.CrafterRefreshed    -= LastRequestedJobOnCrafterRefreshed;
            }

            m_lastRequestedJob = job;
            m_lastRequestedJob.CrafterUnSubscribed += LastRequestedJobOnCrafterUnSubscribed;
            m_lastRequestedJob.CrafterSubscribed   += LastRequestedJobOnCrafterSubscribed;
            m_lastRequestedJob.CrafterRefreshed    += LastRequestedJobOnCrafterRefreshed;

            InventoryHandler.SendJobCrafterDirectoryListMessage(Character.Client, job.AvailableCrafters.Select(x => x.Jobs[job.Id]));
        }
コード例 #20
0
ファイル: AMD_APP.cs プロジェクト: tr002196/GrinbleMiner
        public void StartSolving()
        {
            if (Devices.All(d => !d.Allow))
            {
                return;
            }

            Log(Level.Info, $"Starting {Devices.Count(d => d.Allow)} solvers...");

            solvingTasks.Clear();

            solvingTasks.AddRange((Devices as Device.AMD[]).AsParallel().Where(d => d.Allow).Select(device =>
            {
                return(Task.Factory.StartNew(() => StartSolvingByDevice(device), TaskCreationOptions.LongRunning));
            }).AsEnumerable());

            currentJob = NetworkInterface.Pool.Handler.CurrentJob;
            NetworkInterface.Pool.Handler.OnNewJob += OnNewJobHandler;
        }
コード例 #21
0
        private void UpdateJobTemplate(JObject jMessage)
        {
            if (jMessage.ContainsKey("result"))
            {
                var tempJob = JsonConvert.DeserializeObject <JobTemplate>(jMessage["result"].ToString(), serializeSettings);
                if (tempJob == null || string.IsNullOrWhiteSpace(tempJob.PrePOW))
                {
                    return;
                }

                tempJob.SetOrigin(this);

                if (CurrentJob == null || (CurrentJob.JobID != tempJob.JobID || CurrentJob.Height != tempJob.Height))
                {
                    lastUpdateTime = DateTime.Now;
                    CurrentJob     = tempJob;
                    Log(Level.Info, false, $"New job #{CurrentJob.JobID} detected, height: {CurrentJob.Height}, difficulty: {CurrentJob.Difficulty}");
                }
            }
        }
コード例 #22
0
        private void UpdateJob(string @params)
        {
            var tempJob = JsonConvert.DeserializeObject <JobTemplate>(@params, serializeSettings);

            if (tempJob == null || string.IsNullOrWhiteSpace(tempJob.PrePOW))
            {
                return;
            }

            tempJob.SetOrigin(this);

            if (tempJob.GetScale() == 1)
            {
                Log(Level.Warn, false, $"Invalid PrePOW:{Environment.NewLine}{CurrentJob.PrePOW}");
            }

            else if (CurrentJob == null || (CurrentJob.JobID != tempJob.JobID || CurrentJob.Height != tempJob.Height))
            {
                lastUpdateTime = DateTime.Now;
                CurrentJob     = tempJob;
                Log(Level.Info, false, $"New job #{CurrentJob.JobID} detected, height: {CurrentJob.Height}, difficulty: {CurrentJob.Difficulty}");
            }
        }
コード例 #23
0
    public JobTemplate CreateJobTemplate(
        string projectId, string location, string templateId)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the parent location name.
        LocationName parentLocation = new LocationName(projectId, location);

        // Build the job template config.
        VideoStream videoStream0 = new VideoStream
        {
            H264 = new VideoStream.Types.H264CodecSettings
            {
                BitrateBps   = 550000,
                FrameRate    = 60,
                HeightPixels = 360,
                WidthPixels  = 640
            }
        };

        VideoStream videoStream1 = new VideoStream
        {
            H264 = new VideoStream.Types.H264CodecSettings
            {
                BitrateBps   = 2500000,
                FrameRate    = 60,
                HeightPixels = 720,
                WidthPixels  = 1280
            }
        };

        AudioStream audioStream0 = new AudioStream
        {
            Codec      = "aac",
            BitrateBps = 64000
        };

        ElementaryStream elementaryStream0 = new ElementaryStream
        {
            Key         = "video_stream0",
            VideoStream = videoStream0
        };

        ElementaryStream elementaryStream1 = new ElementaryStream
        {
            Key         = "video_stream1",
            VideoStream = videoStream1
        };

        ElementaryStream elementaryStream2 = new ElementaryStream
        {
            Key         = "audio_stream0",
            AudioStream = audioStream0
        };

        MuxStream muxStream0 = new MuxStream
        {
            Key               = "sd",
            Container         = "mp4",
            ElementaryStreams = { "video_stream0", "audio_stream0" }
        };

        MuxStream muxStream1 = new MuxStream
        {
            Key               = "hd",
            Container         = "mp4",
            ElementaryStreams = { "video_stream1", "audio_stream0" }
        };

        JobConfig jobConfig = new JobConfig
        {
            ElementaryStreams = { elementaryStream0, elementaryStream1, elementaryStream2 },
            MuxStreams        = { muxStream0, muxStream1 }
        };

        JobTemplate newJobTemplate = new JobTemplate
        {
            Config = jobConfig
        };

        // Call the API.
        JobTemplate jobTemplate = client.CreateJobTemplate(parentLocation, newJobTemplate, templateId);

        return(jobTemplate);
    }
コード例 #24
0
 public async Task <JobTemplate> UpdateAsync(JobTemplate entity)
 {
     return(await unitOfWork.JobTemplates.UpdateAsync(entity));
 }
コード例 #25
0
 public void SetJobTemplate(JobTemplate template)
 {
     this._microwave.SetJobTemplate(template);
 }
コード例 #26
0
ファイル: JobIndexDialog.cs プロジェクト: Mixi59/Stump
 private void LastRequestedJobOnCrafterRefreshed(JobTemplate jobTemplate, Character character)
 {
     InventoryHandler.SendJobCrafterDirectoryAddMessage(Character.Client, character.Jobs[jobTemplate.Id]);
 }
コード例 #27
0
ファイル: JobIndexDialog.cs プロジェクト: Mixi59/Stump
 private void LastRequestedJobOnCrafterUnSubscribed(JobTemplate jobTemplate, Character character)
 {
     InventoryHandler.SendJobCrafterDirectoryRemoveMessage(Character.Client, character.Jobs[jobTemplate.Id]);
 }
コード例 #28
0
        static void Main(string[] args)
        {
            try {
                // before using the ArgCollection class, let the DigipedeClient grab its args.
                DigipedeClient client = new DigipedeClient();
                args = client.ProcessArguments(args, true);
                ArgCollection argCollection = ArgCollection.GetInstance(args);

                // show help, if requested
                if (argCollection.ExtractOptionalFlag("help"))
                {
                    Console.WriteLine("");
                    Console.WriteLine(UsageMessage);
                    Console.WriteLine(HelpMessage);
                    return;
                }

                // fail if the DigipedeClient doesn't have the args
                SpecialFunctions.CheckCondition(client.IsInitialized, "Digipede Client didn't initialize.");



                string keepTestName = argCollection.ExtractOptional("keepTest", "AlwaysKeep");
                string skipRowIndexFileNameOrNull = argCollection.ExtractOptional <string>("skipRowIndexFile", null);
                string optimizerName = argCollection.ExtractOptional("optimizer", "BrentThenGrid");

                argCollection.CheckNoMoreOptions();

                int pieceCount = argCollection.ExtractNext <int>("pieceCount");
                //int taskPerJobCount = argCollection.ExtractNext<int>("taskPerJobCount");  -- we're not using this -- keep it in case we want to put it back
                string          treeFileName          = argCollection.ExtractNext <string>("treeFile");
                string          predictorFileName     = argCollection.ExtractNext <string>("predictorFile");
                string          targetFileName        = argCollection.ExtractNext <string>("targetFile");
                string          leafDistributionName  = argCollection.ExtractNext <string>("leafDistribution");
                string          nullDataGeneratorName = argCollection.ExtractNext <string>("nullDataGenerator");
                string          niceName                 = argCollection.ExtractNext <string>("niceName");
                string          outputDirectoryName      = argCollection.ExtractNext <string>("outputDirectory");
                RangeCollection nullIndexRangeCollection = argCollection.ExtractNext <RangeCollection>("nullIndexRange");
                SpecialFunctions.CheckCondition(nullIndexRangeCollection.IsBetween(-1, int.MaxValue), "nullIndex must be at least -1");

                argCollection.CheckThatEmpty();

                Directory.CreateDirectory(outputDirectoryName);

                // Define a JobTemplate for PhyloD.
                JobTemplate jobTemplate = CreateJobTemplate();
                // Require 32 bit (ensures we use WOW64 on 64-bit machines) since SpecialFunctions.dll built for x86.
                jobTemplate.Control.UseWow64On64Bit = true;
                // allow task failures (all but one failure will result in job success)
                jobTemplate.JobDefaults.MaxFailures = pieceCount - 1;
                // allow multiple concurrent tasks (one for each core); each isolated in its own process.
                jobTemplate.Control.Concurrency           = ApplicationConcurrency.MultiplePerCore;
                jobTemplate.Control.ProcessHostingOptions = HostingOptions.ManySingleUse;


                // create a Job based on that JobTemplate
                Job job = jobTemplate.NewJob();

                // add job-specific data / files
                FileDefCollection fileDefs = job.FileDefs;
                // files
                Utility.GetNamedFileDef(fileDefs, Constants.TreeFileDefName).RemoteName      = treeFileName;
                Utility.GetNamedFileDef(fileDefs, Constants.PredictorFileDefName).RemoteName = predictorFileName;
                Utility.GetNamedFileDef(fileDefs, Constants.TargetFileDefName).RemoteName    = targetFileName;
                // skipRowIndex file is more complicated because it may not exist, but the JobTemplate requires it.
                FileDef fileDef = Utility.GetNamedFileDef(fileDefs, Constants.SkipRowIndexFileDefName);
                if (skipRowIndexFileNameOrNull == null || skipRowIndexFileNameOrNull == "null")
                {
                    // stream an empty file
                    fileDef.Stream = new MemoryStream(0);
                }
                else
                {
                    // stream the actual file
                    fileDef.LocalName = skipRowIndexFileNameOrNull;
                }

                // Create the tasks for the template
                for (int pieceIndex = 0; pieceIndex < pieceCount; pieceIndex++)
                {
                    // Create a Task for this piece
                    Task task = job.NewTask();
                    // Create an InputData object to encapsulate all input data in one place
                    InputData inputData = new InputData(optimizerName, keepTestName, leafDistributionName, nullDataGeneratorName,
                                                        niceName, outputDirectoryName, pieceIndex, pieceCount, nullIndexRangeCollection.ToString());
                    // create a Worker for this task
                    task.Worker = new PhyloDWorker(inputData);
                }

                // Wire events to catch result data.  Note that retrieving data isn't necessary here --
                // data can be requested in a server call from another process.
                job.TaskCompleted += job_TaskCompleted;

                // Write an event to catch any monitoring errors
                client.MonitoringError += client_MonitoringError;

                // submit the job
                SubmissionResult sr = client.SubmitJob(jobTemplate, job);
                Console.WriteLine("Submitted job {0} with {1} tasks.", sr.JobId, job.Tasks.Count);

                // wait for the result
                JobStatusSummary jss = client.WaitForJobWithStatus(sr.JobId);
                Console.WriteLine("Job finished with status of {0}", jss.Status);
            }
            catch (Exception exception)
            {
                Console.WriteLine("");
                Console.WriteLine(exception.Message);
                if (exception.InnerException != null)
                {
                    Console.WriteLine(exception.InnerException.Message);
                }

                Console.WriteLine("");
                Console.WriteLine(UsageMessage);
                throw;
            }
        }
コード例 #29
0
ファイル: AMD_APP.cs プロジェクト: tr002196/GrinbleMiner
 private void OnNewJobHandler(NetworkInterface.Pool.Stratum currentStratum, JobTemplate newJob)
 {
     currentJob = newJob;
 }