예제 #1
0
 /// <summary>
 /// creates a new TokenReplace object for custom context
 /// </summary>
 /// <param name="AccessLevel">Security level granted by the calling object</param>
 /// <param name="Language">Locale to be used for formatting etc.</param>
 /// <param name="PortalSettings">PortalSettings to be used</param>
 /// <param name="User">user, for which the properties shall be returned</param>
 /// <param name="ModuleID">ID of the current module</param>
 /// <history>
 ///     08/10/2007    sleupold  documented
 ///     10/19/2007    sleupold  ModuleID added
 /// </history>
 public TokenReplace(Scope AccessLevel, string Language, PortalSettings PortalSettings, UserInfo User, int ModuleID)
 {
     CurrentAccessLevel = AccessLevel;
     if (AccessLevel != Scope.NoSettings)
     {
         if (PortalSettings == null)
         {
             if (HttpContext.Current != null)
             {
                 this.PortalSettings = PortalController.GetCurrentPortalSettings();
             }
         }
         else
         {
             this.PortalSettings = PortalSettings;
         }
         if (User == null)
         {
             if (HttpContext.Current != null)
             {
                 this.User = (UserInfo)HttpContext.Current.Items["UserInfo"];
             }
             else
             {
                 this.User = new UserInfo();
             }
             AccessingUser = this.User;
         }
         else
         {
             this.User = User;
             if (HttpContext.Current != null)
             {
                 AccessingUser = (UserInfo)HttpContext.Current.Items["UserInfo"];
             }
             else
             {
                 AccessingUser = new UserInfo();
             }
         }
         if (string.IsNullOrEmpty(Language))
         {
             this.Language = new Localization.Localization().CurrentUICulture;
         }
         else
         {
             this.Language = Language;
         }
         if (ModuleID != Null.NullInteger)
         {
             ModuleId = ModuleID;
         }
     }
     PropertySource["date"]     = new DateTimePropertyAccess();
     PropertySource["datetime"] = new DateTimePropertyAccess();
     PropertySource["ticks"]    = new TicksPropertyAccess();
     PropertySource["culture"]  = new CulturePropertyAccess();
 }
예제 #2
0
 /// <summary>
 /// creates a new TokenReplace object for custom context
 /// </summary>
 /// <param name="accessLevel">Security level granted by the calling object</param>
 /// <param name="language">Locale to be used for formatting etc.</param>
 /// <param name="portalSettings">PortalSettings to be used</param>
 /// <param name="user">user, for which the properties shall be returned</param>
 /// <param name="moduleID">ID of the current module</param>
 public TokenReplace(Scope accessLevel, string language, PortalSettings portalSettings, UserInfo user, int moduleID)
 {
     ModuleId           = int.MinValue;
     CurrentAccessLevel = accessLevel;
     if (accessLevel != Scope.NoSettings)
     {
         if (portalSettings == null)
         {
             if (HttpContext.Current != null)
             {
                 PortalSettings = PortalController.Instance.GetCurrentPortalSettings();
             }
         }
         else
         {
             PortalSettings = portalSettings;
         }
         if (user == null)
         {
             if (HttpContext.Current != null)
             {
                 User = (UserInfo)HttpContext.Current.Items["UserInfo"];
             }
             else
             {
                 User = new UserInfo();
             }
             AccessingUser = User;
         }
         else
         {
             User = user;
             if (HttpContext.Current != null)
             {
                 AccessingUser = (UserInfo)HttpContext.Current.Items["UserInfo"];
             }
             else
             {
                 AccessingUser = new UserInfo();
             }
         }
         Language = string.IsNullOrEmpty(language) ? new Localization.Localization().CurrentUICulture : language;
         if (moduleID != Null.NullInteger)
         {
             ModuleId = moduleID;
         }
     }
     PropertySource["date"]     = new DateTimePropertyAccess();
     PropertySource["datetime"] = new DateTimePropertyAccess();
     PropertySource["ticks"]    = new TicksPropertyAccess();
     PropertySource["culture"]  = new CulturePropertyAccess();
 }
        public void DateTimePropertyAcccess_GetProperty_Sets_PropertyNotFound(string propertyName, bool expected)
        {
            //Arrange
            var dtPropertyAccess = new DateTimePropertyAccess();
            var accessingUser = new UserInfo {Profile = new UserProfile {PreferredTimeZone = TimeZoneInfo.Local}};


            //Act
            bool propertyNotFound = false;
            string propertyValue = dtPropertyAccess.GetProperty(propertyName, "", CultureInfo.InvariantCulture,
                                                                   accessingUser, Scope.DefaultSettings, ref propertyNotFound);

            //Assert
            Assert.AreEqual(expected, propertyNotFound);
        }
        public void DateTimePropertyAcccess_GetProperty_Adjusts_For_TimeZone(string propertyName, string timeZoneId)
        {
            //Arrange
            var dtPropertyAccess = new DateTimePropertyAccess();
            var userTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
            var timeZoneProfileProperty = new ProfilePropertyDefinition(Constants.PORTAL_Zero)
                                              {
                                                  PropertyName = "PreferredTimeZone",
                                                  PropertyValue = timeZoneId
                                              };
            var userProfile = new UserProfile();
            userProfile.ProfileProperties.Add(timeZoneProfileProperty);

            var accessingUser = new UserInfo { Profile = userProfile };
            var culture = CultureInfo.InvariantCulture;

            string expected = String.Empty;

            switch (propertyName)
            {
                case "current":
                    expected = TimeZoneInfo.ConvertTime(DateTime.Now, userTimeZone).ToString("D", culture);
                    break;
                case "now":
                    expected = TimeZoneInfo.ConvertTime(DateTime.Now, userTimeZone).ToString("g", culture);
                    break;
                case "system":
                    expected = DateTime.Now.ToString("g", culture);
                    break;
                case "utc":
                    expected = DateTime.Now.ToUniversalTime().ToString("g", culture);
                    break;
            }


            //Act
            bool propertyNotFound = false;
            string propertyValue = dtPropertyAccess.GetProperty(propertyName, "", culture,
                                                                   accessingUser, Scope.DefaultSettings, ref propertyNotFound);

            //Assert
            Assert.AreEqual(expected, propertyValue);
        }
         public void DateTimePropertyAcccess_GetProperty_Returns_Correct_String_Given_Format_And_Culture(string propertyName, string cultureName, string format)
         {
             //Arrange
             var dtPropertyAccess = new DateTimePropertyAccess();
             var accessingUser = new UserInfo { Profile = new UserProfile { PreferredTimeZone = TimeZoneInfo.Local } };
             var culture = new CultureInfo(cultureName);


             string expected = String.Empty;

             switch (propertyName)
             {
                 case "current":
                     expected = DateTime.Now.ToString(format, culture);
                     break;
                 case "now":
                     expected = DateTime.Now.ToString(format, culture);
                     break;
                 case "system":
                     expected = DateTime.Now.ToString(format, culture);
                     break;
                 case "utc":
                     expected = DateTime.Now.ToUniversalTime().ToString(format, culture);
                     break;
             }


             //Act
             bool propertyNotFound = false;
             string propertyValue = dtPropertyAccess.GetProperty(propertyName, format, culture,
                                                                    accessingUser, Scope.DefaultSettings, ref propertyNotFound);

             //Assert
             Assert.AreEqual(expected, propertyValue);
         }
 /// <summary>
 /// creates a new TokenReplace object for custom context
 /// </summary>
 /// <param name="AccessLevel">Security level granted by the calling object</param>
 /// <param name="Language">Locale to be used for formatting etc.</param>
 /// <param name="PortalSettings">PortalSettings to be used</param>
 /// <param name="User">user, for which the properties shall be returned</param>
 /// <param name="ModuleID">ID of the current module</param>
 /// <history>
 ///     08/10/2007    sleupold  documented
 ///     10/19/2007    sleupold  ModuleID added
 /// </history>
 public TokenReplace(Scope AccessLevel, string Language, PortalSettings PortalSettings, UserInfo User, int ModuleID)
 {
     CurrentAccessLevel = AccessLevel;
     if (AccessLevel != Scope.NoSettings) {
         if (PortalSettings == null) {
             if (HttpContext.Current != null) {
                 this.PortalSettings = PortalController.GetCurrentPortalSettings();
             }
         } else {
             this.PortalSettings = PortalSettings;
         }
         if (User == null) {
             if (HttpContext.Current != null) {
                 this.User = (UserInfo)HttpContext.Current.Items["UserInfo"];
             } else {
                 this.User = new UserInfo();
             }
             AccessingUser = this.User;
         } else {
             this.User = User;
             if (HttpContext.Current != null) {
                 AccessingUser = (UserInfo)HttpContext.Current.Items["UserInfo"];
             } else {
                 AccessingUser = new UserInfo();
             }
         }
         if (string.IsNullOrEmpty(Language)) {
             this.Language = new Localization.Localization().CurrentUICulture;
         } else {
             this.Language = Language;
         }
         if (ModuleID != Null.NullInteger) {
             ModuleId = ModuleID;
         }
     }
     PropertySource["date"] = new DateTimePropertyAccess();
     PropertySource["datetime"] = new DateTimePropertyAccess();
     PropertySource["ticks"] = new TicksPropertyAccess();
     PropertySource["culture"] = new CulturePropertyAccess();
 }