Ejemplo n.º 1
0
        public PartialViewResult LanguageChoose()
        {
            var model = new LanguageChoose();

            //model.CurrentLanguageCode = JwtTokenProvider.GetUserModelCurrentLanguage(Request.Cookies["token"].Value);
            model.CurrentLanguageCode = JwtTokenProvider.GetUserModelCurrentLanguage(HttpContext.Request.Cookies["token"].Value);
            return(PartialView(model));
        }
Ejemplo n.º 2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ITraceManager traceManager = DependencyResolver.Current.GetService(typeof(ITraceManager)) as ITraceManager;

            try
            {
                IAuthenticationService authenticationService = DependencyResolver.Current.GetService(typeof(IAuthenticationService)) as IAuthenticationService;
                ISecurityContext       securityContext       = DependencyResolver.Current.GetService(typeof(ISecurityContext)) as ISecurityContext;
                ILocalizationManager   localizationManager   = DependencyResolver.Current.GetService(typeof(ILocalizationManager)) as ILocalizationManager;

                if (securityContext == null)
                {
                    traceManager.TraceWarning($"Security context can be retrieve from Unity. Skipping ..");
                    return;
                }

                /*IPrincipal principal = filterContext.HttpContext.User;
                 * ClaimsIdentity identity = principal?.Identity as ClaimsIdentity;
                 * string username = identity?.Name;
                 * if (string.IsNullOrEmpty(username))
                 * {
                 *  traceManager.TraceWarning($"Claim username not found. Skipping ..");
                 *  return;
                 * }*/

                var user = JwtTokenProvider.GetUserModel(filterContext.HttpContext.Request.Cookies["token"].Value);
                securityContext.CurrentUser = new SecurityUser(new User
                {
                    Username  = user.Username,
                    Firstname = user.Firstname,
                    Name      = user.Name,
                    RoleCodes = user.Roles.ToList()
                });
                localizationManager.CurrentCulture = new CultureInfo(JwtTokenProvider.GetUserModelCurrentLanguage(filterContext.HttpContext.Request.Cookies["token"].Value));

                filterContext.Controller.ViewBag.LicenseExpired = Task.Run(() => LicenseMapper.CheckLicenseIsExpired()).Result;

                //Refresh cookie if not idle
                filterContext.HttpContext.Response.SetAuthorizationCookie(user);

                //traceManager.TraceDebug($"Current user set to {username} inside security context");

                base.OnActionExecuting(filterContext);
            }
            catch (Exception ex)
            {
                traceManager.TraceError(ex, $"Error while setting action context...");
            }
        }
Ejemplo n.º 3
0
        public async Task <NotificationManageViewModel> GetNotificationManage(int?type, int?to)
        {
            var notificationTypes = await _notificationService.GetNotificationTypes();

            var model       = NotificationTypeMapper.ToNotificationManageViewModel(notificationTypes, type, to, JwtTokenProvider.GetUserModelCurrentLanguage(Request.Cookies["token"].Value));
            var appSettings = await _prepareService.GetAllAppSettings();

            model.CanSendMail = true;
            try
            {
                model.UseAnonymMode = appSettings.Any(_ => _.Key == "SMTP_UseAnonymMode") ? bool.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_UseAnonymMode").Value)) : false;
                model.SenderEmail   = appSettings.Any(_ => _.Key == "Email_Sender_Address") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "Email_Sender_Address").Value) : string.Empty;
                model.Password      = appSettings.Any(_ => _.Key == "Email_Sender_Password") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "Email_Sender_Password").Value) : string.Empty;
                model.ServerAddress = appSettings.Any(_ => _.Key == "SMTP_Client") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_Client").Value) : string.Empty;
                model.ServerPort    = appSettings.Any(_ => _.Key == "SMTP_Port") ? int.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_Port").Value)) : 25;
                model.UseSSL        = appSettings.Any(_ => _.Key == "SMTP_EnableSsl") ? bool.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_EnableSsl").Value)) : true;
                if (string.IsNullOrEmpty(model.SenderEmail))
                {
                    model.CanSendMail = false;
                }
                else if (!model.UseAnonymMode && string.IsNullOrEmpty(model.Password))
                {
                    model.CanSendMail = false;
                }
                else if (string.IsNullOrEmpty(model.ServerAddress))
                {
                    model.CanSendMail = false;
                }
            }
            catch
            {
                model.CanSendMail = false;
            }
            if (type != null)
            {
                var notifTypeSetting = notificationTypes.SingleOrDefault(nt => (int)nt.NotificationCategory == type.Value)?.NotificationTypeSetting;
                if (notifTypeSetting != null)
                {
                    model.CanSendMail &= !string.IsNullOrEmpty(notifTypeSetting.Recipients);
                }
            }
            return(model);
        }
Ejemplo n.º 4
0
        public static ActionColumnViewModel GetPublishedActionAttributes(
            PublishedAction action,
            object attribute,
            string header,
            string mapping,
            Dictionary <string, string> localizations,
            List <RefsCollection> refCollections,
            List <CustomLabel> customLabel
            )
        {
            var model = new ActionColumnViewModel {
                Values = new List <ActionValueViewModel>()
            };
            var referenceMappingNames = new string[] { "Refs1", "Refs2", "Refs3", "Refs4", "Refs5", "Refs6", "Refs7" };

            if (referenceMappingNames.Contains(mapping))
            {
                switch (mapping)
                {
                case "Refs1":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref1)]));
                    break;

                case "Refs2":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref2)]));
                    break;

                case "Refs3":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref3)]));
                    break;

                case "Refs4":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref4)]));
                    break;

                case "Refs5":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref5)]));
                    break;

                case "Refs6":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref6)]));
                    break;

                case "Refs7":
                    model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref7)]));
                    break;
                }
                return(model);
            }

            switch (mapping)
            {
            case nameof(PublishedAction.Thumbnail):
                model.Values.Add(new ActionValueViewModel
                {
                    Type     = "Image",
                    Value    = action.ThumbnailHash,
                    FileHash = action.ThumbnailHash,
                    FileExt  = action.Thumbnail?.Extension
                });
                break;

            case nameof(ProcessReferentialIdentifier.Skill):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? ((Skill)attribute).Label : ""
                });
                break;

            case nameof(ProcessReferentialIdentifier.Operator):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? ((Operator)attribute).Label : ""
                });
                break;

            case nameof(ProcessReferentialIdentifier.Equipment):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? ((Equipment)attribute).Label : ""
                });
                break;

            case nameof(PublishedAction.PublishedResource):
                model.Values.Add(BuildPublishedResourceFile(action.PublishedResource));
                break;

            case nameof(ProcessReferentialIdentifier.Category):
            case nameof(PublishedAction.PublishedActionCategory):
                model.Values.Add(BuildPublishedActionCategoryFile(action.PublishedActionCategory));
                break;

            case nameof(PublishedAction.Start):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString((long)attribute, action.Publication.TimeScale)
                });
                break;

            case nameof(PublishedAction.Finish):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString((long)attribute, action.Publication.TimeScale)
                });
                break;

            case nameof(PublishedAction.Duration):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString((long)attribute, action.Publication.TimeScale)
                });
                break;

            case nameof(PublishedAction.BuildStart):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString((long)attribute, action.Publication.TimeScale)
                });
                break;

            case nameof(PublishedAction.BuildFinish):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = TicksUtil.TicksToString((long)attribute, action.Publication.TimeScale)
                });
                break;

            case nameof(PublishedAction.Refs1):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref1)]));
                break;

            case nameof(PublishedAction.Refs2):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref2)]));
                break;

            case nameof(PublishedAction.Refs3):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref3)]));
                break;

            case nameof(PublishedAction.Refs4):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref4)]));
                break;

            case nameof(PublishedAction.Refs5):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref5)]));
                break;

            case nameof(PublishedAction.Refs6):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref6)]));
                break;

            case nameof(PublishedAction.Refs7):
                model.Values = BuildPublishedReferentialFile(refCollections.FirstOrDefault(u => u.Label == localizations[nameof(Ref7)]));
                break;

            case nameof(PublishedAction.CustomNumericValue):
            case nameof(PublishedAction.CustomNumericValue2):
            case nameof(PublishedAction.CustomNumericValue3):
            case nameof(PublishedAction.CustomNumericValue4):
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? Convert.ToDecimal(attribute).ToString(CultureInfo.CreateSpecificCulture(JwtTokenProvider.GetUserModelCurrentLanguage(System.Web.HttpContext.Current.Request.Cookies["token"].Value))).TrimEnd('0') : ""
                });
                break;

            default:
                model.Values.Add(new ActionValueViewModel
                {
                    Type  = "Text",
                    Value = attribute != null ? attribute.ToString() : ""
                });
                break;
            }
            return(model);
        }