Exemplo n.º 1
0
    public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HContext context)
    {
      var state = _state.As<MainState>() ?? new MainState();

      foreach (var json in jsons.OrEmpty())
      {

        switch (json.JPath("data", "command")?.ToString())
        {
          case "text":
            state = state.With(text: json.JPath("value")?.ToString());
            System.Threading.Thread.Sleep(new Random().Next(0, 500));
            break;
          default:            
            break;
        }
      }
     

      var page = Page(state);
      return new NitroBolt.Wui.HtmlResult<HElement>
      {
        Html = page,
        State = state,
      };
    }
Exemplo n.º 2
0
        private static MonitorState Execute(JsonData[] jsons, MonitorState state)
        {

            foreach (var json in jsons.OrEmpty())
            {
                switch (json.JPath("data", "command")?.ToString())
                {

                }
            }
            return state;
        }
Exemplo n.º 3
0
        //
        //  см. также Global.Application_AuthenticateRequest
        //
        public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HttpRequestMessage request)
        {
            Action<HttpResponseMessage> cookieSetter = null;
            var logins = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) { { "Demo", "demodemo" }, { "Test", "test" } };

            foreach (var json in jsons.OrEmpty())
            {

                switch (json.JPath("data", "command")?.ToString())
                {
                    case "login":
                        {
                            var login = json.JPath("data", "login")?.ToString();
                            var password = json.JPath("data", "password")?.ToString();
                            if (logins.Find(login) == password)
                                cookieSetter = request.SetUserAndGetCookieSetter(login);
                            else
                            {
                                //display error
                            }
                        }
                        break;
                    case "logout":
                        cookieSetter = request.SetUserAndGetCookieSetter(null);
                        break;
                    default:
                        break;
                }

                if (request.UserName() != null)
                {
                    switch (json.JPath("data", "command")?.ToString())
                    {
                        default:
                            break;
                    }

                }
            }
            var account = request.UserName();


            var page = Page(logins, account, request);
            return new HtmlResult
            {
                Html = page,
                State = null,
                ResponseProcessor = cookieSetter,
            };
        }
Exemplo n.º 4
0
        public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HContext context)
        {
            var state = _state.As<MainState>() ?? new MainState();

            foreach (var json in jsons.OrEmpty())
            {
                switch (json.JPath("data", "command")?.ToString())
                {
                    case "mouse-event":
                        {
                            var x = ConvertHlp.ToInt(json.JPath("data", "x"));
                            var y = ConvertHlp.ToInt(json.JPath("data", "y"));
                            if (x != null && y != null)
                            {
                                using (var client = new MouseClient(Zuma.VmIp))
                                {
                                    client.MoveTo(x.Value, y.Value, 800, 600);
                                }
                            }
                        }
                        break;
                    case "reset":
                        {
                            using (var client = new MouseClient(Zuma.VmIp))
                            {
                                client.Reset();
                            }
                        }
                        break;
                    case "screenshot":
                        {
                            new VmClient().Screenshot().Save(context.HttpContext.Server.MapPath($"~/App_Data/{DateTime.UtcNow.Ticks}.png"));
                        }
                        break;
                    default:
                        break;
                }
            }

            var page = Page(state);
            return new NitroBolt.Wui.HtmlResult<HElement>
            {
                Html = page,
                State = state,
            };
        }
Exemplo n.º 5
0
        public static HtmlResult HView(object _state, JsonData[] jsons, HttpRequestMessage request)
        {
            var state = _state.As<MainState>() ?? new MainState();

            foreach (var json in jsons.OrEmpty())
            {

                switch (json.JPath("data", "command")?.ToString())
                {
                    case "text":
                        state = state.With(text: json.JPath("value")?.ToString());
                        System.Threading.Thread.Sleep(new Random().Next(0, 500));
                        break;
                    case "link":
                        state = state.With(text: "self:" + new Random().Next(1000));
                        break;
                    case "error":
                        throw new Exception("ошибка");
                    case "x":
                        state = state.With(text: json.JPath("value")?.ToString());
                        break;
                    case "x-container":
                        state = state.With(text: json.JPath("data", "x")?.ToString());
                        break;
                    case "array-name":
                        state = state.With(arrayNameResult: json.JPath("data", "x")?.ToString());
                        break;
                    default:
                        break;
                }
            }


            var page = Page(state);
            return new HtmlResult
            {
                Html = page,
                State = state,
            };
        }
Exemplo n.º 6
0
        public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HttpRequestMessage request)
        {
            var state = _state.As<MainState>() ?? new MainState();

            foreach (var json in jsons.OrEmpty())
            {
                //var account = MemoryDatabase.World.Accounts.FirstOrDefault(_account => _account.Name == "darkgray");

                switch (json.JPath("data", "command")?.ToString())
                {
                    default:
                        //state = new MyLibState(new[] { new Message(json.ToString_Fair()) }.Concat(state.Messages).Take(10).ToArray());
                        break;
                }
            }


            var page = Page(state, request);
            return new NitroBolt.Wui.HtmlResult<HElement>
            {
                Html = page,
                State = state,
            };
        }
Exemplo n.º 7
0
    public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HContext context)
    {
      var state = _state.As<MainState>() ?? new MainState();

      foreach (var json in jsons.OrEmpty())
      {
        switch (json.JPath("data", "command")?.ToString())
        {
          case "new-order":
            {
              var name = json.JPath("data", "name")?.ToString() ?? "C";
              var isDelivery = json.JPath("data", "is-delivery")?.ToString() == "True";
              var toTime = ToTime(json.JPath("data", "to-time")?.ToString());
              var status = toTime == null ? ProductStatus.New: ProductStatus.InQueue;
              var products = name == "B" ? new[] { new Product("K", status) } : new[] { new Product("M", status), new Product("P", status) };
              state = state.With(orders: state.Orders.Add(new Order(name: name, isDelivery: isDelivery, status: toTime == null ? OrderStatus.New: OrderStatus.InQueue, products: ImmutableArray.Create(products), toTime: toTime)));  
            }
            break;
          case "product-prepare":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var productId = ConvertHlp.ToGuid(json.JPath("data", "product"));
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId);
              if (product != null && product.Status != ProductStatus.New)
                product = null;
              if (product != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Prepare)))));
              }
            }
            break;
          case "product-ready":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var productId = ConvertHlp.ToGuid(json.JPath("data", "product"));
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId);
              if (product != null && product.Status != ProductStatus.Prepare)
                product = null;
              if (product != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Ready)))));
              }
            }
            break;
          case "order-build":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              if (order != null && order.Status != OrderStatus.Prepare && !order.IsReady)
                order = null;
              if (order != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Ready)));
              }
            }
            break;
          case "courier":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var courier = json.JPath("data", "courier")?.ToString();
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              if (order != null && order.Status != OrderStatus.Ready && !order.IsDelivery)
                order = null;
              if (order != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToDelivery, courier: courier)));
              }
            }
            break;
          case "order-deliveried":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              if (order != null && order.Status != OrderStatus.ToDelivery)
                order = null;
              if (order != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Deliveried)));
              }
            }
            break;
          case "order-to-table":
            {
              var orderId = ConvertHlp.ToGuid(json.JPath("data", "order"));
              var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId);
              if (order != null && order.Status != OrderStatus.Ready && order.IsDelivery)
                order = null;
              if (order != null)
              {
                state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToTable)));
              }
            }
            break;
          default:
            break;
        }
      }
      state = state.With(orders: DeQueue(state.Orders, DateTime.Now));

      var page = Page(state);
      return new NitroBolt.Wui.HtmlResult<HElement>
      {
        Html = page,
        State = state,
      };
    }