Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var proxy = ActorProxy.Create <ISimpleStatefulActor>(ActorId.NewId(), new Uri("fabric:/SimpleStatefulActors/SimpleStatefulActorService"));

            Console.WriteLine("Count demo!");
            CountDemo(proxy).Wait();
        }
        public static void Main(string[] args)
        {
            var player1 = ActorProxy.Create <IPlayer>(ActorId.NewId(),
                                                      "fabric:/ActorTicTacToeApplication");
            var player2 = ActorProxy.Create <IPlayer>(ActorId.NewId(),
                                                      "fabric:/ActorTicTacToeApplication");
            var gameId  = ActorId.NewId();
            var game    = ActorProxy.Create <IGame>(gameId, "fabric:/ActorTicTacToeApplication");
            var rand    = new Random();
            var result1 = player1.JoinGameAsync(gameId, "Player 1");
            var result2 = player2.JoinGameAsync(gameId, "Player 2");

            if (!result1.Result || !result2.Result)
            {
                Console.WriteLine("Failed to join game.");
                return;
            }
            var player1Task = Task.Run(() => { MakeMove(player1, game, gameId); });
            var player2Task = Task.Run(() => { MakeMove(player2, game, gameId); });
            var gameTask    = Task.Run(() =>
            {
                string winner = "";
                while (winner == "")
                {
                    var board = game.GetGameBoardAsync().Result;
                    PrintBoard(board);
                    winner = game.GetWinnerAsync().Result;
                    Task.Delay(1000).Wait();
                }
                Console.WriteLine("Winner is: " + winner);
            });

            gameTask.Wait();
            Console.Read();
        }
Exemplo n.º 3
0
        public HostsController()
        {
            ActorId    actorId         = ActorId.NewId();
            string     applicationName = "fabric:/Actor_Statefull_Project";
            IHostActor hostActor       = ActorProxy.Create <IHostActor>(actorId, applicationName);

            this.actor = hostActor;
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var r       = new Random();
            var actorId = (args.Length > 0) ? new ActorId(long.Parse(args[0])) : ActorId.NewId();

            var count = 0;
            var deleteMessageAfter     = r.Next(1, 20);
            var deleteAllMessagesAfter = r.Next(1, 20);

            const string appName           = "fabric:/VoicemailBoxAdvancedApplication";
            var          voicemailBoxActor = ActorProxy.Create <IVoicemailBoxActor>(actorId, appName);

            voicemailBoxActor.SubscribeAsync <IVoicemailBoxActorEvents>(new NewMessagesEventHandler()).Wait();

            PrintConnectionInfo(voicemailBoxActor);
            voicemailBoxActor.GetMessagesAsync().Wait();

            while (true)
            {
                count++;
                PrintConnectionInfo(voicemailBoxActor);

                Console.WriteLine();
                Console.WriteLine(@"Greeting: {0}", voicemailBoxActor.GetGreetingAsync().Result);

                var message = string.Format(CultureInfo.InvariantCulture, "Hello WinFab Actor {0}, Greetings # {1}", actorId, count);
                Console.WriteLine(@"Leaving message: " + message);
                voicemailBoxActor.LeaveMessageAsync(message).Wait();

                Console.WriteLine();
                Console.WriteLine(@"Playing all messages:");
                var messageList = voicemailBoxActor.GetMessagesAsync().Result;
                messageList.Sort((x, y) => x.ReceivedAt.CompareTo(y.ReceivedAt));
                foreach (var m in messageList)
                {
                    Console.WriteLine(@"	 Received: {0}, Message: {1}", m.ReceivedAt, m.Message);
                }

                if (messageList.Count >= deleteAllMessagesAfter)
                {
                    Console.WriteLine();
                    Console.WriteLine(@"Deleting all messages");
                    voicemailBoxActor.DeleteAllMessagesAsync().Wait();
                    deleteAllMessagesAfter = r.Next(1, 20);
                }
                else if (messageList.Count >= deleteMessageAfter)
                {
                    var toBeDeleted = messageList[r.Next(messageList.Count)];

                    Console.WriteLine();
                    Console.WriteLine(@"Deleting message {0}", toBeDeleted.Message);
                    voicemailBoxActor.DeleteMessageAsync(toBeDeleted.Id).Wait();
                    deleteMessageAfter = r.Next(1, 20);
                }

                Thread.Sleep(500);
            }
        }
        public async Task <int> Add3(ActorId idgs, int a, int b, int c)
        {
            ActorEventSource.Current.ActorMessage(this, $"Add {a} + {b} + {c}");
            var proxy = ActorProxy.Create <ITKActorAdd>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");
            var r1    = await proxy.Add(idgs, a, b);

            proxy = ActorProxy.Create <ITKActorAdd>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2"); // New entity
            var r2 = await proxy.Add(idgs, r1, c);

            return(r2);
        }
        static void Main(string[] args)
        {
            var    metadata        = new string[] { "Circle", "Rectangle" };
            string applicationName = "fabric:/MetadataDrvienApplication";

            foreach (var action in metadata)
            {
                IShape proxy = ActorProxy.Create <IShape>(ActorId.NewId(), applicationName, action);
                Console.WriteLine(proxy.DrawAsync().Result);
            }
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            var proxy = ActorProxy.Create <IDeviceIdentityAPI>(ActorId.NewId(), "fabric:/IoTDeviceIdentity");

            int count = 10;

            Console.WriteLine("Setting Count to in Actor {0}: {1}", proxy.GetActorId(), count);
            proxy.SetCountAsync(count).Wait();

            Console.WriteLine("Count from Actor {0}: {1}", proxy.GetActorId(), proxy.GetCountAsync().Result);
        }
Exemplo n.º 8
0
        static void Original()
        {
            var proxy = ActorProxy.Create <ITicTacTechActorService>(ActorId.NewId(), "fabric:/TicTacTech.ActorServiceApplication");

            int count = 10;

            Console.WriteLine("Setting Count to in Actor {0}: {1}", proxy.GetActorId(), count);
            proxy.SetCountAsync(count).Wait();

            Console.WriteLine("Count from Actor {1}: {0}", proxy.GetActorId(), proxy.GetCountAsync().Result);
        }
        public static void Main(string[] args)
        {
            var proxy = ActorProxy.Create <IServiceFabricEventJournal>(ActorId.NewId(), "fabric:/ServiceFabricEventJournalApplication");

            int count = 10;

            Console.WriteLine("Setting Count to in Actor {0}: {1}", proxy.GetActorId(), count);
            List <JournalEntry> p = proxy.GetMessagesAsync(1, long.MaxValue, long.MaxValue).Result;
//            proxy.SetCountAsync(count).Wait();

            //          Console.WriteLine("Count from Actor {1}: {0}", proxy.GetActorId(), proxy.GetCountAsync().Result);
        }
Exemplo n.º 10
0
        public async Task <IEnumerable <AuthorModel> > GetAuthors(string firstname, string lastname)
        {
            IList <AuthorModel> authorList = new List <AuthorModel>();
            var actorDictionary            = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, long> >(AuthorActorsDictName);

            if (actorDictionary.GetCountAsync().Result <= 0)
            {
                var authors = AuthorDataService.GetAuthors(String.Empty, String.Empty);

                using (var tx = this.StateManager.CreateTransaction())
                {
                    foreach (var author in authors)
                    {
                        ActorId             newId = ActorId.NewId();
                        IAuthorActorService authorActorService = ActorProxy.Create <IAuthorActorService>(newId, "fabric:/CoPSample");
                        long actorLongId = authorActorService.GetActorId().GetLongId();

                        await authorActorService.SaveAuthor(new AuthorModel()
                        {
                            Firstname = author.Firstname,
                            Lastname  = author.Lastname,
                            Twitter   = author.RowKey,
                            Phone     = author.Phone,
                            Email     = author.Email
                        });

                        await actorDictionary.AddOrUpdateAsync(tx, author.RowKey, actorLongId,
                                                               (key, oldValue) => actorLongId);
                    }

                    await tx.CommitAsync();
                }
            }

            using (var tx = this.StateManager.CreateTransaction())
            {
                var actorIds = actorDictionary.CreateEnumerable();

                foreach (var actorId in actorIds)
                {
                    IAuthorActorService authorActorService = ActorProxy.Create <IAuthorActorService>(new ActorId(actorId.Value), "fabric:/CoPSample");
                    var author = await authorActorService.GetAuthor();

                    authorList.Add(author);
                }

                await tx.CommitAsync();
            }

            return(authorList.Where(a =>
                                    (String.IsNullOrEmpty(firstname) ? true : a.Firstname.ToLower().Contains(firstname.ToLower())) &&
                                    (String.IsNullOrEmpty(lastname) ? true : a.Lastname.ToLower().Contains(lastname.ToLower()))));
        }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            Thread.Sleep(15000);
            var proxy = ActorProxy.Create <ITKActorGlobalSum>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");

            ActorId idgs = proxy.GetActorId();

            proxy.IncrementAdd().Wait();

            Console.WriteLine($"{idgs}: {proxy.GetCountAdd().Result}");

            var proxy1  = ActorProxy.Create <ITKActorAdd>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");
            var result1 = proxy1.DoWorkAsync().Result;

            Console.WriteLine(result1);

            var proxy2  = ActorProxy.Create <ITKActorSub>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");
            var result2 = proxy2.Sub(idgs, 5, 2).Result;

            var proxy3  = ActorProxy.Create <ITKActorAdd>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");
            var result3 = proxy3.Add3(idgs, 5, 2, 1).Result;


            Console.WriteLine($"{idgs}: Add: {proxy.GetCountAdd().Result}");
            Console.WriteLine($"{idgs}: Sub: {proxy.GetCountSub().Result}");

            Console.WriteLine("END");
            Console.ReadLine();
            //Task.Run(async () =>
            //{
            //    try
            //    {
            //        var proxy = ActorProxy.Create<ITKActorGlobalSum>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");

            //        int count = 10;
            //        Console.WriteLine("Setting Count to in Actor {0}: {1}", proxy.GetActorId(), count);
            //        proxy.SetCountAsync(count).Wait();

            //        Console.WriteLine("Count from Actor {0}: {1}", proxy.GetActorId(), proxy.GetCountAsync().Result);

            //        var proxy1 = ActorProxy.Create<ITKActorAdd>(ActorId.NewId(), "fabric:/TK_ServiceFabricCalculatorV2");
            //        var result1 = await proxy1.DoWorkAsync();
            //        Console.WriteLine(result1);
            //        Console.WriteLine("END");
            //        Console.ReadLine();
            //    }
            //    catch (Exception ex)
            //    {
            //        Console.WriteLine(ex.ToString());
            //    }
            //});
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            //Vehicle No 1
            ActorId   vehicleId = ActorId.NewId();
            Telemetry telemetry = new Telemetry()
            {
                Id = vehicleId.GetLongId(),
                EmergencySituation = null,
                Speed = 100,
            };
            var vehicle = ActorProxy.Create <IVehicleActor>(vehicleId, "fabric:/VehicleActorApplication");

            Task <bool> ingestTask = vehicle.IngestTelemetryAsync(telemetry);

            ingestTask.Wait();

            telemetry.Speed = telemetry.Speed - 40;
            ingestTask      = vehicle.IngestTelemetryAsync(telemetry);
            ingestTask.Wait();

            Task <VehicleHealth> health = vehicle.GetVehicleStateAsync(vehicleId.GetLongId());

            health.Wait();
            Console.WriteLine(health.Result.VehicleState);

            for (int i = 0; i < 10; i++)
            {
                //Vehicle No 2
                vehicleId = ActorId.NewId();
                telemetry = new Telemetry()
                {
                    Id = vehicleId.GetLongId(),
                    EmergencySituation = null,
                    Speed = 100,
                };
                vehicle = ActorProxy.Create <IVehicleActor>(ActorId.NewId(), "fabric:/VehicleActorApplication");

                ingestTask = vehicle.IngestTelemetryAsync(telemetry);
                ingestTask.Wait();

                telemetry.Speed = telemetry.Speed - 40;
                ingestTask      = vehicle.IngestTelemetryAsync(telemetry);
                ingestTask.Wait();

                health = vehicle.GetVehicleStateAsync(vehicleId.GetLongId());
                health.Wait();
                Console.WriteLine(health.Result.VehicleState);
            }

            Console.ReadLine();
        }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            var producer = ActorProxy.Create <IProducer>(ActorId.NewId(), "PC");
            var consumer = ActorProxy.Create <IConsumer>(ActorId.NewId(), "PC");
            var state    = ActorProxy.Create <ISharedState>(ActorId.NewId(), "PC");

            consumer.SetBound(2).Wait();
            var t1 = producer.Produce(state);
            var t2 = consumer.Consume(state);

            Task.WaitAll(t1, t2);

            //Console.ReadLine();
        }
Exemplo n.º 14
0
        public async Task <IEnumerable <string> > Get()
        {
            // Talk to a stateless SERVICE to get the counter
            ICounter counter =
                ServiceProxy.Create <ICounter>(0, new Uri(theApplicationUri + "/FirstStatefulService"));
            long count = await counter.GetCountAsync();

            // Talk to a stateless ACTOR to get a random number
            string theRandomNum = "42.0";
            var    simpleActor  = ActorProxy.Create <IVerySimpleActor>(ActorId.NewId(), theApplicationUri);

            theRandomNum = await simpleActor.GetRandomValue();

            return(new string[] { String.Format("Hello world! Here's the count : {0} and here's a random number {1:0.00}", count.ToString(), theRandomNum) });
        }
        public async Task <IActionResult> Start(int startTrans)
        {
            try
            {
                var actor = ActorProxy.Create <IQState>(ActorId.NewId(), "fabric:/QLearningServiceFab/");

                await actor.StartTrainingAsync(startTrans);

                return(Ok(startTrans));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IEnumerable <RouteInfo> > GetRoutes()
        {
            var appName = CloudConfigurationManager.GetSetting("sfAppName");
            var svcName = CloudConfigurationManager.GetSetting("sfSvcNameTemplate");

            var catalog = ActorProxy.Create <IRouteCatalog>(ActorId.NewId(), appName, string.Format(svcName, "RouteCatalog"));

            var infos = new List <RouteInfo>();

            foreach (var route in await catalog.GetRoutes())
            {
                infos.Add(await route.GetInfo());
            }

            return(infos);
        }
Exemplo n.º 17
0
        public async Task <Order> Get(Guid orderKey)
        {
            try {
                //NOTES: In the MSDN example, it provides a partition id of '0', don't do this for stateless!!
                //service fabric will resolve the partition itself for stateless!
                IOrderActor orderRepository =
                    ActorProxy.Create <IOrderActor>(ActorId.NewId(), new Uri("fabric:/OrderService/OrderActorService"));

                Order order = await orderRepository.Get(orderKey);

                return(order);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Asynchronously activates the actor.
        /// </summary>
        /// <returns>
        /// A <see cref="Task"/> that represents the asynchronous on activate operation.
        /// </returns>
        public override Task OnActivateAsync()
        {
            if (State == null)
            {
                var configPackage = Host.StatefulServiceInitializationParameters.CodePackageActivationContext.GetConfigurationPackageObject("Config");
                var streamSection = configPackage.Settings.Sections["Authentication"];
                var mechanisms    = streamSection.Parameters["Mechanisms"].Value.Split(';');

                State.Mechanisms = new Dictionary <string, ActorId>(StringComparer.OrdinalIgnoreCase);
                foreach (var mech in mechanisms)
                {
                    State.Mechanisms.Add(mech, ActorId.NewId());
                }
            }

            return(base.OnActivateAsync());
        }
Exemplo n.º 19
0
        /// <summary>
        /// This method activates an actor to fulfill the RestockRequest.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task AddRestockRequestAsync(RestockRequest request)
        {
            try
            {
                //Get dictionary of Restock Requests
                IReliableDictionary <InventoryItemId, ActorId> requestDictionary =
                    await this.StateManager.GetOrAddAsync <IReliableDictionary <InventoryItemId, ActorId> >(ItemIdToActorIdMapName);

                ActorId actorId = ActorId.NewId();

                try
                {
                    using (ITransaction tx = this.StateManager.CreateTransaction())
                    {
                        await requestDictionary.AddAsync(tx, request.ItemId, actorId);

                        await tx.CommitAsync();
                    }
                }
                catch (ArgumentException)
                {
                    // restock request already exists
                    return;
                }

                // Create actor proxy and send the request
                IRestockRequestActor restockRequestActor = ActorProxy.Create <IRestockRequestActor>(actorId, this.ApplicationName);

                await restockRequestActor.AddRestockRequestAsync(request);

                // Successfully added, register for event notifications for completion
                await restockRequestActor.SubscribeAsync <IRestockRequestEvents>(this);

                ServiceEventSource.Current.ServiceMessage(this, "Created restock request. Item ID: {0}. Actor ID: {1}", request.ItemId, actorId);
            }
            catch (InvalidOperationException ex)
            {
                ServiceEventSource.Current.Message(string.Format("RestockRequestManagerService: Actor rejected {0}: {1}", request, ex));
                throw;
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(string.Format("RestockRequestManagerService: Exception {0}: {1}", request, ex));
                throw;
            }
        }
Exemplo n.º 20
0
        public static void Main(string[] args)
        {
            ActorId id    = ActorId.NewId();
            var     proxy = ActorProxy.Create <IStatefulActorModel>(id, "fabric:/StatefulActorModelApp");

            int count = 10;

            for (int i = 0; i < 5; i++)
            {
                proxy.SetCountAsync(count);
                Console.WriteLine("Count from Actor {0}", proxy.GetCountAsync().Result);
                count++;
            }

            /*
             * var proxy1 = ActorProxy.Create<IStatefulActorModel>(id, "fabric:/StatefulActorModelApp");
             * Console.WriteLine(proxy.Equals(proxy1));
             */
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            var proxy = ActorProxy.Create <IDeviceActor>(ActorId.NewId(), "fabric:/DeviceApplication");

            proxy.SubscribeAsync(new ClientDeviceEventHandler()).Wait();

            Device device = new Device()
            {
                DeviceID = "1001", SwitchStatus = SwitchStatusDefine.On, Temperature = 24, UpdateTime = DateTime.Now
            };

            string cmd = string.Empty;

            Random rnd = new Random((int)DateTime.Now.Ticks);

            Console.WriteLine("Please input command...");

            while (cmd.ToLower() != "exit")
            {
                switch (cmd.ToLower())
                {
                case "write":
                    device.Temperature = rnd.NextDouble() * 100;
                    device.UpdateTime  = DateTime.Now;

                    proxy.SetTelemetryAsync(device).Wait();
                    OutputDeviceInfo(proxy.GetActorId(), device);
                    Console.WriteLine("Data Written");
                    break;

                case "read":
                    Device deviceRead = proxy.GetTelemetryAsync(device.DeviceID).Result;

                    if (deviceRead != null)
                    {
                        OutputDeviceInfo(proxy.GetActorId(), deviceRead);
                    }
                    break;
                }

                cmd = Console.ReadLine();
            }
        }
Exemplo n.º 22
0
        private static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                for (;;)
                {
                    IHello friend = ActorProxy.Create <IHello>(ActorId.NewId(), ApplicationName);
                    Console.WriteLine(@"\n\nFrom Actor {1}: {0}\n\n", friend.SayHello("Good morning!").Result, friend.GetActorId());
                    Thread.Sleep(50);
                }
            }
            else
            {
                IHello friend = ActorProxy.Create <IHello>(ActorId.NewId(), ApplicationName);
                Console.WriteLine(@"\n\nFrom Actor {1}: {0}\n\n", friend.SayHello("Good morning!").Result, friend.GetActorId());
            }

            Console.WriteLine(@"Press enter to exit ...");
            Console.ReadLine();
        }
Exemplo n.º 23
0
        private static void Main(string[] args)
        {
            var proxy = ActorProxy.Create <ISimpleStatelessActor>(ActorId.NewId(), new Uri("fabric:/SimpleStatelessActors/SimpleStatelessActorService"));

            Console.WriteLine("Press 1 for Messaging demo and 2 for Events demo:");
            var value = Convert.ToInt32(Console.ReadLine());

            switch (value)
            {
            case 1:
                MessageDemo(proxy);
                break;

            case 2:
                EventsDemo(proxy);
                break;
            }
            Console.WriteLine("\n\n----- Press any key to exit! -----");
            Console.ReadLine();
        }
Exemplo n.º 24
0
        public override async Task OnActivateAsync()
        {
            if (State == null)
            {
                State = new UnboundClientState();

                var configPackage = Host.StatefulServiceInitializationParameters.CodePackageActivationContext.GetConfigurationPackageObject("Config");
                var streamSection = configPackage.Settings.Sections["Stream"];
                var features      = streamSection.Parameters["Features"].Value.Split(';');

                State.Features = new Dictionary <XName, ActorId>();
                foreach (var feature in features)
                {
                    var id    = ActorId.NewId();
                    var actor = ActorProxy.Create <IStreamFeature>(id, Constants.ApplicationName, feature);
                    var el    = await actor.CreateDescriptiveElementAsync();

                    State.Features.Add(el.Name, id);
                }
            }
        }
Exemplo n.º 25
0
        public bool Get(string to, string message, string thandle)
        {
            IEmailActorService emailActorService = ActorProxy.Create <IEmailActorService>(ActorId.NewId(), "fabric:/CoPSample");

            return(emailActorService.SendEmail(to, message, thandle).Result);
        }
Exemplo n.º 26
0
        public Task TransitionAsync(int?previousStateToken, int transitionValue)
        {
            var rwd = GetReward(previousStateToken, transitionValue);


            var stateToken = transitionValue;

            if (previousStateToken != null)
            {
                stateToken = int.Parse(previousStateToken.Value + stateToken.ToString());
            }


            var ts = new List <Task>();

            if (rwd == null || !rwd.IsAbsorbing)
            {
                ts.AddRange(GetTransitions(stateToken).Select(p => ActorProxy.Create <IQState>(ActorId.NewId(), "fabric:/QLearningServiceFab").TransitionAsync(stateToken, p)));
            }

            if (rwd != null)
            {
                ts.Add(RegisterReminderAsync("SetReward", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rwd))
                                             , TimeSpan.FromMilliseconds(0)
                                             , TimeSpan.FromMilliseconds(-1), ActorReminderAttributes.Readonly));
            }


            return(Task.WhenAll(ts));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Accepts the connection.
        /// </summary>
        public async void Open()
        {
            using (_socket)
            {
                Write();

                try
                {
                    _client = ActorProxy.Create <IXmlConnection>(ActorId.NewId(), Constants.ApplicationName, Constants.ActorNames.UnboundClient);
                    await _client.SubscribeAsync(this);
                }
                catch (Exception e)
                {
                    ServiceEventSource.Current.ClientConnectionFailure(_socket.Identifier, e.ToString());
                    return;
                }

                while (!_cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        await CreateXmlAsync();

                        var element = await ReadStartElementAsync(_cancellationToken);

                        var stanza = Stanza.FromOpeningTag(element);

                        while (!_cancellationToken.IsCancellationRequested)
                        {
                            var result = await _client.OnStanzaReceivedAsync(stanza);

                            // Remove stanza elements from the document once we are
                            // done with them.
                            if (!stanza.OpeningTagOnly)
                            {
                                stanza.Element.Remove();
                            }

                            if (result != null)
                            {
                                if (result.Response != null)
                                {
                                    await WriteStanzaAsync(result.Response);
                                }

                                switch (result.StreamAction)
                                {
                                case StreamAction.Close: await CloseAsync(); return;

                                case StreamAction.Abort: return;

                                case StreamAction.StartTls: await StartTlsAsync(); break;
                                }

                                if ((int)result.StreamAction >= (int)StreamAction.Reset)
                                {
                                    break;
                                }
                            }

                            element = await ReadFullElementAsync(_cancellationToken);

                            stanza = Stanza.FromFullElement(element);
                        }
                    }
                    catch (Exception e)
                    {
                        var result = await _client.OnErrorOccurredAsync(e);

                        if (result != null && result.Response != null)
                        {
                            await WriteStanzaAsync(result.Response);
                        }

                        // Errors at this level always terminate the connection.
                        return;
                    }
                }
            }
        }
Exemplo n.º 28
0
        public IEnumerable <EmailModel> Get(string fromDate, string toDate)
        {
            IEmailActorService emailActorService = ActorProxy.Create <IEmailActorService>(ActorId.NewId(), "fabric:/CoPSample");

            return(emailActorService.EmailHistory(fromDate, toDate).Result);
        }