Esempio n. 1
0
        public static OSVRConfig Read(string filePath, string serverRoot)
        {
            var ret      = new OSVRConfig();
            var includes = new List <OSVRInclude>();

            ret.Includes = includes;

            using (var configReader = File.OpenText(filePath))
                using (var jr = new JsonTextReader(configReader))
                {
                    JToken token = JObject.ReadFrom(jr);
                    if (!(token is JObject))
                    {
                        return(null);
                    }
                    ret.Body = (JObject)token;

                    // Display
                    var displayInclude = OSVRInclude.Parse(ret.Body, "display", serverRoot);
                    if (displayInclude != null)
                    {
                        includes.Add(displayInclude);
                    }

                    // RenderManager
                    var renderManagerInclude = OSVRInclude.Parse(ret.Body, "renderManagerConfig", serverRoot);
                    if (renderManagerInclude != null)
                    {
                        includes.Add(renderManagerInclude);
                    }
                }
            return(ret);
        }
Esempio n. 2
0
        public static IEnumerable <ServerConfigSample> GetAvailableSamples(string serverPath)
        {
            var displaysPath = System.IO.Path.Combine(serverPath, "sample-configs");

            var displayFiles =
                from displayFile in System.IO.Directory.EnumerateFiles(displaysPath)
                where displayFile.Contains("osvr_server_config")
                select new ServerConfigSample()
            {
                FileName = System.IO.Path.GetFileName(displayFile),
                Body     = OSVRConfig.Read(displayFile, serverPath),
            };

            // These will be filtered out for the client, but log something
            // to let us know of badly formed sample configs.
            foreach (var errorDisplayFile in
                     from displayFile in displayFiles
                     where displayFile.Body == null && displayFile.FileName != null
                     select displayFile)
            {
                Console.WriteLine("Could not parse sample {0}", errorDisplayFile.FileName);
            }

            // filter the sample configs to only those that parse correctly.
            return(from displayFile in displayFiles
                   where displayFile.Body != null && displayFile.FileName != null
                   select displayFile);
        }
Esempio n. 3
0
        public static void SetCurrent(OSVRConfig value, string serverRoot)
        {
            var configPath = Path.Combine(serverRoot, "osvr_server_config.json");

            // ignoring includes.
            var            mainConfigBody = value.Body;
            JsonSerializer serializer     = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;
            serializer.Formatting        = Formatting.Indented;
            using (StreamWriter sw = System.IO.File.CreateText(configPath))
                using (JsonWriter jw = new JsonTextWriter(sw))
                {
                    serializer.Serialize(jw, mainConfigBody);
                }
        }
Esempio n. 4
0
        public static OSVRConfig GetCurrent(IConfiguration config, string serverRoot)
        {
            var configPath = Path.Combine(serverRoot, "osvr_server_config.json");

            return(OSVRConfig.Read(configPath, serverRoot));
        }