示例#1
0
        public bool TryAdd(string filepath, out SessionDefinition definition)
        {
            FileInfo file = new FileInfo(filepath);

            string key = file.FullName;

            if (file.Exists && TryLoadDefinition(file, out definition))
            {
                if (_definitions.ContainsKey(key) == false)
                {
                    _definitions.Add(key, definition);

                    DefinitionsChanged?.Invoke(this, CollectionChangedEventArgs <SessionDefinition> .CreateForAddedItem(definition));

                    return(true);
                }
                else if (_definitions[key].CreatedAt != definition.CreatedAt)
                {
                    var removed = _definitions[key];
                    _definitions.Remove(key);
                    _definitions.Add(key, definition);

                    DefinitionsChanged?.Invoke(this, CollectionChangedEventArgs <SessionDefinition> .Create(definition, removed));

                    return(true);
                }
            }
            // TODO add message file does not exist

            definition = null;
            return(false);
        }
示例#2
0
        private void TryUpdateDefaultDefinition()
        {
            var deviceTypes = _devices.Devices.Select(device => device.DeviceType).ToList();

            if (DefaultDefinition == null ||
                DefaultDefinition.SelectedDeviceTypes.Intersect(deviceTypes).Count() != deviceTypes.Count)
            {
                DefaultDefinition = CreateDefaultDefinition(deviceTypes);
            }
        }
示例#3
0
        public SessionRecordingSettings(SessionDefinition definition, string sessionId, DateTime openedAt)
        {
            ISettings sessionSection;

            _storage.TryGetSection(SETTINGS_SECTION_SESSION, out sessionSection);

            StartedAtProperty  = new ConfigurationSettingProperty("StartedAt", typeof(DateTime), DateTime.MinValue, sessionSection);
            FinishedAtProperty = new ConfigurationSettingProperty("FinishedAt", typeof(DateTime), DateTime.MinValue, sessionSection);
            OpenedAtProperty   = new ConfigurationSettingProperty("OpenedAt", openedAt, sessionSection);
            IdProperty         = new ConfigurationSettingProperty("Id", sessionId, sessionSection);
            NameProperty       = new ConfigurationSettingProperty("Name", definition.Name, sessionSection);
            ProjectProperty    = new ConfigurationSettingProperty("Project", definition.Project, sessionSection);
        }
示例#4
0
        public SessionRecording Record(SessionDefinition definition)
        {
            // create recording from definition
            var recording = new SessionRecording(definition, _adapters);

            // close previous recording
            Close();

            // set new recording
            CurrentRecording = recording;

            return(recording);
        }
        public SessionDefinition LoadFromFile(string filepath)
        {
            using (var reader = new StreamReader(filepath))
            {
                // deserialize
                var definition = SessionDefinition.Create();
                _serializer.Populate(reader, definition);

                //definition.CreatedAt = file.LastWriteTime;

                return(definition);
            }
        }
示例#6
0
        internal SessionRecording(SessionDefinition definition, IAdaptersControl adapters)
        {
            definition.ThrowIfNull(nameof(definition));

            Definition = definition;
            _adapters  = adapters;

            DateTime openedAt  = DateTime.Now;
            string   sessionId = CreateRecordingId(openedAt, definition.Project, definition.Name);

            Settings = new SessionRecordingSettings(definition, sessionId, openedAt);

            InsertSteps(_preSteps, definition.PreSessionSteps);
            InsertSteps(_postSteps, definition.PostSessionSteps);
            InsertSteps(_steps, definition.SessionSteps);

            if (_steps.Count == 0)
            {
                InsertStep(_steps, SessionStep.Default);
            }

            if (definition.Welcome != null && definition.Welcome.Ignore == false)
            {
                InsertStep(_preSteps, new SessionStep()
                {
                    Action = definition.Welcome
                });
            }

            RecorderConfigurations = ValidateRecorders(definition.Recorders).DefaultIfEmpty(DefaultRecorderDefinition).ToDictionary
                                     (
                d => d.Name,
                d => (IDictionary <string, object>)d.Configuration.ToDictionary(r => r.Key, r => r.Value, StringComparer.CurrentCultureIgnoreCase),
                StringComparer.CurrentCultureIgnoreCase
                                     );

            DeviceConfigurations = ValidateDevices(definition.Devices).ToDictionary
                                   (
                d => d.Device,
                d => (IDictionary <string, object>)d.Configuration.ToDictionary(c => c.Key, c => c.Value, StringComparer.CurrentCultureIgnoreCase)
                                   );

            _stateMachine = CreateStateMachine();
        }
示例#7
0
        private bool TryLoadDefinition(FileInfo file, out SessionDefinition definition)
        {
            try
            {
                definition           = _service.LoadFromFile(file.FullName);
                definition.CreatedAt = file.LastWriteTime;

                // force default Local recorder
                if (definition.Recorders.Any(r => r.Name.Equals("Local", StringComparison.CurrentCultureIgnoreCase)) == false)
                {
                    definition.Recorders.Add(new SessionRecorderDefinition("Local"));
                }

                return(true);
            }
            catch (Exception ex)
            {
                // TODO LOG
            }

            definition = null;
            return(false);
        }
示例#8
0
        private static SessionDefinition CreateDefaultDefinition(IEnumerable <DeviceType> deviceTypes)
        {
            var definition = SessionDefinition.Create();

            definition.Devices             = deviceTypes.Select(type => new SessionDeviceDefinition(type, null)).ToList();
            definition.Project             = "Default";
            definition.Source              = "Local";
            definition.Name                = "Recording";
            definition.SerializationFormat = "JSON";
            definition.StrictStart         = true;

            definition.Welcome.Ignore = true;

            definition.Recorders.Add(new SessionRecorderDefinition("Local"));
            definition.Recorders.Add(new SessionRecorderDefinition("Buffer"));

            bool hasEyeTracker = definition.SelectedDeviceTypes.Any(device => device.Equals(DeviceType.Physiological.EYETRACKER));

            if (hasEyeTracker)
            {
                definition.PreSessionSteps.Add(new SessionStep()
                {
                    Action = new EyeTrackerCalibrationActionSettings()
                });
                definition.SessionSteps.Add(new SessionStep()
                {
                    Action = new EyeTrackerValidationActionSettings()
                    {
                        PointDuration = 2000
                    }, Completion = new SessionStepCompletionSettings()
                    {
                        Hotkeys = new List <Hotkey>()
                        {
                            Hotkey.F10
                        }
                    }
                });
            }

            definition.SessionSteps.Add(new SessionStep()
            {
                Action = new ShowDesktopActionSettings()
                {
                    MinimizeAll = false
                }, Completion = new SessionStepCompletionSettings()
                {
                    Hotkeys = new List <Hotkey>()
                    {
                        Hotkey.F10
                    }
                }
            });

            if (hasEyeTracker)
            {
                definition.PostSessionSteps.Add(new SessionStep()
                {
                    Action = new FixationFilterActionSettings()
                });
            }

            return(definition);
        }