Exemple #1
0
        protected internal async Task <AuditScope> StartAsync()
        {
            _saveMode = SaveMode.InsertOnStart;
            // Execute custom on scope created actions
            await Configuration.InvokeScopeCustomActionsAsync(ActionType.OnScopeCreated, this);

            // Process the event insertion (if applies)
            if (_options.IsCreateAndSave)
            {
                EndEvent();
                await SaveEventAsync();

                _ended = true;
            }
            else if (_creationPolicy == EventCreationPolicy.InsertOnStartReplaceOnEnd || _creationPolicy == EventCreationPolicy.InsertOnStartInsertOnEnd)
            {
                await SaveEventAsync();

                _saveMode = _creationPolicy == EventCreationPolicy.InsertOnStartReplaceOnEnd ? SaveMode.ReplaceOnEnd : SaveMode.InsertOnEnd;
            }
            else if (_creationPolicy == EventCreationPolicy.InsertOnEnd)
            {
                _saveMode = SaveMode.InsertOnEnd;
            }
            else if (_creationPolicy == EventCreationPolicy.Manual)
            {
                _saveMode = SaveMode.Manual;
            }
            return(this);
        }
Exemple #2
0
        private async Task SaveEventAsync(bool forceInsert = false)
        {
            if (IsEndedOrDisabled())
            {
                return;
            }
            // Execute custom on event saving actions
            await Configuration.InvokeScopeCustomActionsAsync(ActionType.OnEventSaving, this);

            if (IsEndedOrDisabled())
            {
                return;
            }
            if (_eventId != null && !forceInsert)
            {
                await _dataProvider.ReplaceEventAsync(_eventId, _event);
            }
            else
            {
                _eventId = await _dataProvider.InsertEventAsync(_event);
            }
            // Execute custom after saving actions
            await Configuration.InvokeScopeCustomActionsAsync(ActionType.OnEventSaved, this);
        }