Exemple #1
0
        /// <summary>
        /// Creates an instance of a DynamicView. Must call <see cref="StartAsync"/> to send
        /// initial <see cref="DataEventTransaction"/> instance and listen for new <see cref="DataEventTransaction"/>instances.
        /// </summary>
        public DynamicView CreateDynamicView(string sql, dynamic values = null, string name = null, string[] keyFieldNames = null)
        {
            DynamicView dynamicQuery = new DynamicView(this, sql, values, name, keyFieldNames);

            this.dynamicViews.Add(dynamicQuery);
            return(dynamicQuery);
        }
Exemple #2
0
        protected async Task <DataEvent[]> GetInitialDataEventsAsync(DynamicView dynamicView)
        {
            DataEvent[] initialDataEvents = await dynamicView.GetInitialDataEventsAsync();

            dynamicView.ResetDirtyParams();
            dynamicView.UpdateChildDynamicParams(initialDataEvents);
            return(initialDataEvents);
        }
Exemple #3
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());
        }
Exemple #4
0
 protected string GetImpactedRecordsStorageKey(DynamicView dynamicView, DataEvent dataEvent, TransactionState transactionState)
 {
     return($"{dynamicView.Id} {dataEvent.id} {transactionState}");
 }