/// <summary> /// Through the path to the file to download /// </summary> /// <param name="response">This page response</param> /// <param name="path">File path</param> public static void Download(HttpResponse response, string path) { try { var pushbyte = File.ReadAllBytes(path); FileInfo fileInfo = new FileInfo(path); response.Clear(); response.ClearHeaders(); response.ClearContent(); response.ContentType = PageContentType.GetConteneType(fileInfo.Extension); // file type response.AddHeader("Content-Length", pushbyte.Length.ToString()); response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8).Replace("+", "%20")); response.BinaryWrite(pushbyte); if (response.IsClientConnected) { response.Flush(); } } catch (Exception ex) { PageBase.Log.Error("System log : " + ex); throw ex; } }
private void LoadContentFromHistory(bool autoSkip = false) { if (_navigationHistory.Count == 0) { return; } IsContentEventsActive(false); NavigationHistoryNode node; do { node = _navigationHistory.Pop(); } while (autoSkip && node.SkipWhenGoBack && _navigationHistory.Count != 0); switch (node.Type) { case PageContentType.Page: { node.Content.DataContext = node.DataContext; PageContent.Content = node.Content; SwitchNavBarLayout(node.Content).Wait(); HideOverlay(); ClearOverlay(); break; } case PageContentType.Overlay: { if (node.SubContent != null) { node.SubContent.DataContext = node.SubDataContext; PageContent.Content = node.SubContent; } node.Content.DataContext = node.DataContext; OverlayContent.Content = node.Content; SwitchNavBarLayout(node.Content).Wait(); ShowOverlay(); break; } default: throw new ArgumentException( "Invalid page content type for history node", nameof(node.Type)); } _currentPageContentType = node.Type; }
private NavigationController() { Initialized += OnCreated; Initialized += OnInitialized; Loaded += OnEnter; Unloaded += OnExit; IsCreated = false; _navBarPagesLayouts = new Dictionary <Type, NavBarLayoutType>(); _navigationHistory = new ChunkedArrayL <NavigationHistoryNode>(); _currentPageContentType = PageContentType.Page; _currentPageSkipWhenGoBack = false; InitializeComponent(); DataContext = this; }
private void SetPage(PageContent page, PageViewModel dataContext = null, bool skipWhenGoBack = false) { if (!OverlayIsOpen() && ReferenceEquals(PageContent.Content, page) && (dataContext == null || ReferenceEquals((PageContent.Content as PageContent)?.DataContext, dataContext))) { return; } UpdateLayout(); GC.WaitForPendingFinalizers(); GC.Collect(); IsContentEventsActive(false); SaveContentToHistory(); if (dataContext != null) { if (dataContext.PageType != page.GetType()) { var exception = new ArgumentException($"The {nameof(dataContext)} page type must match the {nameof(page)} type", nameof(dataContext)); Events.OnError(this, new RErrorEventArgs(exception, exception.Message)); throw exception; } page.DataContext = dataContext; } PageContent.Content = page; _currentPageContentType = PageContentType.Page; _currentPageSkipWhenGoBack = skipWhenGoBack; SwitchNavBarLayout(page).Wait(); HideOverlay(); ClearOverlay(); IsContentEventsActive(true); }
/// <summary> /// Get code by type from layout /// </summary> /// <param name="type"></param> /// <param name="pageName"></param> /// <param name="pageId"></param> /// <returns></returns> private async Task <(string, Page)> GetLayoutCode(PageContentType type, string pageName = "layout", Guid?pageId = null) { try { var layout = pageId == null ? _pagesContext.Pages.Include(x => x.Settings).FirstOrDefault(x => x.Settings.Name == pageName) : await GetPageAsync(pageId.Value); if (layout == null) { return(string.Empty, null); } var code = string.Empty; switch (type) { case PageContentType.Html: code = layout.Settings.HtmlCode; break; case PageContentType.Js: code = layout.Settings.JsCode; break; case PageContentType.Css: code = layout.Settings.CssCode; break; } return(code, layout); } catch (Exception e) { Console.WriteLine(e); } return(string.Empty, null); }
private void SetPageContent(PageContentType content) { switch (content) { case PageContentType.ConnectionError: if (ConnectionErrorView != null) { ConnectionErrorView.View.Visibility = ViewStates.Visible; } if (_contentView != null) { _contentView.Visibility = ViewStates.Gone; } if (NoItemsView != null) { NoItemsView.View.Visibility = ViewStates.Gone; } break; case PageContentType.Content: if (ConnectionErrorView != null) { ConnectionErrorView.View.Visibility = ViewStates.Gone; } if (_contentView != null) { _contentView.Visibility = ViewStates.Visible; } if (NoItemsView != null) { NoItemsView.View.Visibility = ViewStates.Gone; } break; case PageContentType.Empty: if (ConnectionErrorView != null) { ConnectionErrorView.View.Visibility = ViewStates.Gone; } if (_contentView != null) { _contentView.Visibility = ViewStates.Gone; } if (NoItemsView != null) { NoItemsView.View.Visibility = ViewStates.Visible; } break; } }