コード例 #1
0
ファイル: LocalizationService.cs プロジェクト: magseet/AttiLA
        /// <summary>
        /// Implementation of service operation.
        /// </summary>
        /// <param name="contextId"></param>
        /// <returns></returns>
        public bool TrackingStart(string contextId)
        {
            if (contextId == null || !ContextService.IsValidObjectID(contextId))
            {
                var detail = new ServiceException
                {
                    Code = ServiceExceptionCode.Arguments
                };
                throw new FaultException <ServiceException>(detail);
            }

            lock (_lockStatus)
            {
                var previousState = ServiceState;

                try
                {
                    if (contextId == _localizer.ContextId && previousState == ServiceStateCode.Tracking)
                    {
                        // do nothing
                        return(true);
                    }

                    // prepare for tracking
                    _tracker.ScenarioId = null;
                    _localizer.Enabled  = false;
                    ServiceState        = ServiceStateCode.Tracking;

                    // notify all subscribers
                    var serviceStatus = new ServiceStatus
                    {
                        ContextId    = contextId,
                        ServiceState = ServiceStateCode.Tracking
                    };
                    DoReportServiceStatus(serviceStatus);


                    if (contextId != _localizer.ContextId)
                    {
                        // prepare for new context
                        ConsecutiveCorrectPredictions = 0;
                        _localizer.ContextId          = contextId;
                    }

                    // perform a first prediction
                    _localizer.CreationAllowed = true;
                    var prediction = _localizer.Prediction();
                    if (prediction == null || prediction.PredictedScenario == null)
                    {
                        return(false);
                    }
                    DispatchPrediction(prediction);
                    // enable localizer timer for the next predictions
                    _localizer.Enabled = true;
                }
                catch (ArgumentException)
                {
                    Silence();
                    var detail = new ServiceException
                    {
                        Code = ServiceExceptionCode.Arguments
                    };
                    throw new FaultException <ServiceException>(detail);
                }
                catch
                {
                    Silence();
                    return(false);
                }

                return(true);
            }
        }