public override async Task <bool> SendExecutionLogToCentralDBAsync(LiteDB.ObjectId runsetId, Guid executionId, eDeleteLocalDataOnPublish deleteLocalData)
        {
            //Get the latest execution details from LiteDB
            LiteDbManager dbManager      = new LiteDbManager(new ExecutionLoggerHelper().GetLoggerDirectory(WorkSpace.Instance.Solution.LoggerConfigurations.CalculatedLoggerFolder));
            LiteDbRunSet  liteDbRunSet   = dbManager.GetLatestExecutionRunsetData(runsetId?.ToString());
            List <string> screenshotList = PopulateMissingFieldsAndGetScreenshotsList(liteDbRunSet, executionId);

            CentralExecutionLoggerHelper centralExecutionLogger = new CentralExecutionLoggerHelper(WorkSpace.Instance.Solution.LoggerConfigurations.CentralLoggerEndPointUrl);

            //Map the data to AccountReportRunset Object
            AccountReportRunSet accountReportRunSet = centralExecutionLogger.MapDataToAccountReportObject(liteDbRunSet);

            accountReportRunSet.ExecutionId = executionId;


            //Publish the Data and screenshots to Central DB
            await centralExecutionLogger.SendRunsetExecutionDataToCentralDBAsync(accountReportRunSet);

            await centralExecutionLogger.SendScreenShotsToCentralDBAsync(executionId, screenshotList);


            //Delete local data if configured
            if (deleteLocalData == eDeleteLocalDataOnPublish.Yes)
            {
                try
                {
                    dbManager.DeleteDocumentByLiteDbRunSet(liteDbRunSet);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Error when deleting local LiteDB data after Publis", ex);
                }


                foreach (string screenshot in screenshotList)
                {
                    try
                    {
                        File.Delete(screenshot);
                    }
                    catch (Exception ex)
                    {
                        Reporter.ToLog(eLogLevel.DEBUG, "Deleting screenshots after published to central db", ex);
                    }
                }
            }


            return(true);
        }
        public async System.Threading.Tasks.Task PublishToCentralDBAsync(LiteDB.ObjectId runsetId, Guid executionId)
        {
            if (Configuration.PublishLogToCentralDB == ExecutionLoggerConfiguration.ePublishToCentralDB.Yes)
            {
                try
                {
                    Reporter.ToLog(eLogLevel.INFO, string.Format("######## Publishing {0} Execution details to central DB", GingerDicser.GetTermResValue(eTermResKey.RunSet)));
                    Configuration.IsPublishToCentralDBRunning = true;

                    await mExecutionLogger.SendExecutionLogToCentralDBAsync(runsetId, executionId, Configuration.DeleteLocalDataOnPublish);

                    Reporter.ToLog(eLogLevel.INFO, string.Format("########################## Execution details Publish to Central DB Completed", GingerDicser.GetTermResValue(eTermResKey.RunSet)));
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Exception during Send exeuction data to central DB", ex);
                }
                finally
                {
                    Configuration.IsPublishToCentralDBRunning = false;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Insert a new document to this collection. Document Id must be a new value in collection - Returns document Id
        /// </summary>
        public virtual BsonValue Insert(T document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            // set an id value if document object needs
            this.Database.Mapper.SetAutoId(document, this.GetBsonCollection());

            var doc = this.Database.Mapper.ToDocument(document);

            BsonValue id;

            // add ObjectId to _id if _id not found
            if (!doc.RawValue.TryGetValue("_id", out id))
            {
                id = doc["_id"] = ObjectId.NewObjectId();
            }

            // test if _id is a valid type
            if (id.IsNull || id.IsMinValue || id.IsMaxValue)
            {
                throw LiteException.InvalidDataType("_id", id);
            }

            // serialize object
            var bytes = BsonSerializer.Serialize(doc);

            this.Database.Transaction.Begin();

            try
            {
                var col = this.GetCollectionPage(true);

                // storage in data pages - returns dataBlock address
                var dataBlock = this.Database.Data.Insert(col, bytes);

                // store id in a PK index [0 array]
                var pk = this.Database.Indexer.AddNode(col.PK, id);

                // do links between index <-> data block
                pk.DataBlock          = dataBlock.Position;
                dataBlock.IndexRef[0] = pk.Position;

                // for each index, insert new IndexNode
                foreach (var index in col.GetIndexes(false))
                {
                    var key = doc.Get(index.Field);

                    var node = this.Database.Indexer.AddNode(index, key);

                    // point my index to data object
                    node.DataBlock = dataBlock.Position;

                    // point my dataBlock
                    dataBlock.IndexRef[index.Slot] = node.Position;
                }

                this.Database.Transaction.Commit();

                return(id);
            }
            catch
            {
                this.Database.Transaction.Rollback();
                throw;
            }
        }