Ejemplo n.º 1
0
        public async Task <IScanResourceModel> Save(IScanResourceModel scanResource)
        {
            if (null == scanResource)
            {
                return(null);
            }

            await this.Db.ScanResources.ReplaceOrInsertOneAsync((ScanResource)scanResource);

            return(scanResource);
        }
Ejemplo n.º 2
0
        protected sealed override async Task Execute(IObserver observer, CancellationToken cancellationToken)
        {
            using (IKamajiContext db = DI.Provider.GetService <IKamajiContext>())
            {
                IEnumerable <IScanModel> scanList = await this.GetScanList(db);

                if (null != scanList && scanList.Any())
                {
                    scanList = scanList.OrderBy(p => p.CreatedDate);
                    foreach (IScanModel scan in scanList)
                    {
                        INodeModel node = await ChoseNode(db, scan);

                        if (null != node)//eğer node bağlandıysa.
                        {
                            IScanResourceModel scanResource = await db.ScanResources.GetBy(scan.ScanResourceId);

                            if (null != scanResource)
                            {
                                string prerequisiteName = await db.ScanPrerequisites.GetNameBy(scanResource.ScanPrerequisiteId);

                                bool result = (await NodesClient.Instance.AssignScan(node, prerequisiteName, scanResource.Name, scan)) == 1;

                                if (result)
                                {
                                    scan.State = ScanState.Assigned;
                                    scan.LastAssignedNodeId = node.NodeId;
                                    await db.Scans.Edit(scan);

                                    observer.Notify("ScanQueueService.Execute", $"a {scan.Asset} of {scanResource.Name} job has been assign to a node which name  is '{node.Address}'.", null);
                                }
                                else
                                {
                                    scan.State = ScanState.AssignFailed;
                                    await OnAssingFailed(db, scan);

                                    observer.Notify("ScanQueueService.Execute", $"Warning!!!!. A {scan.Asset} of {scanResource.Name} job couldn't assign to a node which name  is '{node.Address}'.", null);
                                }
                            }
                        }
                        else
                        {
                            // scan.Enabled = false;//Burası biraz sıkıntılı
                            scan.State = ScanState.AssignFailed;
                            await OnAssingFailed(db, scan);

                            observer.Notify("ScanQueueService.Execute", $"Warning!!!!... Assigning has been failed. The scan asset: {scan.Asset}.", null);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        [HttpGet]//Node bunu çağırıyor.
        public Task <IActionResult> GetScanResourceBy(string name)
        {
            return(this.ResultAsync(async() =>
            {
                ScanResourceModel ret = null;
                if (!String.IsNullOrEmpty(name))
                {
                    IScanResourceModel entity = await this.Db.ScanResources.GetBy(name);
                    if (null != entity)
                    {
                        ret = new ScanResourceModel();
                        ret.CopyPropertiesFrom(entity);

                        ret.ScanPrerequisiteName = await this.Db.ScanPrerequisites.GetNameBy(entity.ScanPrerequisiteId);
                    }
                }

                return ret;
            }));
        }
Ejemplo n.º 4
0
        public Task <IActionResult> SaveScanResource(ScanResourceModel model)
        {
            return(this.ResultAsync(async() =>
            {
                int ret = 0;
                if (model.IsModelValid())
                {
                    IScanResourceModel entity = this.Db.ModelFactory.CreateScanResourceModel();
                    entity.CopyPropertiesFrom(model);
                    entity.CreatedDate = await this.Db.GetDbDateTime();
                    entity.LastModifiedDate = entity.CreatedDate;

                    if (!String.IsNullOrEmpty(model.ScanPrerequisiteName))
                    {
                        entity.ScanPrerequisiteId = await this.Db.ScanPrerequisites.GetScanPrerequisiteId(model.ScanPrerequisiteName);//a scan may not have an prerequest.
                    }
                    await this.Db.ScanResources.Save(entity);
                    ret = 1;
                }

                return ret;
            }));
        }