コード例 #1
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (null == authCookie)
            {
                return;
            }
            var authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            if (null == authTicket)
            {
                return;
            }

            List <Role> roles = AsyncInline.Run(() => new UserManager().GetRolesAsync(authTicket.Name));

            if (roles.Count == 0)
            {
                FormsAuthentication.SignOut();
                return;
            }

            string[] roleStrs = roles.Select(p => p.ToString()).ToArray();

            var id = new FormsIdentity(authTicket);

            Context.User = new GenericPrincipal(id, roleStrs);
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: zyhbill/YummyOnline
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (null == authCookie)
            {
                return;
            }
            var authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            if (null == authTicket)
            {
                return;
            }

            YummyOnlineDAO.Models.Staff staff = AsyncInline.Run(() => new StaffManager().FindStaffById(authTicket.Name));
            if (staff == null)
            {
                FormsAuthentication.SignOut();
                return;
            }
            string                 connStr             = AsyncInline.Run(() => new YummyOnlineManager().GetHotelConnectionStringById(staff.HotelId));
            HotelManager           hotelManager4Waiter = new HotelManager(connStr);
            List <StaffRoleSchema> schemas             = AsyncInline.Run(() => hotelManager4Waiter.GetStaffRoles(staff.Id));

            string[] roleStrs = schemas.Select(p => p.Schema.ToString()).ToArray();

            var id = new FormsIdentity(authTicket);

            Context.User = new GenericPrincipal(id, roleStrs);
        }
コード例 #3
0
ファイル: BaseController.cs プロジェクト: zyhbill/YummyOnline
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (CurrHotel != null)
            {
                ViewBag.HotelId      = CurrHotel?.Id;
                ViewBag.CssThemePath = AsyncInline.Run(() => { return(YummyOnlineManager.GetHotelById(CurrHotel.Id)); }).CssThemePath;
            }

            base.OnActionExecuted(filterContext);
        }
コード例 #4
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception exception = filterContext.Exception;

            AsyncInline.Run(() => new YummyOnlineManager().RecordLog(Log.LogProgram.OrderSystem, Log.LogLevel.Error,
                                                                     $"Host: {HttpContext.Current.Request.UserHostAddress}, RequestUrl: {HttpContext.Current.Request.RawUrl}, Message: {exception.Message}",
                                                                     $"PostData: {HttpPost.GetPostData(HttpContext.Current.Request)}, Exception: {exception}"));

            filterContext.ExceptionHandled = true;
            filterContext.Result           = new RedirectResult($"~/Error/HttpError500");
        }
コード例 #5
0
ファイル: BaseController.cs プロジェクト: zyhbill/YummyOnline
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Hotel currHotel = filterContext.HttpContext.Session["Hotel"] as Hotel;

            if (currHotel != null)
            {
                Hotel hotel = AsyncInline.Run(() => new YummyOnlineManager().GetHotelById(currHotel.Id));
                if (!hotel.Usable)
                {
                    filterContext.Result = new RedirectResult("/Error/HotelUnavailable");
                    return;
                }
            }

            base.OnActionExecuting(filterContext);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args != null && args.Length > 1)
            {
#if UNDOK
                if (args[0].ToUpper() == "CONTROL")
                {
                    AsyncInline.Run(async() => { await Start(args[1]); });
                }
#endif
            }
            else
            {
                Application.Run(new Test());
            }
        }
コード例 #7
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (commandBar.Visibility != Windows.UI.Xaml.Visibility.Visible)
            {
                commandBar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            if (e.NavigationParameter is Playlist)
            {
                pivot.SelectedIndex = 1;
            }
            DefaultViewModel["MusicLibrary"]    = MusicLibrary.Instance;
            DefaultViewModel["PlaylistManager"] = PlaylistManager.Instance;

            var a = Task.Run(new Action(() =>
            {
                try
                {
                    Song currentSong = NowPlayingInformation.CurrentSong;
                    Album album      = MusicLibrary.Instance.GetAlbum(currentSong);
                    if (currentSong != null && album != null && !string.IsNullOrEmpty(album.CachedImagePath))
                    {
                        var b = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => songTitleText.Text = currentSong.SongTitle);

                        Uri uri;
                        if (Uri.TryCreate(album.CachedImagePath, UriKind.RelativeOrAbsolute, out uri))
                        {
                            IRandomAccessStream ras = AsyncInline.Run(new Func <Task <IRandomAccessStream> >(() =>
                                                                                                             Utilities.ResizeImageFile(uri, 180)));
                            b = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                            {
                                nowPlayingArt.SetSource(ras);
                                nowPlayingRow.Height = new GridLength(180);
                            });
                        }
                    }
                    else
                    {
                        var b = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => nowPlayingRow.Height = new GridLength(0));
                    }
                }
                catch { }
            }));
        }
コード例 #8
0
        public Task LoadCache(CoreDispatcher dispatcher, StorageFile cacheFile = null)
        {
            if (Interlocked.CompareExchange(ref _hasLoadedCache, 1, 0) == 1)
            {
                return(null);
            }

            return(Task.Run(new Action(() =>
            {
                try
                {
                    _cache = AsyncInline.Run(new Func <Task <MusicLibraryCache> >(() => MusicLibraryCache.Deserialize(cacheFile)));
                    var c = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low,
                                                () =>
                    {
                        foreach (Artist artist in _cache.Artists.Values)
                        {
                            AddItemToGroup(ArtistGroupDictionary, artist, a => a.ArtistName[0]);
                        }
                        foreach (List <Album> albums in _cache.Albums.Values)
                        {
                            foreach (Album album in albums)
                            {
                                AddItemToGroup(AlbumGroupDictionary, album, a => a.AlbumName[0]);
                            }
                        }
                        foreach (List <Song> songs in _cache.Songs.Values)
                        {
                            foreach (Song song in songs)
                            {
                                AddItemToGroup(SongGroupDictionary, song, a => song.SongTitle[0]);
                            }
                        }
                    });
                }
                catch { }
            })));
        }