public static void LoadConfig(string path) { dynamic val = ReadConfigFile(path); try { var i = val["Layers"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } foreach (Dictionary <string, object> dict in val["Layers"]) { string name = ""; int zi; try { name = (string)dict["Name"]; zi = (int)dict["zIndex"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } All.Add(new Layer(name, zi)); } }
public void All_exception_ctors_should_work_as_expected() { /* Arrange / Act */ var inner = new Exception(); var err1 = new ConfigError(ConfigErrorCode.InvalidNode, "SomeError"); var err2 = new ConfigError(ConfigErrorCode.InvalidNode, "SomeOtherError"); var ex1 = new ConfigException("SomeMessage1", ConfigErrorCode.MissingGetter); var ex2 = new ConfigException("SomeMessage2", ConfigErrorCode.MissingSetter, inner); var ex3 = new ConfigException(null); var ex4 = new ConfigException(new[] { err1, err2 }); /* Assert */ ex1.Message.Should().Be("SomeMessage1"); ex1.Errors.Should().ContainSingle(e => e.Code == ConfigErrorCode.MissingGetter); ex1.InnerException.Should().BeNull(); ex2.Message.Should().Be("SomeMessage2"); ex2.Errors.Should().ContainSingle(e => e.Code == ConfigErrorCode.MissingSetter); ex2.InnerException.Should().BeSameAs(inner); ex3.Message.Should().Be(string.Empty); ex3.Errors.Should().BeEmpty(); ex3.InnerException.Should().BeNull(); ex4.Message.Should().Be("SomeError\r\nSomeOtherError"); ex4.Errors.Should().HaveCount(2); ex4.InnerException.Should().BeNull(); }
public void ConstructorWithMessage() { var message = "Error..."; var exception = new ConfigException(message); Assert.AreEqual(message, exception.Message); }
private void コンストラクタ_exception_message_args_で設定したメッセージ引数を使ってMessageプロパティはメッセージ変換する(String args, String result) { // when ConfigException exception = new ConfigException(new Exception(), "ddd", args); // then Assert.AreEqual(result, exception.Message); }
public void コンストラクタ_message_args_で設定したメッセージがnullのときMessageプロパティはデフォルトメッセージを返す() { // when ConfigException exception = new ConfigException((string)null); // then Assert.IsNotNull(exception.Message); }
private void コンストラクタ_exceptionで設定した例外はInnerExceptionプロパティで取得できる(Exception cause) { // when ConfigException exception = new ConfigException(cause); // then Assert.AreSame(cause, exception.InnerException); }
public void ConstructorWithMessageAndException() { var message = "Error..."; var inner = new Exception(); var exception = new ConfigException(message, inner); Assert.AreEqual(message, exception.Message); Assert.AreEqual(inner, exception.InnerException); }
private void init() { try { introspectPhpModuleClass(_module.getClass()); } catch (Exception e) { throw ConfigException.create(e); } }
private void コンストラクタ_message_args_で設定したメッセージはMessageプロパティで取得できる(String message) { // when ConfigException exception = new ConfigException(message); // then Assert.AreEqual(message, exception.Message); Assert.AreEqual(message, exception.ResourceKey); }
private void Cultureプロパティで設定されたカルチャでMessageプロパティはメッセージ変換する(CultureInfo culture, string result) { // when ConfigException exception = new ConfigException("aaa"); exception.Culture = culture; // then Assert.AreEqual(result, exception.Message); }
private void Cultureプロパティに設定した値はCultureプロパティで取得できる(CultureInfo culture) { // setup ConfigException exception = new ConfigException(""); // when exception.Culture = culture; // then Assert.AreEqual(culture, exception.Culture); }
private void MyClickedItemListener(object sender, RadioGroup.CheckedChangeEventArgs e) { // Handle errors through java Exceptions ErrorManager.EnableExceptions(true); try { // get the current settings from the BarcodeManager configuration = ScannerProperties.Edit(manager); // disables KeyboardWedge configuration.KeyboardWedge.Enable.Set(false); // enable wedge intent configuration.IntentWedge.Enable.Set(true); switch (e.CheckedId) { case Resource.Id.radioBroadcast: // set wedge intent action and category configuration.IntentWedge.Action.Set(ACTION_BROADCAST_RECEIVER); configuration.IntentWedge.Category.Set(CATEGORY_BROADCAST_RECEIVER); // set wedge intent delivery through broadcast configuration.IntentWedge.DeliveryMode.Set(IntentDeliveryMode.Broadcast); configuration.Store(manager, false); break; case Resource.Id.radioStartActivity: // set wedge intent action and category configuration.IntentWedge.Action.Set(ACTION); configuration.IntentWedge.Category.Set(CATEGORY); // intent delivery startActivity configuration.IntentWedge.DeliveryMode.Set(IntentDeliveryMode.StartActivity); configuration.Store(manager, false); break; } } catch (Exception exception) //catch any errors that occured. { if (exception is ConfigException) { ConfigException ex = (ConfigException)exception; Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message); } else if (exception is DecodeException) { DecodeException ex = (DecodeException)exception; Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message); } else { Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message); } } }
public Server() { var directoryInfo = Directory.GetParent(Environment.CurrentDirectory).Parent; if (directoryInfo != null) { string projectDir = directoryInfo.Parent.FullName; ConfigModel jsonConfig; var path = projectDir + "\\Configs\\ServerConfig.JSON"; if (!File.Exists(path)) { if (File.Exists("ServerConfig.JSON")) { path = "ServerConfig.JSON"; } else { Exception ex = new FileNotFoundException("Cannot find config file! path:" + path); _logger.Fatal(ex); throw ex; } } _logger.Info("Reading configurations.."); using (var r = new StreamReader(path)) { string json = r.ReadToEnd(); jsonConfig = JsonConvert.DeserializeObject <ConfigModel>(json); } _ipAddrStr = jsonConfig.Addr["ip"]; if (!int.TryParse(jsonConfig.Addr["port"], out _port)) { Exception ex = new ConfigException("Bad port"); _logger.Fatal(ex, "Bad port"); throw ex; } _appToken = jsonConfig.AppToken; _sqlServerName = jsonConfig.MSSQLName; } else { _logger.Fatal("Cannot find directory"); throw new ArgumentException("Directory was wrong"); } ConfigLogger("log.txt"); _logger.Info("Start listening.."); }
private void コンストラクタ_exception_message_args_で設定したリソースキーはMessageプロパティでメッセージ変換される(String key, String result) { try { // when setup(); Resi.Add(new ResourceManager("XPFriend.JunkTest.testres.Resources_test01", typeof(ResiTest).Assembly)); ConfigException exception = new ConfigException(new Exception(), key); // then Assert.AreEqual(result, exception.Message); Assert.AreEqual(key, exception.ResourceKey); } finally { cleanup(); } }
private void LoadConfig() { dynamic val = ReadConfigFile("ProjectConfig.json"); ProjectConfig pc = new ProjectConfig(); try { pc.Name = val["Name"]; pc.Author = val["Author"]; pc.ProjectVersion = val["ProjectVersion"]; pc.ShadowEngineVersion = val["ShadowEngineVersion"]; dynamic sr = val["StartResolution"]; pc.StartResolution = new System.Drawing.Size(sr["Width"], sr["Height"]); pc.StartFullscreen = val["StartFullscreen"]; pc.AxisConfigPath = val["AxisConfigPath"]; pc.AxisConfigAutoLoad = val["AxisConfigAutoLoad"]; pc.LayerConfigPath = val["LayerConfigPath"]; pc.LayerConfigAutoLoad = val["LayerConfigAutoLoad"]; pc.TextureConfigPath = val["TextureConfigPath"]; pc.TextureConfigAutoLoad = val["TextureConfigAutoLoad"]; } catch (Exception e) { Exception ex = new ConfigException("ProjectConfig.json file is incorrect", e); Log.Exception(ex); throw ex; } this.Config = pc; if (this.Config.AxisConfigAutoLoad) { Axis.LoadConfig(this.Config.AxisConfigPath); } if (this.Config.LayerConfigAutoLoad) { Layer.LoadConfig(this.Config.LayerConfigPath); } if (this.Config.TextureConfigAutoLoad) { Texture.LoadConfig(this.Config.TextureConfigPath); } }
public bool Serve() { if (!IPAddress.TryParse(_ipAddrStr, out var ipAddr)) //WTF RIDER ?????? { Exception ex = new ConfigException("Cannot parse IPAddr"); _logger.Fatal(ex); throw ex; } try { _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _serverSocket.Bind(new IPEndPoint(ipAddr, _port)); _serverSocket.Listen(ConnMaxValue); _serverSocket.ReceiveTimeout = Timeout; _serverSocket.SendTimeout = Timeout; _status = true; } catch (SocketException e) { _logger.Error(e, "Cannot initialize server socket... "); return(false); } catch (Exception e) { _logger.Fatal(e, "Unhandled server socket ititialize error.."); throw; } _clientListenLoop = new Thread(ClientLoop); _clientListenLoop.Priority = ThreadPriority.Highest; _clientListenLoop.Start(); return(_status); }
public AdventureData GenerateAdventure(RegionData selectedRegion) { var randomType = selectedRegion.GetRandomLocationType(); LocationData type = locations.First(x => x.Name == randomType); var adventure = new AdventureData() { Region = selectedRegion.Name, AdventureType = type.Name, Scale = type.Scale }; try { adventure.Level = GetRandomLevel(selectedRegion.GetTier()); adventure.PrimaryMonster = selectedRegion.GetRandomMonster(r.NextDouble()); adventure.Size = type.GetSize(); adventure.HasBoss = type.GetBoss(); adventure.SubType = type.GetSubtype(); } catch (Exception e) { var exc = new ConfigException("Creating adventure failed due to configuration issues. Check the format of region and adventure types", e); throw exc; } return(adventure); }
protected static dynamic ReadConfigFile(string path) { path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + '/' + path; FileStream fs; try { fs = new FileStream(path, FileMode.Open, FileAccess.Read); } catch (Exception e) { Exception ex = new ConfigException("Cannot open file \"" + path + "\"", e); Log.Exception(ex); throw ex; } StreamReader sr = new StreamReader(fs); string str = sr.ReadToEnd(); sr.Close(); fs.Close(); object obj; JavaScriptSerializer jss = new JavaScriptSerializer(); try { obj = jss.Deserialize <dynamic>(str); } catch (Exception e) { Exception ex = new ConfigException("Cannot convert config file to object in \"" + path + "\"", e); Log.Exception(ex); throw ex; } return(obj); }
/// <summary> /// Loads axes configuration from file. /// </summary> public static void LoadConfig(string path) { Axes = new Collection <Axis>(); dynamic val = ReadConfigFile(path); try { var i = val["Axes"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } foreach (Dictionary <string, object> dict in val["Axes"]) { string name = ""; Keys pos; Keys neg; try { name = (string)dict["Name"]; pos = (Keys)Enum.Parse(typeof(Keys), (string)dict["PositiveName"]); neg = (Keys)Enum.Parse(typeof(Keys), (string)dict["NegativeName"]); } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } Axis a = new Axis(name, neg, pos); Axis.setup(a); } }
public PrivacyProtocolConfigException(PrivacyProtocolType type, ConfigException ex) : base(ex.Message) { this.PrivacyProtocolType = type; }
public static void LoadConfig(string path) { dynamic val = ReadConfigFile(path); try { var a = val["Image"]["Regular"]; var b = val["Image"]["Grid"]; var c = val["Other"]["Color"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } foreach (Dictionary <string, object> dict in val["Image"]["Regular"]) { string name; string p; try { name = (string)dict["Name"]; p = (string)dict["ImagePath"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } RegularTexture t = new RegularTexture(name, p); if (dict.ContainsKey("InterpolationMode")) { t.InterpolationMode = (System.Drawing.Drawing2D.InterpolationMode) Enum.Parse(typeof(System.Drawing.Drawing2D.InterpolationMode), (string)dict["InterpolationMode"]); } All.Add(t); } foreach (Dictionary <string, object> dict in val["Image"]["Grid"]) { string name; string p; int xc; int yc; try { name = (string)dict["Name"]; p = (string)dict["ImagePath"]; xc = (int)dict["xCount"]; yc = (int)dict["yCount"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } GridTexture t = new GridTexture(name, p, xc, yc); if (dict.ContainsKey("InterpolationMode")) { t.InterpolationMode = (System.Drawing.Drawing2D.InterpolationMode) Enum.Parse(typeof(System.Drawing.Drawing2D.InterpolationMode), (string)dict["InterpolationMode"]); } All.Add(t); } foreach (Dictionary <string, object> dict in val["Other"]["Color"]) { string name; string hex; ColorTextureShape shape; try { name = (string)dict["Name"]; hex = (string)dict["HexColor"]; Dictionary <string, object> sd = (Dictionary <string, object>)dict["Size"]; shape = (ColorTextureShape)Enum.Parse(typeof(ColorTextureShape), (string)dict["ShapeString"]); } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } ColorConverter cc = new ColorConverter(); Color c = (Color)cc.ConvertFromString(hex); All.Add(new ColorTexture(name, c, shape)); } foreach (Texture t in All) { if (t is ImageTexture) { ((ImageTexture)t).InitializeImage(); } } }
private async Task <TreeNodeInfo> getNodeByGdid(HashSet <GDID> graph, TreePtr tree, GDID gNode, DateTime asOfUtc, ICacheParams caching) { var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getNodeByGdid) + gNode.ToHexString() + asOfUtc.Ticks; var result = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { if (!graph.Add(gNode)) { //circular reference var err = new ConfigException("Circular reference in config tree = `{0}`, gnode = `{1}`, asof = `{2}`".Args(tree, gNode, asOfUtc)); WriteLogFromHere(Log.MessageType.CatastrophicError, err.Message, err, pars: new { tree = tree.ToString(), gnode = gNode, asof = asOfUtc }.ToJson()); throw err; } //1 - fetch THIS level - rightmost part of the tree var qry = new Query <TreeNodeInfo>("Tree.GetNodeInfoByGdid") { new Query.Param("tree", tree), new Query.Param("gdid", gNode), new Query.Param("asof", asOfUtc) }; var node = await m_Data.TreeLoadDocAsync(tree, qry); if (node == null) { return(null); } //2 - if IAM ROOT, there is no parent for root node.EffectiveConfig = new ConfigVector(node.LevelConfig.Content);//Copy node.FullPath = Constraints.VERY_ROOT_PATH_SEGMENT; if (node.Gdid == Constraints.G_VERY_ROOT_NODE) { return(node); } //3 - Fetch parent of THIS TreeNodeInfo nodeParent = await getNodeByGdid(graph, tree, node.G_Parent, asOfUtc, caching).ConfigureAwait(false); if (nodeParent == null) { return(null); } //4 - calculate effective config var cfgNode = node.LevelConfig.Node.NonEmpty(nameof(node.LevelConfig)); var cfgParent = nodeParent.EffectiveConfig.Node.NonEmpty(nameof(nodeParent.EffectiveConfig)); var confResult = new MemoryConfiguration() { Application = this.App }; confResult.CreateFromNode(cfgParent); //inherit confResult.Root.OverrideBy(cfgNode); //override node.EffectiveConfig.Node = confResult.Root; node.FullPath = TreePath.Join(nodeParent.FullPath, node.PathSegment); //the security check is done post factum AFTER tree node full path is known return(node); } ).ConfigureAwait(false); if (result == null) { return(null); } App.Authorize(new TreePermission(TreeAccessLevel.Read, result.FullPathId)); return(result); }
public void ConstructorEmpty() { var exception = new ConfigException(); Assert.AreEqual("Exception of type 'Celerik.NetCore.Services.ConfigException' was thrown.", exception.Message); }