public void As_Generic() { Expression <Func <ICache, string, object> > get = (o, s) => o.Get(s); Expression <Func <Memcached, string, object> > read = (i, s) => i.Read(s); Expression <Action <ICache, string, object> > set = (o, s, obj) => o.Set(s, obj); Expression <Action <Memcached, string, object> > insert = (i, s, obj) => i.Put(s, obj); ICache cache = new Passthrough <ICache, Memcached>() .Create() .WithPassthrough(o => o.Name, i => i.InstanceName) .WithPassthrough(get, read) .WithPassthrough(set, insert) .As(); Assert.AreEqual("Memcached", cache.Name); cache.Name = "NewName"; Assert.AreEqual("NewName", cache.Name); var value = DateTime.Now; cache.Set("x", value); object value2 = cache.Get("x"); Assert.AreEqual(value, value2); }
public void Modify(Passthrough type, ushort value) { Array.Copy(Util.ushortToBytesLe(value), 0, config, 2, 2); config[1] = (byte)(((int)type) & 0x7); bridge.sendCommand(DATA_PROCESSOR, DataProcessor.PARAMETER, source.eventConfig[2], config); }
public void Passthrough() { PtTest pt = new PtTest(); Passthrough pter = new Passthrough( pt ); string program = @" pt.test(5, ""bob"", [""1"", ""2""], true, pt) pt.property = ""bar"" a = pt.property b = pt.arbitrary c = pt.other pt.arbitrary = ""new value"" d = pt.arbitrary pt.test2(1, 2, ""3"") e = """" def func(x): e += x pt.complex(1, func) f = pt.complex(2) g = pt.complex(3) h = pt.complex(4) i = pt.complex(5) j = pt.dumpcontext() k = 0 try: pt.complex(6) except e: k = e l = 0 try: l = pt.throwme except e: l = e m = 0 try: pt.throwme = ""foo"" except e: m = e n = 0 try: pt.callnthrow() except e: n = e "; Runner r = new Runner(); r.pushSecurityContext( new TestSC( "Base Context" ) ); pter.registerConst( r.state.constScope, "pt" ); runAndDump( "Passthrough", r, program, () => "object dump: {0} {1} {2} {3} {4} {5}\r\n".FormatI( dumpObject( pt._a ), dumpObject( pt._b ), dumpObject( pt._c ), dumpObject( pt._d ), dumpObject( pt._e ), dumpObject( pt._f ) ) ); }
public void GetConfigured_Type() { var dateTime = new DateTime(2001, 1, 1); var oldDateTime = Passthrough.GetConfigured <DateTime>(dateTime); var oldDateTimeString = oldDateTime.ToString(); Assert.AreEqual(DateTime.MinValue.ToString(), oldDateTimeString); }
public IRouteComponent Limit(Passthrough type, ushort value) { if (source.attributes.length() <= 0) { throw new IllegalRouteOperationException("Cannot limit null data"); } var config = new DataProcessorConfig.PassthroughConfig(type, value); var next = source.transform(config); return(postCreate(next.Item2, new PassthroughEditorInner(config, next.Item1, state.bridge))); }
protected override void OnGenerate() { var token = T.Token; switch (token.Type) { case 0: { var error = (CommonErrorNode) token; Errors.ErrorParse(error); break; } case TemplateParser.Statement: { Ctx.Sink.Emit(OpCodes.Ldarg_0); var s = new Statement(T); Errors.AddRange(s.Generate(Ctx)); Ctx.EmitAppendToBuffer(); break; } case TemplateParser.Passthrough: { Ctx.Sink.Emit(OpCodes.Ldarg_0); var s = new Passthrough(T); Errors.AddRange(s.Generate(Ctx)); Ctx.EmitAppendToBuffer(); break; } case TemplateParser.Control: { var ctl = new Control(T); Errors.AddRange(ctl.Generate(Ctx)); break; } case TemplateLexer.Unparsed: case TemplateLexer.Literal: { Ctx.Sink.Emit(OpCodes.Ldarg_0); Ctx.Sink.Emit(OpCodes.Ldstr, token.Text); Ctx.EmitAppendLiteralToBuffer(); break; } case TemplateLexer.EOF: { break; } } }
public void GetConfigured() { ICache cache = Passthrough.GetConfigured <ICache>(); Assert.AreEqual("AppFabricCache", cache.Name); cache.Name = "NewName"; Assert.AreEqual("NewName", cache.Name); var value = DateTime.Now; cache.Set("x", value); object value2 = cache.Get("x"); Assert.AreEqual(value, value2); }
public void As() { var setup = new Passthrough(); var cache = setup.Create("PassthroughSample.Tests.Stubs.AspNetCache, PassthroughSample.Tests") .WithPassthrough("Name", "CacheName") .WithPassthrough("Get", "Retrieve") .WithPassthrough("Set", "Insert") .As<ICache>(); Assert.AreEqual("AspNetCache", cache.Name); cache.Name = "NewName"; Assert.AreEqual("NewName", cache.Name); var value = DateTime.Now; cache.Set("x", value); object value2 = cache.Get("x"); Assert.AreEqual(value, value2); }
public IRouteComponent Limit(Passthrough type, ushort value) { if (source.attributes.length() <= 0) { throw new IllegalRouteOperationException("Cannot limit null data"); } DataTypeBase processor = source.dataProcessorCopy(source, source.attributes.dataProcessorCopy()); byte[] config = new byte[4] { 0x1, (byte)(((int)type) & 0x7), 0, 0 }; Array.Copy(Util.ushortToBytesLe(value), 0, config, 2, 2); DataTypeBase processorState = new IntegralDataType(DATA_PROCESSOR, Util.setRead(DataProcessor.STATE), new DataAttributes(new byte[] { 2 }, (byte)1, (byte)0, false)); return(postCreate(processorState, new PassthroughEditorInner(config, processor, state.bridge))); }
public void As() { var setup = new Passthrough(); var cache = setup.Create("PassthroughSample.Tests.Stubs.AspNetCache, PassthroughSample.Tests") .WithPassthrough("Name", "CacheName") .WithPassthrough("Get", "Retrieve") .WithPassthrough("Set", "Insert") .As <ICache>(); Assert.AreEqual("AspNetCache", cache.Name); cache.Name = "NewName"; Assert.AreEqual("NewName", cache.Name); var value = DateTime.Now; cache.Set("x", value); object value2 = cache.Get("x"); Assert.AreEqual(value, value2); }
public void As_Generic() { Expression<Func<ICache, string, object>> get = (o, s) => o.Get(s); Expression<Func<Memcached, string, object>> read = (i, s) => i.Read(s); Expression<Action<ICache, string, object>> set = (o, s, obj) => o.Set(s, obj); Expression<Action<Memcached, string, object>> insert = (i, s, obj) => i.Put(s, obj); ICache cache = new Passthrough<ICache, Memcached>() .Create() .WithPassthrough(o => o.Name, i => i.InstanceName) .WithPassthrough(get, read) .WithPassthrough(set, insert) .As(); Assert.AreEqual("Memcached", cache.Name); cache.Name = "NewName"; Assert.AreEqual("NewName", cache.Name); var value = DateTime.Now; cache.Set("x", value); object value2 = cache.Get("x"); Assert.AreEqual(value, value2); }
internal PassthroughConfig(byte[] config) : base(config[0]) { type = (Passthrough)(config[1] & 0x7); value = Util.bytesLeToUshort(config, 2); }
/// <summary> /// Adds a value to the state's scope. /// </summary> /// <remarks> /// Coral-native types are added as-is, while other types are Passthrough wrapped. /// </remarks> public void addToScope( string name, object value ) { if( value == null || value is int || value is bool || value is string || value is string[] ) _state.scope.set( name, Util.CoerceFromDotNet( value ) ); else { var wrapped = new Passthrough( value ); wrapped.registerScope( _state.scope, name ); } }
/// <summary> /// Determines whether the specified <see cref="Passthrough" />, is equal to this instance. /// </summary> /// <param name="other">The other.</param> /// <returns>true if equal; otherwise, false</returns> protected bool Equals(Passthrough other) => Attributes.Equals(other.Attributes) && string.Equals(Text, other.Text);
internal PassthroughConfig(Passthrough type, ushort value) : base(ID) { this.type = type; this.value = value; }
public static void RegisterObject( ConstScope scope ) { var pt = new Passthrough( new MathObject() ); pt.registerConst( scope, "math" ); }
/// <summary> /// Converts a .NET type to a Coral type. /// </summary> public static object CoerceFromDotNet( object value ) { if( value == null ) return null; else { Type rvt = value.GetType(); if( rvt == typeof( int ) || rvt == typeof( string ) || rvt == typeof( bool ) ) return value; else if( value is Array ) { var rv = new List<object>(); foreach( var v in (Array)value ) rv.Add( CoerceFromDotNet( v ) ); return rv; } else if( value is Dictionary<object, object> || value is List<object> ) { // There are potentially unsafe things in here if these were passed from // outside the interpreter, but rewriting them would destroy their references // from being passed across metal boundaries. return value; } else { Passthrough pt = new Passthrough( value ); return pt.getObject( "<anon>" ); } } }