async Task EchoLoop() { var buffer = new byte[BufferSize]; var seg = new ArraySegment <byte>(buffer); while (this.socket.State == WebSocketState.Open) { var incoming = await this.socket.ReceiveAsync(seg, CancellationToken.None); ////var incomingdecoded = new ArraySegment<byte>(buffer, 0, incoming.Count); var incomingdecoded = Encoding.Default.GetString(buffer, 0, incoming.Count); ActorId actorId = new ActorId("Demo"); ISoppingCart sc = ActorProxy.Create <ISoppingCart>(actorId, "fabric:/SFActorDemoApp"); ShoppingItem si = new ShoppingItem { ShoppingItemCategory = incomingdecoded, IPAddress = this.IPAddress, AddedOn = DateTime.UtcNow }; await sc.AddToCartAsync(si); ActorId actorId2 = new ActorId("Demo"); ISoppingCart sc2 = ActorProxy.Create <ISoppingCart>(actorId2, "fabric:/SFActorDemoApp"); var ret = sc2.GetCartItemsAsync().Result; //ret.NewCartItem =((ShoppingCategoryEnum)Convert.ToInt16(ret.NewCartItem)).ToString(); ret.NewCartItem = ((FaultyShoppingCategoryEnum)Convert.ToInt16(ret.NewCartItem)).ToString(); var data = JsonConvert.SerializeObject(ret); var encoded = Encoding.UTF8.GetBytes(data); var buffer2 = new ArraySegment <Byte>(encoded, 0, encoded.Length); await this.socket.SendAsync(buffer2, WebSocketMessageType.Text, true, CancellationToken.None); } }
public IActionResult Index(IndexModel indexModel) { //ActorId actorId = new ActorId(HttpContext.Connection.RemoteIpAddress.ToString()); ActorId actorId = new ActorId("Demo"); ISoppingCart sc = ActorProxy.Create <ISoppingCart>(actorId, "fabric:/SFActorDemoApp"); ShoppingItem si = new ShoppingItem { ShoppingItemCategory = indexModel.ShoppingCategory }; sc.AddToCartAsync(si); return(RedirectToAction("Index")); }