public void IpcCallback() { var binding = new LocalBinding { MaxConnections = 5 }; var path = "ipc:///" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; DoHostWithCallback(binding, path); DoHostWithCallback(binding, path); }
public void Ipc_byteArray() { var uri = "ipc:///" + MethodBase.GetCurrentMethod().Name; using (var server = new ServiceHost(new Service(), new Uri(uri))) { var binding = new LocalBinding { MaxConnections = 5 }; server.AddServiceEndpoint(typeof(IService), binding, uri); server.Open(); Thread.Sleep(100); using (var channelFactory = new ChannelFactory <IService>(binding)) { var client = channelFactory.CreateChannel(new EndpointAddress(uri)); client.Execute(new byte[0]); byte[] bytes = new byte[512]; new Random().NextBytes(bytes); var timer = new Stopwatch(); timer.Start(); for (int i = 0; i < 5000; i++) { client.Execute(bytes); } timer.Stop(); Trace.WriteLine(timer.ElapsedMilliseconds.ToString() + " ms", MethodBase.GetCurrentMethod().Name); } } }
public void CallLocalService() { var address = @"ipc:///1/test.test/test" + MethodBase.GetCurrentMethod().Name; var binding = new LocalBinding(); var data = new CallbackData { Data = "1" }; var srv = new CallbackService(data); var callback = new CallbackServiceCallback(); using (var host = new ServiceHost(srv, new Uri(address))) { host.AddServiceEndpoint(typeof(ICallbackService), binding, address); host.Open(); using (var factory = new DuplexChannelFactory <ICallbackService>(new InstanceContext(callback), binding)) { var client = factory.CreateChannel(new EndpointAddress(address)); client.Call(); } callback.Wait.WaitOne(); Assert.AreEqual(data.Data, callback.Called.Data); } }
public void CallLocalService() { var address = @"ipc:///1/test.test/test" + MethodBase.GetCurrentMethod().Name; var binding = new LocalBinding(); var data = new CallbackData { Data = "1" }; var srv = new CallbackService(data); var callback = new CallbackServiceCallback(); using (var host = new ServiceHost(srv, new Uri(address))) { host.AddServiceEndpoint(typeof(ICallbackService), binding, address); host.Open(); using (var factory = new DuplexChannelFactory<ICallbackService>(new InstanceContext(callback), binding)) { var client = factory.CreateChannel(new EndpointAddress(address)); client.Call(); } callback.Wait.WaitOne(); Assert.AreEqual(data.Data, callback.Called.Data); } }
public void PipeChannel_openClose_fail() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var b = new LocalBinding(); var serv = new Service(null); var host = new ServiceHost(serv, new Uri(address)); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); var f = new ChannelFactory <IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); c.DoWithParamsAndResult(null, Guid.Empty); host.Close(); Exception comminicationEx = null; try { c.DoWithParamsAndResult(null, Guid.Empty); } catch (Exception ex) { comminicationEx = ex; } var obj = c as ICommunicationObject; var state = obj.State; Assert.AreEqual(CommunicationState.Faulted, state); Assert.That(comminicationEx, new ExceptionTypeConstraint(typeof(CommunicationException))); }
public void Ipc_byteArray() { var uri = "ipc:///" + MethodBase.GetCurrentMethod().Name; using (var server = new ServiceHost(new Service(), new Uri(uri))) { var binding = new LocalBinding { MaxConnections = 5 }; server.AddServiceEndpoint(typeof(IService), binding, uri); server.Open(); Thread.Sleep(100); using (var channelFactory = new ChannelFactory<IService>(binding)) { var client = channelFactory.CreateChannel(new EndpointAddress(uri)); client.Execute(new byte[0]); byte[] bytes = new byte[512]; new Random().NextBytes(bytes); var timer = new Stopwatch(); timer.Start(); for (int i = 0; i < 5000; i++) client.Execute(bytes); timer.Stop(); Trace.WriteLine(timer.ElapsedMilliseconds.ToString() + " ms", MethodBase.GetCurrentMethod().Name); } } }
public int CreateBinding(Core.Name name, int registerIndex, Diagnostics.Span span) { var binding = new LocalBinding(); binding.name = name; binding.registerIndex = registerIndex; binding.declSpan = span; this.localBindings.Add(binding); return this.localBindings.Count - 1; }
public int CreateBinding(Core.Name name, int registerIndex, Diagnostics.Span span) { var binding = new LocalBinding(); binding.name = name; binding.registerIndex = registerIndex; binding.declSpan = span; this.localBindings.Add(binding); return(this.localBindings.Count - 1); }
public void IpcCallbackLoop() { var binding = new LocalBinding { MaxConnections = 5 }; var path = "ipc:///" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var reportWatch = new NStopwatch.Reportwatch(); for (int i = 0; i < 1000; i++) { DoHostWithCallbackInternal(reportWatch, binding, path); } reportWatch.ReportAll(); }
public void PipeChannel_notOpenedServer_created() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var b = new LocalBinding(); var f = new ChannelFactory <IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); var obj = c as ICommunicationObject; var state = obj.State; Assert.AreEqual(CommunicationState.Created, state); }
public void InterfaceInheritance() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new InheritanceService(); var host = new ServiceHost(serv, new Uri(address)); var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IInheritanceService), b, address); host.Open(); var f = new ChannelFactory<IInheritanceService>(b); var c = f.CreateChannel(new EndpointAddress(address)); c.Do(); c.DoBase(); host.Dispose(); }
public void LongLocalName() { var address = @"ipc:///1/test.test/testtestLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNamefd0286a60b9b4db18659-b715e5db5b3bd0286a6-0b9b-4db1-8659-b715e5db5b3b"; var serv = new Service(null); var host = new ServiceHost(serv, new Uri(address)); var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); var f = new ChannelFactory <IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); var result = c.DoWithParamsAndResult(":)", Guid.NewGuid()); Assert.AreEqual(2, result.d1); host.Dispose(); }
public void InterfaceInheritance() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new InheritanceService(); var host = new ServiceHost(serv, new Uri(address)); var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IInheritanceService), b, address); host.Open(); var f = new ChannelFactory <IInheritanceService>(b); var c = f.CreateChannel(new EndpointAddress(address)); c.Do(); c.DoBase(); host.Dispose(); }
public void WorksWithSystemServiceModelAttributes() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new WcfSimpleService(); using (var host = new ServiceHost(serv, new Uri(address))) { var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IWcfSimpleService), b, address); host.Open(); using (var f = new ChannelFactory <IWcfSimpleService>(b)) { var c = f.CreateChannel(new EndpointAddress(address)); c.Do(); } } }
public void Ipc_byteArray() { var binding = new LocalBinding { MaxConnections = 5 }; var path = "ipc:///" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var tester = new FirstCallTester(Console.Out); tester.Start("1 Service"); DoWcfHost(binding, path); tester.Stop(); tester.Start("2 Service2"); DoWcfHost2(binding, path); tester.Stop(); tester.Start("3 Service2"); DoWcfHost2(binding, path); tester.Stop(); tester.Start("4 Service2"); DoWcfHost2(binding, path); tester.Stop(); tester.Report(); }
public void Local() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new Service(null); using (var host = new ServiceHost(serv, new Uri(address))) { var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); using (var f = new ChannelFactory <IService>(b)) { var c = f.CreateChannel(new EndpointAddress(address)); var result = c.DoWithParamsAndResult(":)", Guid.NewGuid()); Assert.AreEqual(2, result.d1); } } }
/// <summary> /// Bind a local to the current scope. /// </summary> /// <param name="name">The name of the variable.</param> /// <param name="idx">The index of the variable in the locals table.</param> /// <param name="token">The symbol token for the given variable.</param> /// <param name="startOffset">The starting offset for the binding. Set to 0 to default to current scope.</param> /// <param name="endOffset">The ending offset for the binding. Set to 0 to default to current scope.</param> public void BindLocal(string name, int idx, uint token, int startOffset, int endOffset) { Contract.Requires(name != null); // Check to make sure a scope is open if (currentScope == null) { throw new Exception("You must have an open scope in order to bind locals."); } // Create the new local binding object LocalBinding lb = new LocalBinding(); lb.Name = name; lb.Index = idx; lb.Token = new SymbolToken((int)token); lb.OffsetStart = startOffset; lb.OffsetEnd = endOffset; // Add to the current scope currentScope.Locals.Add(lb); }
public BindingInit(LocalBinding binding, Expr init) { _binding = binding; _init = init; }
public void PipeChannel_openClose_fail() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var b = new LocalBinding(); var serv = new Service(null); var host = new ServiceHost(serv, new Uri(address)); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); var f = new ChannelFactory<IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); c.DoWithParamsAndResult(null, Guid.Empty); host.Close(); Exception comminicationEx = null; try { c.DoWithParamsAndResult(null, Guid.Empty); } catch (Exception ex) { comminicationEx = ex; } var obj = c as ICommunicationObject; var state = obj.State; Assert.AreEqual(CommunicationState.Faulted, state); Assert.That(comminicationEx, new ExceptionTypeConstraint(typeof(CommunicationException))); }
public void PipeChannel_notOpenedServer_created() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var b = new LocalBinding(); var f = new ChannelFactory<IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); var obj = c as ICommunicationObject; var state = obj.State; Assert.AreEqual(CommunicationState.Created, state); }
public void LongLocalName() { var address = @"ipc:///1/test.test/testtestLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNamefd0286a60b9b4db18659-b715e5db5b3bd0286a6-0b9b-4db1-8659-b715e5db5b3b"; var serv = new Service(null); var host = new ServiceHost(serv, new Uri(address)); var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); var f = new ChannelFactory<IService>(b); var c = f.CreateChannel(new EndpointAddress(address)); var result = c.DoWithParamsAndResult(":)", Guid.NewGuid()); Assert.AreEqual(2, result.d1); host.Dispose(); }
public void Local() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new Service(null); using (var host = new ServiceHost(serv, new Uri(address))) { var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IService), b, address); host.Open(); using (var f = new ChannelFactory<IService>(b)) { var c = f.CreateChannel(new EndpointAddress(address)); var result = c.DoWithParamsAndResult(":)", Guid.NewGuid()); Assert.AreEqual(2, result.d1); } } }
/// <summary> /// Gets the description of this endpoint /// </summary> /// <returns>The description of this endpoint</returns> public override string ToString() { return("Local: " + LocalBinding.ToString() + ", Remote: " + RemoteBinding.ToString()); }
public HostArg(ParameterType paramType, Expr argExpr, LocalBinding lb) { _paramType = paramType; _argExpr = argExpr; _localBinding = lb; }
private static LocalBinding RegisterLocal(Symbol sym, Symbol tag, Expression init ) { LocalBinding b = new LocalBinding(sym,tag,init); IPersistentMap localsMap = (IPersistentMap) LOCAL_ENV.deref(); LOCAL_ENV.set(localsMap.assoc(b.Symbol,b)); MethodDef method = (MethodDef)METHODS.deref(); if ( method != null ) method.Locals = (IPersistentMap)method.Locals.assoc(b,b); return b; }
public override Expression VisitMemberBinding(MemberBinding memberBinding){ if (memberBinding == null) return null; TypeNode boundType = memberBinding.BoundMember as TypeNode; if (boundType != null) { if (this.currentMethod != null && this.currentMethod.Scope != null && this.currentMethod.Scope.CapturedForClosure) boundType = this.currentMethod.Scope.FixTypeReference(boundType); return new Literal(boundType, SystemTypes.Type, memberBinding.SourceContext); } // fixup special target objects if member is part of a closure if (memberBinding.TargetObject != null && memberBinding.BoundMember != null && memberBinding.BoundMember.DeclaringType is ClosureClass && this.currentClosureLocal != null){ switch (memberBinding.TargetObject.NodeType){ case NodeType.This: case NodeType.Base: case NodeType.ImplicitThis: memberBinding.TargetObject.Type = memberBinding.BoundMember.DeclaringType; break; } } Property prop = memberBinding.BoundMember as Property; if (prop != null){ Method getter = prop.Getter; if (getter == null) getter = prop.GetBaseGetter(); if (getter == null) return null; bool baseCall = memberBinding.TargetObject is Base; memberBinding = new MemberBinding(this.VisitExpression(memberBinding.TargetObject), getter); MethodCall call = new MethodCall(memberBinding, null); if (!baseCall && getter.IsVirtualAndNotDeclaredInStruct) call.NodeType = NodeType.Callvirt; call.Type = prop.Type; return call; } Field f = memberBinding.BoundMember as Field; if (f != null && f.IsLiteral){ if (f.DefaultValue != null) return f.DefaultValue; Literal lit = this.VisitExpression(f.Initializer) as Literal; if (lit != null){ f.DefaultValue = lit; f.Initializer = null; return lit; }else{ f.Flags &= ~(FieldFlags.Literal|FieldFlags.HasDefault); f.Flags |= FieldFlags.InitOnly; } } if (memberBinding.TargetObject is ImplicitThis){ //Might be a local or a parameter if (f == null) goto done; BlockScope bscope = f.DeclaringType as BlockScope; if (bscope != null){ if (!bscope.CapturedForClosure || bscope.MembersArePinned){ Local loc = this.currentMethod.GetLocalForField(f); loc.Pinned = loc.Pinned || bscope.MembersArePinned; loc.SourceContext = memberBinding.SourceContext; Expression localBinding = new LocalBinding(loc, memberBinding.SourceContext); Reference refType = loc.Type as Reference; if (refType != null && loc.Pinned) { // change type from T& to T* using conv.i localBinding = new UnaryExpression(localBinding, NodeType.Conv_I, refType.ElementType.GetPointerType()); } return localBinding; } if (this.currentClosureLocal == null) return null; if (f.DeclaringType != this.currentClosureLocal.Type){ //REVIEW: hasty hack. Go over this and figure out how to do it properly. f.DeclaringType = this.currentClosureLocal.Type; f.Type = this.currentMethod.Scope.FixTypeReference(f.Type); // check to see if we need to mangle the name MemberList list = f.DeclaringType.GetMembersNamed(f.Name); if (list != null && list.Count > 0) { // add offset to name to get a unique name f.Name = Identifier.For(f.Name.Name + f.DeclaringType.Members.Count); } f.DeclaringType.Members.Add(f); if (f.DeclaringType.Template != null) { Field tf = (Field)f.Clone(); tf.DeclaringType = f.DeclaringType.Template; f.DeclaringType.Template.Members.Add(tf); } f.Flags &= ~FieldFlags.InitOnly; } memberBinding.TargetObject = this.currentClosureLocal; goto done; } MethodScope mscope = f.DeclaringType as MethodScope; if (mscope != null){ ParameterField pField = f as ParameterField; if (pField != null && (!mscope.CapturedForClosure || this.currentClosureLocal == null || f.Type is Reference)) return new ParameterBinding(pField.Parameter, memberBinding.SourceContext); memberBinding.TargetObject = this.currentClosureLocal; goto done; } ClosureClass closure = f.DeclaringType as ClosureClass; if (closure != null){ ParameterField pField = f as ParameterField; if (this.currentClosureLocal != null) { memberBinding.TargetObject = this.currentClosureLocal; TypeNode currentClosure = this.currentClosureLocal.Type; while (!closure.IsStructurallyEquivalentTo(currentClosure) && currentClosure != null){ Field thisVal = currentClosure.GetField(StandardIds.ThisValue); if (thisVal == null) break; memberBinding.TargetObject = new MemberBinding(memberBinding.TargetObject, thisVal); currentClosure = thisVal.Type; } } } } Expression tObj = memberBinding.TargetObject; if (tObj != null && tObj.Type != null && tObj.Type.IsValueType){ MemberBinding mb = tObj as MemberBinding; if (mb != null && mb.BoundMember is Field && ((Field)mb.BoundMember).IsInitOnly){ StatementList stats = new StatementList(2); Local loc = new Local(tObj.Type); stats.Add(new AssignmentStatement(loc, tObj)); stats.Add(new ExpressionStatement(new UnaryExpression(loc, NodeType.AddressOf, loc.Type.GetReferenceType()))); memberBinding.TargetObject = new BlockExpression(new Block(stats), loc.Type.GetReferenceType()); }else memberBinding.TargetObject = new UnaryExpression(tObj, NodeType.AddressOf, tObj.Type.GetReferenceType()); } done: memberBinding.TargetObject = this.VisitExpression(memberBinding.TargetObject); if (memberBinding.TargetObject == this.currentThisParameter && this.currentThisParameter != null) { ClosureClass cc = TypeNode.StripModifiers(this.currentThisParameter.Type) as ClosureClass; if (cc != null && memberBinding.BoundMember != null && memberBinding.BoundMember.DeclaringType != null && !this.GetTypeView(cc).IsAssignableTo(memberBinding.BoundMember.DeclaringType)){ memberBinding.TargetObject = this.GetBindingPath(this.currentThisParameter, memberBinding.BoundMember.DeclaringType); } } else if (memberBinding.TargetObject != null){ ClosureClass cc = TypeNode.StripModifiers(memberBinding.TargetObject.Type) as ClosureClass; if (cc != null && memberBinding.BoundMember != null && memberBinding.BoundMember.DeclaringType != null && !cc.IsAssignableTo(memberBinding.BoundMember.DeclaringType)) { memberBinding.TargetObject = this.GetBindingPath(memberBinding.TargetObject, memberBinding.BoundMember.DeclaringType); } if (memberBinding.TargetObject.Type != null && memberBinding.TargetObject.Type.IsValueType) { BlockExpression bexpr = memberBinding.TargetObject as BlockExpression; if (bexpr != null) { if (bexpr.Block != null && bexpr.Block.Statements != null && bexpr.Block.Statements.Count > 0) { ExpressionStatement es = bexpr.Block.Statements[bexpr.Block.Statements.Count-1] as ExpressionStatement; if (es != null && es.Expression != null && es.Expression.Type != null && es.Expression.Type.IsValueType) es.Expression = new UnaryExpression(memberBinding.TargetObject, NodeType.AddressOf, memberBinding.TargetObject.Type.GetReferenceType()); } } else { memberBinding.TargetObject = new UnaryExpression(memberBinding.TargetObject, NodeType.AddressOf, memberBinding.TargetObject.Type.GetReferenceType()); } } } return memberBinding; }
public void WorksWithSystemServiceModelAttributes() { var address = @"ipc:///test" + MethodBase.GetCurrentMethod().Name; var serv = new WcfSimpleService(); using (var host = new ServiceHost(serv, new Uri(address))) { var b = new LocalBinding(); host.AddServiceEndpoint(typeof(IWcfSimpleService), b, address); host.Open(); using ( var f = new ChannelFactory<IWcfSimpleService>(b)) { var c = f.CreateChannel(new EndpointAddress(address)); c.Do(); } } }