コード例 #1
0
ファイル: JobQueueManager.cs プロジェクト: cburriss/SyncObjX
        public static bool?QueueRequestIsComplete(Guid queueRequestId)
        {
            object _lock = new object();

            lock (_lock)
            {
                JobQueueRequest queueRequest;

                queueRequestsById.TryGetValue(queueRequestId, out queueRequest);

                if (queueRequest == null)
                {
                    return(null);
                }
                else
                {
                    switch (queueRequest.Status)
                    {
                    case JobQueueRequestStatus.Waiting:
                    case JobQueueRequestStatus.InProgress:
                        return(false);

                    case JobQueueRequestStatus.Completed:
                        return(true);

                    default:
                        throw new EnumValueNotImplementedException <JobQueueRequestStatus>(queueRequest.Status);
                    }
                }
            }
        }
コード例 #2
0
        public void RunPoller()
        {
            if (downloadPollerTask == null || downloadPollerTask.IsCompleted)
            {
                downloadPollerTask = Task.Run(async() =>
                {
                    while (HasWork())
                    {
                        try
                        {
                            await Task.Delay(1000);

                            DownloadHelper helper;
                            if (!string.IsNullOrWhiteSpace(currentId) && downloads.TryGetValue(currentId, out helper))
                            {
                                if (helper.State == DownloadHelper.DownloadState.Canceled)
                                {
                                    continue;
                                }
                                if (helper.State == DownloadHelper.DownloadState.Downloading)
                                {
                                    continue;
                                }
                                if (helper.State != DownloadHelper.DownloadState.Completed)
                                {
                                    await helper.StartDownload();
                                    continue;
                                }
                            }
                            var next = downloads.FirstOrDefault();
                            if (string.IsNullOrWhiteSpace(next.Key))
                            {
                                continue;
                            }
                            helper = next.Value;
                            if (helper.State == DownloadHelper.DownloadState.Canceled)
                            {
                                continue;
                            }
                            if (helper.State == DownloadHelper.DownloadState.Downloading)
                            {
                                continue;
                            }
                            if (helper.State != DownloadHelper.DownloadState.Completed)
                            {
                                await helper.StartDownload();
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManager.Shared.Report(ex);
                        }
                    }
                });
            }
        }
コード例 #3
0
        protected override View ViewFor(int section, int row)
        {
            var tuple = new Tuple <int, int>(section, row);

            if (!CurrentViews.TryGetValue(tuple, out var view) || (view?.IsDisposed ?? true))
            {
                CurrentViews[tuple] = view = Cell(section, row);
                view.Parent         = this;
            }
            return(view);
        }
コード例 #4
0
        public void Copy()
        {
            var keys   = new object[245];
            var values = new object[245];

            for (int i = 0; i < 245; i++)
            {
                keys[i]   = new object();
                values[i] = new object();
            }

            var indexes = new EntryIndex <object> [245];

            for (int i = 0; i < 245; i++)
            {
                var key   = keys[i];
                var value = values[i];

                FixedSizeDictionary.AddOrReplace(key, value, out var index);
                indexes[i] = index;

                Assert.True(FixedSizeDictionary.ContainsKey(index));
                Assert.True(FixedSizeDictionary.ContainsKey(key));
                Assert.True(FixedSizeDictionary.TryGetValue(key, out var actualValue));

                Assert.Equal(value, actualValue);

                Assert.True(FixedSizeDictionary.TryGetValue(index, out actualValue));

                Assert.Equal(value, actualValue);
            }

            var destination = new FixedSizeDictionary <object, object, EqualityComparers.ReferenceEqualityComparer <object> >(15, 17, new EqualityComparers.ReferenceEqualityComparer <object>());

            FixedSizeDictionary.CopyTo(destination);
            FixedSizeDictionary.Clear();

            for (int i = 0; i < 245; i++)
            {
                var key   = keys[i];
                var value = values[i];
                destination.TryGetIndex(key, out var index);

                Assert.True(destination.ContainsKey(index));
                Assert.True(destination.ContainsKey(key));
                Assert.True(destination.TryGetValue(key, out var actualValue));

                Assert.Equal(value, actualValue);

                Assert.True(destination.TryGetValue(index, out actualValue));

                Assert.Equal(value, actualValue);
            }
        }
コード例 #5
0
        public object this[ChainSegment segment]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                var knownVariableIndex = (int)segment.WellKnownVariable;
                if (segment.WellKnownVariable != WellKnownVariable.None && _wellKnownVariables[knownVariableIndex].IsNotEmpty)
                {
                    return(_data[_wellKnownVariables[knownVariableIndex]]);
                }

                return(_data.TryGetValue(segment, out var value) ? value : null);
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            set
            {
                var knownVariableIndex = (int)segment.WellKnownVariable;
                if (segment.WellKnownVariable != WellKnownVariable.None)
                {
                    _data.AddOrReplace(segment, value, out _wellKnownVariables[knownVariableIndex]);
                    return;
                }

                _data.AddOrReplace(segment, value, out _);
            }
        }
コード例 #6
0
        protected override View ViewFor(int index)
        {
            var item = List[index];

            if (!CurrentViews.TryGetValue(item, out var view) || (view?.IsDisposed ?? true))
            {
                CurrentViews[item] = view = Cell(item);
                view.Parent        = this;
            }
            return(view);
        }
コード例 #7
0
        public override bool Play()
        {
            var success = CurrentPlayer?.Play() ?? false;

            if (!success && CurrentSong != null)
            {
                isVideoDict.TryGetValue(CurrentSongId, out var isVideo);
                PlaySong(currentSong, isVideo);
                return(true);
            }
            SetVideo(CurrentPlayer);
            return(success);
        }
コード例 #8
0
ファイル: JobQueueManager.cs プロジェクト: cburriss/SyncObjX
        public static bool?JobInstanceIsComplete(Guid jobInstanceId)
        {
            object _lock = new object();

            lock (_lock)
            {
                JobInstance jobInstance;

                jobInstancesById.TryGetValue(jobInstanceId, out jobInstance);

                if (jobInstance == null)
                {
                    return(null);
                }
                else
                {
                    switch (jobInstance.Status)
                    {
                    case JobQueueStatus.Scheduled:
                    case JobQueueStatus.Delayed_NoAvailableThread:
                    case JobQueueStatus.InProgress:
                    case JobQueueStatus.InProgress_MaxDelayExceeded:
                        return(false);

                    case JobQueueStatus.DidNotRun_ErrorWithinQueueRequest:
                    case JobQueueStatus.Terminated_WithError:
                    case JobQueueStatus.Completed_WithError:
                    case JobQueueStatus.Completed:
                        return(true);

                    default:
                        throw new EnumValueNotImplementedException <JobQueueStatus>(jobInstance.Status);
                    }
                }
            }
        }
コード例 #9
0
        public void AddOrReplace()
        {
            var objects = new object[245];

            for (int i = 0; i < 245; i++)
            {
                objects[i] = new object();
            }

            for (int iteration = 0; iteration < 5; iteration++)
            {
                for (int i = 0; i < 245; i++)
                {
                    var key   = objects[i];
                    var value = new object();

                    FixedSizeDictionary.AddOrReplace(key, value, out var index);

                    Assert.True(FixedSizeDictionary.ContainsKey(index));
                    Assert.True(FixedSizeDictionary.ContainsKey(key));
                    Assert.True(FixedSizeDictionary.TryGetValue(key, out var actualValue));

                    Assert.Equal(value, actualValue);

                    Assert.True(FixedSizeDictionary.TryGetValue(index, out actualValue));

                    Assert.Equal(value, actualValue);
                }
            }
        }