private void TransitionToFinalStatus(ActivityContextStatus status, ActivityEventArgs eventArgs)
        {
            bool flag = false;

            try
            {
                int num;
                try
                {
                    this.spinLock.Enter(ref flag);
                    num         = this.status;
                    this.status = (int)status;
                }
                finally
                {
                    if (flag)
                    {
                        this.spinLock.Exit();
                    }
                }
                if (num == 0)
                {
                    this.stopwatch.Stop();
                    this.endTime = new DateTime?(DateTime.UtcNow);
                    ExTraceGlobals.ActivityContextTracer.TraceDebug <Guid, ActivityContextStatus>((long)this.LocalId.GetHashCode(), "ActivityScopeImpl.TransitionToFinalStatus key {0}, Status={1}.", this.LocalId, status);
                    ActivityContext.RaiseEvent(this, eventArgs);
                }
            }
            finally
            {
                this.Dispose();
                ActivityContext.ClearThreadScope();
            }
        }
示例#2
0
            /// <param name="task">アクティビティのタスク</param>
            /// <param name="handler">タスク終了時のイベントハンドラ</param>
            /// <returns>アクティビティスレッド</returns>
            protected Thread Create(ActivityTask task, ActivityEventHandler handler)
            {
                ThreadStart start = new ThreadStart(delegate
                {
                    ActivityEventArgs args = new ActivityEventArgs();
                    try
                    {
                        task();
                        args.IsCompleted = true;
                    }
                    catch (ThreadAbortException ex)
                    {
                        args.IsAborted = true;
                        args.Exception = ex;
                    }
                    catch (Exception ex)
                    {
                        args.Exception = ex;
                    }
                    finally
                    {
                        MotorControler mc = MotorControler.GetInstance(parameterManager);
                        mc.AbortMoving();
                        mc.SlowDownStopAll();

                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                });

                return(Create(start));
            }
示例#3
0
 /// <summary>
 /// 表面認識処理にて,上ゲル上部を認識したときのイベントハンドラです.
 /// </summary>
 private void surfaceUpTop_Recognized(object sender, ActivityEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(delegate {
         string message = string.Format(Properties.Strings.SurfaceUpTopRecognizing, e.ZValue);
         WriteLine(message);
     }), null);
 }
示例#4
0
        /// <summary>
        /// 表面認識処理が終了したときのイベントハンドラです.
        /// </summary>
        private void surface_Exited(object sender, ActivityEventArgs e)
        {
            string message = "";

            if (e.IsAborted)
            {
                message = Properties.Strings.AbortedSurfaceRecognizing;
            }
            else if (e.IsCompleted)
            {
                message = Properties.Strings.SurfaceComplete;
            }
            else if (!e.IsCompleted && !e.IsAborted)
            {
                message = string.Format(
                    "{0} {1}: {2}",
                    Properties.Strings.Surface,
                    Properties.Strings.Error,
                    e.Exception.Message);
            }
            Dispatcher.BeginInvoke(new Action(delegate {
                WriteLine(message);
                window.IsTabsEnabled = true;
            }), null);
            IsControllable = true;
        }
示例#5
0
        private void ActivityUpdated(object sender, ActivityEventArgs e)
        {
            var activity = e.Activity;
            var outlet   = activity.Outlet;

            var outletViewModel = FindOutletViewModel(outlet);

            if (outletViewModel != null)
            {
                var acitivityId        = activity.Id;
                var activityViewModels = outletViewModel.Activities;
                for (var index = 0; index < activityViewModels.Count; index++)
                {
                    var activityViewModel = activityViewModels[index];
                    if (activityViewModel.Activity.Id == acitivityId)
                    {
                        activityViewModels[index] = new ActivityViewModel(outletViewModel, activity);
                        break;
                    }
                }

                this.Sort();
                this.ApplyCurrentTextSearch();
            }
        }
示例#6
0
 private void ActivityReceived(object sender, ActivityEventArgs e)
 {
     if (string.Equals(e.Activity.Type, "message")) // only add messages to our list
     {
         Messages.Add(e.Activity);
     }
 }
示例#7
0
 /// <summary>
 /// 撮影処理が行われたときのイベントハンドラ
 /// </summary>
 private void accumImage_OnShot(object sender, ActivityEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(delegate() {
         AccumImage accumImage = AccumImage.GetInstance(parameterManager);
         progressBar.Value     = accumImage.CompletePercent;
         shootNumLabel.Content = accumImage.NumOfShots.ToString();
     }), null);
 }
示例#8
0
        private void View_RaiseActivityAddedEvent(object sender, ActivityEventArgs e)
        {
            LastActivity = e.Description;
            IStorage storage = new CsvFileStorage(_baseDataPath, _fileExtension);

            storage.SaveActivity(e.TimeStamp, Interval, e.Description);
            _view.Output($@"{Properties.Resources.BL_ScreenSavedInfo} ({DateTime.Now:t})");
        }
        /// <summary>
        /// Raises the Activity event.
        /// </summary>
        /// <param name="e">An ActivityEventArgs that contains the event data.</param>
        protected virtual void OnActivity(ActivityEventArgs e)
        {
            EventHandler <ActivityEventArgs> eh = Activity;

            if (eh != null)
            {
                eh(this, e);
            }
        }
示例#10
0
        protected virtual void OnActivityChanged(ActivityEventArgs e)
        {
            var handler = ActivityChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
示例#11
0
 /// <summary>
 /// Raises the ActivityAsync event.
 /// </summary>
 /// <param name="e">An ActivityEventArgs that contains the event data.</param>
 protected virtual void OnActivityAsync(ActivityEventArgs e)
 {
     EventHandler<ActivityEventArgs> eh = ActivityAsync;
     if (eh != null)
         foreach (EventHandler<ActivityEventArgs> subscriber in eh.GetInvocationList())
             subscriber.BeginInvoke(
                 this, e, new AsyncCallback(
                     OnActivityAsyncCompleted), subscriber);
 }
        private static void GlobalActivityLogger(object sender, ActivityEventArgs args)
        {
            IActivityScope activityScope = sender as IActivityScope;

            if (activityScope.ActivityType == ActivityType.Global && (args.ActivityEventType == ActivityEventType.EndActivity || args.ActivityEventType == ActivityEventType.SuspendActivity))
            {
                RequestDetailsLoggerBase <T> requestDetailsLoggerBase = RequestDetailsLoggerBase <T> .InitializeRequestLogger(activityScope);

                ServiceCommonMetadataPublisher.PublishServerInfo(requestDetailsLoggerBase.ActivityScope);
                requestDetailsLoggerBase.Commit();
            }
        }
示例#13
0
 bool IMessageFilter.PreFilterMessage(ref Message m)
 {
     if (Enum.IsDefined(typeof(ActivityMessages), m.Msg))
     {
         _TimeRemaining = _IdleTime;
         _TimeElapsed = ZeroTime;
         ActivityEventArgs e = new ActivityEventArgs((ActivityMessages)m.Msg);
         OnActivityAsync(e);
         OnActivity(e);
     }
     return false;
 }
示例#14
0
 /// <summary>
 /// グリッドマーク自動検索処理が終了したときのイベントハンドラです.
 /// </summary>
 private void gridMark_Exited(object sender, ActivityEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(delegate {
         if (e.IsAborted)
         {
             WriteLine(Properties.Strings.AbortGridMarkSearch);
         }
         else if (e.IsCompleted)
         {
             WriteLine(Properties.Strings.GridMarkSearchComplete);
         }
     }));
 }
        private async Task NotifyActivity(TimeSpan timeSinceLastUserInput)
        {
            var timeStamp = DateTime.Now;

            if (!_isUserCurrentlyActive)
            {
                // If the user went idle, we need to subtract the time since last input in order to
                // calculate the timestamp the user stopped being active.

                timeStamp -= timeSinceLastUserInput;
            }

            var activityEvent = new ActivityEventArgs(_isUserCurrentlyActive, timeStamp);

            await ActivityEvents.OnActivityStateChanged.Raise(activityEvent);
        }
示例#16
0
        private void accumImage_Exited(object sender, ActivityEventArgs e)
        {
            switch (mode)
            {
            case ShootingMode.Plurality:
                Dispatcher.BeginInvoke(new Action(saveParaImages), null);
                break;

            case ShootingMode.Accumlative:
                Dispatcher.BeginInvoke(new Action(saveProjectedImages), null);
                break;
            }

            System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(delegate {
                abortButton.IsEnabled = false;
                ledGroupBox.IsEnabled = true;
                MessageBox.Show("Complete");
            }), null);
        }
示例#17
0
        void MainActivity_OptionsItemSelected(object sender, ActivityEventArgs e)
        {
            var item = sender as IMenuItem;

            switch (item.ItemId)
            {
            case global::Android.Resource.Id.Home:
                MainActivity.OpenCloseDrawer();
                break;

            case Resource.Id.action_bar_refresh:
                ViewModel.RefreshCommand.Execute(null);
                break;

            default:
                return;
            }
            e.Handled = true;
        }
示例#18
0
            /// <summary>
            /// 撮影を開始します.
            /// </summary>
            /// <exception cref="System.ArgumentOutOfRangeException"></exception>
            /// <exception cref="InActionException"></exception>
            /// <exception cref="MotorActiveException"></exception>
            public void Start()
            {
                MotorControler mc = MotorControler.GetInstance(parameterManager);

                if (mc.IsMoving)
                {
                    throw new MotorActiveException();
                }
                if (IsActive)
                {
                    throw new InActionException();
                }
                if (interval <= 0)
                {
                    throw new ArgumentOutOfRangeException(Properties.Strings.ValMustPositiveNotZero);
                }


                shootingThread = Create(new ThreadStart(delegate() {
                    ActivityEventArgs eventArgs = new ActivityEventArgs();
                    try {
                        shootingThreadTask();
                        eventArgs.IsCompleted = true;
                    } catch (ThreadAbortException ex) {
                        eventArgs.IsAborted = true;
                        eventArgs.Exception = ex;
                    } catch (Exception ex) {
                        eventArgs.IsCompleted = false;
                        eventArgs.Exception   = ex;
                    } finally {
                        mc.SlowDownStopAll();

                        if (Exited != null)
                        {
                            Exited(this, eventArgs);
                        }
                    }
                }));
                shootingThread.IsBackground = true;
                shootingThread.Start();
            }
示例#19
0
        private async Task OnActivityStateChanged(ActivityEventArgs eventArgs)
        {
            _retryCancellationTokenSource.Cancel();
            _retryCancellationTokenSource = new CancellationTokenSource();

            var logTimeModel = new LogTimeModel()
            {
                IsActive  = eventArgs.IsActive,
                Timestamp = eventArgs.TimeStamp,
            };

            var httpContent = new StringContent(
                JsonSerializer.Serialize(logTimeModel),
                Encoding.UTF8,
                "application/json");

            await _retryPolicy.ExecuteAsync(
                (ctx, ct) => _httpClient.PostAsync(FunctionMap.Get(Function.LogTime), httpContent, ct),
                _retryContext,
                _retryCancellationTokenSource.Token);
        }
示例#20
0
        private void ActivityInserted(object sender, ActivityEventArgs e)
        {
            var activity = e.Activity;
            var outlet   = activity.Outlet;

            var outletViewModel = FindOutletViewModel(outlet);

            if (outletViewModel == null)
            {
                // Create new OutletViewModel
                outletViewModel = new AgendaOutletViewModel(this, new AgendaOutlet(outlet, new List <Activity>()));

                // Add it to the list
                this.AllOutlets.TryAdd(outlet.Id, outletViewModel);
            }

            // Add the new activity
            outletViewModel.Activities.Add(new ActivityViewModel(outletViewModel, activity));

            this.Sort();
            this.ApplyCurrentTextSearch();
        }
示例#21
0
 private void ActivityCloudConnectorActivityAdded(object sender, ActivityEventArgs e)
 {
     AddActivityFromCloud(e.Activity);
 }
示例#22
0
 void ActivityNode_ActivityAdded( object sender, ActivityEventArgs e )
 {
     activitiesCache.AddOrUpdate( e.Activity.Id, e.Activity, ( key, oldValue ) => e.Activity );
 }
示例#23
0
        private void recogThread_Task()
        {
            Camera camera = Camera.GetInstance();

            camera.Start();
            MotorControler mc = MotorControler.GetInstance(parameterManager);

            surfaces[0] = UpTop;
            surfaces[1] = UpBottom;
            surfaces[2] = LowTop;
            surfaces[3] = LowBottom;

            // 現在位置が,前回の表面認識結果に基づいて下ゲル以下にいる場合は下ゲル下部から上方向に順に表面認識を行う.
            // 一方,ベース及び上ゲル以上にいる場合は上ゲル上部から下方向に順に表面認識を行う.
            // そのためにforループの条件式を設定する
            GelLayer layerNow = getWhichLayerNow();
            int      i, end;
            Action   fomula;

            if (layerNow == GelLayer.Under || layerNow == GelLayer.UnderOut)
            {
                i      = surfaces.Length;
                end    = 0;
                fomula = (() => -- i);
            }
            else
            {
                i      = 0;
                end    = surfaces.Length;
                fomula = (() => ++ i);
            }

            for (i = 0; i < end; fomula())
            {
                mc.MovePointZ(surfaces[i]);
                mc.Join();
                bool   presentResult = false, previousResult = IsInGel();
                bool[] votes   = new bool[parent.NumOfVoting];
                int    counter = 1;
                while (presentResult == previousResult)
                {
                    previousResult = presentResult;
                    mc.MovePointZ(surfaces[i] + everyRange * counter);
                    while (mc.Moving)
                    {
                        for (int j = 0; j < votes.Length; ++j)
                        {
                            votes[i] = IsInGel();
                            Thread.Sleep(parent.DelayTime);
                        }
                        presentResult = Surface.Vote(votes);
                        if (presentResult != previousResult)
                        {
                            mc.AbortMoving();
                        }
                    }
                    counter *= -1;
                    counter += (counter > 0 ? 1 : 0);
                    if (Math.Abs(everyRange * counter) > searchRange)
                    {
                        throw new SurfaceFailedException("Distance limit out.");
                    }
                }
                surfaces[i] = mc.GetPoint().Z;
                // 境界面認識時のイベントを発生させる.
                ActivityEventArgs eventArgs = new ActivityEventArgs();
                eventArgs.ZValue = surfaces[i];
                switch (i)
                {
                case 3:
                    if (LowBottomRecognized != null)
                    {
                        LowBottomRecognized(this, eventArgs);
                    }
                    break;

                case 2:
                    if (LowTopRecognized != null)
                    {
                        LowTopRecognized(this, eventArgs);
                    }
                    break;

                case 1:
                    if (UpBottomRecognized != null)
                    {
                        UpBottomRecognized(this, eventArgs);
                    }
                    break;

                case 0:
                    if (UpTopRecognized != null)
                    {
                        UpTopRecognized(this, eventArgs);
                    }
                    break;
                }
            }
            dateTime = DateTime.Now;
        }
示例#24
0
 protected virtual void OnActivityChanged(ActivityEventArgs e)
 {
     var handler = ActivityChanged;
     if (handler != null) handler(this, e);
 }
示例#25
0
 void ActivityNode_ActivityAdded(object sender, ActivityEventArgs e)
 {
     activitiesCache.AddOrUpdate(e.Activity.Id, e.Activity, (key, oldValue) => e.Activity);
 }
示例#26
0
 void ActivityNode_ActivityChanged(object sender, ActivityEventArgs e)
 {
     activitiesCache[e.Activity.Id].UpdateAllProperties(e.Activity);
 }
示例#27
0
 void node_ActivityAdded(object sender, ActivityEventArgs e)
 {
     // OnActivityAdded(e);
 }
示例#28
0
 private void ActivitySent(object sender, ActivityEventArgs e)
 {
     PreviousSentActivity = e.Activity;
     Messages.Add(PreviousSentActivity);
 }
示例#29
0
 private void ActivityDeleted(object sender, ActivityEventArgs e)
 {
     throw new NotImplementedException();
 }
示例#30
0
 private void ActivityClientActivityChanged(object sender, ActivityEventArgs e)
 {
     _activityBuffer[e.Activity.Id] = e.Activity;
 }
示例#31
0
            /// <summary>
            /// 撮影処理を行います.
            /// <para>別スレッドのタスクとして実行してください.直接呼び出さないでください.</para>
            /// </summary>
            private void shootingThreadTask()
            {
                if (Started != null)
                {
                    Started(this, new EventArgs());
                }

                imagesUri = new List <string>();
                shotPoint = new List <double>();

                MotorControler mc     = MotorControler.GetInstance(parameterManager);
                Camera         camera = Camera.GetInstance();

                camera.Start();
                numOfShot = 0;

                // 撮影開始地点へ移動する
                mc.MovePointZ(startPoint);
                mc.Join();

                StreamWriter writer = new StreamWriter(string.Format(@"{0}\{1}.txt", filepath, filenameprefix));

                // 撮影終了地点に移動しながら画像を確保する
                double pnInterval   = (startPoint > endPoint ? -interval : interval);
                double presentPoint = mc.GetPoint().Z;

                while (isShootContinue(presentPoint))
                {
                    mc.MoveDistance(pnInterval, VectorId.Z);
                    mc.Join();
                    presentPoint = mc.GetPoint().Z;

                    byte[] b           = camera.ArrayImage;
                    Mat    src         = new Mat(440, 512, MatType.CV_8U, b);
                    string pngfileName = string.Format(@"{0}\{1}{2:000}.png", filepath, filenameprefix, numOfShot);
                    src.ImWrite(pngfileName);

                    shotPoint.Add(presentPoint);
                    writer.WriteLine(presentPoint.ToString());

                    ++numOfShot;

                    if (OnShort != null)
                    {
                        ActivityEventArgs e = new ActivityEventArgs();
                        e.ZValue = presentPoint;
                        OnShort(this, e);
                    }
#if false//20140225 yokoyama,jyoshida
                    mc.MoveDistance(pnInterval, VectorId.Z, delegate {
                        presentPoint = mc.GetPoint().Z;
                        Camera c     = Camera.GetInstance();
                        saveTemp(c.Image);
                        shotPoint.Add(presentPoint);
                        ++numOfShot;
                        if (OnShort != null)
                        {
                            ActivityEventArgs e = new ActivityEventArgs();
                            e.ZValue            = presentPoint;
                            OnShort(this, e);
                        }
                    });
#endif
                }//while

                writer.Close();
                mc.SlowDownStop(VectorId.Z);
            }
示例#32
0
 void ActivitySystem_ActivityAdded(object sender, ActivityEventArgs e)
 {
     Notifier.NotifyAll(NotificationType.ActivityAdded, e.Activity);
 }
示例#33
0
 void ActivityNode_ActivityChanged( object sender, ActivityEventArgs e )
 {
     activitiesCache[ e.Activity.Id ].UpdateAllProperties( e.Activity );
 }
示例#34
0
 private void ActivityCloudConnectorActivityUpdated(object sender, ActivityEventArgs e)
 {
     ActivityStore.Activities[e.Activity.Id] = e.Activity;
     _publisher.Publish(ActivityEvent.ActivityChanged.ToString(), e.Activity);
 }
示例#35
0
 void ActivitySystem_ActivityAdded(object sender, ActivityEventArgs e)
 {
     Notifier.NotifyAll(NotificationType.ActivityAdded, e.Activity);
 }
示例#36
0
 private void Current_ActivityStateChanged(object sender, ActivityEventArgs e)
 {
     Log.Debug("X:ShortestPath", $"Activity Changed: {e.Activity.LocalClassName} -  {e.Event}");
 }
示例#37
0
 private void Current_ActivityStateChanged(object sender, ActivityEventArgs e)
 {
     Toast.MakeText(Application.Context, $"Activity Changed: {e.Activity.LocalClassName} -  {e.Event}", ToastLength.Short).Show();
 }