Exemplo n.º 1
0
 public void LoadExperimentConfig(string name)
 {
     lock (configLock) {
         string text = System.IO.File.ReadAllText(System.IO.Path.Combine(fileManager.ConfigPath(), name + ".json"));
         experimentConfig = FlexibleConfig.LoadFromText(text);
         if ((string)GetSetting("experimentName") != name)
         {
             Notify(new Exception(" Config and experiment names do not match"));
         }
     }
 }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        // Unity interal event handling
        SceneManager.sceneLoaded += onSceneLoaded;

        // create objects not tied to unity
        fileManager = new FileManager(this);
        syncBox     = new NonUnitySyncbox(this);
        onKey       = new ConcurrentQueue <Action <string, bool> >();

        // load system configuration file // TODO: function
        string text = System.IO.File.ReadAllText(System.IO.Path.Combine(fileManager.ConfigPath(), SYSTEM_CONFIG));

        lock (configLock) {
            systemConfig = FlexibleConfig.LoadFromText(text);
        }

        // Get all configuration files
        string configPath = fileManager.ConfigPath();

        string[] configs = Directory.GetFiles(configPath, "*.json");
        if (configs.Length < 2)
        {
            // TODO: notify
            ShowWarning("Configuration File Error", 5000);
            DoIn(new EventBase(Quit), 5000);
        }

        JArray exps = new JArray();

        for (int i = 0, j = 0; i < configs.Length; i++)
        {
            Debug.Log(configs[i]);
            if (!configs[i].Contains(SYSTEM_CONFIG))
            {
                exps.Add(Path.GetFileNameWithoutExtension(configs[i]));
            }
            j++;
        }
        ChangeSetting("availableExperiments", exps);


        // Syncbox interface
        if (!(bool)GetSetting("isTest"))
        {
            syncBox.Init();
        }


        // Start experiment Launcher scene
        mainEvents.Do(new EventBase(LaunchLauncher));
        eventsPerFrame = (int)(GetSetting("eventsPerFrame") ?? 5);
    }
Exemplo n.º 3
0
    public virtual dynamic LoadState(string participant, int session)
    {
        if (System.IO.File.Exists(System.IO.Path.Combine(manager.fileManager.SessionPath(participant, session), "experiment_state.json")))
        {
            string  json    = System.IO.File.ReadAllText(System.IO.Path.Combine(manager.fileManager.SessionPath(participant, session), "experiment_state.json"));
            dynamic jObjCfg = FlexibleConfig.LoadFromText(json);
            dynamic state   = FlexibleConfig.CastToStatic(jObjCfg);

            if (state.isComplete)
            {
                manager.Notify(new InvalidOperationException("Session Already Complete"));
            }

            return(state);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 4
0
    public virtual void SaveState()
    {
        string path = System.IO.Path.Combine(manager.fileManager.SessionPath(), "experiment_state.json");

        FlexibleConfig.WriteToText(state, path);
    }