public void YamlTest() { var ys = new SerializerBuilder().Build(); var s = ys.Serialize(new { Field1 = "one", Field2 = "two", }); Console.WriteLine(s); Assert.AreEqual($"Field1: one{Environment.NewLine}Field2: two{Environment.NewLine}", s); var x = new { Name = "None", Count = 4, }; s = ys.Serialize(new { Field1 = "one", Field2 = "two", Az1 = x, Az2 = x, }); Console.WriteLine(s); Assert.AreEqual($"Field1: one{Environment.NewLine}Field2: two{Environment.NewLine}Az1: &o0{Environment.NewLine} Name: None{Environment.NewLine} Count: 4{Environment.NewLine}Az2: *o0{Environment.NewLine}", s); var site = new IvrSiteSchema { HostedZoneDomain = "my.site.domain.net", SipProviders = new List <string> { "Twilio", }, IngressPorts = new List <PortSpec> { PortSpec.Parse("SIP 5060"), PortSpec.Parse("RTP 5064-6000"), }, RdpProps = new RdpProps { UserName = "******", Password = "******", Cidrs = new List <string> { "1.2.3.4/32", } }, HostGroups = new List <HostGroup> { new HostGroup { AllocateNewElasticIPs = true, HostCount = 2, InstallS3i = "https://raw.githubusercontent.com/OlegBoulanov/s3i/develop/Examples/Config.ini", }, new HostGroup { AllocateNewElasticIPs = false, HostCount = 16, InstallS3i = "https://raw.githubusercontent.com/OlegBoulanov/s3i/develop/Examples/Config.ini", }, }, }; s = ys.Serialize(site); Console.WriteLine(s); var yd = new YamlDotNet.Serialization.DeserializerBuilder().Build(); var site2 = yd.Deserialize <IvrSiteSchema>(s); Assert.AreEqual(2, site2.HostGroups.Count()); /* * Console.WriteLine("******"); * using(var sr = new StreamReader($"{OSAgnostic.Home}/Projects/CdkTest-1.yaml")) { * var site1 = yd.Deserialize<IvrSiteSchema>(sr.ReadToEnd()); * Console.WriteLine(ys.Serialize(site1)); * } */ }
private FeatureSpec HandleFeatures() { if (!ThisToken().Match(TokenTypes.Features)) { return(new NoneFeature { BeginPosition = ThisToken().TokenBeginIdx, EndPosition = ThisToken().TokenBeginIdx }); } Consume(); FeatureSpec spec = null; TryParseAndResumeToToken(() => { if (ThisToken().Match(TokenTypes.None)) { spec = new NoneFeature { BeginPosition = ThisToken().TokenBeginIdx, }; Consume(); return; } // IOType 可能有两个 Token,所以要考虑这两种情况 if (LookAhead(3).Match(TokenTypes.Parameter) || LookAhead(4).Match(TokenTypes.Parameter)) { var parameterSpec = new ParameterSpec { BeginPosition = ThisToken().TokenBeginIdx, }; spec = parameterSpec; HandleParameterSpec(parameterSpec); } else { var portSpec = new PortSpec { BeginPosition = ThisToken().TokenBeginIdx, }; spec = portSpec; HandlePortSpec(portSpec); } }, TokenTypes.Semicolon); var token = ConsumeType(TokenTypes.Semicolon); if (spec != null) { spec.EndPosition = token.TokenEndIdx; } return(spec); }
public Arnie(string src) { _src = src; _isPrint = false; _pspec = new PortSpec[] { new PortSpec(0, typeof(string), "Probe"), }; _port = new Port(_pspec); }
public void Parse() { ParseAndCheck("SIP 5060"); ParseAndCheck("SIPS 5060-5061"); ParseAndCheck("RTP 5062-5600"); //PortRangeSpec.Parse("XYZ:"); Assert.Throws(typeof(FormatException), () => { PortSpec.Parse("XYZ"); }); Assert.Throws(typeof(FormatException), () => { PortSpec.Parse("X Y Z"); }); Assert.Throws(typeof(FormatException), () => { PortSpec.Parse("X Y-Z-W"); }); Assert.Throws(typeof(FormatException), () => { PortSpec.Parse("XYZ "); }); }
public term(string src) { _src = src; _pspec = new PortSpec[] { new PortSpec(0, typeof(string), "[IN]Display"), new PortSpec(1, typeof(string), "[OUT]Key"), }; _port = new Port(_pspec); _term = new terminal(); var task = MakeThread(); }
public Sample(string arg) { _pspec = new PortSpec[] { new PortSpec(0, typeof(string), "[IN]Probe"), new PortSpec(1, typeof(bool), "ON"), new PortSpec(2, typeof(bool), "OFF"), new PortSpec(3, typeof(bool), "And(in1)"), new PortSpec(4, typeof(bool), "And(in2)"), new PortSpec(5, typeof(bool), "And(out)"), new PortSpec(6, typeof(bool), "Not(in)"), new PortSpec(7, typeof(bool), "Not(out)"), }; _port = new Port(_pspec); }
private void HandlePortSpec(PortSpec portSpec) { TryParseAndResumeToToken(() => { // Identifier portSpec.Identifier = ConsumeType(TokenTypes.Identifier); }, TokenTypes.SingleColon); TryParseAndResumeToToken(() => { ConsumeType(TokenTypes.SingleColon); portSpec.IoType = HandleIoType(portSpec); }, TokenTypes.Data, TokenTypes.Event); portSpec.PortType = HandlePortType(); portSpec.Associations = TryHandleAssociationBlock(); }
private static Port InstantiatePortOfType(Chip c, PortSpec s) => s switch {
void ParseAndCheck(string s) { Assert.AreEqual(s, PortSpec.Parse(s).ToString()); }