public void T()
        {
            var httpConnect = new HttpConnect();
            var response    = httpConnect.InvokeAsync <HelloResponse>(HttpMethod.Get, "http://127.0.0.1:8088/hello/Mark").Result;

            //Assert.AreEqual();
        }
예제 #2
0
        /// <summary>
        /// 代为向服务器发起一次从属关系查询。
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public BelongRelation BelongQuery(string type, string id)
        {
            var param = new Dictionary <string, string>()
            {
                { "type", type },
                { "id", id }
            };
            HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/belong"), "GET", param: param);

            con.authentication = authentication;
            con.Connect();
            if (con.status == HttpStatusCode.OK)
            {
                JObject jo = JObject.Parse(con.response);
                if (jo["relation"] != null)
                {
                    var relation = jo["relation"].ToString();
                    switch (relation)
                    {
                    case "other": return(BelongRelation.Other);

                    case "self": return(BelongRelation.Self);

                    case "sub": return(BelongRelation.Sub);

                    case "parent": return(BelongRelation.Parent);

                    case "manager": return(BelongRelation.Manager);

                    default: return(BelongRelation.None);
                    }
                }
            }
            return(BelongRelation.None);
        }
예제 #3
0
 protected override void Thread_Looping()
 {
     base.Thread_Looping();
     if (pathcheckEnumerator.MoveNext())
     {
         string      path        = pathcheckEnumerator.Current;
         HttpConnect httpconnect = new HttpConnect(path);
         bool        isLegal     = false;
         bool        isOver      = false;
         httpconnect.CheckResource(delegate(bool result, object obj)
         {
             isOver  = true;
             isLegal = result;
             if (!isLegal)
             {
                 AppendMissionLog(obj.ToString());
             }
         });
         while (!isOver)
         {
         }
         resourceFinished++;
         if (isLegal)
         {
             resourceSucceed++;
         }
         SetMissionProgress((resourceFinished) / ((float)pathToCheckCollection.Count));
     }
     else
     {
         AppendMissionLog(string.Format("共检查{0}项配置文件中的{1}项资源,其中{2}项资源访问出错", configDic.Count, resourceFinished, resourceFinished - resourceSucceed));
         EndMissionThread();
     }
 }
예제 #4
0
 static void Main(String[] args)
 {
     try
     {
         HttpConnect myHttpConnect = new HttpConnect();
         // If the Uri is valid  then 'ConnectHttpServer' method will connect to the server.
         myHttpConnect.ConnectHttpServer("www.contoso.com");
     }
     catch (WebException e)
     {
         Console.WriteLine("\nThe New Message is:" + e.Message);
     }
 }
        /// <summary>
        /// 登陆指令。
        /// </summary>
        public void DoLogin()
        {
            SetLoginOperate(true);
            var username = UsernameTxt.Text;
            var password = PasswordTxt.Password;

            Task.Run(() => {
                OptionClass option = OptionClass.Get();
                JObject loginjson  = new JObject();
                loginjson.Add("username", new JValue(username));
                loginjson.Add("password", new JValue(password));
                HttpConnect con = new HttpConnect(option.GetURL(""), "POST", username: username, password: password, data: loginjson.ToString());
                con.Connect();
                var code = con.status;
                Content.Dispatcher.Invoke(() => {
                    if (code == HttpStatusCode.OK)
                    {
                        //登陆成功
                        //需要将相关信息写入option。
                        //仅在登陆成功时写入记住密码/自动登录/用户名/密码。
                        option.Username       = username;
                        option.RememberPasswd = RememberPasswd.IsChecked ?? false;
                        if (option.RememberPasswd)
                        {
                            option.AutoLogin = AutoLogin.IsChecked ?? false;
                            option.Password  = password;
                        }
                        option.WriteToConfig();
                        User user           = User.Get();
                        user.authentication = new Auth(con.authentication.username, con.authentication.password);
                        NavigateToMain();
                    }
                    else if (code == HttpStatusCode.Unauthorized)
                    {
                        SetNotice("非法账户或者错误的登录信息");
                        SetLoginOperate(false);
                    }
                    else
                    {
                        SetNotice(con.response);
                        SetLoginOperate(false);
                    }
                });
            });
        }
 /// <summary>
 /// 检执行UI操作,查对服务器的链接。
 /// </summary>
 public void CheckConnection()
 {
     SetContent(ContentStatus.Connecting);
     Task.Run(() => {
         OptionClass option = OptionClass.Get();
         HttpConnect con    = new HttpConnect(option.GetURL(""), "GET");
         con.Connect();
         var code = con.status;
         Content.Dispatcher.Invoke(() => {
             if (code == HttpStatusCode.OK)
             {
                 SetContent(ContentStatus.Login);
             }
             else
             {
                 SetContent(ContentStatus.Disconnect);
             }
         });
     });
 }
예제 #7
0
        public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs)
        {
            HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/schedule"), "GET");

            con.Connect();
            if (con.status == System.Net.HttpStatusCode.OK)
            {
                var     response = con.response;
                JObject data     = JObject.Parse(response);
                TimeRange.Text = string.Format("执行时间:{0} - {1}", data["begin"].ToString(), data["end"].ToString());
                JArray items = data["items"] as JArray;
                foreach (var i in items)
                {
                    Tuple <int, string, string> itemdata = new Tuple <int, string, string>(int.Parse(i["no"].ToString()), i["begin"].ToString(), i["end"].ToString());
                    var ctrl = new schedule_timeitem();
                    ctrl.Height  = 60;
                    ctrl.content = itemdata;
                    TimeList.Children.Add(ctrl);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 更新权限信息。如果无法连接无服务器,则会返回异常状态码。
        /// </summary>
        /// <returns></returns>
        public HttpStatusCode UpdateAuthority()
        {
            HttpConnect con = new HttpConnect(OptionClass.Get().GetURL("action/self-authority"), "GET");

            con.authentication = authentication;
            con.Connect();
            if (con.status == HttpStatusCode.OK)
            {
                authority.Clear();
                JObject jo = JObject.Parse(con.response);
                if (jo["auth"] != null)
                {
                    var authnumber = long.Parse((jo["auth"] as JValue).Value.ToString());
                    foreach (var i in AuthorityItem.getAuthorityArray(authnumber))
                    {
                        authority.Add(i);
                    }
                }
            }
            return(con.status);
        }
예제 #9
0
 static void Main()
 {
     try
     {
         Console.WriteLine("Please give any Intranet Site Address (eg:manjeera.wipro.com)");
         String      uriConnect    = Console.ReadLine();
         HttpConnect myHttpConnect = new HttpConnect();
         myHttpConnect.ConnectHttpServer(uriConnect);
     }
     catch (WebException e)
     {
         Console.WriteLine("\nThe  WebException is :" + e.Message);
         Console.WriteLine("\nThe status of the WebException is :" + e.Status);
         Console.WriteLine("\nThe Inner Exception is :'" + e.InnerException + "'");
         Console.WriteLine("\nThe Web Response is:\n");
         StreamReader readStream = new StreamReader(e.Response.GetResponseStream());
         Console.WriteLine(readStream.ReadToEnd());
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
예제 #10
0
 public UpdataTask() 
 {
     hc = new HttpConnect();
     dop = new DataOper(); 
 }
예제 #11
0
 public Presenter()
 {
     hc  = new HttpConnect();
     gdb = new GetDB();
 }