예제 #1
0
파일: NodeUri.cs 프로젝트: helios-io/helios
 public static INode GetNodeFromUri(Uri uri)
 {
     uri.NotNull();
     var transport = TransportType.All;
     Enum.TryParse(uri.Scheme, true, out transport);
     return NodeBuilder.BuildNode().Host(uri.Host).WithPort(uri.Port).WithTransportType(transport);
 }
예제 #2
0
        /// <summary>
        /// 初始化一个新的代理请求模型。
        /// </summary>
        /// <param name="uri">代理Uri(绝对的Url地址)。</param>
        /// <param name="retryCount">重试次数。</param>
        /// <param name="timeout">每次请求超时时间(毫秒)。</param>
        public AgentRequestModel(Uri uri, ushort retryCount = 3, ushort timeout = 5000)
        {
            uri.NotNull("uri");

            if (!uri.IsAbsoluteUri || !uri.Scheme.Equals("http"))
                throw new ArgumentException("代理Uri必需是一个绝对的Url地址。", "uri");

            if (timeout == 0)
                throw new ArgumentOutOfRangeException("timeout", timeout, "每次请求超时时间不能小于0毫秒。");

            Timeout = timeout;
            RetryCount = retryCount;
            Uri = uri;
        }
예제 #3
0
 public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator)
 {
     Data.Collection result = new Data.Collection(data, type);
     Reflect.Type elementType = this.GetElementType(type);
     int c = 0;
     foreach (object child in data as System.Collections.IEnumerable)
     {
         Uri.Locator l = null;
         if (locator.NotNull())
         {
             l = locator.Copy();
             l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + (c++).ToString();
         }
         result.Nodes.Add(storage.Serialize(elementType, child, l));
     }
     return result;
 }
예제 #4
0
파일: Class.cs 프로젝트: imintsystems/Kean
 public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator resource)
 {
     Data.Node result;
     Uri.Locator l = storage.Resolver.Update(data, resource);
     if (l.NotNull())
         result = new Data.Link(l);
     else
     {
         result = new Data.Branch(data, type);
         foreach (Reflect.Property property in data.GetProperties())
         {
             ParameterAttribute[] attributes = property.GetAttributes<ParameterAttribute>();
             if (attributes.Length == 1 && property.Data.NotNull())
             {
                 string name = attributes[0].Name ?? property.Name.Convert(Casing.Pascal, storage.Casing);
                 if (resource.NotNull())
                 {
                     l = resource.Copy();
                     l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + name;
                 }
                 (result as Data.Branch).Nodes.Add(storage.Serialize(property.Type, property.Data, l).UpdateName(name).UpdateAttribute(attributes[0]).UpdateLocator(resource));
             }
         }
     }
     return result;
 }