protected override async Task OnInitAsync() { RegisteredFunction.Invoke <bool>("removeCss", "outside"); var resultChart = await MegaService.Fetcher.Fetch("/api/Product/GetDashboardChart"); var resultPie = await MegaService.Fetcher.Fetch("/api/Product/GetDashboardPieOrder"); var catDis = resultPie["CategoryDistribution"].ToObject <ICollection <Category> >(); CategoryCount = resultPie["CountProduct"].ToObject <int>(); LatestOrders = resultPie["LastOrders"].ToObject <ICollection <OrderData> >(); EarningLastWeek = resultChart["EarningLastWeek"].ToObject <ICollection <double> >(); PercentageCash = resultChart["PercentageCash"].ToObject <double>(); PercentagePayPal = resultChart["PercentagePayPal"].ToObject <double>(); EarningThisMonth = resultChart["EarningThisMonth"].ToObject <double>(); EarningToday = resultChart["EarningToday"].ToObject <double>(); PreparePieChart(catDis); LoadChart(); var resultTops1 = await MegaService.Fetcher.Fetch("/api/Product/GetDashboardTopsProducts"); var resultTops2 = await MegaService.Fetcher.Fetch("/api/Product/GetDashboardTopsUsers"); TopUsers = resultTops2["TopUsers"].ToObject <ICollection <User> >(); TopProducts = resultTops1["TopProducts"].ToObject <ICollection <Product> >(); TopBrands = resultTops2["TopBrands"].ToObject <ICollection <Brand> >(); TopCategories = resultTops1["TopCategories"].ToObject <ICollection <Category> >(); }
/// <inheritdoc /> protected override void UpdateDisplay(RenderBatch batch) { RegisteredFunction.InvokeUnmarshalled <int, RenderBatch, object>( "renderBatch", _browserRendererId, batch); }
protected async Task SaveExtra(Extra extra) { var result = RegisteredFunction.Invoke <bool>("validateExtra", $"#extra_optional_{extra.Id}"); if (result) { // TODO: SAVE STUFFIE TO SERVER HERE var saveResult = await MegaService.Fetcher.Fetch("/api/product/UpdateExtra/", new { Product.Id, Extra = extra }); var saveBool = saveResult["Result"].ToObject <bool>(); var newExtra = saveResult["Extra"].ToObject <Extra>(); extra.Id = newExtra.Id; extra.Options.Clear(); newExtra.Options.ForEach(o => { extra.Options.Add(o); }); Toastr(saveBool); StateHasChanged(); } }
public override Task <string> GetStringAsync(Uri requestUri) { if (requestUri == null) { return(null); } string absoluteURI = string.Empty; if (requestUri.IsAbsoluteUri) { absoluteURI = requestUri.AbsoluteUri; } else { absoluteURI = BaseAddress + requestUri.PathAndQuery; } int id = TaskDispatcher.CreateTaskToDispatch(TaskDispatcher.CommonTask.StringToCSharp(), out Task <string> futurTask); RegisteredFunction.Invoke <string>("daddoon_jQuery_SendAsync", id, WebRequestMethods.Http.Get, absoluteURI, new RequestMetadata() { timeout = Timeout.TotalMilliseconds, headers = ParseHeaders(DefaultRequestHeaders) }, null); return(futurTask); }
public void WatchLocation(Action <Location> watchCallback) { var requestId = Guid.NewGuid(); _watches.Add(requestId, watchCallback); RegisteredFunction.Invoke <object>("WatchLocation", requestId); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { switch (logLevel) { case LogLevel.Trace: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Trace", JsonUtil.Serialize(state)); break; case LogLevel.Debug: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Debug", JsonUtil.Serialize(state)); break; case LogLevel.Information: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Info", JsonUtil.Serialize(state)); break; case LogLevel.Warning: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Warn", JsonUtil.Serialize(state)); break; case LogLevel.Critical: case LogLevel.Error: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Error", JsonUtil.Serialize(state)); if (exception != null) { RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Error", JsonUtil.Serialize(exception)); } break; default: break; } }
/// <inheritdoc /> protected override async Task <HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <HttpResponseMessage>(); cancellationToken.Register(() => tcs.TrySetCanceled()); int id; lock (_idLock) { id = _nextRequestId++; _pendingRequests.Add(id, tcs); } RegisteredFunction.Invoke <object>( $"{typeof(BrowserHttpMessageHandler).FullName}.Send", id, request.Method.Method, request.RequestUri, request.Content == null ? null : await GetContentAsString(request.Content), SerializeHeadersAsJson(request)); return(await tcs.Task); }
protected async Task AddNewCoupon() { var result = await RegisteredFunction.InvokeAsync <bool>("validateCoupon"); if (result) { if (NewCoupon.Type == (int)Consts.CouponType.Date) { CouponDateStr = MegaService.Util.GetInput <string>("#new-coupon-date"); var parseResult = DateTime.TryParse(CouponDateStr, out var dateTime); if (!parseResult) { return; } NewCoupon.DateExpired = dateTime; } NewCoupon.Id = -1; //signify the coupon as not saved yet Product.Coupons.Add(NewCoupon); // TODO: SAVE STUFFIE TO SERVER HERE var saveResult = await MegaService.Fetcher.Fetch("/api/product/AddCoupon/", new { Product.Id, Coupon = NewCoupon }); var saveBool = saveResult["Result"].ToObject <bool>(); Toastr(saveBool); NewCoupon = null; StateHasChanged(); } }
protected override async Task OnInitAsync() { RegisteredFunction.Invoke <bool>("removeCss", "metronic"); MegaService.Util.InitComponents(); // MegaService.Util.InitAdminComponents(); Loaded = true; }
public HTMLTableSectionElement createTHead() { return(new HTMLTableSectionElement() { uid = RegisteredFunction.Invoke <string>("createElement", "thead") }); }
public void DispatchInit(object state) { if (IsEnabled) { RegisteredFunction.Invoke <object>(jsFunctionName, "init", state); } }
public Task Start() { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); var callbackId = Guid.NewGuid().ToString(); Callbacks[callbackId] = new Action(() => tcs.SetResult(true)); var success = RegisteredFunction.Invoke <bool>(StartHubClientProxyMethod, _id, callbackId); if (!success) { Callbacks[callbackId] = null; throw new InvalidOperationException("Unable to register callback on the proxy"); } return(Task.WhenAny(tcs.Task, Task.Delay(5000).ContinueWith((t) => { if (!tcs.Task.IsCompleted) { return Task.FromException(new InvalidOperationException("Send timed out")); } else { return tcs.Task; } }))); }
private static Point GetOffsetPoint(HTMLElement element) { #if BLAZOR var rev = RegisteredFunction.Invoke <string>("getOffsetPoint", element.uid, Settings.IsFF).Split(','); return(new Point(Convert.ToInt32(rev[0]), Convert.ToInt32(rev[1]))); #else double top = 0; double left = 0; do { dynamic dym = element; if (Settings.IsFF) { var rec = element.getBoundingClientRect().As <ClientRect>(); top += rec.top; left += rec.left; //element = dym.offsetParent; element = element.parentElement; } else { top += dym.offsetTop; left += dym.offsetLeft; element = dym.offsetParent; } } while (element != null); return(new Point((int)left, (int)top)); #endif }
public HTMLDocumentFragement createDocumentFragment() { return(new HTMLDocumentFragement() { uid = RegisteredFunction.Invoke <string>("createDocumentFragment") }); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } var message = formatter(state, exception); if (!(state is FormattedLogObject)) { var internalFormatter = new FormattedLogObject(logLevel, message, exception); message = internalFormatter.ToString(); } #if !DESKTOP_BUILD RegisteredFunction.InvokeUnmarshalled <object>(LoggerFunctionName, message); #else Console.WriteLine(message); #endif }
protected void OnClickInternal(UIMouseEventArgs e) { if (!Enabled) { return; } var menuId = RegisteredFunction.Invoke <string>("BlazorContextMenu.MenuItem.GetMenuId", MenuItemElement); var menu = BlazorContextMenuHandler.GetMenu(menuId); var contextMenuTarget = menu.GetTarget(); var args = new MenuItemClickEventArgs(e, menuId, contextMenuTarget, MenuItemElement, this); if (Click != null) { Click(args); if (!args.IsCanceled) { BlazorContextMenuHandler.HideMenu(menuId); } } else if (ClickAsync != null) { ClickAsync(args).ContinueWith((t) => { if (!args.IsCanceled) { BlazorContextMenuHandler.HideMenu(menuId); } }); } }
/// Function := Name '(' ArgList ')' void ParseFunction(TokenQueue tokens) { var funcStartPosition = tokens.PeekToken().Position; RegisteredFunction function = ParseFunctionName(tokens); Token current = tokens.PeekToken(); if (current.TokenType != TokenType.OpenParenthesis) { throw new ParserExceptionWithPosistion(string.Format("Expected open bracket at {0}.", current.Position), current.Position); } tokens.NextToken(); int args = 0; ParseArgList(tokens, ref args); current = tokens.PeekToken(); if (args != function.ArgCount) { throw new ParserExceptionWithPosistion(string.Format("Invalid number of function parameters in function {0}. Expected {1} at {2}.", function.Name, function.ArgCount, current.Position), current.Position); } if (current.TokenType != TokenType.CloseParenthesis) { throw new ParserExceptionWithPosistion(string.Format("Expected close bracket at {0}.", current.Position), current.Position); } // Append function names after all their arguments. EmitFunction(function, funcStartPosition); tokens.NextToken(); }
internal static void Init(BrowserRenderer br, string domElementSelector, Action onFinish) { if (br == null) { throw new NullReferenceException(); } br.AddComponent <BlazorXamarinExtensionScript>(domElementSelector); xamService = new BlazorXamarinDeviceService(); InternalHelper.SetTimeout(async() => { //Safety for detect if RuntimePlatform is a Mobile app or a Browser //First detect Browser context eligible for Xamarin, then returning the proper Xamarin RuntimePlatform try { if (RegisteredFunction.Invoke <bool>("BlazorXamarinRuntimeCheck")) { string resultRuntimePlatform = await xamService.GetRuntimePlatform(); RuntimePlatform = resultRuntimePlatform; } else { RuntimePlatform = Browser; } } catch (Exception ex) { RuntimePlatform = Browser; } onFinish?.Invoke(); }, 100); }
protected override void OnAfterRender() { if (this._isFirstRender) { this._isFirstRender = false; RegisteredFunction.Invoke <bool>(ATTACH_FUNCTION, this._MDCTopAppBar); } }
protected override async Task OnInitAsync() { RegisteredFunction.Invoke <bool>("initializeSignalR"); await LoadProduct(); RegisteredFunction.Invoke <bool>("tabs"); RegisteredFunction.Invoke <bool>("slick"); }
protected async Task DeleteBook() { RegisteredFunction.Invoke <bool>("hideDeleteDialog"); await Http.PostAsync("/Books/Delete/" + DeleteId, null); await LoadBooks(int.Parse(Page)); }
protected override void OnAfterRender() { if (this._isFirstRender) { this._isFirstRender = false; RegisteredFunction.Invoke <bool>(ADD_RIPPLE_FUNCTION, this._MDCButton); } }
public HTMLDocumentElement() { uid = RegisteredFunction.Invoke <string>("document"); _body = new HTMLElement() { uid = RegisteredFunction.Invoke <string>("body") }; }
protected async Task DeleteBook() { RegisteredFunction.Invoke <bool>("hideDeleteDialog"); await BooksClient.DeleteBook(DeleteId); await LoadBooks(int.Parse(Page)); }
public static void RemoveConnection(string connectionId) { if (_connections.ContainsKey(connectionId)) { _connections.Remove(connectionId); } RegisteredFunction.Invoke <object>(REMOVE_CONNECTION_METHOD, connectionId); }
/// <inheritdoc /> public void NavigateTo(string uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } RegisteredFunction.InvokeUnmarshalled <object>($"{_functionPrefix}.navigateTo", uri); }
public TItem GetItem <TItem>(string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } return(RegisteredFunction.Invoke <TItem>(MethodNames.GET_ITEM_METHOD, StorageTypeNames.LOCAL_STORAGE, key)); }
public void RemoveItem(string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } RegisteredFunction.InvokeUnmarshalled <object>(MethodNames.REMOVE_ITEM_METHOD, StorageTypeNames.LOCAL_STORAGE, key); }
public void SetItem <TItem>(string key, TItem item) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } RegisteredFunction.Invoke <object>(MethodNames.SET_ITEM_METHOD, StorageTypeNames.LOCAL_STORAGE, key, JsonUtil.Serialize(item)); }
protected override async Task OnInitAsync() { RegisteredFunction.Invoke <bool>("removeCss", "outside"); await LoadUsers(); // MegaService.Util.InitializeSignalR(); MegaService.Util.InitAdminComponents(); Loaded = true; }