Esempio n. 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ILevelDesignView designView  = new LevelDesignForm();
            IErrorHandler    designCheck = new ErrorHandler();
            IMapEditor       designModel = new MapEditor(designCheck);

            ILevelDesignController designController = new Controller(designView, designModel);

            FileHandlerNS.IFiler filer = new FileHandler();
            ISaver  saver  = (ISaver)filer;
            ILoader loader = (ILoader)filer;

            IView gameView = new WindowsFormView();

            GameNS.Game    gameModel = new GameNS.Game();
            GameController gControl  = new GameController(gameModel, gameView);
            GameBoardForm  gameBoard = new GameBoardForm(gameView, gControl);

            FilerForm filerView = new FilerForm();

            FilerNS.IFiler        gameFiler    = new FilerNS.Filer();
            FileHandlerController filerControl = new FileHandlerController(saver, loader, filer, gameFiler, gameModel, filerView);

            MainForm f = new MainForm(designController, filerControl, gameBoard);

            Application.Run(f);
        }
Esempio n. 2
0
        public async Task ProcessFileTest_SingleTextFile()
        {
            string inputFile = @".\George Berkeley - Principles of Human Knowledge.txt";

            FileHandlerController fhc = new FileHandlerController();
            ConcurrentDictionary <string, long> wordCounts = new ConcurrentDictionary <string, long>();
            FileInfo fi = new FileInfo(inputFile);
            await fhc.ProcessFile(fi, wordCounts);

            Assert.AreEqual(22, wordCounts["wherein"]);
        }
Esempio n. 3
0
 public MainForm(ILevelDesignController designControl, FileHandlerController filerControl, GameBoardForm gameBoard)
 {
     DesignController = designControl;
     FilerControl     = filerControl;
     GameBoard        = gameBoard;
     FileSave        += new FileHandled(Save);
     FileLoad        += new FileHandled(ToLoad);
     SetFile         += new FileHandled(SetLoaded);
     LoadGame        += new FileHandled(toLoadGame);
     SaveGame        += new FileHandled(toSaveGame);
     SetSaveFile     += new FileHandled(saveFile);
     MapTest         += new FileHandled(levelToGame);
     InitializeComponent();
     GameBoard.setParent(this);
 }
Esempio n. 4
0
        public async Task ProcessFileTest_SingleArchiveFile()
        {
            long totalWordCount =
                (1 * FileWordCounts.PrinciplesofHumanKnowledge) +
                (1 * FileWordCounts.ThreeDialogues) +
                (1 * FileWordCounts.CritiqueofPureReason) +
                (1 * FileWordCounts.Theodicy) +
                (1 * FileWordCounts.EssayConcerningHumaneUnderstandingVol1) +
                (1 * FileWordCounts.EssayConcerningHumaneUnderstandingVol2);

            string inputFile = @".\NestedFiles.zip";

            FileHandlerController fhc = new FileHandlerController();
            FileInfo fi = new FileInfo(inputFile);
            ConcurrentDictionary <string, long> wordCounts = new ConcurrentDictionary <string, long>();
            await fhc.ProcessFile(fi, wordCounts);

            Assert.AreEqual(totalWordCount, wordCounts.Values.Sum());
            Assert.AreEqual(2, wordCounts["DEFINITION"]);
            Assert.AreEqual(4, wordCounts["Definition"]);
            Assert.AreEqual(79, wordCounts["definition"]);
        }
Esempio n. 5
0
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
            });

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
            {
                ClientId                  = SettingsHelper.ClientId,
                Authority                 = SettingsHelper.Authority,
                ClientSecret              = SettingsHelper.AppKey,
                ResponseType              = "code id_token",
                Resource                  = "https://graph.microsoft.com",
                PostLogoutRedirectUri     = "/",
                TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuer = false
                },
                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    SecurityTokenValidated = (context) =>
                    {
                        return(Task.FromResult(0));
                    },
                    AuthenticationFailed = (context) =>
                    {
                        string message = Uri.EscapeDataString(context.Exception.Message);
                        context.OwinContext.Response.Redirect("/Home/Error?msg=" + message);
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    },
                    AuthorizationCodeReceived = async(context) =>
                    {
                        var code = context.Code;
                        ClientCredential credential = new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey);

                        string tenantID     = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
                        string signInUserId = context.AuthenticationTicket.Identity.FindFirst(AuthHelper.ObjectIdentifierClaim).Value;

                        var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(SettingsHelper.Authority,
                                                                                                                    new AzureTableTokenCache(signInUserId));

                        AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(code,
                                                                                                             new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)),
                                                                                                             credential,
                                                                                                             SettingsHelper.AADGraphResourceId);
                    },
                    RedirectToIdentityProvider = (context) =>
                    {
                        string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
                        context.ProtocolMessage.RedirectUri           = appBaseUrl + "/";
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;

                        FileHandlerActivationParameters fileHandlerActivation;
                        if (FileHandlerController.IsFileHandlerActivationRequest(new HttpRequestWrapper(HttpContext.Current.Request), out fileHandlerActivation))
                        {
                            context.ProtocolMessage.LoginHint  = fileHandlerActivation.UserId;
                            context.ProtocolMessage.DomainHint = "organizations";
                            CookieStorage.Save(HttpContext.Current.Request.Form, HttpContext.Current.Response);
                        }

                        var challengeProperties = context.OwinContext?.Authentication?.AuthenticationResponseChallenge?.Properties;
                        if (null != challengeProperties && challengeProperties.Dictionary.ContainsKey("prompt"))
                        {
                            context.ProtocolMessage.Prompt = challengeProperties.Dictionary["prompt"];
                        }

                        return(Task.FromResult(0));
                    }
                }
            });
        }
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
            });

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
            {
                ClientId                  = SettingsHelper.ClientId,
                Authority                 = SettingsHelper.Authority,
                ClientSecret              = SettingsHelper.AppKey,
                ResponseType              = "code id_token",
                Resource                  = "https://graph.microsoft.com",
                PostLogoutRedirectUri     = "/",
                TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    // instead of using the default validation (validating against a single issuer value, as we do in line of business apps (single tenant apps)),
                    // we turn off validation
                    //
                    // NOTE:
                    // * In a multitenant scenario you can never validate against a fixed issuer string, as every tenant will send a different one.
                    // * If you don’t care about validating tenants, as is the case for apps giving access to 1st party resources, you just turn off validation.
                    // * If you do care about validating tenants, think of the case in which your app sells access to premium content and you want to limit access only to the tenant that paid a fee,
                    //       you still need to turn off the default validation but you do need to add logic that compares the incoming issuer to a list of tenants that paid you,
                    //       and block access if that’s not the case.
                    // * Refer to the following sample for a custom validation logic: https://github.com/AzureADSamples/WebApp-WebAPI-MultiTenant-OpenIdConnect-DotNet
                    ValidateIssuer = false
                },
                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    SecurityTokenValidated = (context) =>
                    {
                        // If your authentication logic is based on users then add your logic here
                        return(Task.FromResult(0));
                    },
                    AuthenticationFailed = (context) =>
                    {
                        // Pass in the context back to the app
                        string message = Uri.EscapeDataString(context.Exception.Message);
                        context.OwinContext.Response.Redirect("/Home/Error?msg=" + message);
                        context.HandleResponse();     // Suppress the exception
                        return(Task.FromResult(0));
                    },
                    AuthorizationCodeReceived = async(context) =>
                    {
                        var code = context.Code;
                        ClientCredential credential = new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey);

                        string tenantID     = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
                        string signInUserId = context.AuthenticationTicket.Identity.FindFirst(AuthHelper.ObjectIdentifierClaim).Value;

                        var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(SettingsHelper.Authority,
                                                                                                                    new AzureTableTokenCache(signInUserId));

                        // Get the access token for AAD Graph. Doing this will also initialize the token cache associated with the authentication context
                        // In theory, you could acquire token for any service your application has access to here so that you can initialize the token cache
                        AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(code,
                                                                                                             new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)),
                                                                                                             credential,
                                                                                                             SettingsHelper.AADGraphResourceId);
                    },
                    RedirectToIdentityProvider = (context) =>
                    {
                        // This ensures that the address used for sign in and sign out is picked up dynamically from the request
                        // this allows you to deploy your app (to Azure Web Sites, for example)without having to change settings
                        // Remember that the base URL of the address used here must be provisioned in Azure AD beforehand.
                        string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
                        context.ProtocolMessage.RedirectUri           = appBaseUrl + "/";
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;

                        if (FileHandlerController.IsFileHandlerActivationRequest(new HttpRequestWrapper(HttpContext.Current.Request), out FileHandlerActivationParameters fileHandlerActivation))
                        {
                            // Add LoginHint and DomainHint if the request includes a form handler post
                            context.ProtocolMessage.LoginHint  = fileHandlerActivation.UserId;
                            context.ProtocolMessage.DomainHint = "organizations";

                            // Save the form in the cookie to prevent it from getting lost in the login redirect
                            CookieStorage.Save(HttpContext.Current.Request.Form, HttpContext.Current.Response);
                        }

                        // Allow us to change the prompt in consent mode if the challenge properties specify a prompt type
                        var challengeProperties = context.OwinContext?.Authentication?.AuthenticationResponseChallenge?.Properties;
                        if (null != challengeProperties && challengeProperties.Dictionary.ContainsKey("prompt"))
                        {
                            context.ProtocolMessage.Prompt = challengeProperties.Dictionary["prompt"];
                        }

                        return(Task.FromResult(0));
                    }
                }
            });