Ejemplo n.º 1
0
        private VolumeCollection SetVolumeByDetection(List <Models.Approach> approaches, List <Controller_Event_Log> detectorEvents)
        {
            var controllerEventLogRepository = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            foreach (var approach in approaches)
            {
                foreach (var detector in approach.Detectors)
                {
                    if (detector.DetectionTypes.Any(d => d.DetectionTypeID == DetectionType.DetectionTypeID))
                    {
                        if (detector.LaneType.LaneTypeID == 1)
                        {
                            Detectors.Add(detector);
                            detectorEvents.AddRange(controllerEventLogRepository.GetEventsByEventCodesParamWithOffsetAndLatencyCorrection(
                                                        detector.Approach.SignalID, _approachVolumeOptions.StartDate,
                                                        _approachVolumeOptions.EndDate, new List <int> {
                                82
                            }, detector.DetChannel,
                                                        detector.GetOffset(), detector.LatencyCorrection));
                        }
                    }
                }
            }
            return(new VolumeCollection(_approachVolumeOptions.StartDate, _approachVolumeOptions.EndDate, detectorEvents, _approachVolumeOptions.SelectedBinSize));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultSentenceDetector"/> class.
        /// </summary>
        /// <param name="detectors">The detectors.</param>
        /// <param name="tokenizer">The tokenizer.</param>
        public DefaultSentenceDetector(IEnumerable <IDetector> detectors, ITokenizer tokenizer)
        {
            Detectors = detectors.Where(x => x.GetType().Assembly != typeof(DefaultSentenceDetector).Assembly).ToDictionary(x => x.Name);
            foreach (var Detector in detectors.Where(x => x.GetType().Assembly == typeof(DefaultSentenceDetector).Assembly &&
                                                     !Detectors.ContainsKey(x.Name)))
            {
                Detectors.Add(Detector.Name, Detector);
            }

            Tokenizer = tokenizer;
        }
Ejemplo n.º 3
0
 public AppWindowMonitor(Profile profile, string processName) : base(profile)
 {
     ProcessName       = processName;
     AppWindowActivity = new AppWindowActivity(this, Type, processName, TimeSpan.FromMilliseconds(5000));
     if (AppWindowActivity.Status == ApiStatus.Ok)
     {
         Detectors.Add(AppWindowActivity);
         this.Status = ApiStatus.Initializing;
         Info("Creating app window monitor for process {0}.", processName);
     }
     else
     {
         Error("Could not create AppWindowActivity detector for process {0}.", processName);
         this.Status = ApiStatus.Error;
     }
 }
Ejemplo n.º 4
0
        public override ApiResult Init()
        {
            if (Status != ApiStatus.Initializing)
            {
                return(ApiResult.Failure);
            }

            if (Detector.Status == ApiStatus.Initialized)
            {
                Detectors.Add(Detector);
                return(SetInitializedStatusAndReturnSucces());
            }
            else
            {
                Error("Storage device activity detector did not initialize.");
                return(SetErrorStatusAndReturnFailure());
            }
        }
Ejemplo n.º 5
0
        public static void LoadAll( )
        {
            lock ( Locker )
            {
                if (Loaded)
                {
                    return;
                }

                //Todo:Load All internal type
                foreach (TypeInfo type in typeof(Program).GetTypeInfo( ).
                         Assembly.DefinedTypes.
                         Where(type => type.GetCustomAttributes(typeof(DetectorAttribute), false).Any( ) &&
                               typeof(ThingsDetector).GetTypeInfo( ).IsAssignableFrom(type)))
                {
                    Detectors.Add(Activator.CreateInstance(type, Source) as ThingsDetector);
                }

                Loaded = true;
            }
        }
Ejemplo n.º 6
0
        private void LoadFilesFromDisk(string folder)
        {
            if (string.IsNullOrEmpty(folder))
            {
                folder = Path;
            }
            var Files = System.IO.Directory.EnumerateFiles(folder, "*.*", System.IO.SearchOption.AllDirectories).OrderBy((x) => x).ToArray();

            foreach (string file in Files)
            {
                if (System.IO.Path.GetExtension(file).ToLower() == ".xaml")
                {
                    Workflows.Add(Workflow.FromFile(this, file));
                }
                else if (System.IO.Path.GetExtension(file).ToLower() == ".json")
                {
                    var      json = System.IO.File.ReadAllText(file);
                    Detector _d   = JsonConvert.DeserializeObject <Detector>(json);
                    if (!string.IsNullOrEmpty(_d._id))
                    {
                        var exists = RobotInstance.instance.Detectors.FindById(_d._id);
                        if (exists != null)
                        {
                            _d._id = null;
                        }
                        else
                        {
                            _d.isLocalOnly = true;
                        }
                    }
                    if (string.IsNullOrEmpty(_d._id))
                    {
                        _d._id = Guid.NewGuid().ToString();
                    }
                    _d.isDirty = true;
                    _d.Start(true);
                    Detectors.Add(_d);
                }
            }
        }
Ejemplo n.º 7
0
 public override ApiResult Init()
 {
     if (Status != ApiStatus.Initializing)
     {
         return(ApiResult.Failure);
     }
     try
     {
         for (int i = 0; i < Paths.Count; i++)
         {
             KeyValuePair <DirectoryInfo, string> path = Paths.ElementAt(i);
             Detectors.Add(new FileSystemActivity(path.Key.FullName, path.Value, true, this,
                                                  typeof(DirectoryChangesMonitor)));
         }
         return(SetInitializedStatusAndReturnSucces());
     }
     catch (Exception e)
     {
         Error(e, "Error occurred initializing a detector.");
         return(SetErrorStatusAndReturnFailure());
     }
 }
Ejemplo n.º 8
0
        public Reporter RegisterDetector(Func <ClrRuntime, Report, IEnumerable <IIssue> > detector)
        {
            Detectors.Add(detector);

            return(this);
        }
Ejemplo n.º 9
0
        public async Task LoadFileFromDisk(string file)
        {
            if (System.IO.Path.GetExtension(file).ToLower() == ".xaml")
            {
                var wf = Workflow.FromFile(this, file);
                wf.projectid = _id;
                wf._acl      = _acl;
                await wf.Save();
            }
            else if (System.IO.Path.GetExtension(file).ToLower() == ".json")
            {
                var     json = System.IO.File.ReadAllText(file);
                JObject o    = null;
                try
                {
                    o = JObject.Parse(json);
                }
                catch (Exception ex)
                {
                    Log.Warning("Error parsing " + file);
                    Log.Error(ex.Message);
                    return;
                }
                if (!o.ContainsKey("_type"))
                {
                    Log.Warning("skipping " + file + " missing _type field");
                    return;
                }
                var _type = o.Value <string>("_type");
                if (_type == "workitemqueue")
                {
                    var _wiq = JsonConvert.DeserializeObject <WorkitemQueue>(json);
                    _wiq.projectid = _id;
                    _wiq._acl      = _acl;
                    _wiq.isDirty   = true;
                    _wiq.projectid = _id;
                    if (!string.IsNullOrEmpty(_wiq._id))
                    {
                        var exists = RobotInstance.instance.dbWorkItemQueues.FindById(_wiq._id);
                        if (exists == null)
                        {
                            exists = RobotInstance.instance.dbWorkItemQueues.Find(x => x.name.ToLower() == _wiq.name.ToLower()).FirstOrDefault();
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(exists.name))
                            {
                                exists.name = "";
                            }
                            if (exists.name.ToLower() != _wiq.name.ToLower())
                            {
                                _wiq._id = null;
                                exists   = null;
                            }
                        }
                        if (exists != null)
                        {
                            Log.Warning("Skipping workitem queeu " + exists.name + " it already exists");
                            return;
                        }
                        else
                        {
                            _wiq.isLocalOnly = true;
                        }
                    }
                    _wiq.isDirty = true;
                    if (global.webSocketClient != null && global.webSocketClient.user != null && global.webSocketClient.isConnected)
                    {
                        if (_wiq.isLocalOnly || string.IsNullOrEmpty(_wiq._id))
                        {
                            await _wiq.Save(true);
                        }
                        else
                        {
                            await _wiq.Save();
                        }
                    }
                    else if (!string.IsNullOrEmpty(Config.local.wsurl))
                    {
                        System.Windows.MessageBox.Show("Not connected to " + Config.local.wsurl + " so cannot validate WorkItemQueue, removing queue from import");
                    }
                    else
                    {
                        await _wiq.Save(true);
                    }
                    Log.Output("Adding workitem queue " + _wiq.name);
                }
                if (_type == "detector")
                {
                    var _d = JsonConvert.DeserializeObject <Detector>(json);
                    if (!string.IsNullOrEmpty(_d._id))
                    {
                        var exists = RobotInstance.instance.dbDetectors.FindById(_d._id);
                        if (exists != null)
                        {
                            _d._id = null;
                        }
                        else
                        {
                            _d.isLocalOnly = true;
                        }
                    }
                    if (string.IsNullOrEmpty(_d._id))
                    {
                        _d._id = Guid.NewGuid().ToString();
                    }
                    _d.projectid = _id;
                    _d._acl      = _acl;
                    _d.isDirty   = true;
                    _d.projectid = _id;
                    _d.Start(true);
                    Detectors.Add(_d);
                    Log.Output("Adding detector " + _d.name);
                }
                if (_type == "workflow")
                {
                    var _wf = JsonConvert.DeserializeObject <Workflow>(json);

                    var exists = RobotInstance.instance.dbWorkflows.FindById(_wf._id);
                    _wf.projectid = _id;
                    if (exists == null)
                    {
                        exists = RobotInstance.instance.dbWorkflows.Find(x => x.ProjectAndName.ToLower() == _wf.ProjectAndName.ToLower()).FirstOrDefault();
                    }
                    else
                    {
                        if (exists.ProjectAndName.ToLower() != _wf.ProjectAndName.ToLower())
                        {
                            _wf._id = null;
                            exists  = null;
                        }
                    }
                    if (exists != null)
                    {
                        Log.Warning("Skipping workitem queeu " + exists.name + " it already exists");
                        return;
                    }
                    else
                    {
                        _wf.isLocalOnly = true;
                    }
                    //if (!string.IsNullOrEmpty(_wf._id))
                    //{
                    //    var exists = RobotInstance.instance.Workflows.Where(x => x._id == _wf._id).FirstOrDefault();
                    //    if (exists != null) { _wf._id = null; } else { _wf.isLocalOnly = true; }
                    //}
                    if (string.IsNullOrEmpty(_wf._id))
                    {
                        _wf._id = Guid.NewGuid().ToString();
                    }
                    _wf.isDirty   = true;
                    _wf.projectid = _id;
                    _wf._acl      = _acl;
                    await _wf.Save();

                    Log.Output("Adding workflow " + _wf.name);
                }
            }
        }
Ejemplo n.º 10
0
 public ErroneousValue(DateTime timeStamp, IDetectionMethod detector, Sensor owner)
     : this(timeStamp, owner)
 {
     Detectors.Add(detector);
 }