예제 #1
0
        public async Task AddOrGetExisting_ValueIsRebuildAfterInvalidation()
        {
            string testValue                      = "value1";
            string testkey                        = "key1";
            int    valueGeneratedTimes            = 0;
            Func <Task <TestValue> > valueFactory = () =>
            {
                valueGeneratedTimes++;
                return(Task.FromResult(new TestValue(testValue)));
            };

            var cache = TaskCache.Create(k => valueFactory());

            var value1 = await cache.AddOrGetExistingAsync(testkey)
                         .ConfigureAwait(false);

            Assert.True(testValue == value1.Value);

            var value2 = await cache.AddOrGetExistingAsync(testkey)
                         .ConfigureAwait(false);

            Assert.True(testValue == value2.Value);

            Assert.True(1 == valueGeneratedTimes, "Value should be generated only once.");

            cache.Invalidate(testkey);

            var value3 = await cache.AddOrGetExistingAsync(testkey)
                         .ConfigureAwait(false);

            Assert.True(testValue == value3.Value);

            Assert.True(2 == valueGeneratedTimes, "Value should be regenerated after invalidation.");
        }
 public DataStaxEnterpriseSuggestedVideos(ISession session, TaskCache<string, PreparedStatement> statementCache, IRestClient restClient)
 {
     if (session == null) throw new ArgumentNullException("session");
     if (statementCache == null) throw new ArgumentNullException("statementCache");
     _session = session;
     _restClient = restClient;
 }
        private void dgv_taskList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            switch (dgv_taskList.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString())
            {
            case "通过":
                if (MessageBoxEx.Show("确定审批通过?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var taskId = (int)dgv_taskList.Rows[e.RowIndex].Cells["taskId"].Value;
                    TaskCache.updateTaskState(taskId, (int)TaskStateEnum.Passed);
                    init(_taskStateArray, _style);
                }
                break;

            case "驳回":
                TaskReject tr = new AviationSafetyExperiment.TaskReject();
                if (tr.ShowDialog() == DialogResult.OK)
                {
                    string remark = tr.rejectReason;
                    var    taskId = (int)dgv_taskList.Rows[e.RowIndex].Cells["taskId"].Value;
                    TaskCache.updateTaskState(taskId, (int)TaskStateEnum.Rejected, remark);
                    init(_taskStateArray, _style);
                }
                break;

            case "打开任务":
                var taskInfoId = (int)dgv_taskList.Rows[e.RowIndex].Cells["taskId"].Value;
                //this.Parent
                if (dgv_taskList.Rows[e.RowIndex].Cells["taskStateName"].Value.ToString() == "未审批" && this.Parent.Name == "expandablePanel_new")
                {
                }
                else
                {
                    TaskExecuteForm tef = new AviationSafetyExperiment.TaskExecuteForm(taskInfoId);
                    tef.init(_taskStateArray[0]);    //用于打开任务时,取第一个任务状态
                    tef.ShowDialog(this);
                }
                break;

            case "完成":
                if (MessageBoxEx.Show("确定任务完成?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var taskId = (int)dgv_taskList.Rows[e.RowIndex].Cells["taskId"].Value;
                    TaskCache.updateTaskState(taskId, (int)TaskStateEnum.Completed);
                    init(_taskStateArray, _style);
                }
                break;

            case "关闭":
                if (MessageBoxEx.Show("确定关闭任务?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    var taskId = (int)dgv_taskList.Rows[e.RowIndex].Cells["taskId"].Value;
                    TaskCache.updateTaskState(taskId, (int)TaskStateEnum.Closed);
                    init(_taskStateArray, _style);
                }
                break;

            default:
                break;
            }
        }
        public EncodingListenerJob(CloudQueueClient cloudQueueClient, ISession session, TaskCache <string, PreparedStatement> statementCache, IBus bus)
        {
            if (cloudQueueClient == null)
            {
                throw new ArgumentNullException("cloudQueueClient");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (statementCache == null)
            {
                throw new ArgumentNullException("statementCache");
            }
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }

            _cloudQueueClient = cloudQueueClient;
            _session          = session;
            _statementCache   = statementCache;
            _bus = bus;

            _initialized = false;
        }
예제 #5
0
        public void createTask()
        {
            indicatorIdList = its.getSelectedIndicatorIdList();
            if (indicatorIdList.Count == 0)
            {
                MessageBoxEx.Show("请选择指标模板,并从中选取要测试的指标", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            Tb_taskInfo task = new Db.Entity.Tb_taskInfo();

            task.percent      = 0;
            task.taskRound    = 1;
            task.taskClass    = (int)cbb_taskClass.SelectedValue;
            task.taskCode     = txt_taskCode.Text.Trim();
            task.taskExecutor = ccb_taskExecutor.Text;//txt_taskExecutor.Text.Trim();
            task.taskName     = txt_taskName.Text.Trim();
            task.taskType     = taskType;
            task.taskState    = (int)TaskStateEnum.Created;
            task.createTime   = DateTime.Now;
            try
            {
                TaskCache.createTask(task, indicatorIdList, brandModelIdDic);
                MessageBox.Show("任务创建成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Parent.Controls.Remove(this);
            }
            catch (Exception ex)
            {
                MessageBox.Show("任务创建失败,原因是:" + ex.Message, "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #6
0
 public SuggestVideos(ISession session, TaskCache<string, PreparedStatement> statementCache)
 {
     if (session == null) throw new ArgumentNullException("session");
     if (statementCache == null) throw new ArgumentNullException("statementCache");
     _session = session;
     _statementCache = statementCache;
 }
예제 #7
0
        public PublishVideoWhenProcessingComplete(ISession session, TaskCache <string, PreparedStatement> statementCache,
                                                  IBus bus, CloudMediaContext cloudMediaContext)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (statementCache == null)
            {
                throw new ArgumentNullException("statementCache");
            }
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }
            if (cloudMediaContext == null)
            {
                throw new ArgumentNullException("cloudMediaContext");
            }
            _session           = session;
            _statementCache    = statementCache;
            _bus               = bus;
            _cloudMediaContext = cloudMediaContext;

            _random = new Random();
        }
 public DataStaxEnterpriseSearch(ISession session, TaskCache<string, PreparedStatement> statementCache)
 {
     if (session == null) throw new ArgumentNullException("session");
     if (statementCache == null) throw new ArgumentNullException("statementCache");
     _session = session;
     _statementCache = statementCache;
 }
예제 #9
0
 public EncodeVideoWhenAcceptedHandler(ISession session, TaskCache <string, PreparedStatement> statementCache, IBus bus, CloudMediaContext cloudMediaContext,
                                       INotificationEndPoint notificationEndPoint)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     if (bus == null)
     {
         throw new ArgumentNullException("bus");
     }
     if (cloudMediaContext == null)
     {
         throw new ArgumentNullException("cloudMediaContext");
     }
     if (notificationEndPoint == null)
     {
         throw new ArgumentNullException("notificationEndPoint");
     }
     _session              = session;
     _statementCache       = statementCache;
     _bus                  = bus;
     _cloudMediaContext    = cloudMediaContext;
     _notificationEndPoint = notificationEndPoint;
 }
예제 #10
0
        public static T GetTask <T>(TaskCache task)
            where T : CacheObject, new()
        {
            var t = new T();

            t.SetClone(task.Id, task.CreateDate);
            return(DCT.Execute(c => c.HubClient.RSendQueryObject("GetTask", obj: t)));
        }
예제 #11
0
 public TaskList()
 {
     ProcessCache = new TaskCache
     {
         Name      = null,
         Processes = Process.GetProcesses().ToList()
     };
 }
 public VideoCatalogService(ISession session, TaskCache<string, PreparedStatement> statementCache, IBus bus)
 {
     if (session == null) throw new ArgumentNullException("session");
     if (statementCache == null) throw new ArgumentNullException("statementCache");
     _session = session;
     _statementCache = statementCache;
     _bus = bus;
 }
예제 #13
0
 public TaskList(string name)
 {
     ProcessCache = new TaskCache
     {
         Name      = name,
         Processes = Process.GetProcessesByName(name).ToList()
     };
 }
예제 #14
0
 public MessagePump(IMessageReceiver receiver, int maxDegreeOfParallelism)
 {
     _receiver = receiver;
     _receiver.InvokeMessageHandler = OnMessageReceived;
     _maxDegreeOfParallelism        = maxDegreeOfParallelism;
     _cache     = new TaskCache();
     _throttler = new TaskThrottler(maxDegreeOfParallelism, _cache);
 }
예제 #15
0
 private Task ToEntity2(TaskCache arg1, Task arg2)
 {
     arg2.ErrorDescription = arg1.Error;
     arg2.LastStep         = arg1.LastStep;
     arg2.Ip = arg1.Ip;
     arg2.IsAnonimousProxy = arg1.IsAnonimousProxy;
     return(arg2);
 }
예제 #16
0
 private void btn_pass_Click(object sender, EventArgs e)
 {
     if (MessageBoxEx.Show("确定审批通过?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
     {
         TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Passed);
         MainFormAdapter.reloadTaskApproval();
         this.Close();
     }
 }
예제 #17
0
 private void ben_close_Click(object sender, EventArgs e)
 {
     if (MessageBoxEx.Show("您确定要关闭此测试任务?" + Environment.NewLine + "任务关闭后将无法对剩余的指标进行测试。", "操作警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Closed);
         MainFormAdapter.reloadTaskMainPanel();
         this.Close();
     }
 }
 public RefreshYouTubeVideoSourcesJob(ISession session, TaskCache <string, PreparedStatement> statementCache, ISampleDataService sampleDataService)
     : base(session, statementCache)
 {
     if (sampleDataService == null)
     {
         throw new ArgumentNullException("sampleDataService");
     }
     _sampleDataService = sampleDataService;
 }
예제 #19
0
 public AddSampleCommentsJob(ISession session, TaskCache <string, PreparedStatement> statementCache, ISampleDataService sampleDataService)
     : base(session, statementCache)
 {
     if (sampleDataService == null)
     {
         throw new ArgumentNullException("sampleDataService");
     }
     _sampleDataService = sampleDataService;
 }
예제 #20
0
        /// <summary>
        /// 检查任务是否第一次打开。如是,则更新任务状态为“已开始”,同时添加任务生命周期
        /// </summary>
        private void checkAndSignFirstOpen()
        {
            var isPassed = TaskLifecycleCache.getCache().FirstOrDefault(l => l.taskId == taskInfoId && l.taskState == (int)TaskStateEnum.Passed);
            var isOpened = TaskLifecycleCache.getCache().FirstOrDefault(l => l.taskId == taskInfoId && l.taskState == (int)TaskStateEnum.Running);

            if (isPassed != null && isOpened == null)//如果审批通过,但从未打开过
            {
                TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Running);
            }
        }
예제 #21
0
        public async Task AddOrGetExisting_FailedTasksAreNotPersisted()
        {
            string testValue        = "value1";
            string testkey          = "key1";
            string exceptionMessage = "First two calls will fail.";

            int valueGeneratedTimes = 0;
            Func <Task <TestValue> > valueFactory = () =>
            {
                valueGeneratedTimes++;

                return(Task.Factory.StartNew(() =>
                {
                    if (valueGeneratedTimes <= 2)
                    {
                        throw new Exception(
                            exceptionMessage);
                    }
                    return new TestValue(testValue);
                }));
            };

            var cache = TaskCache.Create(k => valueFactory());


            var cacheTask = cache.AddOrGetExistingAsync(testkey);

            await SilentlyHandleFaultingTaskAsync(cacheTask, exceptionMessage)
            .ConfigureAwait(false);

            Assert.True(cacheTask.IsFaulted, "First value generation should fail.");
            Assert.True(1 == valueGeneratedTimes, "Value should be build 1 times.");

            cacheTask = cache.AddOrGetExistingAsync(testkey);
            await SilentlyHandleFaultingTaskAsync(cacheTask, exceptionMessage)
            .ConfigureAwait(false);

            Assert.True(cacheTask.IsFaulted, "Second value generation should fail.");
            Assert.True(2 == valueGeneratedTimes, "Value should be build 2 times, because first failed.");

            cacheTask = cache.AddOrGetExistingAsync(testkey);
            var cacheValue = await cacheTask.ConfigureAwait(false);

            Assert.True(cacheTask.IsCompleted, "Value generation should succeed the third time.");
            Assert.True(3 == valueGeneratedTimes, "Value should be build 3 times, because first two times failed.");
            Assert.True(testValue == cacheValue.Value, "Cache should return correct value.");

            cacheTask  = cache.AddOrGetExistingAsync(testkey);
            cacheValue = await cacheTask.ConfigureAwait(false);

            Assert.True(cacheTask.IsCompleted, "Value generation should succeed the fourth time.");
            Assert.True(3 == valueGeneratedTimes,
                        "Value should be build 3 times, because first two times failed, but third succeeded.");
            Assert.True(testValue == cacheValue.Value, "Cache should return correct value.");
        }
예제 #22
0
        protected SampleDataJob(ISession session, TaskCache<string, PreparedStatement> statementCache)
        {
            if (session == null) throw new ArgumentNullException("session");
            if (statementCache == null) throw new ArgumentNullException("statementCache");
            _session = session;
            _statementCache = statementCache;

            _jobName = GetType().FullName;
            _logger = LogManager.GetLogger(GetType());
            NextRunTime = DateTimeOffset.MaxValue;
        }
 public Task <long> PublishAsync(string channel, string value)
 {
     if (this.IsConnected)
     {
         return(this.multiplexer.GetSubscriber().PublishAsync(channel, value));
     }
     else
     {
         return(TaskCache.FromResult(0L));
     }
 }
        public AddSampleYouTubeVideosJob(ISession session, TaskCache<string, PreparedStatement> statementCache, ISampleDataService sampleDataService,
                                         IManageSampleYouTubeVideos youTubeManager, IGetSampleData sampleDataRetriever)
            : base(session, statementCache)
        {
            if (sampleDataService == null) throw new ArgumentNullException("sampleDataService");
            if (youTubeManager == null) throw new ArgumentNullException("youTubeManager");
            if (sampleDataRetriever == null) throw new ArgumentNullException("sampleDataRetriever");

            _sampleDataService = sampleDataService;
            _youTubeManager = youTubeManager;
            _sampleDataRetriever = sampleDataRetriever;
        }
 public void init(int taskId)
 {
     taskInfo = TaskCache.getCacheById(taskId);
     if (taskInfo == null)
     {
         MessageBoxEx.Show("未能查询到测试任务");
     }
     else
     {
         bindTaskInfo();
     }
 }
예제 #26
0
        private void btn_reject_Click(object sender, EventArgs e)
        {
            TaskReject tr = new AviationSafetyExperiment.TaskReject();

            if (tr.ShowDialog() == DialogResult.OK)
            {
                string remark = tr.rejectReason;
                TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Rejected, remark);
                MainFormAdapter.reloadTaskApproval();
                this.Close();
            }
        }
예제 #27
0
        public async Task AddOrGetExisting_ReturnsValueFromValueFactory()
        {
            string testValue = "value1";
            Func <Task <TestValue> > valueFactory = () => Task.FromResult(new TestValue(testValue));

            var cache = TaskCache.Create(k => valueFactory());

            var value = await cache.AddOrGetExistingAsync("key1")
                        .ConfigureAwait(false);

            Assert.True(testValue == value.Value);
        }
 public Task <KeyValuePair <string, string>[]> GetConfigAsync()
 {
     if (this.IsConnected)
     {
         var server = this.GetServer();
         return(server.ConfigGetAsync());
     }
     else
     {
         return(TaskCache.FromResult(new KeyValuePair <string, string>[] { }));
     }
 }
        public LinqUserManagementService(ISession session, TaskCache<string, PreparedStatement> statementCache, IBus bus)
        {
            if (session == null) throw new ArgumentNullException("session");
            if (statementCache == null) throw new ArgumentNullException("statementCache");
            if (bus == null) throw new ArgumentNullException("bus");
            _session = session;
            _statementCache = statementCache;
            _bus = bus;

            _userProfileTable = new Table<UserProfile>(session);
            _userCredentialsTable = new Table<UserCredentials>(session);
        }
 public SearchVideosByTag(ISession session, TaskCache <string, PreparedStatement> statementCache)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     _session        = session;
     _statementCache = statementCache;
 }
 public RecordVideosAddedHandler(ISession session, TaskCache <string, PreparedStatement> statementCache)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     _session        = session;
     _statementCache = statementCache;
 }
        public WindowsServiceBusMessagePump(string queueName, string connectionString, int maxDegreeOfParalism, int preFetch = 10)
        {
            _namespaceManager     = NamespaceManager.CreateFromConnectionString(connectionString);
            _messagingFactory     = MessagingFactory.Create(_namespaceManager.Address, _namespaceManager.Settings.TokenProvider);
            _client               = QueueClient.CreateFromConnectionString(connectionString, queueName);
            _client.PrefetchCount = PrefetchCount;

            _messageOptions = new OnMessageOptions();
            _messageOptions.AutoComplete       = false;
            _messageOptions.MaxConcurrentCalls = maxDegreeOfParalism;

            _cache = new TaskCache();
        }
 public StatisticsService(ISession session, TaskCache <string, PreparedStatement> statementCache)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     _session        = session;
     _statementCache = statementCache;
 }
예제 #34
0
 public GetSampleData(ISession session, TaskCache <string, PreparedStatement> statementCache)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     _session        = session;
     _statementCache = statementCache;
 }
 public UserManagementService(ISession session, TaskCache <string, PreparedStatement> statementCache, IBus bus)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (statementCache == null)
     {
         throw new ArgumentNullException("statementCache");
     }
     _session        = session;
     _statementCache = statementCache;
     _bus            = bus;
 }
 public EncodingListenerJob(CloudQueueClient cloudQueueClient, ISession session, TaskCache<string, PreparedStatement> statementCache, IBus bus)
 {
     if (cloudQueueClient == null) throw new ArgumentNullException("cloudQueueClient");
     if (session == null) throw new ArgumentNullException("session");
     if (statementCache == null) throw new ArgumentNullException("statementCache");
     if (bus == null) throw new ArgumentNullException("bus");
     
     _cloudQueueClient = cloudQueueClient;
     _session = session;
     _statementCache = statementCache;
     _bus = bus;
     
     _initialized = false;
 }
예제 #37
0
 private void btn_done_Click(object sender, EventArgs e)
 {
     if (checkCanDone() == false)
     {
         MessageBoxEx.Show("您尚有未填写的指标测试结果,无法完成任务。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Completed);
         MainFormAdapter.reloadTaskMainPanel();
         MessageBoxEx.Show("任务已设置为【完成】状态");
         this.Close();
     }
 }
예제 #38
0
        public LeaseManager(ISession session, TaskCache<string, PreparedStatement> statementCache, LeaseManagerConfig config)
        {
            if (session == null) throw new ArgumentNullException("session");
            if (statementCache == null) throw new ArgumentNullException("statementCache");
            if (config == null) throw new ArgumentNullException("config");
            
            _session = session;
            _statementCache = statementCache;
            _leaseName = config.LeaseName;
            _uniqueId = config.UniqueId;

            // Start by assuming we are not the lease owner
            _leaseOwnerUntil = DateTimeOffset.MinValue;
        }
예제 #39
0
        private TaskCache ToCache2(Task arg2)
        {
            var arg1  = new TaskCache();
            var board = BCT.Context.BulletinDb.Boards.Find(arg2.BoardId);

            if (board != null)
            {
                arg1.Board = board.Name;
            }
            arg1.Command    = arg2.CommandEnum.ToString();
            arg1.StateDesc  = arg2.StateEnum.ToString();
            arg1.TargetDate = arg2.TargetDate;
            return(arg1);
        }
 public AddSampleCommentsJob(ISession session, TaskCache<string, PreparedStatement> statementCache, ISampleDataService sampleDataService) 
     : base(session, statementCache)
 {
     if (sampleDataService == null) throw new ArgumentNullException("sampleDataService");
     _sampleDataService = sampleDataService;
 }
예제 #41
0
 public TaskCache CreateTaskCache()
 {
     var cache = new TaskCache(TimeSpan.FromMilliseconds(CacheFactory.GetExpirationTime()));
     new TreeCacheGarbageCollector(cache, CacheFactory.GetArchiveDumpingTime(), taskDumper);
     return cache;
 }
 public RefreshYouTubeVideoSourcesJob(ISession session, TaskCache<string, PreparedStatement> statementCache, ISampleDataService sampleDataService) 
     : base(session, statementCache)
 {
     if (sampleDataService == null) throw new ArgumentNullException("sampleDataService");
     _sampleDataService = sampleDataService;
 }