internal static void PrintStackTrace(this Exception e, TextWriter writer) { writer.WriteLine(e.ToString()); string trace = e.StackTrace ?? string.Empty; foreach (string line in trace.Split('\n', '\r')) { if (!string.IsNullOrEmpty(line)) writer.WriteLine(" " + line); } }
public override void Emit(IProcessorArchitecture arch, TextWriter writer) { EmitRegisters(arch, "// DataOut:", DataOut, writer); writer.WriteLine(); EmitFlagGroup(arch, "// DataOut (flags):", grfOut, writer); writer.WriteLine(); SymbolicIn.Emit(arch, "// SymbolicIn:", writer); writer.WriteLine(); EmitLocals("// LocalsOut:", writer); if (TerminatesProcess) writer.WriteLine("// Terminates process"); }
/// <summary> /// Determines whether the scuedule for the specified aspect (e.g. planned or actual) of this activity /// is valid. If it is not, then when it completes, the textWriter will contain a description of why not. /// </summary> /// <param name="tw">The textWriter that declares why the time period's schedule might not be valid.</param> /// <param name="timePeriodKey">The time period key.</param> /// <returns>true if the schedule under this activity is valid.</returns> public bool Validate(System.IO.TextWriter tw, object timePeriodKey) { bool allValid = false; while (!allValid) { List <IMilestone> milestones = GatherAllMilestones(timePeriodKey); List <MilestoneRelationship> relationships = new List <MilestoneRelationship>(); foreach (IMilestone ms in milestones) { foreach (MilestoneRelationship mr in ms.Relationships) { if (!relationships.Contains(mr)) { relationships.Add(mr); } } } allValid = true; foreach (MilestoneRelationship mr in relationships) { if (!mr.IsSatisfied()) { allValid = false; tw?.WriteLine(mr.ToString()); } } } return(true); }
protected override void DumpChildren(TextWriter Out, uint Depth) { foreach (VEntry e in Fields.Values) { Indent(Out, Depth); Out.Write(e.Name); Out.WriteLine(" ="); e.Value.Dump(Out, Depth+1); } }
internal static void Start(System.IO.TextWriter consoleOut) { var pollInterval = Configuration.Indexing.IndexHealthMonitorRunningPeriod * 1000.0; _timer = new System.Timers.Timer(pollInterval); _timer.Elapsed += Timer_Elapsed; _timer.Disposed += Timer_Disposed; _timer.Enabled = true; consoleOut?.WriteLine("IndexHealthMonitor started. Frequency: {0} s", Configuration.Indexing.IndexHealthMonitorRunningPeriod); }
protected override void DumpChildren(TextWriter Out, uint Depth) { foreach (Element e in Elements) { e.First.Dump(Out, Depth); if (e.ArrowPos != null) { Indent(Out, Depth+1); Out.WriteLine("->"); e.Second.Dump(Out, Depth+1); } } }
/// <summary> /// Runs the test. /// </summary> /// <param name="name">Name.</param> /// <param name="testMethod">Test method.</param> /// <param name="output">Output.</param> public static void RunTest(string name, Action testMethod, TextWriter output = null) { if (output == null) output = Console.Out; string _oldNL = output.NewLine; try { output.WriteLine(_runTestFormatStart, name); testMethod(); output.WriteLine(_runTestFormatSuccess, name); } catch (FaultException<ExceptionDetail> ex) { output.WriteLine(_runTestFormatError, name); output.WriteLine(_runTestFormatException, ex.GetType().FullName, ex.Message, ex.StackTrace); foreach (DictionaryEntry de in ex.Data) output.Write("\t{0} = {1}\n", de.Key.ToString(), de.Value.ToString()); int indent = 0; for (ExceptionDetail detail = ex.Detail; detail != null; detail = detail.InnerException) output.WriteLine(string.Concat(" ------ Inner Exception ------\n", string.Format(_runTestFormatException, detail.Type, detail.Message, detail.StackTrace)) .Replace("\n", string.Concat("\n", new string(' ', ++indent * 2))).TrimStart('\n')); } catch (Exception ex) { output.WriteLine(_runTestFormatError, name); output.WriteLine(_runTestFormatException, ex.GetType().FullName, ex.Message, ex.StackTrace); foreach (DictionaryEntry de in ex.Data) output.Write("\t{0} = {1}\n", de.Key.ToString(), de.Value.ToString()); int indent = 0; for (Exception innerEx = ex.InnerException; innerEx != null; innerEx = innerEx.InnerException) output.WriteLine(string.Concat("\n ------ Inner Exception ------\n", string.Format(_runTestFormatException, innerEx.GetType().FullName, innerEx.Message, innerEx.StackTrace)) .Replace("\n", string.Concat("\n", new string(' ', ++indent * 2))).TrimStart('\n')); } finally { output.NewLine = _oldNL; // you COULD wrap this in a using() if you write a class implementing IDisposable with this line in Dispose() } }
public virtual void PrintGrammar( TextWriter output ) { ANTLRTreePrinter printer = new ANTLRTreePrinter( new Antlr.Runtime.Tree.CommonTreeNodeStream( grammarTree ) ); //printer.setASTNodeClass( "org.antlr.tool.GrammarAST" ); try { string g = printer.toString( this, false ); output.WriteLine( g ); } catch ( RecognitionException re ) { ErrorManager.Error( ErrorManager.MSG_SYNTAX_ERROR, re ); } }
public override void WriteCommand(System.IO.TextWriter writer) { writer.WriteLine("Apply {"); Commands.WriteCommands(writer); writer.WriteLine("}"); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = helper.Protocol == Protocol.Ice1; var manager = IServerManagerPrx.Parse(helper.GetTestProxy("ServerManager", 0), communicator); var locator = communicator.DefaultLocator !.Clone(ITestLocatorPrx.Factory); Console.WriteLine("registry checkedcast"); var registry = locator.GetRegistry() !.Clone(ITestLocatorRegistryPrx.Factory); TestHelper.Assert(registry != null); System.IO.TextWriter output = helper.Output; output.Write("testing ice1 string/URI parsing... "); output.Flush(); IObjectPrx base1, base2, base3, base4, base5, base6, base7; if (ice1) { base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); base3 = IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator); base4 = IObjectPrx.Parse("ServerManager", communicator); base5 = IObjectPrx.Parse("test2", communicator); base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); base7 = IObjectPrx.Parse("test3 -f facet", communicator); } else { base1 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base2 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base3 = IObjectPrx.Parse("ice:test", communicator); base4 = IObjectPrx.Parse("ice:ServerManager", communicator); base5 = IObjectPrx.Parse("ice:test2", communicator); base6 = IObjectPrx.Parse("ice:ReplicatedAdapter//test", communicator); base7 = IObjectPrx.Parse("ice:test3#facet", communicator); } output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); var anotherLocator = ILocatorPrx.Parse(ice1 ? "anotherLocator" : "ice:anotherLocator", communicator); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Locator == null); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = locator; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); // TODO: We also test ice_router/ice_getRouter(perhaps we should add a test/Ice/router test?) TestHelper.Assert(base1.Router == null); var anotherRouter = IRouterPrx.Parse(ice1 ? "anotherRouter" : "ice:anotherRouter", communicator); base1 = base1.Clone(router: anotherRouter); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter)); var router = IRouterPrx.Parse(ice1 ? "dummyrouter" : "ice:dummyrouter", communicator); communicator.DefaultRouter = router; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !)); communicator.DefaultRouter = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.StartServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj1 = base1.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj1 != null); var obj2 = base2.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj2 != null); var obj3 = base3.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj3 != null); var obj4 = base4.CheckedCast(IServerManagerPrx.Factory); TestHelper.Assert(obj4 != null); var obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); var obj6 = base6.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj6 != null); output.WriteLine("ok"); output.Write("testing AdapterId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing ReplicaGroupId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj6.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); obj5.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { base1 = IObjectPrx.Parse(ice1 ? "unknown/unknown" : "ice:unknown/unknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { base1 = IObjectPrx.Parse( ice1 ? "test @ TestAdapterUnknown" : "ice:TestAdapterUnknown//test", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); IObjectPrx basencc = IObjectPrx.Parse( ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(cacheConnection: false); int count = locator.GetRequestCount(); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. TestHelper.Assert(++count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout TestHelper.Assert(count == locator.GetRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator) .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); TestHelper.Assert(IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj1 = ITestIntfPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator); IHelloPrx?hello = obj1.GetHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "TestAdapter"); hello.SayHello(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "ReplicatedAdapter"); hello.SayHello(); output.WriteLine("ok"); output.Write("testing well-known proxy with facet... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "bonjour -f abc" : "ice:bonjour#abc", communicator); hello.SayHello(); hello = IHelloPrx.Parse(ice1 ? "hello -f abc" : "ice:hello#abc", communicator); try { hello.SayHello(); TestHelper.Assert(false); } catch (NoEndpointException) // hello does not have an abc facet { } output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj1.GetReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false); TestHelper.Assert(hello != null); count = locator.GetRequestCount(); hello.IcePing(); TestHelper.Assert(++count == locator.GetRequestCount()); var results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 999); count = locator.GetRequestCount(); hello = hello.Clone(location: ImmutableArray.Create("unknown")); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync().ContinueWith( t => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is NoEndpointException) { } }, TaskScheduler.Default)); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 1999); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } RegisterAdapterEndpoints( registry, "TestAdapter3", replicaGroupId: "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); RegisterAdapterEndpoints( registry, "TestAdapter3", replicaGroupId: "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch (ConnectionRefusedException) { } RegisterAdapterEndpoints( registry, "TestAdapter3", "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestUnknown" : "ice:TestUnknown//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter4" : "ice:TestAdapter4//test3", communicator)); // Update RegisterAdapterEndpoints( registry, "TestAdapter4", "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } RegisterAdapterEndpoints( registry, "TestAdapter4", "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } RegisterAdapterEndpoints( registry, "TestAdapter4", "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.AddObject(IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator)); try { IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; using Communicator ic = helper.Initialize(properties); RegisterAdapterEndpoints( registry, "TestAdapter5", "", ResolveLocation(locator, "TestAdapter") !); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 3; TestHelper.Assert(count == locator.GetRequestCount()); UnregisterAdapterEndpoints(registry, "TestAdapter5", ""); registry.AddObject(IObjectPrx.Parse(helper.GetTestProxy("test3", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); obj1.Shutdown(); manager.StartServer(); hello.SayHello(); output.WriteLine("ok"); // TODO: this does not work with ice2 because we currently don't retry on any remote exception, including // ONE. if (ice1) { output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); obj1.MigrateHello(); hello.GetConnection().GoAwayAsync(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); output.WriteLine("ok"); } output.Write("shutdown server... "); output.Flush(); obj1.Shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { obj3.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { TestHelper.Assert(obj5 != null); obj5.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to colocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints( "Hello", ice1 ? "tcp -h localhost" : "ice+tcp://localhost:0"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(id, new Hello()); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx; if (ice1) { helloPrx = IHelloPrx.Parse($"{id}", communicator); } else { helloPrx = IHelloPrx.Parse($"ice:{id}", communicator); } TestHelper.Assert(helloPrx.GetConnection() is ColocatedConnection); // Ensure that calls on the indirect proxy (with adapter ID) is colocated helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() is ColocatedConnection); // Ensure that calls on the direct proxy is colocated helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).Clone( endpoints: adapter.PublishedEndpoints, location: ImmutableArray <string> .Empty).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() is ColocatedConnection); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.Shutdown(); output.WriteLine("ok"); }
public void Write(TextWriter writer) { SortedList<string,string> vals = new SortedList<string,string>(); writer.WriteLine("Values:"); foreach (KeyValuePair<Expression,Expression> de in valid) { string s = string.Format("{0}: <{1}>", de.Key, de.Value); vals.Add(s, s); } foreach (string s in vals.Values) { writer.WriteLine("\t{0}", s); } writer.WriteLine("Identifiers:"); throw new NotImplementedException("Fix this once we decided to use ValueNumbering again."); //for (int i = 0; i != nodes.Count; ++i) //{ // throw new NotImplementedException("Use hashtable for ssaIds // SsaIdentifier info = ssaIds[i];"); // //writer.WriteLine("\t{0}: <{1}>", info.Identifier, nodes[i].vn); //} }
public void Dump(TextWriter Out, uint Depth) { Indent(Out, Depth); Out.WriteLine(DumpHeader()); DumpChildren(Out, Depth+1); }
/// <summary> /// Writes flow state that is true on exit from the basic block. /// </summary> /// <param name="arch"></param> /// <param name="writer"></param> public void WriteAfter(IProcessorArchitecture arch, TextWriter writer) { EmitRegisters(arch, "// DataOut:", DataOut, writer); writer.WriteLine(); EmitFlagGroup(arch, "// DataOut (flags):", grfOut, writer); writer.WriteLine(); EmitLocals("// LocalsOut:", writer); if (TerminatesProcess) writer.WriteLine("// Terminates process"); }
public void Write(System.IO.TextWriter wr) { wr.WriteLine("*** MODEL"); foreach (var f in Functions.OrderBy(f => f.Name)) { if (f.Arity == 0) { wr.WriteLine("{0} -> {1}", f.Name, f.GetConstant()); } } foreach (var f in Functions.OrderBy(f => f.Name)) { if (f.Arity != 0) { wr.WriteLine("{0} -> {{", f.Name); // first, add the entries to a list, so that they can be sorted before printing List <Tuple <string, Element> > entries = new List <Tuple <string, Element> >(); foreach (var app in f.Apps) { var args = ""; foreach (var a in app.Args) { args += a + " "; } entries.Add(new Tuple <string, Element>(args, app.Result)); } foreach (var entry in entries.OrderBy(pair => pair.Item1)) { wr.WriteLine(" {0}-> {1}", entry.Item1, entry.Item2); } if (f.Else != null) { wr.WriteLine(" else -> {0}", f.Else); } wr.WriteLine("}"); } } foreach (var s in States) { if (s == InitialState && s.VariableCount == 0) { continue; } wr.WriteLine("*** STATE {0}", s.Name); foreach (var v in s.Variables.OrderBy(nm => nm)) { wr.WriteLine(" {0} -> {1}", v, s.TryGet(v)); } wr.WriteLine("*** END_STATE", s.Name); } wr.WriteLine("*** END_MODEL"); }
public override void WriteCode(System.IO.TextWriter writer, int indent, int CurStack) { WriteInstHeader(writer, indent); writer.WriteLine("{0}// CIL NOP", IndentString(indent)); }
public static void WriteMarkupContentAsHTML(System.IO.TextWriter output, string content, Encoding encoding = null, // UTF8 if null char open = '<', char close = '>', string mkpPRE = "pre", string mkpCssForeColorPrefix = "conForeColor_", string mkpCssBackColorPrefix = "conBackColor_", ConsoleColor defaultForeColor = ConsoleColor.White, ConsoleColor defaultBackColor = ConsoleColor.Black) { // [mkpPRE]<span class='conColor_red'>This string will be red</span>[/mkpPRE] if (mkpPRE.IsNotNullOrWhiteSpace()) { output.Write('<'); output.Write(mkpPRE); output.Write('>'); } TokenParser parser = new TokenParser(content, open, close); Stack <ConsoleColor> stack = new Stack <ConsoleColor>(); bool collapsespaces = false; ConsoleColor foreColor = defaultForeColor, backColor = defaultBackColor; bool isSpanOpen = false; foreach (TokenParser.Token tok in parser) { if (tok.IsSimpleText) { if (collapsespaces) { output.Write(WebUtility.HtmlEncode(tok.Content.Trim())); } else { output.Write(WebUtility.HtmlEncode(tok.Content)); } continue; } string name = tok.Name.ToUpperInvariant().Trim(); if (name == "LITERAL") { collapsespaces = false; continue; } if (name == "HTML") { collapsespaces = true; continue; } if (name == "BR") { output.WriteLine(); continue; } if ((name == "SP") || (name == "SPACE")) { string txt = " "; int cnt = 1; try { cnt = int.Parse(tok["COUNT"]); } catch { } while (txt.Length < cnt) { txt += " "; } output.Write(WebUtility.HtmlEncode(txt)); continue; } if (name == "PUSH") { stack.Push(foreColor); stack.Push(backColor); continue; } if (name == "POP") { if (stack.Count > 1) { backColor = stack.Pop(); foreColor = stack.Pop(); if (isSpanOpen) { isSpanOpen = false; output.Write("</span>"); if (stack.Count > 1) { isSpanOpen = true; output.Write("<span class='{0}{1} {2}{3}'>".Args(mkpCssForeColorPrefix, foreColor, mkpCssBackColorPrefix, backColor)); } } } continue; } if (name == "RESET") { foreColor = defaultForeColor; if (isSpanOpen) { isSpanOpen = false; output.Write("</span>"); } continue; } if ((name == "F") || (name == "FORE") || (name == "FOREGROUND")) { try { ConsoleColor clr = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), tok["COLOR"], true); foreColor = clr; if (isSpanOpen) { output.Write("</span>"); } output.Write("<span class='{0}{1} {2}{3}'>".Args(mkpCssForeColorPrefix, foreColor, mkpCssBackColorPrefix, backColor)); isSpanOpen = true; } catch { } continue; } if ((name == "B") || (name == "BACK") || (name == "BACKGROUND")) { try { ConsoleColor clr = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), tok["COLOR"], true); backColor = clr; if (isSpanOpen) { output.Write("</span>"); } output.Write("<span class='{0}{1} {2}{3}'>".Args(mkpCssForeColorPrefix, foreColor, mkpCssBackColorPrefix, backColor)); isSpanOpen = true; } catch { } continue; } if ((name == "J") || (name == "JUST") || (name == "JUSTIFY")) { try { int width = int.Parse(tok["WIDTH"]); direction dir = (direction)Enum.Parse(typeof(direction), tok["DIR"], true); string txt = tok["TEXT"]; switch (dir) { case direction.Right: { while (txt.Length < width) { txt = " " + txt; } break; } case direction.Center: { while (txt.Length < width) { txt = " " + txt + " "; } if (txt.Length > width) { txt = txt.Substring(0, txt.Length - 1); } break; } default: { while (txt.Length < width) { txt = txt + " "; } break; } } output.Write(WebUtility.HtmlEncode(txt)); } catch { } continue; } } if (mkpPRE.IsNotNullOrWhiteSpace()) { output.Write('<'); output.Write('/'); output.Write(mkpPRE); output.Write('>'); } }
/// <summary> /// 向页面输出HTML。 /// </summary> /// <param name="output">字符输出对象,调用 WriteLine 方法向界面输出 HTML 内容。</param> public void WriterHtml(System.IO.TextWriter output) { output.WriteLine("系统信息<hr>"); output.WriteLine(DateTime.Now.ToString()); }
void print(BinOp exp) { Out.Write("BinOp "); switch (exp.Op) { case BINOP.Op.Plus: Out.Write('+'); break; case BINOP.Op.Minus: Out.Write('-'); break; case BINOP.Op.Times: Out.Write('*'); break; case BINOP.Op.Divide: Out.Write('/'); break; default: Out.Write(exp.Op); break; } Out.WriteLine(' ' + exp.Dst.ToString() + ' ' + exp.Left + ' ' + exp.Right); }
public static void println <T>(this TextWriter writer, T value) { writer.WriteLine(value); }
static public void log(string info) { Text.WriteLine("[" + DateTime.Now.ToString() + "] " + info); Flush(); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; bool ice1 = helper.Protocol == Protocol.Ice1; TestHelper.Assert(communicator != null); var com = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator); string testTransport = helper.Transport; var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); System.IO.TextWriter output = helper.Output; output.Write("testing binding with single endpoint... "); output.Flush(); { // Use "default" here to ensure that it still works IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default"); TestHelper.Assert(adapter != null); ITestIntfPrx?test1 = adapter.GetTestIntf(); ITestIntfPrx?test2 = adapter.GetTestIntf(); TestHelper.Assert(test1 != null && test2 != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(test3.GetConnection() == test2.GetConnection()); try { test3.IcePing(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter11", testTransport) !, com.CreateObjectAdapter("Adapter12", testTransport) !, com.CreateObjectAdapter("Adapter13", testTransport) ! }; // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are // eventually tried. var names = new List <string> { "Adapter11", "Adapter12", "Adapter13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection(we always send the request over the same // connection.) { foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = t.GetAdapterName(); for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++) { TestHelper.Assert(t.GetAdapterName() == name); } foreach (IRemoteObjectAdapterPrx adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapters. com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.GetAdapterName()); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new IRemoteObjectAdapterPrx[5] { com.CreateObjectAdapter("AdapterRandom11", testTransport) !, com.CreateObjectAdapter("AdapterRandom12", testTransport) !, com.CreateObjectAdapter("AdapterRandom13", testTransport) !, com.CreateObjectAdapter("AdapterRandom14", testTransport) !, com.CreateObjectAdapter("AdapterRandom15", testTransport) ! }; int count = 20; int adapterCount = adapters.Length; while (--count > 0) { ITestIntfPrx[] proxies; if (count == 1) { com.DeactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new ITestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new IRemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new IRemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = CreateTestIntfPrx(new List <IRemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].GetAdapterNameAsync(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].IcePing(); } catch { } } var connections = new List <Connection>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].GetCachedConnection() is Connection connection) { if (!connections.Contains(connection)) { connections.Add(connection); } } } TestHelper.Assert(connections.Count <= adapterCount); foreach (IRemoteObjectAdapterPrx a in adapters) { try { a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } catch { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI11", testTransport) !, com.CreateObjectAdapter("AdapterAMI12", testTransport) !, com.CreateObjectAdapter("AdapterAMI13", testTransport) ! }; // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are // eventually tried. var names = new List <string> { "AdapterAMI11", "AdapterAMI12", "AdapterAMI13" }; while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Ensure that the proxy correctly caches the connection (we always send the request over the // same connection.) { foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.IcePing(); } ITestIntfPrx t = CreateTestIntfPrx(adapters); string name = GetAdapterNameWithAMI(t); for (int i = 0; i < 10; i++) { TestHelper.Assert(GetAdapterNameWithAMI(t) == name); } foreach (IRemoteObjectAdapterPrx?adpt in adapters) { adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapters. com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <IRemoteObjectAdapterPrx>(adapters); ITestIntfPrx test1 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test2 = CreateTestIntfPrx(adpts); Shuffle(ref adpts); ITestIntfPrx test3 = CreateTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(GetAdapterNameWithAMI(test1)); test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // Deactivate an adapter and ensure that we can still establish the connection to the remaining // adapter. com.DeactivateObjectAdapter(adapters[2]); ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter21", testTransport) !, com.CreateObjectAdapter("Adapter22", testTransport) !, com.CreateObjectAdapter("Adapter23", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); var names = new List <string> { "Adapter21", "Adapter22", "Adapter23" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } obj = obj.Clone(endpointSelection: EndpointSelectionType.Random); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter31", testTransport) !, com.CreateObjectAdapter("Adapter32", testTransport) !, com.CreateObjectAdapter("Adapter33", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter31"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter32"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter33"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter36", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter36"); } obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter35", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter35"); } obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter34", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter34"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", testTransport); TestHelper.Assert(adapter != null); ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false); ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false); TestHelper.Assert(!test1.IsConnectionCached); TestHelper.Assert(!test2.IsConnectionCached); TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.DeactivateObjectAdapter(adapter); var test3 = test1.Clone(ITestIntfPrx.Factory); try { TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter51", testTransport) !, com.CreateObjectAdapter("Adapter52", testTransport) !, com.CreateObjectAdapter("Adapter53", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "Adapter51", "Adapter52", "Adapter53" }; while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.GetAdapterName()); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI51", testTransport) !, com.CreateObjectAdapter("AdapterAMI52", testTransport) !, com.CreateObjectAdapter("AdapterAMI53", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "AdapterAMI51", "AdapterAMI52", "AdapterAMI53" }; while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(GetAdapterNameWithAMI(obj)); } com.DeactivateObjectAdapter(adapters[2]); TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI52")); Deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter61", testTransport) !, com.CreateObjectAdapter("Adapter62", testTransport) !, com.CreateObjectAdapter("Adapter63", testTransport) ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(obj.GetAdapterName() == "Adapter64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection and AMI... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("AdapterAMI61", testTransport) !, com.CreateObjectAdapter("AdapterAMI62", testTransport) !, com.CreateObjectAdapter("AdapterAMI63", testTransport) ! }; ITestIntfPrx?obj = CreateTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); // Ensure that endpoints are tried in order by deactivating the adapters one after the other. for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61"); } com.DeactivateObjectAdapter(adapters[0]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62"); } com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63"); } com.DeactivateObjectAdapter(adapters[2]); try { obj.GetAdapterName(); } catch (ConnectFailedException) { } IReadOnlyList <Endpoint> endpoints = obj.Endpoints; adapters.Clear(); // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { // Now, re-activate the adapters with the same endpoints in the opposite order. adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65"); } adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString())); for (int i = 0; i < 3; i++) { TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64"); } Deactivate(com, adapters); } } output.WriteLine("ok"); if (helper.Protocol == Protocol.Ice1) { output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter71", testTransport), com.CreateObjectAdapter("Adapter72", "udp") }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71")); ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram); TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.GetAdapterName(); TestHelper.Assert(false); } catch (InvalidOperationException) { // expected } } output.WriteLine("ok"); } if (communicator.GetProperty("Ice.Plugin.IceSSL") != null) { output.Write("testing secure and non-secure endpoints... "); output.Flush(); { var adapters = new List <IRemoteObjectAdapterPrx> { com.CreateObjectAdapter("Adapter81", "ssl") !, com.CreateObjectAdapter("Adapter82", "tcp") ! }; ITestIntfPrx obj = CreateTestIntfPrx(adapters); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true); // TODO: update when PreferNonSecure default is updated ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false); TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection()); TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection()); com.DeactivateObjectAdapter(adapters[1]); for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration. if (helper.Protocol == Protocol.Ice1) { com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA. for (int i = 0; i < 5; i++) { TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83")); obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); } } com.DeactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // expected } Deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); var ipv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "0" } }; var ipv6 = new Dictionary <string, string>() { { "IPv4", "0" }, { "IPv6", "1" } }; var bothPreferIPv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "0" } }; var bothPreferIPv6 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "1" } }; Dictionary <string, string>[] clientProps = { ipv4, ipv6, bothPreferIPv4, bothPreferIPv6 }; Func <string, string> getEndpoint = host => TestHelper.GetTestEndpoint(new Dictionary <string, string>(communicator.GetProperties()) { ["Test.Host"] = host }, 2, "tcp"); var anyipv4 = new Dictionary <string, string>(ipv4) { ["Adapter.Endpoints"] = getEndpoint("0.0.0.0"), ["Adapter.PublishedEndpoints"] = getEndpoint("127.0.0.1") }; var anyipv6 = new Dictionary <string, string>(ipv6) { ["Adapter.Endpoints"] = getEndpoint("::0"), ["Adapter.PublishedEndpoints"] = getEndpoint("::1") }; var anyboth = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "Adapter.Endpoints", getEndpoint("::0") }, { "Adapter.PublishedEndpoints", getEndpoint("localhost") } }; var localipv4 = new Dictionary <string, string>(ipv4) { ["Adapter.Endpoints"] = getEndpoint("127.0.0.1") }; var localipv6 = new Dictionary <string, string>(ipv6) { ["Adapter.Endpoints"] = getEndpoint("::1") }; Dictionary <string, string>[] serverProps = { anyipv4, anyipv6, anyboth, localipv4, localipv6 }; bool ipv6NotSupported = false; foreach (Dictionary <string, string> p in serverProps) { var serverCommunicator = new Communicator(p); ObjectAdapter oa; try { oa = serverCommunicator.CreateObjectAdapter("Adapter"); oa.Activate(); } catch (DNSException) { serverCommunicator.Dispose(); continue; // IP version not supported. } catch (TransportException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.Dispose(); continue; // IP version not supported. } IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory); try { prx.IcePing(); } catch (DNSException) // TODO: is this really an expected exception? { serverCommunicator.Dispose(); continue; } catch (ObjectNotExistException) // TODO: is this really an expected exception? { serverCommunicator.Dispose(); continue; } string strPrx = prx.ToString() !; foreach (Dictionary <string, string> q in clientProps) { var clientCommunicator = new Communicator(q); prx = IObjectPrx.Parse(strPrx, clientCommunicator); try { prx.IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { // Expected, no object registered. } catch (DNSException) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch (TransportException) { TestHelper.Assert((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) || (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) || (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) || (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) || (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) || (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) || (p == bothPreferIPv6 && q == ipv6)); } clientCommunicator.Dispose(); } serverCommunicator.Dispose(); } output.WriteLine("ok"); } com.Shutdown(); }
public override void WriteCommand(System.IO.TextWriter writer) { writer.WriteLine(string.Format("Loop {0} {{", ProjectSerializer.SecureList(Repetitions.ConvertAll <string>((int rep) => rep.ToString())))); Commands.WriteCommands(writer); writer.WriteLine("}"); }
private void EmitLocals(string caption, TextWriter writer) { if (StackVarsOut.Count <= 0) return; writer.Write(caption); SortedList<string, string> list = new SortedList<string, string>(); foreach (KeyValuePair<Storage, int> de in StackVarsOut) { Storage id = (Storage)de.Key; StringWriter sb = new StringWriter(); id.Write(sb); string sName = sb.ToString(); list[sName] = string.Format("{0}({1})", sName, de.Value); } foreach (string s in list.Values) { writer.Write(" "); writer.Write(s); } writer.WriteLine(); }
public static void Write(Models.Solution solution, System.IO.TextWriter writer) { if (!writer.Encoding.Equals(System.Text.Encoding.UTF8)) { throw new System.Exception("Solution writer requires UTF8 encoding."); } System.Text.UTF8Encoding encoding = (System.Text.UTF8Encoding)writer.Encoding; byte[] bom = encoding.GetPreamble(); if (bom.Length != 3 || bom[0] != 239 || bom[1] != 187 || bom[2] != 191) { throw new System.Exception("Solution writer requires UTF8 encoding with a Byte Order Mark."); } if (!HasVC(solution)) { writer.WriteLine(""); } writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 10.00"); writer.WriteLine("# Visual Studio 2008"); foreach (Models.Project project in solution.Projects) { if (project.Path.EndsWith(".vcproj")) { writer.WriteLine("Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\""); if (project.Dependencies.Count > 0) { writer.WriteLine(" ProjectSection(ProjectDependencies) = postProject"); foreach (System.Guid dependency in project.Dependencies) { writer.WriteLine(" {"+ dependency.ToString().ToUpper() + "} = {" + dependency.ToString().ToUpper() + "}"); } writer.WriteLine(" EndProjectSection"); } writer.WriteLine("EndProject"); } else if (project.Path.EndsWith(".csproj")) { writer.WriteLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\""); writer.WriteLine("EndProject"); } else if (project.Path.EndsWith(".vbproj")) { writer.WriteLine("Project(\"{F184B08F-C81C-45F6-A57F-5ABD9991F28F}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\""); if (project.Dependencies.Count > 0) { writer.WriteLine(" ProjectSection(ProjectDependencies) = postProject"); foreach (System.Guid dependency in project.Dependencies) { writer.WriteLine(" {"+ dependency.ToString().ToUpper() + "} = {" + dependency.ToString().ToUpper() + "}"); } writer.WriteLine(" EndProjectSection"); } writer.WriteLine("EndProject"); } else { throw new System.Exception("Invalid project: " + project.Path); } } writer.WriteLine("Global"); writer.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); foreach (Models.Config config in solution.Configs) { writer.WriteLine(" "+ config.Name + " = " + config.Name + ""); } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = postSolution"); foreach (Models.Project project in solution.Projects) { foreach (Models.Config config in solution.Configs) { writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}." + config.Name + ".ActiveCfg = " + config.Name + ""); writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}." + config.Name + ".Build.0 = " + config.Name + ""); } } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(SolutionProperties) = preSolution"); writer.WriteLine(" HideSolutionNode = FALSE"); writer.WriteLine(" EndGlobalSection"); writer.WriteLine("EndGlobal"); writer.Flush(); }
public static void println(this TextWriter writer) { writer.WriteLine(); }
public void Export_SpriteIDs(System.IO.TextWriter tw, string strSpriteset) { tw.WriteLine(String.Format("const int k{0}_{1} = {2};", strSpriteset, m_strName, m_nExportSpriteID)); }
private void LogSuspiciousResults() { LogWriter = System.IO.File.CreateText("E:\\temp\\sorata\\result.txt"); foreach (MIPSEvaluator.Result res in MIPS.Results) { bool log = false; for (int i = 0; i < res.Arguments.Length; i++) if ((res.Arguments[i] >> 24) == 0x04 || (res.Arguments[i] >> 24) == 0x05 || (res.Arguments[i] >> 24) == 0x06) log = true; if (log) LogWriter.WriteLine(res.ToString()); } LogWriter.Close(); }
private void btnAsHtml_Click(object sender, EventArgs e) { string filePath = System.IO.Path.GetTempPath() + "DataDictionary_" + Guid.NewGuid().ToString("N") + ".html"; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.TextWriter textWriter = System.IO.File.CreateText(filePath); textWriter.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title>"); textWriter.WriteLine("<style type=\"text/css\">"); textWriter.WriteLine("table.dataDictionary { border-width: 1px; border-collapse: collapse; border-color: black; width: 100%;}"); textWriter.WriteLine("table.dataDictionary th { border-width: 1px; border-style: solid; padding: 4px; border-color: black; font-family: Verdana; font-size: x-small; font-weight:bold; background-color:#4a7ac9; color:#FFFFFF;}"); textWriter.WriteLine("table.dataDictionary td { border-width: 1px; border-style: solid; padding: 4px; border-color: black; font-family: Verdana; font-size: x-small; font-weight:normal;}"); textWriter.WriteLine(".styleTitle { font-family: \"Verdana\"; font-size: x-small; font-weight: normal; }"); textWriter.WriteLine("</style>"); textWriter.WriteLine("<br/>"); if (displayTable.TableName.StartsWith("code") == false) { textWriter.WriteLine(string.Format("<span class=\"styleTitle\"><strong>Data Dictionary for View [ {0} ]</strong></span><br />", view.Name)); textWriter.WriteLine(string.Format("<span class=\"styleTitle\">{0}</span><br />", view.FullName)); } textWriter.WriteLine(string.Format("<span class=\"styleTitle\">{0}</span><br />", DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString())); textWriter.WriteLine("<br/>"); textWriter.WriteLine("<table class=\"dataDictionary\">"); if (displayTable.TableName.StartsWith("code") == false) { textWriter.WriteLine("<tr><th>Page Position</th><th>Page Name</th><th>Tab Index</th><th>Prompt</th><th>Field Type</th><th>Name</th><th>Variable Type</th><th>Format</th><th>Special Info</th></tr>"); bool highlightRow = false; DataView dataView = new DataView(displayTable); dataView.Sort = sortExp; DataTable sortedTable = dataView.ToTable(); foreach (DataRow row in sortedTable.Rows) { textWriter.WriteLine(string.Format("<tr style=\"background-color: #{0}\">", highlightRow ? "EEEEEE" : "FFFFFF")); textWriter.WriteLine(string.Format("<td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td>", row[0].ToString(), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString(), row[6].ToString(), row[7].ToString(), row[8].ToString())); textWriter.WriteLine("</tr>"); highlightRow = !highlightRow; } } else { bool highlightRow = false; DataView dataView = new DataView(displayTable); DataTable table = dataView.ToTable(); textWriter.WriteLine("<tr>"); foreach (DataColumn column in table.Columns) { textWriter.WriteLine("<th>{0}</th>", column.ColumnName); } foreach (DataRow row in table.Rows) { textWriter.WriteLine(string.Format("<tr style=\"background-color: #{0}\">", highlightRow ? "EEEEEE" : "FFFFFF")); object[] itemArray = row.ItemArray; foreach (object obj in itemArray) { textWriter.WriteLine(string.Format("<td>{0}</td>", (string)obj)); } textWriter.WriteLine("</tr>"); highlightRow = !highlightRow; } } textWriter.WriteLine("</table></body></html>"); textWriter.Close(); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = filePath; proc.Start(); }
public static void InitLog() { Writer = new System.IO.StreamWriter("log.log"); Writer.WriteLine("----------log started------------"); }
public void WriteAsJSON(System.IO.TextWriter writer) { /* * IEnumerable simpleList = repeatObjectList as IEnumerable; * if (simpleList != null) * { * //System.Collections.Hashtable * * foreach (object item in simpleList) * { * object realItem = item; * if (item is DictionaryEntry) * { * realItem = ((DictionaryEntry)item).Value; * } */ bool wroteOpener = false; bool isArray = true; foreach (object item in TargetCollection) { object realItem = item; //first loop determine if array or object //others prepend a comma if (wroteOpener) { writer.WriteLine(", "); } else { if (item is DictionaryEntry) { writer.WriteLine("{"); isArray = false; } else { writer.WriteLine("["); isArray = true; } wroteOpener = true; } if (item is DictionaryEntry) { realItem = ((DictionaryEntry)item).Value; writer.Write(JsonData.JSSafeQuote(((DictionaryEntry)item).Key.ToString())); writer.Write(":"); } if (realItem is IJsonSerializable) { ((IJsonSerializable)realItem).WriteAsJSON(writer); } else { if (AllowReflectiveSerialization) { writer.Write(BaseJsonSerializer.ExpensiveGetJsonDataAsString(realItem)); } else { writer.Write(JsonData.JSSafeQuote(realItem.ToString())); } } } if (!wroteOpener) { WriteEmptyArray(writer); } else { if (isArray) { writer.WriteLine("]"); } else { writer.WriteLine("}"); } } }
private static void Log(string msg, string level = "verbose") { logOutput?.WriteLine($"{level}: {msg}"); }
public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text public virtual void SynErr(int line, int col, int n) { string s; switch (n) { case 0: s = "EOF expected"; break; case 1: s = "intnumber expected"; break; case 2: s = "floatnumber expected"; break; case 3: s = "id expected"; break; case 4: s = "true expected"; break; case 5: s = "false expected"; break; case 6: s = "stringtext expected"; break; case 7: s = "newline expected"; break; case 8: s = "\"setup\" expected"; break; case 9: s = "\"loop\" expected"; break; case 10: s = "\"{\" expected"; break; case 11: s = "\";\" expected"; break; case 12: s = "\"=\" expected"; break; case 13: s = "\"}\" expected"; break; case 14: s = "\",\" expected"; break; case 15: s = "\"if\" expected"; break; case 16: s = "\"while\" expected"; break; case 17: s = "\"(\" expected"; break; case 18: s = "\")\" expected"; break; case 19: s = "\"for\" expected"; break; case 20: s = "\"switch\" expected"; break; case 21: s = "\"case\" expected"; break; case 22: s = "\":\" expected"; break; case 23: s = "\"default\" expected"; break; case 24: s = "\"else\" expected"; break; case 25: s = "\".\" expected"; break; case 26: s = "\"[\" expected"; break; case 27: s = "\"]\" expected"; break; case 28: s = "\"return\" expected"; break; case 29: s = "\"||\" expected"; break; case 30: s = "\"&\" expected"; break; case 31: s = "\"==\" expected"; break; case 32: s = "\"!=\" expected"; break; case 33: s = "\">=\" expected"; break; case 34: s = "\">\" expected"; break; case 35: s = "\"<=\" expected"; break; case 36: s = "\"<\" expected"; break; case 37: s = "\"!\" expected"; break; case 38: s = "\"+\" expected"; break; case 39: s = "\"-\" expected"; break; case 40: s = "\"*\" expected"; break; case 41: s = "\"/\" expected"; break; case 42: s = "\"%\" expected"; break; case 43: s = "\"void\" expected"; break; case 44: s = "\"int\" expected"; break; case 45: s = "\"float\" expected"; break; case 46: s = "\"string\" expected"; break; case 47: s = "\"boolean\" expected"; break; case 48: s = "\"struct\" expected"; break; case 49: s = "\"List\" expected"; break; case 50: s = "??? expected"; break; case 51: s = "invalid ASSIG"; break; case 52: s = "invalid TYPE"; break; case 53: s = "invalid STRUCTFIELD"; break; case 54: s = "invalid STMT"; break; case 55: s = "invalid STMT"; break; case 56: s = "invalid IFELSTMT"; break; case 57: s = "invalid CALL"; break; case 58: s = "invalid VALUE"; break; case 59: s = "invalid BOOL"; break; case 60: s = "invalid LOGI_EQUALOp"; break; case 61: s = "invalid LOGI_NOT"; break; case 62: s = "invalid LOGI_LGOp"; break; case 63: s = "invalid addExpr"; break; case 64: s = "invalid terminalExpr"; break; case 65: s = "invalid multExprOp"; break; default: s = "error " + n; break; } errorStream.WriteLine(errMsgFormat, line, col, s); count++; }
public TimedWriteLine(System.IO.TextWriter output, string testName = null) { this.output = output; this._testName = testName ?? new StackTrace(1, fNeedFileInfo: false).GetFrame(0).GetMethod().Name; output.WriteLine(_testName); _sw.Start(); }
/// <summary> /// MUST BE SYNCHRON /// GAPS MUST BE ORDERED /// </summary> internal static void Start(int lastDatabaseId, int lastExecutedId, int[] gaps, System.IO.TextWriter consoleOut) { if (consoleOut != null) { consoleOut.WriteLine("Executing unprocessed activities. {0}-{1} {2}", lastExecutedId, lastDatabaseId, CompletionState.GapsToString(gaps, 5, 3)); } SnLog.WriteInformation("Executing unprocessed activities.", EventId.RepositoryRuntime, properties: new Dictionary <string, object> { { "LastDatabaseId", lastDatabaseId }, { "LastExecutedId", lastExecutedId }, { "CountOfGaps", gaps.Length }, { "Gaps", String.Join(", ", gaps) } }); DependencyManager.Start(); var count = 0; if (gaps.Any()) { var loadedActivities = new IndexingActivityLoader(gaps, true); foreach (LuceneIndexingActivity loadedActivity in loadedActivities) { // wait and start processing loaded activities in the meantime WaitIfOverloaded(true); SnTrace.IndexQueue.Write("IAQ: Startup: A{0} enqueued from db.", loadedActivity.Id); IndexingActivityHistory.Arrive(loadedActivity); _arrivalQueue.Enqueue(loadedActivity); _lastQueued = loadedActivity.Id; count++; } } if (lastExecutedId < lastDatabaseId) { var loadedActivities = new IndexingActivityLoader(lastExecutedId + 1, lastDatabaseId, true); foreach (LuceneIndexingActivity loadedActivity in loadedActivities) { // wait and start processing loaded activities in the meantime WaitIfOverloaded(true); SnTrace.IndexQueue.Write("IAQ: Startup: A{0} enqueued from db.", loadedActivity.Id); IndexingActivityHistory.Arrive(loadedActivity); _arrivalQueue.Enqueue(loadedActivity); _lastQueued = loadedActivity.Id; count++; } } if (_lastQueued < lastExecutedId) { _lastQueued = lastExecutedId; } // ensure that the arrival activity queue is not empty at this pont. DependencyManager.ActivityEnqueued(); if (lastDatabaseId != 0 || lastExecutedId != 0 || gaps.Any()) { while (IsWorking()) { Thread.Sleep(200); } } // At this point we know for sure that the original gap is not there anymore. // In case there is a false gap (e.g. because there are missing activity ids // in the db) we have to remove these ids manually from the in-memory gap. if (gaps.Any()) { TerminationHistory.RemoveGaps(gaps); // Commit is necessary because otherwise the gap is removed only in memory, but // the index is not updated in the file system. LuceneManager.Commit(); } SnLog.WriteInformation($"Executing unprocessed activities ({count}) finished.", EventId.RepositoryLifecycle); }
/// <summary> /// MUST BE SYNCHRON /// GAPS MUST BE ORDERED /// </summary> internal static void Start(int lastDatabaseId, int lastExecutedId, int[] gaps, System.IO.TextWriter consoleOut) { consoleOut?.WriteLine("Executing unprocessed activities. {0}-{1} {2}", lastExecutedId, lastDatabaseId, IndexingActivityStatus.GapsToString(gaps, 5, 3)); SnLog.WriteInformation("Executing unprocessed activities.", EventId.RepositoryRuntime, properties: new Dictionary <string, object> { { "LastDatabaseId", lastDatabaseId }, { "LastExecutedId", lastExecutedId }, { "CountOfGaps", gaps.Length }, { "Gaps", IndexingActivityStatus.GapsToString(gaps, 100, 3) } }); IndexingActivityBase.NotIndexableContentCollection.Clear(); DependencyManager.Start(); var count = 0; if (gaps.Any()) { var loadedActivities = new IndexingActivityLoader(gaps, true); foreach (var indexingActivity in loadedActivities) { var loadedActivity = (IndexingActivityBase)indexingActivity; // wait and start processing loaded activities in the meantime WaitIfOverloaded(true); SnTrace.IndexQueue.Write("IAQ: Startup: A{0} enqueued from db.", loadedActivity.Id); IndexingActivityHistory.Arrive(loadedActivity); ArrivalQueue.Enqueue(loadedActivity); _lastQueued = loadedActivity.Id; count++; } } if (lastExecutedId < lastDatabaseId) { var loadedActivities = new IndexingActivityLoader(lastExecutedId + 1, lastDatabaseId, true); foreach (var indexingActivity in loadedActivities) { var loadedActivity = (IndexingActivityBase)indexingActivity; // wait and start processing loaded activities in the meantime WaitIfOverloaded(true); SnTrace.IndexQueue.Write("IAQ: Startup: A{0} enqueued from db.", loadedActivity.Id); IndexingActivityHistory.Arrive(loadedActivity); ArrivalQueue.Enqueue(loadedActivity); _lastQueued = loadedActivity.Id; count++; } } if (_lastQueued < lastExecutedId) { _lastQueued = lastExecutedId; } // ensure that the arrival activity queue is not empty at this pont. DependencyManager.ActivityEnqueued(); if (lastDatabaseId != 0 || lastExecutedId != 0 || gaps.Any()) { while (IsWorking()) { Thread.Sleep(200); } } if (IndexingActivityBase.NotIndexableContentCollection.Any()) { const int maxWrittenCount = 100; // Collect the first n ContentId, VersionId pairs into one message // (key: version id, value: content id). var data = string.Join("; ", IndexingActivityBase.NotIndexableContentCollection.Take(maxWrittenCount) .OrderBy(x => x.Value) .Select(x => $"{x.Value},{x.Key}")); var firstN = IndexingActivityBase.NotIndexableContentCollection.Count > maxWrittenCount ? $" first {maxWrittenCount}" : string.Empty; // Write one aggregated message SnLog.WriteWarning($"Cannot index {IndexingActivityBase.NotIndexableContentCollection.Count}" + $" content. The{firstN} related ContentId, VersionId pairs: {data}"); // Do not keep memory for unnecessary data IndexingActivityBase.NotIndexableContentCollection.Clear(); } // At this point we know for sure that the original gap is not there anymore. // In case there is a false gap (e.g. because there are missing activity ids // in the db) we have to remove these ids manually from the in-memory gap. if (gaps.Any()) { TerminationHistory.RemoveGaps(gaps); // Commit is necessary because otherwise the gap is removed only in memory, but // the index is not updated in the file system. IndexManager.CommitAsync(CancellationToken.None).GetAwaiter().GetResult(); // explicit commit } SnLog.WriteInformation($"Executing unprocessed activities ({count}) finished.", EventId.RepositoryLifecycle); }
public void PrintFilter(System.IO.TextWriter textWriter) { if (textWriter == null) { throw new ArgumentNullException("textWriter"); } textWriter.WriteLine("========== Patterns for allowed types:"); foreach (string s in this.require_types) { textWriter.WriteLine(s); } textWriter.WriteLine("========== Patterns for forbidden types:"); foreach (string s in this.forbid_types) { textWriter.WriteLine(s); } textWriter.WriteLine("========== Patterns for allowed methods/constructors:"); foreach (string s in this.require_members) { textWriter.WriteLine(s); } textWriter.WriteLine("========== Patterns for forbidden methods/constructors:"); foreach (string s in this.forbid_members) { textWriter.WriteLine(s); } textWriter.WriteLine("========== Patterns for allowed fields:"); foreach (string s in this.require_fields) { textWriter.WriteLine(s); } textWriter.WriteLine("========== Patterns for forbidden fields:"); foreach (string s in this.forbid_fields) { textWriter.WriteLine(s); } }
private static void Stats(TextWriter writer) { MemoryManager memmgr = MemoryManager.Global; writer.WriteLine("-- Used: {0}", memmgr.UsedBytes); writer.WriteLine("-- Allocated: {0}", memmgr.AllocatedBytes); VirtualMemoryManager vmm = memmgr as VirtualMemoryManager; if (vmm != null) vmm.Dump(writer); }
protected virtual void Ack() { @out.WriteLine("ack"); @out.Flush(); }
public void Postprocess(MegaloStaticDatabase associatedStaticDb, TextWriter errorWriter = null) { Contract.Requires(associatedStaticDb != null); // #REVIEW_BLAM: I've added TraceInformation calls now, can we get rid of the TextWriter? this.StaticDatabase = associatedStaticDb; #region ValueTypes foreach (var type in ValueTypes) { if (type.BaseType.RequiresBitLength() && type.BitLength == 0) { string msg = string.Format("ValueType '{0}' doesn't define bitLength", ValueTypeNames[type.NameIndex]); Debug.Trace.MegaloProto.TraceInformation(msg); errorWriter?.WriteLine(msg); } switch (type.BaseType) { case MegaloScriptValueBaseType.Flags: { var etype = Enums[type.EnumIndex]; int bc_difference = etype.ValidBitLengthForFlags(type.BitLength); if (bc_difference < 0) { string msg = string.Format("Flags '{0}->{1}' bitLength '{2}' is too small (need {3} more bits)", etype.Name, ValueTypeNames[type.NameIndex], type.BitLength, -bc_difference); Debug.Trace.MegaloProto.TraceInformation(msg); errorWriter?.WriteLine(msg); } } break; case MegaloScriptValueBaseType.Enum: { var etype = Enums[type.EnumIndex]; int bc_difference = etype.ValidBitLengthForEnum(type.BitLength, type.EnumTraits); if (bc_difference < 0) { string msg = string.Format("Enum '{0}->{1}' bitLength '{2}' is too small (need {3} more bits)", etype.Name, ValueTypeNames[type.NameIndex], type.BitLength, -bc_difference); Debug.Trace.MegaloProto.TraceInformation(msg); errorWriter?.WriteLine(msg); } } break; case MegaloScriptValueBaseType.Index: { if (type.IndexTraits == MegaloScriptValueIndexTraits.PointerRaw) { int bit_length = type.BitLength; if (bit_length != Bits.kByteBitCount && bit_length != Bits.kInt16BitCount && bit_length != Bits.kInt32BitCount) { string msg = string.Format("Index-type '{0}' is a 'raw' value but doesn't use a natural word size: {1}", ValueTypeNames[type.NameIndex], bit_length); Debug.Trace.MegaloProto.TraceInformation(msg); errorWriter?.WriteLine(msg); } } } break; } } #endregion #region Actions foreach (var action in Actions) { var state = new MegaloScriptProtoParamsPostprocessState(errorWriter, action); state.Postprocess(); } #endregion // #TODO_BLAM: would be nice to dump unused ActionTemplates...as I only copy-pasted H4's in Reach's DB }
public override void WriteResults(System.IO.TextWriter tw) { tw.WriteLine(string.Join(", ", ((ulong[])this.data).Select(u => "0x" + u.ToString("X") + "UL").ToArray())); }
/// <summary> /// Writes flow state that is true on entry to the basic block. /// </summary> /// <param name="arch"></param> /// <param name="writer"></param> public void WriteBefore(IProcessorArchitecture arch, TextWriter writer) { SymbolicIn.Emit(arch, "// SymbolicIn:", writer); writer.WriteLine(); }
/// <summary> /// Writes flow state that is true on entry to the basic block. /// </summary> /// <param name="arch"></param> /// <param name="writer"></param> public void WriteBefore(IProcessorArchitecture arch, TextWriter writer) { SymbolicIn.Emit(arch, "// SymbolicIn:", writer); writer.WriteLine(); }
private void DisplayVersion(TextWriter stdout) { stdout.WriteLine("Pickles version {0}", Assembly.GetExecutingAssembly().GetName().Version); }
void Run() { AddSemanticOperator(NoState, Neither, 0, NotApplic, "", "None", false); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, "(", "PrecedenceGroupingParenthesis", false); // NB: // These two postfix operators materialize in the Binary State, however, they are unary operators! // This is reason for separate notion of state vs arity. AddSemanticOperator(BinaryState, Unary, 2, LeftRight, "++", "PostfixIncrement"); AddSemanticOperator(BinaryState, Unary, 2, LeftRight, "--", "PostfixDecrement"); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "(", "FunctionCall"); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, ")", "EmptyArgumentList", false); AddSemanticOperator(BinaryState, Neither, 0, NotApplic, ")", "CloseParenOrArgList", false); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "[", "Subscript"); AddSemanticOperator(UnaryState, Neither, 0, NotApplic, "]", "EmptySubscript", false); AddSemanticOperator(BinaryState, Neither, 0, NotApplic, "]", "CloseSubscript", false); AddSemanticOperator(BinaryState, Binary, 2, LeftRight, ".", "Selection"); // binary but requires special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 2, LeftRight, "->", "IndirectSelection"); // binary but required special parsing of right operand as member name AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "++", "PrefixIncrement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "--", "PrefixDecrement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "+", "FixPoint"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "-", "Negation"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "!", "LogicalNot"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "~", "BitwiseComplement"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "*", "Indirection"); AddSemanticOperator(UnaryState, Unary, 3, RightLeft, "&", "AddressOf"); AddSemanticOperator(BinaryState, Binary, 4, LeftRight, ".*", "SelectionReference"); // binary but requires special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 4, LeftRight, "->*", "IndirectSelectionReference"); // binary but required special parsing of right operand as member name AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "*", "Multiplication"); AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "/", "Division"); AddSemanticOperator(BinaryState, Binary, 5, LeftRight, "%", "Modulo"); AddSemanticOperator(BinaryState, Binary, 6, LeftRight, "+", "Addition"); AddSemanticOperator(BinaryState, Binary, 6, LeftRight, "-", "Subtraction"); AddSemanticOperator(BinaryState, Binary, 7, LeftRight, "<<", "BitwiseLeftShift"); AddSemanticOperator(BinaryState, Binary, 7, LeftRight, ">>", "BitwiseRightShift"); AddSemanticOperator(BinaryState, Binary, 8, LeftRight, "<=>", "Order"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, "<", "LessThan", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, "<=", "LessOrEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, ">", "GreaterThan", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 9, LeftRight, ">=", "GreaterOrEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 10, LeftRight, "==", "EqualEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 10, LeftRight, "!=", "NotEqual", true, "Relational"); AddSemanticOperator(BinaryState, Binary, 11, LeftRight, "&", "BitwiseAnd"); AddSemanticOperator(BinaryState, Binary, 12, LeftRight, "^", "BitwiseXor"); AddSemanticOperator(BinaryState, Binary, 13, LeftRight, "|", "BitwiseOr"); AddSemanticOperator(BinaryState, Binary, 14, LeftRight, "&&", "ShortCircutAnd"); AddSemanticOperator(BinaryState, Binary, 15, LeftRight, "||", "ShortCircutOr"); AddSemanticOperator(BinaryState, Binary, 16, RightLeft, "?", "TernaryTest", false); AddSemanticOperator(BinaryState, Ternary, 16, RightLeft, ":", "TernaryChoice"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "=", "Assignment", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "*=", "AssignmentMultiplication", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "/=", "AssignmentDivision", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "%=", "AssignmentModulo", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "+=", "AssignmentAddition", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "-=", "AssignmentSubtraction", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "&=", "AssignmentBitwiseAnd", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "^=", "AssignmentBitwiseXor", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "|=", "AssignmentBitwiseOr", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, "<<=", "AssignmentBitwiseLeftShift", true, "Assignment"); AddSemanticOperator(BinaryState, Binary, 17, RightLeft, ">>=", "AssignmentBitwiseRightShift", true, "Assignment"); // We'll need two operators for this in our AST's, so we can tell the difference between // comma as an expression separator and comma as an argument separator after parsing. // Parsing removes ()'s and after parsing we'll still need to be able to differentiate // between a(x,y) which is a function call with two arguments, x and y, // and a((x,y)) which is a function call with one argument // (derived from the value of y after evalutating x) AddSemanticOperator(BinaryState, Binary, 18, LeftRight, ",", new [] { "ExpressionSeparator", "ArgumentSeparator" }); var namespacePath = "com.erikeidt.Draconum"; List <string> operators = new List <string> (); List <string> precedence = new List <string> (); List <string> arity = new List <string> (); List <string> treeNodes = new List <string> (); List <string> unaryOperators = new List <string> (); List <string> binaryOperators = new List <string> (); List <string> ternaryOperators = new List <string> (); List <Tuple <string, string> > unaryStateTokenSet = new List <Tuple <string, string> > (); List <Tuple <string, string> > binaryStateTokenSet = new List <Tuple <string, string> > (); foreach (var so in _semanticOperators) { foreach (var on in so.Names) { switch (so.Section) { case UnaryState: unaryStateTokenSet.Add(new Tuple <string, string> (so.Token, on)); break; case BinaryState: binaryStateTokenSet.Add(new Tuple <string, string> (so.Token, on)); break; } operators.Add(on); precedence.Add((so.Precedence * 2 + (so.Lr == RightLeft ? 0 : 1)).ToString()); if (so.HasTreeNodes) { treeNodes.Add("partial class " + on + "TreeNode : " + (so.BaseClass ?? so.Arity.ToString()) + "OperatorTreeNode {"); switch (so.Arity) { case Unary: arity.Add("1"); unaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, arg ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree arg ) : base ( op, arg ) { }"); break; case Binary: arity.Add("2"); binaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, left, right ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree left, AbstractSyntaxTree right ) : base ( op, left, right ) { }"); break; case Ternary: arity.Add("3"); ternaryOperators.Add("case " + on + ": " + "res = new " + on + "TreeNode ( op, pre, mid, post ); break;"); treeNodes.Add("\tpublic " + on + "TreeNode ( Operator op, AbstractSyntaxTree pre, AbstractSyntaxTree mid, AbstractSyntaxTree post ) : base ( op, pre, mid, post ) { }"); break; default: arity.Add("0"); break; } treeNodes.Add("}"); treeNodes.Add(null); } else { arity.Add("0"); } } } System.IO.TextWriter file = System.IO.File.CreateText(OutputFilePath + @"Operators.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine("\tclass Operators {"); file.WriteLine("\t\tpublic enum Operator : byte {"); SendStrings(file, "\t\t\t{0},", operators); file.WriteLine("\t\t}"); file.WriteLine(); file.WriteLine("\t\tpublic static byte [] Precedence = {"); SendStrings(file, "\t\t\t{0},", precedence); file.WriteLine("\t\t};"); file.WriteLine(); file.WriteLine("\t\tpublic static byte [] Arity = {"); SendStrings(file, "\t\t\t{0},", arity); file.WriteLine("\t\t};"); file.WriteLine("\t}"); file.WriteLine("}"); file.Dispose(); file = System.IO.File.CreateText(OutputFilePath + @"ExpressionParser.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine(); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine("\tusing static Operators;"); file.WriteLine("\tusing static Operators.Operator;"); file.WriteLine(); file.WriteLine("\tpartial class ExpressionParser {"); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildUnaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar arg = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", unaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildBinaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar right = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar left = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", binaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine(); file.WriteLine("\t\tpublic AbstractSyntaxTree BuildTernaryTreeNode ( Operator op )"); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tvar post = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar mid = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar pre = _operandStack.Pop ();"); file.WriteLine("\t\t\tvar res = (AbstractSyntaxTree) null;"); file.WriteLine("\t\t\tswitch ( op ) {"); SendStrings(file, "\t\t\t\t{0}", ternaryOperators); file.WriteLine("\t\t\t}"); file.WriteLine("\t\t\treturn res;"); file.WriteLine("\t\t}"); file.WriteLine("\t}"); file.WriteLine("}"); file.WriteLine(); file.WriteLine(); file.WriteLine("/*"); var soa = unaryStateTokenSet.ToArray(); Array.Sort(soa, TokenComparer); file.WriteLine("Unary State Tokens & Operators"); SendStrings(file, "\t\t{0}", Array.ConvertAll <Tuple <string, string>, string> (soa, x => x.Item1 + "\t" + x.Item2)); soa = binaryStateTokenSet.ToArray(); Array.Sort(soa, TokenComparer); file.WriteLine(); file.WriteLine("Binary State Tokens & Operators"); SendStrings(file, "\t\t{0}", Array.ConvertAll <Tuple <string, string>, string> (soa, x => x.Item1 + "\t" + x.Item2)); file.WriteLine("*/"); file.Dispose(); file = System.IO.File.CreateText(OutputFilePath + @"AbstractSyntaxTree.gen.cs"); SendStrings(file, "{0}", CopyrightText); file.WriteLine(); file.WriteLine("// ReSharper disable PartialTypeWithSinglePart"); file.WriteLine(); file.WriteLine("namespace " + namespacePath + " {"); file.WriteLine(" using static Operators;"); file.WriteLine(); SendStrings(file, "\t{0}", treeNodes); file.WriteLine("}"); file.Dispose(); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var com = Test.IRemoteCommunicatorPrx.Parse($"communicator:{helper.GetTestEndpoint(0)}", communicator); var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); System.IO.TextWriter output = helper.GetWriter(); output.Write("testing binding with single endpoint... "); output.Flush(); { Test.IRemoteObjectAdapterPrx?adapter = com.createObjectAdapter("Adapter", "default"); TestHelper.Assert(adapter != null); Test.ITestIntfPrx?test1 = adapter.getTestIntf(); Test.ITestIntfPrx?test2 = adapter.getTestIntf(); TestHelper.Assert(test1 != null && test2 != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); test2.IcePing(); com.deactivateObjectAdapter(adapter); var test3 = Test.ITestIntfPrx.UncheckedCast(test1); TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(test3.GetConnection() == test2.GetConnection()); try { test3.IcePing(); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter11", "default") !, com.createObjectAdapter("Adapter12", "default") !, com.createObjectAdapter("Adapter13", "default") ! }; // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("Adapter11"); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <Test.IRemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.getAdapterName()); test1.GetConnection().Close(ConnectionClose.GracefullyWithWait); } // // Ensure that the proxy correctly caches the connection(we // always send the request over the same connection.) // { foreach (Test.IRemoteObjectAdapterPrx adpt in adapters) { adpt.getTestIntf() !.IcePing(); } var t = createTestIntfPrx(adapters); string name = t.getAdapterName(); int nRetry = 10; int i; for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++) { ; } TestHelper.Assert(i == nRetry); foreach (var adpt in adapters) { adpt.getTestIntf() !.GetConnection().Close(ConnectionClose.GracefullyWithWait); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter(adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <Test.IRemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(test1.getAdapterName()); test1.GetConnection().Close(ConnectionClose.GracefullyWithWait); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter((Test.IRemoteObjectAdapterPrx)adapters[2]); var obj = createTestIntfPrx(adapters); TestHelper.Assert(obj.getAdapterName().Equals("Adapter12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new Test.IRemoteObjectAdapterPrx[5] { com.createObjectAdapter("AdapterRandom11", "default") !, com.createObjectAdapter("AdapterRandom12", "default") !, com.createObjectAdapter("AdapterRandom13", "default") !, com.createObjectAdapter("AdapterRandom14", "default") !, com.createObjectAdapter("AdapterRandom15", "default") ! }; int count = 20; int adapterCount = adapters.Length; while (--count > 0) { Test.ITestIntfPrx[] proxies; if (count == 1) { com.deactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new Test.ITestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new Test.IRemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new Test.IRemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = createTestIntfPrx(new List <Test.IRemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].getAdapterNameAsync(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].IcePing(); } catch (Exception) { } } var connections = new List <Connection?>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].GetCachedConnection() != null) { if (!connections.Contains(proxies[i].GetCachedConnection())) { connections.Add(proxies[i].GetCachedConnection()); } } } TestHelper.Assert(connections.Count <= adapterCount); foreach (Test.IRemoteObjectAdapterPrx a in adapters) { try { a.getTestIntf() !.GetConnection().Close(ConnectionClose.GracefullyWithWait); } catch (Exception) { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("AdapterAMI11", "default") !, com.createObjectAdapter("AdapterAMI12", "default") !, com.createObjectAdapter("AdapterAMI13", "default") ! }; // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("AdapterAMI11"); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <Test.IRemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.IcePing(); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.GetConnection().Close(ConnectionClose.GracefullyWithWait); } // // Ensure that the proxy correctly caches the connection(we // always send the request over the same connection.) // { foreach (var adpt in adapters) { adpt.getTestIntf() !.IcePing(); } var t = createTestIntfPrx(adapters); string name = getAdapterNameWithAMI(t); int nRetry = 10; int i; for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++) { ; } TestHelper.Assert(i == nRetry); foreach (var adpt in adapters) { adpt.getTestIntf() !.GetConnection().Close(ConnectionClose.GracefullyWithWait); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <Test.IRemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); TestHelper.Assert(test2.GetConnection() == test3.GetConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.GetConnection().Close(ConnectionClose.GracefullyWithWait); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter(adapters[2]); var obj = createTestIntfPrx(adapters); TestHelper.Assert(getAdapterNameWithAMI(obj).Equals("AdapterAMI12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter21", "default") !, com.createObjectAdapter("Adapter22", "default") !, com.createObjectAdapter("Adapter23", "default") ! }; var obj = createTestIntfPrx(adapters); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); var names = new List <string> { "Adapter21", "Adapter22", "Adapter23" }; while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); } obj = obj.Clone(endpointSelection: EndpointSelectionType.Random); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); } deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing ordered endpoint selection... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter31", "default") !, com.createObjectAdapter("Adapter32", "default") !, com.createObjectAdapter("Adapter33", "default") ! }; var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } var endpoints = obj.Endpoints; adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++) { ; } TestHelper.Assert(i == nRetry); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++) { ; } TestHelper.Assert(i == nRetry); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++) { ; } TestHelper.Assert(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { Test.IRemoteObjectAdapterPrx?adapter = com.createObjectAdapter("Adapter41", "default"); TestHelper.Assert(adapter != null); Test.ITestIntfPrx test1 = adapter.getTestIntf() !.Clone(cacheConnection: false); Test.ITestIntfPrx test2 = adapter.getTestIntf() !.Clone(cacheConnection: false); TestHelper.Assert(!test1.IsConnectionCached); TestHelper.Assert(!test2.IsConnectionCached); TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null); TestHelper.Assert(test1.GetConnection() == test2.GetConnection()); test1.IcePing(); com.deactivateObjectAdapter(adapter); var test3 = Test.ITestIntfPrx.UncheckedCast(test1); try { TestHelper.Assert(test3.GetConnection() == test1.GetConnection()); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter51", "default") !, com.createObjectAdapter("Adapter52", "default") !, com.createObjectAdapter("Adapter53", "default") ! }; Test.ITestIntfPrx obj = createTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "Adapter51", "Adapter52", "Adapter53" }; while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter(adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter(adapters[2]); TestHelper.Assert(obj.getAdapterName().Equals("Adapter52")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("AdapterAMI51", "default") !, com.createObjectAdapter("AdapterAMI52", "default") !, com.createObjectAdapter("AdapterAMI53", "default") ! }; Test.ITestIntfPrx obj = createTestIntfPrx(adapters).Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); var names = new List <string> { "AdapterAMI51", "AdapterAMI52", "AdapterAMI53" }; while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter(adapters[2]); TestHelper.Assert(getAdapterNameWithAMI(obj).Equals("AdapterAMI52")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter61", "default") !, com.createObjectAdapter("Adapter62", "default") !, com.createObjectAdapter("Adapter63", "default") ! }; var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } var endpoints = obj.Endpoints; adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++) { ; } TestHelper.Assert(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++) { ; } TestHelper.Assert(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString()) !); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++) { ; } TestHelper.Assert(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection and AMI... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("AdapterAMI61", "default") !, com.createObjectAdapter("AdapterAMI62", "default") !, com.createObjectAdapter("AdapterAMI63", "default") ! }; var obj = createTestIntfPrx(adapters); obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered); TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered); obj = obj.Clone(cacheConnection: false); TestHelper.Assert(!obj.IsConnectionCached); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++) { ; } TestHelper.Assert(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (ConnectFailedException) { } var endpoints = obj.Endpoints; adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString()) !); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++) { ; } TestHelper.Assert(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString()) !); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++) { ; } TestHelper.Assert(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString()) !); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++) { ; } TestHelper.Assert(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter71", "default") !, com.createObjectAdapter("Adapter72", "udp") ! }; var obj = createTestIntfPrx(adapters); TestHelper.Assert(obj.getAdapterName().Equals("Adapter71")); var testUDP = obj.Clone(invocationMode: InvocationMode.Datagram); TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection()); try { testUDP.getAdapterName(); TestHelper.Assert(false); } catch (System.InvalidOperationException) { // expected } } output.WriteLine("ok"); if (communicator.GetProperty("Ice.Plugin.IceSSL") != null) { output.Write("testing secure and non-secure endpoints... "); output.Flush(); { var adapters = new List <Test.IRemoteObjectAdapterPrx> { com.createObjectAdapter("Adapter81", "ssl") !, com.createObjectAdapter("Adapter82", "tcp") ! }; var obj = createTestIntfPrx(adapters); int i; for (i = 0; i < 5; i++) { TestHelper.Assert(obj.getAdapterName().Equals("Adapter82")); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); } var testNonSecure = obj.Clone(preferNonSecure: true); // TODO: update when PreferNonSecure default is updated var testSecure = obj.Clone(preferNonSecure: false); TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection()); TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection()); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < 5; i++) { TestHelper.Assert(obj.getAdapterName().Equals("Adapter81")); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); } com.createObjectAdapter("Adapter83", (obj.Endpoints[1]).ToString()); // Recreate a tcp OA. for (i = 0; i < 5; i++) { TestHelper.Assert(obj.getAdapterName().Equals("Adapter83")); obj.GetConnection().Close(ConnectionClose.GracefullyWithWait); } com.deactivateObjectAdapter(adapters[0]); try { testSecure.IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { // expected } deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); var ipv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "0" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var ipv6 = new Dictionary <string, string>() { { "IPv4", "0" }, { "IPv6", "1" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var bothPreferIPv4 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "0" }, { "Adapter.Endpoints", "tcp -h localhost" } }; var bothPreferIPv6 = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "PreferIPv6Address", "1" }, { "Adapter.Endpoints", "tcp -h localhost" } }; Dictionary <string, string>[] clientProps = { ipv4, ipv6, bothPreferIPv4, bothPreferIPv6 }; string endpoint = "tcp -p " + helper.GetTestPort(2).ToString(); var anyipv4 = new Dictionary <string, string>(ipv4); anyipv4["Adapter.Endpoints"] = endpoint; anyipv4["Adapter.PublishedEndpoints"] = $"{endpoint} -h 127.0.0.1"; var anyipv6 = new Dictionary <string, string>(ipv6); anyipv6["Adapter.Endpoints"] = endpoint; anyipv6["Adapter.PublishedEndpoints"] = $"{endpoint} -h \".1\""; var anyboth = new Dictionary <string, string>() { { "IPv4", "1" }, { "IPv6", "1" }, { "Adapter.Endpoints", endpoint }, { "Adapter.PublishedEndpoints", $"{endpoint} -h \"::1\":{endpoint} -h 127.0.0.1" } }; var localipv4 = new Dictionary <string, string>(ipv4); localipv4["Adapter.Endpoints"] = "tcp -h 127.0.0.1"; var localipv6 = new Dictionary <string, string>(ipv6); localipv6["Adapter.Endpoints"] = "tcp -h \"::1\""; Dictionary <string, string>[] serverProps = { anyipv4, anyipv6, anyboth, localipv4, localipv6 }; bool ipv6NotSupported = false; foreach (var p in serverProps) { Communicator serverCommunicator = new Communicator(p); ObjectAdapter oa; try { oa = serverCommunicator.CreateObjectAdapter("Adapter"); oa.Activate(); } catch (DNSException) { serverCommunicator.Destroy(); continue; // IP version not supported. } catch (TransportException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.Destroy(); continue; // IP version not supported. } var prx = oa.CreateProxy("dummy", IObjectPrx.Factory); try { prx.Clone(collocationOptimized: false).IcePing(); } catch (DNSException) // TODO: is this really an expected exception? { serverCommunicator.Destroy(); continue; } catch (ObjectNotExistException) // TODO: is this really an expected exception? { serverCommunicator.Destroy(); continue; } string strPrx = prx.ToString() !; foreach (var q in clientProps) { Communicator clientCommunicator = new Communicator(q); prx = IObjectPrx.Parse(strPrx, clientCommunicator); try { prx.IcePing(); TestHelper.Assert(false); } catch (ObjectNotExistException) { // Expected, no object registered. } catch (DNSException) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch (TransportException) { TestHelper.Assert((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) || (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) || (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) || (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) || (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) || (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) || (p == bothPreferIPv6 && q == ipv6)); } clientCommunicator.Destroy(); } serverCommunicator.Destroy(); } output.WriteLine("ok"); } com.shutdown(); }
public void WriteToStream(System.IO.TextWriter stream) { stream.WriteLine("#define {0}", name); stream.WriteLine(Code); }