public async Task <IActionResult> Chat(string language, int?chatId = null)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(StatusCode(403));
            }

            if (chatId.HasValue)
            {
                var userId = _userManager.GetUserId(HttpContext.User);

                var user = _dbContext.Users.FirstOrDefault(u => u.Id == userId);

                if (user != null)
                {
                    user.CurrentChatId = chatId.Value;
                    await _dbContext.SaveChangesAsync();
                }
                else
                {
                    return(Error());
                }
            }
            return(View());
        }
Beispiel #2
0
        public async Task <IActionResult> Register(string language, RegisterViewModel model)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userCreationResult = await _userManager.CreateAsync(AppUser.CreateFromRegisterViewModel(model), model.Password);

            if (userCreationResult.Succeeded)
            {
                return(RedirectToAction("SignIn", "Login"));
            }

            foreach (var error in userCreationResult.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            return(View(model));
        }
Beispiel #3
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            string cultureName = null;

            // Attempt to read the culture cookie from Request
            HttpCookie cultureCookie = Request.Cookies["_culture"];

            if (cultureCookie != null)
            {
                cultureName = cultureCookie.Value;
            }
            else
            {
                cultureName = Request.UserLanguages != null && Request.UserLanguages.Length > 0 ?
                              Request.UserLanguages[0] : // obtain it from HTTP header AcceptLanguages
                              null;
            }
            // Validate culture name
            cultureName = CultureUtility.GetImplementedCulture(cultureName); // This is safe

            // Modify current thread's cultures
            Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            return(base.BeginExecuteCore(callback, state));
        }
Beispiel #4
0
 public IActionResult SignIn(string language)
 {
     if (!CultureUtility.SetCurrentThreadCulture(language))
     {
         return(NotFound());
     }
     return(View());
 }
 public PaymentController(IPaymentApiProxy paymentApiProxy, CultureUtility cultureUtility,
                          NetworkUtility networkUtility, UserContext userContext, Configurations configurations)
 {
     _paymentApiProxy = paymentApiProxy;
     _cultureUtility  = cultureUtility;
     _networkUtility  = networkUtility;
     _userContext     = userContext;
     _configurations  = configurations;
 }
        //public DefaultController()
        //{
        //}

        public DefaultController(CultureUtility cultureUtility, HttpContextBase httponContextBase, CmsHelper cmsHelper, Configurations configuration)
        {
            Contract.Requires(cultureUtility != null);
            Contract.Requires(httponContextBase != null);
            Contract.Requires(configuration != null);

            _cultureUtility    = cultureUtility;
            _httponContextBase = httponContextBase;
            _cmsHelper         = cmsHelper;
            _configurations    = configuration;
        }
        public CmsController(CmsEngine cmsEngine, CultureUtility cultureUtility, HttpContextBase httponContextBase, Configurations configurations)
        {
            Contract.Requires(cmsEngine != null);
            Contract.Requires(cultureUtility != null);
            Contract.Requires(httponContextBase != null);
            Contract.Requires(configurations != null);

            _cmsEngine         = cmsEngine;
            _cultureUtility    = cultureUtility;
            _httponContextBase = httponContextBase;
            _configurations    = configurations;
        }
Beispiel #8
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Text == null)
            {
                return(null);
            }

            // Do your translation lookup here, using whatever method you require
            var translated = CultureUtility.GetResxNameByValue(Text);

            return(translated);
        }
        public async Task <IActionResult> Index(string language)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Chat", "Home", new { chatId = user.CurrentChatId }));
            }
            return(Redirect($"/{language}/login/signin"));
        }
Beispiel #10
0
        private void DisplayErrorPage(HttpContextBase httpContext, Configurations configurations,
                                      CultureUtility cultureUtility, HttpStatusCode fileHttpStatusCode, HttpStatusCode headerHttpStatusCode)
        {
            string errorPagePath = string.Format(configurations.ErrorPagePath, (int)fileHttpStatusCode,
                                                 cultureUtility.GetCultureCode());

            if (!File.Exists(Server.MapPath(errorPagePath)))
            {
                errorPagePath = string.Format(configurations.ErrorPagePath, (int)HttpStatusCode.NotFound,
                                              DefaultCultureCode);
            }

            Log.InfoFormat("Displaying {0}.", errorPagePath);

            httpContext.Response.StatusCode  = (int)headerHttpStatusCode;
            httpContext.Response.ContentType = MediaTypeNames.Text.Html;
            httpContext.Response.WriteFile(errorPagePath);
            httpContext.Response.End();
        }
Beispiel #11
0
        public void SetCulture(string culture)
        {
            // Validate input
            string cultureName = CultureUtility.GetImplementedCulture(culture);
            // Save culture in a cookie
            HttpCookie cookie = Request.Cookies["_culture"];

            if (cookie != null)
            {
                cookie.Value = cultureName;   // update cookie value
            }
            else
            {
                cookie         = new HttpCookie("_culture");
                cookie.Value   = cultureName;
                cookie.Expires = DateTime.Now.AddYears(1);
            }

            // Modify current thread's cultures
            Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            Response.Cookies.Add(cookie);
        }
 override protected void OnInit(EventArgs e)
 {
     CultureUtility.SetThreadCulture();
     base.OnInit(e);
     _commonparameterManagerData = new CommonParameterDataProvider();
 }
 protected override void OnInit(EventArgs e)
 {
     CultureUtility.SetThreadCulture();
     base.OnInit(e);
 }
Beispiel #14
0
        /// <summary>
        /// Internal Main. This is used for testing.
        /// </summary>
        public static int MainInternal(string[] args, CommandOutputLogger log)
        {
#if DEBUG
            try
            {
                // .NET JIT compiles one method at a time. If this method calls `MSBuildLocator` directly, the
                // try block is never entered if Microsoft.Build.Locator.dll can't be found. So, run it in a
                // lambda function to ensure we're in the try block. C# IIFE!
                ((Action)(() => MSBuildLocator.RegisterDefaults()))();
            }
            catch
            {
                // MSBuildLocator is used only to enable Visual Studio debugging.
                // It's not needed when using a patched dotnet sdk, so it doesn't matter if it fails.
            }

            var debugNuGetXPlat = Environment.GetEnvironmentVariable("DEBUG_NUGET_XPLAT");

            if (args.Contains(DebugOption) || string.Equals(bool.TrueString, debugNuGetXPlat, StringComparison.OrdinalIgnoreCase))
            {
                args = args.Where(arg => !StringComparer.OrdinalIgnoreCase.Equals(arg, DebugOption)).ToArray();
                Debugger.Launch();
            }
#endif

            // Optionally disable localization.
            if (args.Any(arg => string.Equals(arg, CommandConstants.ForceEnglishOutputOption, StringComparison.OrdinalIgnoreCase)))
            {
                CultureUtility.DisableLocalization();
            }

            var app = InitializeApp(args, log);

            // Remove the correct item in array for "package" commands. Only do this when "add package", "remove package", etc... are being run.
            if (app.Name == DotnetPackageAppName)
            {
                // package add ...
                args[0] = null;
                args    = args
                          .Where(e => e != null)
                          .ToArray();
            }

            NetworkProtocolUtility.SetConnectionLimit();

            XPlatUtility.SetUserAgent();

            app.OnExecute(() =>
            {
                app.ShowHelp();

                return(0);
            });

            log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.OutputNuGetVersion, app.FullName, app.LongVersionGetter()));

            int exitCode = 0;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (Exception e)
            {
                bool   handled = false;
                string verb    = null;
                if (args.Length > 1)
                {
                    // Redirect users nicely if they do 'dotnet nuget sources add' or 'dotnet nuget add sources'
                    if (StringComparer.OrdinalIgnoreCase.Compare(args[0], "sources") == 0)
                    {
                        verb = args[1];
                    }
                    else if (StringComparer.OrdinalIgnoreCase.Compare(args[1], "sources") == 0)
                    {
                        verb = args[0];
                    }

                    if (verb != null)
                    {
                        switch (verb.ToLowerInvariant())
                        {
                        case "add":
                        case "remove":
                        case "update":
                        case "enable":
                        case "disable":
                        case "list":
                            log.LogMinimal(string.Format(CultureInfo.CurrentCulture,
                                                         Strings.Sources_Redirect, $"dotnet nuget {verb} source"));
                            handled = true;
                            break;

                        default:
                            break;
                        }
                    }
                }

                if (!handled)
                {
                    // Log the error
                    if (ExceptionLogger.Instance.ShowStack)
                    {
                        log.LogError(e.ToString());
                    }
                    else
                    {
                        log.LogError(ExceptionUtilities.DisplayMessage(e));
                    }

                    // Log the stack trace as verbose output.
                    log.LogVerbose(e.ToString());

                    exitCode = 1;

                    ShowBestHelp(app, args);
                }
            }

            // Limit the exit code range to 0-255 to support POSIX
            if (exitCode < 0 || exitCode > 255)
            {
                exitCode = 1;
            }

            return(exitCode);
        }
        /// <summary>
        /// Dummy data for side panel
        /// </summary>
        /// <returns></returns>
        private List <SimpleObject> PreparedObject()
        {
            var dummyData = new List <SimpleObject>();

            SimpleObject obj = new SimpleObject();

            obj.HeaderText = CultureUtility.GetResxNameByValue("Submissions");
            obj.ChildItemList.Add(new ChildItems {
                TextValue = CultureUtility.GetResxNameByValue("ManageSubmissions"), DataValue = "MS1"
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = CultureUtility.GetResxNameByValue("Timesheet");
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "View Timesheet", DataValue = "T1"
            });
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Create Timesheet", DataValue = "T2", BubbleCount = 5
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Expense";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "View Expense Report", DataValue = "E1"
            });
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Create Expense Report", DataValue = "E2"
            });
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Approve Expense Report", DataValue = "E3", BubbleCount = 2
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Engagement";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "View Engagement", DataValue = "Eg1"
            });

            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Payment";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "View Payment History", DataValue = "P1"
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Dossier";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Information", DataValue = "D1"
            });
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Security", DataValue = "D2"
            });
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Contact Us", DataValue = "D3"
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Dashboard";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Dashboard", DataValue = "D1"
            });
            dummyData.Add(obj);

            obj            = new SimpleObject();
            obj.HeaderText = "Logout";
            obj.ChildItemList.Add(new ChildItems {
                TextValue = "Logout", DataValue = "D1"
            });
            dummyData.Add(obj);

            return(dummyData);
        }
Beispiel #16
0
        /// <summary>
        /// Internal Main. This is used for testing.
        /// </summary>
        public static int MainInternal(string[] args, CommandOutputLogger log)
        {
#if DEBUG
            var debugNuGetXPlat = Environment.GetEnvironmentVariable("DEBUG_NUGET_XPLAT");

            if (args.Contains(DebugOption) || string.Equals(bool.TrueString, debugNuGetXPlat, StringComparison.OrdinalIgnoreCase))
            {
                args = args.Where(arg => !StringComparer.OrdinalIgnoreCase.Equals(arg, DebugOption)).ToArray();

                Console.WriteLine("Waiting for debugger to attach.");
                Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");

                while (!Debugger.IsAttached)
                {
                    System.Threading.Thread.Sleep(100);
                }

                Debugger.Break();
            }
#endif

            // Optionally disable localization.
            if (args.Any(arg => string.Equals(arg, CommandConstants.ForceEnglishOutputOption, StringComparison.OrdinalIgnoreCase)))
            {
                CultureUtility.DisableLocalization();
            }

            var app = InitializeApp(args);
            args = args
                   .Where(e => e != "package")
                   .ToArray();

            var verbosity = app.Option(XPlatUtility.VerbosityOption, Strings.Switch_Verbosity, CommandOptionType.SingleValue);

            // Options aren't parsed until we call app.Execute(), so look directly for the verbosity option ourselves
            LogLevel logLevel;
            TryParseVerbosity(args, verbosity, out logLevel);
            log.LogLevel = logLevel;

            NetworkProtocolUtility.SetConnectionLimit();

            XPlatUtility.SetUserAgent();

            // This method has no effect on .NET Core.
            NetworkProtocolUtility.ConfigureSupportedSslProtocols();

            // Register commands
            RegisterCommands(app, log);

            app.OnExecute(() =>
            {
                app.ShowHelp();

                return(0);
            });

            log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.OutputNuGetVersion, app.FullName, app.LongVersionGetter()));

            int exitCode = 0;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (Exception e)
            {
                // Log the error
                if (ExceptionLogger.Instance.ShowStack)
                {
                    log.LogError(e.ToString());
                }
                else
                {
                    log.LogError(ExceptionUtilities.DisplayMessage(e));
                }

                // Log the stack trace as verbose output.
                log.LogVerbose(e.ToString());

                exitCode = 1;
            }

            // Limit the exit code range to 0-255 to support POSIX
            if (exitCode < 0 || exitCode > 255)
            {
                exitCode = 1;
            }

            return(exitCode);
        }
Beispiel #17
0
 public Player(IAccountApiProxy accountApiProxy, CultureUtility cultureUtility, UserContext userContext)
 {
     _accountApiProxy = accountApiProxy;
     _cultureUtility  = cultureUtility;
     _userContext     = userContext;
 }
Beispiel #18
0
        public static int MainCore(string workingDirectory, string[] args)
        {
            // First, optionally disable localization in resources.
            if (args.Any(arg => string.Equals(arg, ForceEnglishOutputOption, StringComparison.OrdinalIgnoreCase)))
            {
                CultureUtility.DisableLocalization();
            }

            // set output encoding to UTF8 if -utf8 is specified
            var oldOutputEncoding = System.Console.OutputEncoding;

            if (args.Any(arg => string.Equals(arg, Utf8Option, StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(arg => !string.Equals(arg, Utf8Option, StringComparison.OrdinalIgnoreCase)).ToArray();
                SetConsoleOutputEncoding(Encoding.UTF8);
            }

            // Increase the maximum number of connections per server.
            if (!RuntimeEnvironmentHelper.IsMono)
            {
                ServicePointManager.DefaultConnectionLimit = 64;
            }
            else
            {
                // Keep mono limited to a single download to avoid issues.
                ServicePointManager.DefaultConnectionLimit = 1;
            }

            NetworkProtocolUtility.ConfigureSupportedSslProtocols();

            var console         = new Console();
            var fileSystem      = new CoreV2.NuGet.PhysicalFileSystem(workingDirectory);
            var logStackAsError = console.Verbosity == Verbosity.Detailed;

            try
            {
                // Remove NuGet.exe.old
                RemoveOldFile(fileSystem);

                // Import Dependencies
                var p = new Program();
                p.Initialize(fileSystem, console);

                // Add commands to the manager
                foreach (var cmd in p.Commands)
                {
                    p.Manager.RegisterCommand(cmd);
                }

                var parser = new CommandLineParser(p.Manager);

                // Parse the command
                var command = parser.ParseCommandLine(args) ?? p.HelpCommand;
                command.CurrentDirectory = workingDirectory;

                // Fallback on the help command if we failed to parse a valid command
                if (!ArgumentCountValid(command))
                {
                    // Get the command name and add it to the argument list of the help command
                    var commandName = command.CommandAttribute.CommandName;

                    // Print invalid command then show help
                    console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName);

                    p.HelpCommand.ViewHelpForCommand(commandName);
                }
                else
                {
                    SetConsoleInteractivity(console, command as Command);

                    try
                    {
                        command.Execute();
                    }
                    catch (AggregateException e)
                    {
                        var unwrappedEx = ExceptionUtility.Unwrap(e);

                        if (unwrappedEx is CommandLineArgumentCombinationException)
                        {
                            var commandName = command.CommandAttribute.CommandName;

                            console.WriteLine($"{string.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InvalidArguments"), commandName)} {unwrappedEx.Message}");

                            p.HelpCommand.ViewHelpForCommand(commandName);

                            return(1);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (CommandLineArgumentCombinationException e)
                    {
                        var commandName = command.CommandAttribute.CommandName;

                        console.WriteLine($"{string.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("InvalidArguments"), commandName)} {e.Message}");

                        p.HelpCommand.ViewHelpForCommand(commandName);

                        return(1);
                    }
                }
            }
            catch (AggregateException exception)
            {
                var unwrappedEx   = ExceptionUtility.Unwrap(exception);
                var rootException = ExceptionUtility.GetRootException(exception);

                if (unwrappedEx is ExitCodeException)
                {
                    // Return the exit code without writing out the exception type
                    var exitCodeEx = unwrappedEx as ExitCodeException;
                    return(exitCodeEx.ExitCode);
                }
                if (rootException is PathTooLongException)
                {
                    LogHelperMessageForPathTooLongException(console);
                }

                // Log the exception and stack trace.
                ExceptionUtilities.LogException(unwrappedEx, console, logStackAsError);
                return(1);
            }
            catch (ExitCodeException e)
            {
                return(e.ExitCode);
            }
            catch (PathTooLongException e)
            {
                // Log the exception and stack trace.
                ExceptionUtilities.LogException(e, console, logStackAsError);
                LogHelperMessageForPathTooLongException(console);
                return(1);
            }
            catch (Exception exception)
            {
                ExceptionUtilities.LogException(exception, console, logStackAsError);
                return(1);
            }
            finally
            {
                CoreV2.NuGet.OptimizedZipPackage.PurgeCache();
                SetConsoleOutputEncoding(oldOutputEncoding);
            }

            return(0);
        }
Beispiel #19
0
        public static int MainCore(string workingDirectory, string[] args)
        {
            // First, optionally disable localization in resources.
            if (args.Any(arg => string.Equals(arg, ForceEnglishOutputOption, StringComparison.OrdinalIgnoreCase)))
            {
                CultureUtility.DisableLocalization();
            }

            // set output encoding to UTF8 if -utf8 is specified
            var oldOutputEncoding = System.Console.OutputEncoding;

            if (args.Any(arg => string.Equals(arg, Utf8Option, StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(arg => !string.Equals(arg, Utf8Option, StringComparison.OrdinalIgnoreCase)).ToArray();
                SetConsoleOutputEncoding(Encoding.UTF8);
            }

            // Increase the maximum number of connections per server.
            if (!RuntimeEnvironmentHelper.IsMono)
            {
                ServicePointManager.DefaultConnectionLimit = 64;
            }
            else
            {
                // Keep mono limited to a single download to avoid issues.
                ServicePointManager.DefaultConnectionLimit = 1;
            }

            NetworkProtocolUtility.ConfigureSupportedSslProtocols();

            var console    = new Console();
            var fileSystem = new CoreV2.NuGet.PhysicalFileSystem(workingDirectory);

            Func <Exception, string> getErrorMessage = ExceptionUtilities.DisplayMessage;

            try
            {
                // Remove NuGet.exe.old
                RemoveOldFile(fileSystem);

                // Import Dependencies
                var p = new Program();
                p.Initialize(fileSystem, console);

                // Add commands to the manager
                foreach (ICommand cmd in p.Commands)
                {
                    p.Manager.RegisterCommand(cmd);
                }

                CommandLineParser parser = new CommandLineParser(p.Manager);

                // Parse the command
                ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand;
                command.CurrentDirectory = workingDirectory;

                // Fallback on the help command if we failed to parse a valid command
                if (!ArgumentCountValid(command))
                {
                    // Get the command name and add it to the argument list of the help command
                    string commandName = command.CommandAttribute.CommandName;

                    // Print invalid command then show help
                    console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName);

                    p.HelpCommand.ViewHelpForCommand(commandName);
                }
                else
                {
                    SetConsoleInteractivity(console, command as Command);

                    // When we're detailed, get the whole exception including the stack
                    // This is useful for debugging errors.
                    if (console.Verbosity == Verbosity.Detailed || ExceptionLogger.Instance.ShowStack)
                    {
                        getErrorMessage = e => e.ToString();
                    }

                    command.Execute();
                }
            }
            catch (AggregateException exception)
            {
                Exception unwrappedEx = ExceptionUtility.Unwrap(exception);
                if (unwrappedEx is ExitCodeException)
                {
                    // Return the exit code without writing out the exception type
                    var exitCodeEx = unwrappedEx as ExitCodeException;
                    return(exitCodeEx.ExitCode);
                }

                console.WriteError(getErrorMessage(exception));
                return(1);
            }
            catch (Exception exception)
            {
                console.WriteError(getErrorMessage(exception));
                return(1);
            }
            finally
            {
                CoreV2.NuGet.OptimizedZipPackage.PurgeCache();
                SetConsoleOutputEncoding(oldOutputEncoding);
            }

            return(0);
        }