public static void TestContractA_TwoWayCall(string CONF_SRC) { TestServerA.s_Accumulator = 0; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value); var result = cl.Method1(12); Assert.AreEqual("12", result); Assert.AreEqual(12, TestServerA.s_Accumulator); } }
static void Main(string[] args) { try { using (var app = new ServiceBaseApplication(args, null)) run(app.CommandArgs); Environment.ExitCode = 0; } catch (Exception error) { ConsoleUtils.Error(error.ToMessageWithType()); Environment.ExitCode = -1; } }
public void CFG_MountMDBStore() { using (var app = new ServiceBaseApplication(null, CONFIG_1.AsLaconicConfig(handling: ConvertErrorHandling.Throw))) { var ds = app.DataStore as MDBDataStore; Aver.IsNotNull(ds); Aver.AreEqual(2, ds.Areas.Count); Aver.IsTrue(object.ReferenceEquals(ds.CentralArea, ds.Areas[MDBArea.CENTRAL_AREA_NAME])); var auser = ds.Areas["User"] as MDBPartitionedArea; Aver.IsNotNull(auser); Aver.AreEqual(3, auser.Partitions.Count()); } }//test
public void SetUp() { var config = CONFIG.AsLaconicConfig(handling: ConvertErrorHandling.Throw); m_App = new ServiceBaseApplication(null, config); m_Sink = (TwilioSink)((MessageService)MessageService.Instance).Sink; Aver.IsNotNull(m_Sink); Aver.IsTrue(m_Sink.Name.EqualsOrdIgnoreCase("Twilio")); Aver.IsTrue(m_Sink.SupportedChannels == MsgChannels.SMS); Aver.IsTrue(m_Sink.SupportedChannelNames.Contains("Twilio")); Aver.IsTrue(m_Sink.Running); }
static void Main(string[] args) { using (var application = new ServiceBaseApplication(args, null)) { try { var clientLogin = new ClientLoginProcessor(); clientLogin.Run(); } catch { Console.WriteLine("CRITICAL ERROR"); Console.ReadKey(); } } }
public void T6() { var lst = TeztHandler.s_List; lst.Clear(); using (var app = new ServiceBaseApplication(null, CONFIG3_HANDLERS.AsLaconicConfig())) { Thread.Sleep(10000); } Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(14, lst.Count); Assert.AreEqual(10, lst.Count(s => s == "ItonTV::Gorin.True")); Assert.AreEqual(4, lst.Count(s => s == "Nativ::Kedmi.False")); }
public void CH_CallWithRetry_TwoHostErrAbortFalse() { var conf = CONFIG1.AsLaconicConfig(handling: ConvertErrorHandling.Throw); using (var app = new ServiceBaseApplication(null, conf)) { Exception err = null; var arg = "FAIL"; var echoed = ServiceClientHub.CallWithRetry <ITesterClient, object> ( (cl) => cl.TestEcho(arg), new string[] { "/us/east/cle/a/i/wmed0001", "/us/east/cle/a/i/wmed0001" }, (cl, er) => { err = er; Console.WriteLine(er.ToMessageWithType()); return(false); } ); } }
public static void TestContractB_4(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); //Testing overloaded calls Assert.AreEqual("Felix", cl.GetName()); Assert.AreEqual("Felix23", cl.GetName(23)); Assert.AreEqual("Felix42", cl.GetName(42)); Assert.AreEqual("Felix", cl.GetName()); dumpBindingTransports(cl.Binding); } }
public void CH_EchoTwoCalls() { var conf = CONFIG1.AsLaconicConfig(handling: ConvertErrorHandling.Throw); using (var app = new ServiceBaseApplication(null, conf)) { using (var tester = ServiceClientHub.New <ITesterClient>("/us/east/cle/a/ii/wmed0004")) { var arg = "Abcdefg"; var echoed = tester.TestEcho(arg); Aver.AreObjectsEqual(arg, echoed); arg = "Ze Rozenberg"; echoed = tester.TestEcho(arg); Aver.AreObjectsEqual(arg, echoed); } } }
public void SimplePayoutTest() { var conf = LACONF.AsLaconicConfig(); var paySystem = getPaySystem(); using (var app = new ServiceBaseApplication(null, conf)) using (var session = paySystem.StartSession() as PayPalSession) { var to = new Account("user", 211, 3000001); var amount = new Amount("USD", 1.0m); var transaction = session.Transfer(null, Account.EmptyInstance, to, amount); Assert.IsNotNull(transaction); Assert.AreEqual(TransactionType.Transfer, transaction.Type); Assert.AreEqual(amount, transaction.Amount); Assert.AreEqual(Account.EmptyInstance, transaction.From); Assert.AreEqual(to, transaction.To); } }
public static void TASKReturning_TestContractA_TwoWayCall(string CONF_SRC) { TestServerA.s_Accumulator = 0; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value); var call = cl.Async_Method1(12); var task = call.AsTaskReturning <string>(); var result = task.Result; Aver.AreEqual("12", result); Aver.AreEqual(12, TestServerA.s_Accumulator); } }
private static void determineHostName(ServiceBaseApplication bootApp) { var hNode = bootApp.ConfigRoot[CONFIG_AGNI_SECTION][CONFIG_HOST_SECTION]; s_HostName = hNode.AttrByName(CONFIG_HOST_NAME_ATTR).Value; if (s_HostName.IsNullOrWhiteSpace()) { bootApp.writeLog(NFX.Log.MessageType.Warning, "Host name was not specified in config, trying to take from machine env var {0}".Args(ENV_VAR_HOST_NAME)); s_HostName = System.Environment.GetEnvironmentVariable(ENV_VAR_HOST_NAME); } if (s_HostName.IsNullOrWhiteSpace()) { bootApp.writeLog(NFX.Log.MessageType.Warning, "Host name was not specified in neither config nor env var, taking from local computer name"); s_HostName = "{0}/{1}".Args(DEFAULT_HOST_ZONE_PATH, System.Environment.MachineName); } bootApp.writeLog(NFX.Log.MessageType.Info, "Host name: " + s_HostName); }
public static void Main(string[] args) { try { using (var app = new ServiceBaseApplication(true, args, null)) { Console.CancelKeyPress += (_, e) => { app.Stop(); e.Cancel = true; }; System.Environment.ExitCode = run(app); } } catch (Exception error) { ConsoleUtils.Error(error.ToMessageWithType()); ConsoleUtils.Warning(error.StackTrace); Console.WriteLine(); System.Environment.ExitCode = -1; } }
static void Main(string[] args) { using (var application = new ServiceBaseApplication(args, null)) { var message = Console.ReadLine(); using (var client = new CacheServerAutoClient("sync://localhost:8080")) { while (true) { var input = Console.ReadLine(); var cmd = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); exeCommand(client, cmd); } //var responce = client.Echo(message); //Console.WriteLine(responce); } } }
public void Starter2_WithException_Break() { var confSource = @" nfx{ starters{ starter{ name='Alex' type='NFX.NUnit.AppModel.MyStarter, NFX.NUnit' application-start-break-on-exception='true'} starter{ name='Boris' type='NFX.NUnit.AppModel.MyStarter, NFX.NUnit'} } } "; RESULT = null;//NULL REFERENCE should happen var conf = LaconicConfiguration.CreateFromString(confSource); using (var app = new ServiceBaseApplication(null, conf.Root)) { } }
public void CH_CallWithRetry_FirstHostErr() { var conf = CONFIG1.AsLaconicConfig(handling: ConvertErrorHandling.Throw); using (var app = new ServiceBaseApplication(null, conf)) { Exception err = null; var arg = "Abcdefg"; var echoed = ServiceClientHub.CallWithRetry <ITesterClient, object> ( (cl) => cl.TestEcho(arg), new string[] { "/us/east/cle/a/i/wmed0002", "/us/east/cle/a/ii/wmed0004" }, (cl, er) => { err = er; Console.WriteLine(er.ToMessageWithType()); return(false); } ); Aver.AreObjectsEqual(arg, echoed); Aver.IsTrue(err.ToMessageWithType().Contains("address is not valid")); } }
public static void TASK_TestContractB_4_Parallel(string CONF_SRC, bool threadSafe) { const int CNT = 10000; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { //Use the same client..... var cl = new TestContractBClient(App.ConfigRoot.AttrByName(threadSafe?"cs":"cs2").Value); Assert.AreEqual("Felix1223", cl.GetName(1223)); //alloc server var set = new HashSet <int>(); var watch = System.Diagnostics.Stopwatch.StartNew(); //.....for making many parallel calls System.Threading.Tasks.Parallel.For(0, CNT, (i, loop) => { var id = System.Threading.Thread.CurrentThread.ManagedThreadId; lock (set) set.Add(id); //Testing overloaded calls USING asTASK property var result = cl.Async_GetName(i).AsTask.Result.GetValue <string>(); Assert.AreEqual("Felix{0}".Args(i), result); }); var elps = watch.ElapsedMilliseconds; Console.WriteLine("Parallel Glue Test made {0} calls in {1} ms at {2} call/sec and was done by these threads:".Args(CNT, elps, CNT / (elps / 1000d))); dumpBindingTransports(cl.Binding); var cnt = 0; foreach (var id in set) { Console.Write(id + ", "); cnt++; } Console.WriteLine(cnt + " total"); } }
static void Main(string[] args) { try { using (var app = new ServiceBaseApplication(args, null)) using (var server = new WaveServer()) { server.Configure(null); server.Start(); Console.WriteLine("server started..."); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("Critical error:"); Console.WriteLine(ex); Environment.ExitCode = -1; } }
public static void TestContractA_OneWayCall(string CONF_SRC) { TestServerA.s_Accumulator = 0; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value); cl.Method2(93); for (var cnt = 0; cnt < 10 && TestServerA.s_Accumulator != 93; cnt++) { System.Threading.Thread.Sleep(1000); } Assert.AreEqual(93, TestServerA.s_Accumulator); } }
private static void run(ServiceBaseApplication app) { //The command-line arguments are already parsed into configuration object accessible via `CommandArgs` //property of the application context if (app.CommandArgs["?", "h", "help"].Exists) { //`GetText(path)` is an extension method that reads an embedded resource //relative to the specfied type location ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt")); return; } var silent = app.CommandArgs["s", "silent"].Exists; if (!silent) { ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt")); } if (!silent) { Console.WriteLine(); } //Get logic switch ' -logic' from command args line as config section //notice no `if` statements, if addressed nodes do not exist, sentinels are returned instead //we could use `if (cfgLogic.Exists)....` var cfgLogic = app.CommandArgs["logic"]; //Inject the logic from config (BY CONFIGURATION), use DefaultLogic if type is not specified (BY CONVENTION). //This will call Configure(cfgLogic) on the Logic instance after its creation var logic = FactoryUtils.MakeAndConfigure <Logic>(cfgLogic, typeof(DefaultLogic)); //execute injected logic module logic.Execute(); if (!silent) { ConsoleUtils.Info("The End"); } }
private static void ensureMetabaseAppName(ServiceBaseApplication bootApp, IConfigSectionNode mNode) { if (AgniSystem.MetabaseApplicationName == null) { var appName = bootApp.CommandArgs[CMD_ARG_AGNI_SWITCH].AttrByName(CMD_ARG_APP_NAME).Value; if (appName.IsNotNullOrWhiteSpace()) { bootApp.writeLog(NFX.Log.MessageType.Info, "Metabase application name was not defined in code, but is injected from cmd arg '-{0} {1}=<app name>'".Args(CMD_ARG_AGNI_SWITCH, CMD_ARG_APP_NAME)); } else { bootApp.writeLog(NFX.Log.MessageType.Warning, "Metabase application name was not defined in code or cmd switch, reading from '{0}/${1}'".Args(CONFIG_METABASE_SECTION, CONFIG_APPLICATION_NAME_ATTR)); appName = mNode.AttrByName(CONFIG_APPLICATION_NAME_ATTR).Value; } try { AgniSystem.MetabaseApplicationName = appName; } catch (Exception error) { bootApp.writeLog(NFX.Log.MessageType.CatastrophicError, error.ToMessageWithType()); throw error; } bootApp.writeLog(NFX.Log.MessageType.Info, "Metabase application name from config set to: " + AgniSystem.MetabaseApplicationName); } else { bootApp.writeLog(NFX.Log.MessageType.Info, "Metabase application name defined in code: " + AgniSystem.MetabaseApplicationName); if (mNode.AttrByName(CONFIG_APPLICATION_NAME_ATTR).Exists) { bootApp.writeLog(NFX.Log.MessageType.Warning, "Metabase application name defined in code but the boot config also defines the name which was ignored"); } } }
public void Starter1() { var confSource = @" nfx{ starters{ starter{ name='Alex' type='NFX.NUnit.AppModel.MyStarter, NFX.NUnit'} starter{ name='Boris' type='NFX.NUnit.AppModel.MyStarter, NFX.NUnit'} } } "; RESULT = ""; var conf = LaconicConfiguration.CreateFromString(confSource); using (var app = new ServiceBaseApplication(null, conf.Root)) { } Assert.AreEqual("Alex Before;Boris Before;Alex After;Boris After;", RESULT); }
public static void TestContractB_4_AsyncReactor(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using (var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); var reactor = new CallReactor( new Call(cl.Async_GetName(), (r, c) => Assert.AreEqual("Felix", c.CallSlot.GetValue <string>())), new Call(cl.Async_GetName(23), (r, c) => Assert.AreEqual("Felix23", c.CallSlot.GetValue <string>())), new Call(cl.Async_GetName(42), (r, c) => Assert.AreEqual("Felix42", c.CallSlot.GetValue <string>())), new Call(cl.Async_GetName(2, DateTime.Now), (r, c) => Assert.IsTrue(c.CallSlot.GetValue <string>().StartsWith("Felix2"))) ); reactor.Wait(); dumpBindingTransports(cl.Binding); Assert.IsTrue(reactor.Finished); } }
static void Main(string[] args) { try { using (var application = new ServiceBaseApplication(args, null)) { Console.WriteLine("ChatApp Server 1.0\n\nserver is running...\n"); foreach (var server in App.Glue.Servers) { Console.WriteLine(server); } Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("error:"); Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
public void Starter2_WithException_NoBreak() { var confSource = @" nfx{ starters{ starter{ name='Alex' type='NFX.UTest.AppModel.MyStarter, NFX.UTest'} starter{ name='Boris' type='NFX.UTest.AppModel.MyStarter, NFX.UTest'} } } "; RESULT = null;//NULL REFERENCE should happen var conf = LaconicConfiguration.CreateFromString(confSource); using (var app = new ServiceBaseApplication(null, conf.Root)) { } Aver.IsNull(RESULT); //no exception }
static int Main(string[] args) { try { using (var app = new ServiceBaseApplication(args, null)) //explicit rootConfig = null - will search the co-located file run(app); if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine("Strike a key..."); Console.ReadKey(); } return(0); } catch (Exception error) { ConsoleUtils.Error("Program leaked: {0}\n Trace: {1}".Args(error.ToMessageWithType(), error.StackTrace)); return(-1); } }
static void Main(string[] args) { Console.WriteLine("Привет это тест!"); try { using (var app = new ServiceBaseApplication(args, null)) using (var server = new WaveServer()) { server.Configure(null); server.Start(); Console.WriteLine("Севрер запущен"); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("Ошибка"); Console.WriteLine(ex); Environment.ExitCode = -1; Console.ReadLine(); } }
public void KDB_T00011_PutGetRowWithAttributes() { using (var app = new ServiceBaseApplication(null, CONFIG_1.AsLaconicConfig(handling: ConvertErrorHandling.Throw))) { var tbl = "tbla"; DropCollection(tbl); var ds = app.DataStore as DefaultKDBStore; var key = new byte[] { 1, 2, 3 }; var absExp = new DateTime(2300, 1, 1, 14, 00, 00, DateTimeKind.Utc); ds.Put(tbl, key, new TestRow { Name = "SomeName", Description = "SomeDescr" }, 1234, absExp); var result = ds.Get <TestRow>(tbl, key); Aver.IsTrue(result.IsAssigned); Aver.AreEqual("SomeName", result.Value.Name); Aver.AreEqual("SomeDescr", result.Value.Description); Aver.AreEqual(1234, result.SlidingExpirationDays); Aver.AreEqual(absExp, result.AbsoluteExpirationDateUTC); } }
static void Main(string[] args) { try { using (var application = new ServiceBaseApplication(args, null)) { Console.WriteLine("server is running..."); Console.WriteLine("Glue servers:"); foreach (var service in App.Glue.Servers) { Console.WriteLine(" " + service); } Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("error:"); Console.WriteLine(ex.ToString()); } }
private static void run(ServiceBaseApplication app) { if (app.CommandArgs["?", "h", "help"].Exists) { //GetText is an extension method that reads an embedded resource //relative to the specfied type location ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt")); return; } var silent = app.CommandArgs["s", "silent"].Exists; if (!silent) { ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt")); } if (!silent) { Console.WriteLine(); } //Get logic switch ' -logic' from command args line as config section //notice no if statements, if nodes does not exist, sentinels are returned //we could use if (cfgLogic.Exists).... var cfgLogic = app.CommandArgs["logic"]; //Inject the logic from config, use DefaultLogic if type is not specified //this will call Configure(cfgLogic) on the Logic instance var logic = FactoryUtils.MakeAndConfigure <Logic>(cfgLogic, typeof(DefaultLogic)); //execute injected logic module logic.Execute(); if (!silent) { ConsoleUtils.Info("The End"); } }