Beispiel #1
0
        protected async Task <DataEvent[]> GetInitialDataEventsAsync(DynamicView dynamicView)
        {
            DataEvent[] initialDataEvents = await dynamicView.GetInitialDataEventsAsync();

            dynamicView.ResetDirtyParams();
            dynamicView.UpdateChildDynamicParams(initialDataEvents);
            return(initialDataEvents);
        }
Beispiel #2
0
        protected DataEvent[] CreateDynamicViewDataEvents(DataEventTransaction dataEventTransaction, DynamicView dynamicView)
        {
            logger.Trace($"RunAsync():dynamicView.name={dynamicView.Name}");
            List <DataEvent> newRecordDataEvents = new List <DataEvent>();

            // Don't send data events if DynamicView has dirty params because
            // the DynamicView will be requeried anyways
            if (!dynamicView.HasDirtyParams)
            {
                HashSet <string> newRecordDataEventFullKeys = new HashSet <string>();
                foreach (var dataEvent in dataEventTransaction.dataEvents)
                {
                    if (dataEvent is KeyValueDataEvent keyValueDataEvent && dynamicView.TryGetDynamicStatementFromRef(keyValueDataEvent.name, out StatementFromRef dynamicStatementFromRef))
                    {
                        // Fetch the preCommitImpactedRecords
                        Dict[] preCommitImpactedRecords = null;
                        if (HasImpactedRecords(TransactionState.Uncommitted, dataEvent, dynamicStatementFromRef.joinType))
                        {
                            string storageKey = GetImpactedRecordsStorageKey(dynamicView, dataEvent, TransactionState.Uncommitted);
                            preCommitImpactedRecords = (Dict[])dataEventTransaction.Fetch(storageKey);
                        }

                        // Fetch the postCommitImpactedRecords
                        Dict[] postCommitImpactedRecords = null;
                        if (HasImpactedRecords(TransactionState.Committed, dataEvent, dynamicStatementFromRef.joinType))
                        {
                            string storageKey = GetImpactedRecordsStorageKey(dynamicView, dataEvent, TransactionState.Committed);
                            postCommitImpactedRecords = (Dict[])dataEventTransaction.Fetch(storageKey);
                        }

                        // Determine the changes from each data event on each dynamic select
                        RecordDataEvent[] recordDataEvents = dynamicView.ProcessDataChange(dataEvent, preCommitImpactedRecords, postCommitImpactedRecords);
                        if (recordDataEvents != null)
                        {
                            dynamicView.UpdateChildDynamicParams(recordDataEvents);
                            foreach (var recordDataEvent in recordDataEvents)
                            {
                                string fullKey = $"{recordDataEvent.name}:{recordDataEvent.keyValue}";
                                if (!newRecordDataEventFullKeys.Contains(fullKey))
                                {
                                    newRecordDataEventFullKeys.Add(fullKey);
                                    newRecordDataEvents.Add(recordDataEvent);
                                }
                            }
                        }
                    }
                }
            }

            return(newRecordDataEvents.ToArray());
        }