Example #1
0
        internal async Task<int> SaveScanInstance(ScanInstanceModel model)
        {
            int ret = 0;
            if (model.IsModelValid())
            {
                IScanInstanceModel entity = this.Db.ModelFactory.CreateScanInstanceModel();
                entity.CopyPropertiesFrom(model);

                (bool allowSave, object nodeId, object scanResourceId, IScanModel scan) = await this.GetScanIds(model);

                if (allowSave)
                {
                    entity.NodeId = nodeId;
                    entity.ScanId = scan.ScanId;

                    await this.Db.ScanInstances.Save(entity);
                    await this.CheckMaxInstance(scan);
                    ret = 1;

                    ConsoleObserver.Instance.Notify(nameof(ScanWorks) + "_" + nameof(SaveScanInstance), "A scan result has been got and saved.", model);
                }
                else
                {
                    ConsoleObserver.Instance.Notify(nameof(ScanWorks) + "_" + nameof(SaveScanInstance), "A scan result has been got but the value was null or empty.", model);
                }
            }

            return ret;
        }
        public async Task <IScanInstanceModel> Save(IScanInstanceModel scanInstance)
        {
            if (null == scanInstance)
            {
                return(null);
            }

            await this.Db.ScanInstances.ReplaceOrInsertOneAsync((ScanInstance)scanInstance);

            return(scanInstance);
        }