コード例 #1
0
        public void TestToDynamicObject()
        {
            string json = ResourceStringLoader.LoadString("X3Platform.Tests.defaults.test_json");

            // string json = "{\"id\":\"0001\",\"name\":\"x3platform\",\"age\":5,\"groups\":[0,1,2,3],\"createDate\":\"1970-01-01\"}";

            dynamic obj = JsonMapper.ToDynamicObject(json);

            Assert.AreEqual("0001", obj.id);
            Assert.AreEqual("x3platform", obj.name);
            Assert.AreEqual(true, obj.locking);
            Assert.AreEqual(5, obj.age);
            Assert.AreEqual(null, obj.nullValue);
            Assert.AreEqual("x3", obj.objectValue.name);
            Assert.AreEqual(0, obj.groups[0]);
            Assert.AreEqual(1, obj.groups[1]);
            Assert.AreEqual(2, obj.groups[2]);
            Assert.AreEqual(3, obj.groups[3]);

            string result = AjaxUtil.Parse <dynamic>(obj);

            string result1 = JsonMapper.ToJson(obj);

            Assert.AreEqual("a1", obj.name);

            TestInfo t = new TestInfo();

            t.Id = "a";

            dynamic obj1 = JsonMapper.ToDynamicObject(t);
        }
        /// <summary>
        /// Initialize a new instance of the <see cref="FilteredFileNameEditorAttribute"/> class with the <see cref="Type"/> containing the resources and the resource key.
        /// </summary>
        /// <param name="resourceType">The <see cref="Type"/> containing the resources.</param>
        /// <param name="resourceKey">The resource key.</param>
        public FilteredFileNameEditorAttribute(Type resourceType, string resourceKey)
        {
            if (null == resourceType)
            {
                throw new ArgumentNullException("resourceType");
            }

            this.filter          = ResourceStringLoader.LoadString(resourceType.FullName, resourceKey, resourceType.Assembly);
            this.CheckFileExists = true;
        }
コード例 #3
0
 /// <summary>
 /// Gets the pattern used for building the regular expression.
 /// </summary>
 /// <returns>The regular expression pattern.</returns>
 public string GetPattern()
 {
     if (!string.IsNullOrEmpty(pattern))
     {
         return(pattern);
     }
     else
     {
         return(ResourceStringLoader.LoadString(patternResourceType.FullName, patternResourceName, patternResourceType.Assembly));
     }
 }
        public void TestLoadString()
        {
            // ResourceManager rm = new ResourceManager("X3Platform.Tests.ResourceString", Assembly.GetExecutingAssembly());

            string result = ResourceStringLoader.LoadString("X3Platform.Tests.defaults.test_resources");

            // Assert.IsNotNull(result);

            // result = ResourceStringLoader.LoadString("X3Platform.Tests.I18N", "aa");

            // Assert.IsNotNull(result);
        }
コード例 #5
0
 public static string GetExceptionMessage(string exceptionMessage, string exceptionMessageResourceName, string exceptionMessageResourceType)
 {
     if (!string.IsNullOrEmpty(exceptionMessageResourceName))
     {
         Type resourceType = Type.GetType(exceptionMessageResourceType, false);
         if (null != resourceType)
         {
             exceptionMessage = ResourceStringLoader.LoadString(resourceType.FullName,
                                                                exceptionMessageResourceName,
                                                                resourceType.Assembly);
         }
     }
     return(exceptionMessage);
 }
コード例 #6
0
    internal string GetMessageTemplate()
    {
        if (!string.IsNullOrEmpty(this.MessageTemplate))
        {
            return(this.MessageTemplate);
        }
        Type messageTemplateResourceType = this.GetMessageTemplateResourceType();

        if (messageTemplateResourceType != null)
        {
            return(ResourceStringLoader.LoadString(messageTemplateResourceType.FullName,
                                                   this.MessageTemplateResourceName, messageTemplateResourceType.Assembly));
        }
        return(null);
    }
コード例 #7
0
        public void TestUpload()
        {
            // 测试帐号id
            // string accountId = "52cf89ba-7db5-4e64-9c64-3c868b6e7a99";

            AjaxRequestData reqeustData = new AjaxRequestData();

            reqeustData.ActionUri = new Uri(apiHostPrefix + "/api/attachment.file.upload.aspx");

            var content = ResourceStringLoader.LoadString("X3Platform.AttachmentStorage.Tests.data.api.attachment.upload.json");

            var responseText = AjaxRequest.Request(reqeustData, "POST", "application/x-www-form-urlencoded", content);

            dynamic response = JsonMapper.ToDynamicObject(responseText);

            Assert.AreEqual("0", response["mobileRespHeader"]["respCode"].ToString());
        }
コード例 #8
0
        string IStringResolver.GetString()
        {
            string value;

            if (!(this.resourceType == null || string.IsNullOrEmpty(this.resourceName)))
            {
                value
                    = ResourceStringLoader.LoadString(
                          this.resourceType.FullName,
                          this.resourceName,
                          this.resourceType.Assembly);
            }
            else
            {
                value = this.fallbackValue;
            }
            return(value);
        }
コード例 #9
0
ファイル: Pet.cs プロジェクト: kohku/PetMatch
 protected override void ValidationRules()
 {
     AddRule("EmptyName", ResourceStringLoader.GetResourceString("Pet_EmptyName"),
             string.IsNullOrEmpty(this.Name));
     AddRule("MaxNameLength", ResourceStringLoader.GetResourceString("Pet_MaxNameLength"),
             !string.IsNullOrEmpty(this.Name) && this.Name.Length > 100);
     AddRule("EmptyCreatedBy", ResourceStringLoader.GetResourceString("Pet_EmptyCreatedBy"),
             string.IsNullOrEmpty(this.CreatedBy));
     AddRule("MaxCreatedByLength", ResourceStringLoader.GetResourceString("Pet_MaxCreatedByLength"),
             !string.IsNullOrEmpty(this.CreatedBy) && this.CreatedBy.Length > 256);
     AddRule("DuplicatedName", ResourceStringLoader.GetResourceString("Pet_DuplicatedName", new { this.Name }),
             !string.IsNullOrEmpty(this.Name) && this.ChangedProperties.Contains("Name") &&
             Pet.GetPets(null, this.Name).Count(m => m.ID != this.ID) > 0);
     AddRule("EmptyLastUpdatedBy", ResourceStringLoader.GetResourceString("Pet_EmptyLastUpdatedBy"),
             !this.IsNew && this.IsChanged && string.IsNullOrEmpty(this.LastUpdatedBy));
     AddRule("MaxLastUpdatedByLength", ResourceStringLoader.GetResourceString("Pet_MaxLastUpdatedByLength"),
             !this.IsNew && this.IsChanged && !string.IsNullOrEmpty(this.LastUpdatedBy) && this.LastUpdatedBy.Length > 256);
 }
 /// <summary>
 /// Returns the message template for the represented validator.
 /// </summary>
 /// <remarks>
 /// The textual message is given precedence over the resource based mechanism.
 /// </remarks>
 public string GetMessageTemplate()
 {
     if (null != this.messageTemplate)
     {
         return(this.messageTemplate);
     }
     if (null != this.messageTemplateResourceName && null != this.messageTemplateResourceType)
     {
         return(ResourceStringLoader.LoadString(this.messageTemplateResourceType.FullName,
                                                this.messageTemplateResourceName,
                                                this.messageTemplateResourceType.Assembly));
     }
     if (null != this.messageTemplateResourceName || null != this.messageTemplateResourceType)
     {
         throw new InvalidOperationException(Resources.ExceptionPartiallyDefinedResourceForMessageTemplate);
     }
     return(null);
 }
コード例 #11
0
ファイル: StateEntity.cs プロジェクト: kohku/PetMatch
 protected override void ValidationRules()
 {
     AddRule("EmptyName", ResourceStringLoader.GetResourceString("StateEntity_EmptyName"),
             string.IsNullOrEmpty(this.Name));
     AddRule("MaxNameLength", ResourceStringLoader.GetResourceString("StateEntity_MaxNameLength"),
             !string.IsNullOrEmpty(this.Name) && this.Name.Length > 100);
     AddRule("EmptyCreatedBy", ResourceStringLoader.GetResourceString("StateEntity_EmptyCreatedBy"),
             string.IsNullOrEmpty(this.CreatedBy));
     AddRule("MaxCreatedByLength", ResourceStringLoader.GetResourceString("StateEntity_MaxCreatedByLength"),
             !string.IsNullOrEmpty(this.CreatedBy) && this.CreatedBy.Length > 256);
     AddRule("DuplicatedName", ResourceStringLoader.GetResourceString("StateEntity_DuplicatedName", new { this.Name }),
             !string.IsNullOrEmpty(this.Name) && this.ChangedProperties.Contains("Name") &&
             StateEntity.GetStateEntities(this.Name).Where(m => m.ID != this.ID).Count() > 0);
     AddRule("EmptyLastUpdatedBy", ResourceStringLoader.GetResourceString("StateEntity_EmptyLastUpdatedBy"),
             !this.IsNew && this.IsChanged && string.IsNullOrEmpty(this.LastUpdatedBy));
     AddRule("MaxLastUpdatedByLength", ResourceStringLoader.GetResourceString("StateEntity_MaxLastUpdatedByLength"),
             !this.IsNew && this.IsChanged && !string.IsNullOrEmpty(this.LastUpdatedBy) && this.LastUpdatedBy.Length > 256);
     AddRule("HasConcurrencyConflict", "The item has been already changed or processed. Click on refresh to get latest changes.",
             !this.IsNew && this.HasConcurrencyConflict);
 }
コード例 #12
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="ReplaceHandler"/> based on an instance of <see cref="ReplaceHandlerData"/>.
        /// </summary>
        /// <seealso cref="ExceptionHandlerCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="ReplaceHandlerData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="ReplaceHandler"/>.</returns>
        public IExceptionHandler Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ReplaceHandlerData castedObjectConfiguration
                = (ReplaceHandlerData)objectConfiguration;

            string exceptionMessage = castedObjectConfiguration.ExceptionMessage;

            if (!string.IsNullOrEmpty(castedObjectConfiguration.ExceptionMessageResourceName))
            {
                Type exceptionMessageResourceType = Type.GetType(castedObjectConfiguration.ExceptionMessageResourceType, false);

                if (null != exceptionMessageResourceType)
                {
                    exceptionMessage = ResourceStringLoader.LoadString(exceptionMessageResourceType.FullName,
                                                                       castedObjectConfiguration.ExceptionMessageResourceName,
                                                                       exceptionMessageResourceType.Assembly);
                }
            }

            ReplaceHandler createdObject
                = new ReplaceHandler(exceptionMessage, castedObjectConfiguration.ReplaceExceptionType);

            return(createdObject);
        }
コード例 #13
0
 /// <summary>
 /// Gets the localized string based on the key.
 /// </summary>
 /// <param name="value">The key to the string resources.</param>
 /// <returns>The localized string.</returns>
 protected override string GetLocalizedString(string value)
 {
     return(ResourceStringLoader.LoadString(resourceType.FullName, value, resourceType.Assembly));
 }
コード例 #14
0
        public void CanLoadStringFromCallingAssembly()
        {
            string value = ResourceStringLoader.LoadString(typeof(Resources).FullName, "Test");

            Assert.AreEqual("Test", value);
        }
コード例 #15
0
ファイル: FormatValidator.cs プロジェクト: AuthorProxy/QP
 /// <summary>
 /// Gets the pattern used for building the regular expression.
 /// </summary>
 /// <returns>The regular expression pattern.</returns>
 public string GetPattern() => !string.IsNullOrEmpty(Pattern)
     ? Pattern
     : ResourceStringLoader.LoadString(PatternResourceType.FullName, PatternResourceName, PatternResourceType.Assembly);
コード例 #16
0
 public void ExcutingLoadStringWithNullResourceNameThrows()
 {
     ResourceStringLoader.LoadString("Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Properties.Resources", null);
 }
コード例 #17
0
 public void ExcutingLoadStringWithNullBaseNameThrows()
 {
     ResourceStringLoader.LoadString(null, "ValidationCaption");
 }
コード例 #18
0
        public void CanLoadStringFromExecutingAssembly()
        {
            string value = ResourceStringLoader.LoadString("Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Properties.Resources", "ValidationCaption");

            Assert.AreEqual("Validation", value);
        }