public async Task ClearAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            if (reliableDictionary == null)
            {
                await InitializeReliableDictionary();
            }

            await reliableDictionary.ClearAsync(timeout, cancellationToken);
        }
        public async Task ClearMessagesAsync()
        {
            IReliableDictionary <DateTime, Message> messagesDictionary =
                await this.StateManager.GetOrAddAsync <IReliableDictionary <DateTime, Message> >("messages");

            await messagesDictionary.ClearAsync();
        }
Beispiel #3
0
 private async Task ExecuteClearAsync(IReliableDictionary <string, Order> orders)
 {
     using (ITransaction tx = this.stateManager.CreateTransaction())
     {
         await orders.ClearAsync();
     }
 }
        public async Task <ConditionalValue <IReliableDictionary <TKey, TValue> > > TryCopyToReliableDictionary <TKey, TValue>(Dictionary <TKey, TValue> source, string targetKey, IReliableStateManager stateManager) where TKey : IComparable <TKey>, IEquatable <TKey>
        {
            var conditionalValue = await reliableStateManagerHelper.TryGetAsync <IReliableDictionary <TKey, TValue> >(stateManager, targetKey);

            if (!conditionalValue.HasValue)
            {
                return(new ConditionalValue <IReliableDictionary <TKey, TValue> >(false, null));
            }

            IReliableDictionary <TKey, TValue> reliableDictionary = conditionalValue.Value;

            using (ITransaction tx = stateManager.CreateTransaction())
            {
                await reliableDictionary.ClearAsync();

                var tasks = new List <Task>();

                foreach (var kvp in source)
                {
                    tasks.Add(reliableDictionary.SetAsync(tx, kvp.Key, kvp.Value));
                }

                Task.WaitAll(tasks.ToArray());
                await tx.CommitAsync();
            }

            return(new ConditionalValue <IReliableDictionary <TKey, TValue> >(true, reliableDictionary));
        }
        public async Task Clear()
        {
            DateTimeOffset now    = DateTimeOffset.Now;
            var            toKeep = new List <KeyValuePair <Guid, DateTimeOffset> >();

            using (ITransaction tx = this.sm.CreateTransaction())
            {
                var asyncEnumerable = await dictionary.CreateEnumerableAsync(tx);

                using (var asyncEnumerator = asyncEnumerable.GetAsyncEnumerator())
                {
                    while (await asyncEnumerator.MoveNextAsync(CancellationToken.None))
                    {
                        if ((now - asyncEnumerator.Current.Value).TotalSeconds < maxDelaySeconds)
                        {
                            toKeep.Add(asyncEnumerator.Current);
                        }
                    }
                }
                await dictionary.ClearAsync();

                foreach (var pair in toKeep)
                {
                    await dictionary.TryAddAsync(tx, pair.Key, pair.Value);
                }
                await tx.CommitAsync();

                lastClear = DateTimeOffset.Now;
            }
        }
Beispiel #6
0
        public async Task DeleteAllStoryPointEntries()
        {
            IReliableDictionary <Guid, perStoryData> storypointdata =
                await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, perStoryData> >("storypointdata");

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                await storypointdata.ClearAsync();

                await tx.CommitAsync();
            }
        }
        public async Task <ConditionalValue <IReliableDictionary <TKey, TValue> > > TryCopyToReliableDictionary <TKey, TValue>(string sourceKey, string targetKey, IReliableStateManager stateManager) where TKey : IComparable <TKey>, IEquatable <TKey>
        {
            var conditionalValue = await reliableStateManagerHelper.TryGetAsync <IReliableDictionary <TKey, TValue> >(stateManager, sourceKey);

            if (!conditionalValue.HasValue)
            {
                return(new ConditionalValue <IReliableDictionary <TKey, TValue> >(false, null));
            }

            IReliableDictionary <TKey, TValue> source = conditionalValue.Value;

            conditionalValue = await reliableStateManagerHelper.TryGetAsync <IReliableDictionary <TKey, TValue> >(stateManager, targetKey);

            if (!conditionalValue.HasValue)
            {
                return(new ConditionalValue <IReliableDictionary <TKey, TValue> >(false, null));
            }

            IReliableDictionary <TKey, TValue> target = conditionalValue.Value;

            using (ITransaction tx = stateManager.CreateTransaction())
            {
                await target.ClearAsync();

                var asyncEnumerable = await source.CreateEnumerableAsync(tx);

                var asyncEnumerator = asyncEnumerable.GetAsyncEnumerator();
                CancellationTokenSource tokenSource = new CancellationTokenSource();

                var tasks = new List <Task>();

                while (await asyncEnumerator.MoveNextAsync(tokenSource.Token))
                {
                    var currentEntry = asyncEnumerator.Current;
                    tasks.Add(target.SetAsync(tx, currentEntry.Key, currentEntry.Value));
                }

                Task.WaitAll(tasks.ToArray());
                await tx.CommitAsync();
            }

            return(new ConditionalValue <IReliableDictionary <TKey, TValue> >(true, target));
        }
Beispiel #8
0
 public Task ClearAsync(TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
 => m_dictionary.ClearAsync(timeout.DefaultToInfinite(), cancellationToken);
Beispiel #9
0
        private async Task SetScadaModel(string name, Dictionary <Tuple <RegisterType, int>, BasePoint> dictionary)
        {
            historian = new HistoryServiceProxy(ConfigurationReader.ReadValue(_context, "Settings", "History"));
            IReliableDictionary <int, BasePoint> result = null;

            using (var tx = _stateManager.CreateTransaction())
            {
                result = await _stateManager.GetOrAddAsync <IReliableDictionary <int, BasePoint> >(tx, name, TimeSpan.FromSeconds(60));

                if (dictionary == null)
                {
                    await result.ClearAsync();

                    await tx.CommitAsync();

                    return;
                }
                await tx.CommitAsync();
            }
            using (var tx = _stateManager.CreateTransaction())
            {
                var historyData = new List <HistoryDbModel>();
                foreach (var item in dictionary)
                {
                    var point = await result.TryGetValueAsync(tx, MakeKey(item.Key.Item1, item.Key.Item2), TimeSpan.FromSeconds(60), CancellationToken.None);

                    if (point.HasValue)
                    {
                        switch (item.Key.Item1)
                        {
                        case RegisterType.BINARY_INPUT:
                        case RegisterType.BINARY_OUTPUT:
                        {
                            ((DiscretePoint)point.Value).TimeStamp = (item.Value as DiscretePoint).TimeStamp;
                            if (((DiscretePoint)point.Value).Value != (item.Value as DiscretePoint).Value)
                            {
                                ((DiscretePoint)point.Value).Value = (item.Value as DiscretePoint).Value;
                                ((DiscretePoint)point.Value).Alarm = (item.Value as DiscretePoint).Alarm;
                                historyData.Add((((DiscretePoint)point.Value)).ToHistoryDbModel());
                            }
                            break;
                        }

                        case RegisterType.ANALOG_INPUT:
                        case RegisterType.ANALOG_OUTPUT:
                        {
                            ((AnalogPoint)point.Value).TimeStamp = (item.Value as AnalogPoint).TimeStamp;
                            if (((AnalogPoint)point.Value).Value != (item.Value as AnalogPoint).Value)
                            {
                                ((AnalogPoint)point.Value).Value = (item.Value as AnalogPoint).Value;
                                ((AnalogPoint)point.Value).Alarm = (item.Value as AnalogPoint).Alarm;
                                historyData.Add((((AnalogPoint)point.Value)).ToHistoryDbModel());
                            }

                            break;
                        }
                        }
                        await result.SetAsync(tx, MakeKey(item.Key.Item1, item.Key.Item2), point.Value, TimeSpan.FromSeconds(60), CancellationToken.None);
                    }
                    else
                    {
                        await result.SetAsync(tx, MakeKey(item.Key.Item1, item.Key.Item2), item.Value, TimeSpan.FromSeconds(60), CancellationToken.None);
                    }
                }
                await tx.CommitAsync();

                if (historyData.Count > 0)
                {
                    await historian.AddRange(historyData);
                }
            }
        }