public void ConcurrentNetTcpClientConnection()
        {
            IWebHost host = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.NoSecurityRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    System.Threading.Tasks.Task <bool> resultTask = channel.WaitForSecondRequestAsync();
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                    channel.SecondRequest();
                    bool waitResult = resultTask.GetAwaiter().GetResult();
                    Assert.True(waitResult, $"SecondRequest wasn't executed concurrently");
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Beispiel #2
0
        void ScheduleNextStepForCLRTask(System.Threading.Tasks.Task stt)
        {
            _AwaitingCLRTask = stt;
            var awaiter = stt.GetAwaiter();

            awaiter.OnCompleted(_QueueStep);
        }
Beispiel #3
0
 public static void BindFuture <T> (this System.Threading.Tasks.Task <T> task, Future <T> future)
 {
     task.GetAwaiter().OnCompleted(() => {
         future.SetResult2(task);
     });
     future.RegisterOnDispose((_) => {
         task.TryCancelScope();
     });
 }
        static StackObject *GetAwaiter_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Threading.Tasks.Task instance_of_this_method = (System.Threading.Tasks.Task) typeof(System.Threading.Tasks.Task).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetAwaiter();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #5
0
        static StackObject *GetAwaiter_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Threading.Tasks.Task <global::CoroutineAdapter.Adaptor> instance_of_this_method = (System.Threading.Tasks.Task <global::CoroutineAdapter.Adaptor>) typeof(System.Threading.Tasks.Task <global::CoroutineAdapter.Adaptor>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetAwaiter();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #6
0
        static StackObject *GetAwaiter_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Threading.Tasks.Task <System.Collections.Generic.Dictionary <System.Int32, Google.Protobuf.Adapt_IMessage.Adaptor> > instance_of_this_method = (System.Threading.Tasks.Task <System.Collections.Generic.Dictionary <System.Int32, Google.Protobuf.Adapt_IMessage.Adaptor> >) typeof(System.Threading.Tasks.Task <System.Collections.Generic.Dictionary <System.Int32, Google.Protobuf.Adapt_IMessage.Adaptor> >).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetAwaiter();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #7
0
        internal static List <IServiceDispatcher> BuildDispatcher <TService>(ServiceConfiguration <TService> serviceConfig, IServiceProvider services) where TService : class
        {
            IServiceBuilder serviceBuilder = services.GetRequiredService <IServiceBuilder>();

            Uri[] serverUriAddresses = serviceBuilder.BaseAddresses.ToArray();
            ServiceHostObjectModel <TService> serviceHost;

            serviceHost = services.GetRequiredService <ServiceHostObjectModel <TService> >();

            // TODO: Create internal behavior which configures any extensibilities which exist in serviceProvider, eg IMessageInspector
            foreach (ServiceEndpointConfiguration endpointConfig in serviceConfig.Endpoints)
            {
                if (!serviceHost.ReflectedContracts.Contains(endpointConfig.Contract))
                {
                    throw new ArgumentException($"Service type {typeof(TService)} doesn't implement interface {endpointConfig.Contract}");
                }

                ContractDescription contract = serviceHost.ReflectedContracts[endpointConfig.Contract];

                Uri uri             = serviceHost.MakeAbsoluteUri(endpointConfig.Address, endpointConfig.Binding);
                var serviceEndpoint = new ServiceEndpoint(
                    contract,
                    endpointConfig.Binding,
                    new EndpointAddress(uri));

                serviceHost.Description.Endpoints.Add(serviceEndpoint);
            }

            InitializeServiceHost(serviceHost, services);
            ServiceConfigurationDelegateHolder <TService> configDelegate = services.GetService <ServiceConfigurationDelegateHolder <TService> >();

            configDelegate?.Configure(serviceHost);

            // TODO: Add error checking to make sure property chain is correctly populated with objects
            var dispatchers = new List <IServiceDispatcher>(serviceHost.ChannelDispatchers.Count);

            foreach (ChannelDispatcherBase cdb in serviceHost.ChannelDispatchers)
            {
                var cd = cdb as ChannelDispatcher;
                cd.Init();
                System.Threading.Tasks.Task openTask = cd.OpenAsync();
                Fx.Assert(openTask.IsCompleted, "ChannelDispatcher should open synchronously");
                openTask.GetAwaiter().GetResult();
                dispatchers.Add(new ServiceDispatcher(cd));
            }

            return(dispatchers);
        }
Beispiel #8
0
        private static string GetPersistentPath()
        {
#if WINDOWS_UWP || WINDOWS_WSA
            System.Threading.Tasks.Task <StorageFolder> gaFolderTask = System.Threading.Tasks.Task.Run <StorageFolder>(async() => await ApplicationData.Current.LocalFolder.CreateFolderAsync("GameAnalytics", CreationCollisionOption.OpenIfExists));
            return(gaFolderTask.GetAwaiter().GetResult().Path);
#else
            string result = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "GameAnalytics" + Path.DirectorySeparatorChar + System.AppDomain.CurrentDomain.FriendlyName;

            if (!Directory.Exists(result))
            {
                Directory.CreateDirectory(result);
            }

            return(result);
#endif
        }
Beispiel #9
0
 public static void BindFuture(this tTask task, IFuture future)
 {
     task.GetAwaiter().OnCompleted(() => {
         // FIXME: ExceptionDispatchInfo?
         if (task.IsFaulted)
         {
             future.Fail(task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerException : task.Exception);
         }
         else
         {
             future.Complete();
         }
     });
     future.RegisterOnDispose((_) => {
         task.TryCancelScope();
     });
 }
        /// <summary>
        /// Invokes the middleware to controls the specified request.
        /// </summary>
#pragma warning disable CA1822
        public async SystemTask InvokeAsync(WebFramework.HttpContext context)
        {
            WebFramework.HttpRequest request = context.Request;
            if (request != null && TryExtractRuntime(request, out CoyoteRuntime runtime))
            {
                IO.Debug.WriteLine("<Coyote> Runtime '{0}' takes control of the '{1} {2}' handler on thread '{3}'.",
                                   runtime.Id, request.Method, request.Path, SystemThread.CurrentThread.ManagedThreadId);
                TryExtractSourceOperation(request, runtime, out ControlledOperation source);
                var op = HttpOperation.Create(ToHttpMethod(request.Method), request.Path, runtime, source);
                OperationGroup.SetCurrent(op.Group);
                await runtime.TaskFactory.StartNew(state =>
                {
                    SystemTask task = this.Next(context);
                    runtime.WaitUntilTaskCompletes(task);
                    task.GetAwaiter().GetResult();
                },
                                                   op,
Beispiel #11
0
        public void CommunicationDevicePushTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            cd.Push(sendBuf, 0, sendBuf.Length);
            System.Threading.Tasks.Task <int> receiveResult1 = peer.Receive(recvBuf, 0, 4);
            System.Threading.Tasks.Task <int> receiveResult2 = peer.Receive(recvBuf, 4, 6);

            int receiveCount1 = receiveResult1.GetAwaiter().GetResult();
            int receiveCount2 = receiveResult2.GetAwaiter().GetResult();

            Assert.AreEqual(4, receiveCount1);
            Assert.AreEqual(6, receiveCount2);
        }
Beispiel #12
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                RegisterMetadata();
                AddCustomActivityIcons();
                AddNativeActivityIcons();
                AddToolBox();

                if (File.Exists(xamlFile))
                {
                    LoadDesignerAndWorkflow(xamlFile);
                }
                else
                {
                    LoadDesignerAndWorkflow();
                }

                StatusBarText.Text       = "Loading Intellisense...";
                StatusBarText.Foreground = new SolidColorBrush(Colors.Green);
                StatusBarText.FontSize  += 3;
                intellisenseLoadingTask.GetAwaiter().OnCompleted(() =>
                {
                    EditorService editorService = new EditorService
                    {
                        IntellisenseData = intellisense.IntellisenseList,
                        EditorKeyWord    = intellisense.CreateKeywords(),
                    };
                    wd.Context.Services.Publish <System.Activities.Presentation.View.IExpressionEditorService>(editorService);
                    StatusBarText.Text       = "";
                    StatusBarText.Foreground = new SolidColorBrush(Colors.Black);
                    StatusBarText.FontSize  -= 3;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + (ex.InnerException != null ? ex.InnerException.Message : string.Empty));
                Application.Current.Shutdown();
            }
        }
Beispiel #13
0
        public void CommunicationDevicePopTest()
        {
            byte[] sendBuf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] recvBuf = new byte[10];

            Stream      cd   = new Regulus.Remote.Standalone.Stream();
            IStreamable peer = cd as IStreamable;

            System.Threading.Tasks.Task <int> result1 = peer.Send(sendBuf, 0, 4);
            int sendResult1 = result1.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> result2 = peer.Send(sendBuf, 4, 6);
            int sendResult2 = result2.GetAwaiter().GetResult();


            System.Threading.Tasks.Task <int> streamTask1 = cd.Pop(recvBuf, 0, 3);
            int stream1 = streamTask1.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> streamTask2 = cd.Pop(recvBuf, stream1, recvBuf.Length - stream1);
            int stream2 = streamTask2.GetAwaiter().GetResult();

            System.Threading.Tasks.Task <int> streamTask3 = cd.Pop(recvBuf, stream1 + stream2, recvBuf.Length - (stream1 + stream2));
            int stream3 = streamTask3.GetAwaiter().GetResult();



            Assert.AreEqual(10, stream3 + stream2 + stream1);
            Assert.AreEqual((byte)0, recvBuf[0]);
            Assert.AreEqual((byte)1, recvBuf[1]);
            Assert.AreEqual((byte)2, recvBuf[2]);
            Assert.AreEqual((byte)3, recvBuf[3]);
            Assert.AreEqual((byte)4, recvBuf[4]);
            Assert.AreEqual((byte)5, recvBuf[5]);
            Assert.AreEqual((byte)6, recvBuf[6]);
            Assert.AreEqual((byte)7, recvBuf[7]);
            Assert.AreEqual((byte)8, recvBuf[8]);
            Assert.AreEqual((byte)9, recvBuf[9]);
        }
Beispiel #14
0
 private static string GetResult(System.Threading.Tasks.Task <PlainText> task) =>
 task.GetAwaiter().GetResult().Content;
Beispiel #15
0
 public void Shutdown()
 {
     _Enable = false;
     _ResetEvent.Set();
     _Task.GetAwaiter().GetResult();
 }