Exemplo n.º 1
0
        /// <summary>
        /// Creates new options objects with values parsed from string configuration data
        /// </summary>
        /// <param name="cfg">configuration file</param>
        /// <param name="bcClientOptions"></param>
        public HoardServiceOptions(HoardServiceConfig cfg, BCClientOptions bcClientOptions)
        {
            Game = GameID.kInvalidID;
            if (!string.IsNullOrEmpty(cfg.GameID))
            {
                Game = new GameID(System.Numerics.BigInteger.Parse(cfg.GameID, NumberStyles.AllowHexSpecifier));
            }

            if (!string.IsNullOrEmpty(cfg.GameBackendUrl))
            {
                Game.Url = cfg.GameBackendUrl;
            }

            if (!string.IsNullOrEmpty(cfg.ExchangeServiceUrl))
            {
                ExchangeServiceUrl = cfg.ExchangeServiceUrl;
            }

            if (!string.IsNullOrEmpty(cfg.HoardAuthServiceUrl))
            {
                HoardAuthServiceUrl = cfg.HoardAuthServiceUrl;
            }

            if (!string.IsNullOrEmpty(cfg.HoardAuthServiceClientId))
            {
                HoardAuthServiceClientId = cfg.HoardAuthServiceClientId;
            }

            BCClientOptions = bcClientOptions;

            GameCenterContract = cfg.GameCenterContract;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads configuration from path on disk
        /// </summary>
        /// <param name="path">path where configration file is kept (hoardConfig.cfg)</param>
        /// <returns>new configuration object</returns>
        public static HoardServiceConfig Load(string path = null)
        {
            string defaultPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Hoard", "hoardConfig.json");
            string cfgString   = null;

            if (!string.IsNullOrEmpty(path))
            {
                cfgString = System.IO.File.ReadAllText(path);
            }
            else if (System.IO.File.Exists("hoardConfig.json"))
            {
                cfgString = System.IO.File.ReadAllText("hoardConfig.json");
            }
            else if (System.IO.File.Exists(defaultPath))
            {
                cfgString = System.IO.File.ReadAllText(defaultPath);
            }

            HoardServiceConfig config = Newtonsoft.Json.JsonConvert.DeserializeObject <HoardServiceConfig>(cfgString);

            return(config);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads configuration from supplied text stream
        /// </summary>
        /// <param name="data">JSON string representing configuration</param>
        /// <returns>new configuration object</returns>
        public static HoardServiceConfig LoadFromStream(string data)
        {
            HoardServiceConfig config = Newtonsoft.Json.JsonConvert.DeserializeObject <HoardServiceConfig>(data);

            return(config);
        }