Exemple #1
0
        public List <Notification> GetNotifications()
        {
            var url      = _visUrl + string.Format("/getNotification");
            var response = WebRequestHelper.Get(url);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <List <Notification> >(response.Body));
            }

            return(null);
        }
Exemple #2
0
        public List <VisSubscriptionObject> GetSubscriptions(string dataId)
        {
            var url      = _visUrl + string.Format("/subscription?dataId={0}", Uri.EscapeDataString(dataId ?? string.Empty));
            var response = WebRequestHelper.Get(url);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <List <VisSubscriptionObject> >(response.Body));
            }

            return(new List <VisSubscriptionObject>());
        }
Exemple #3
0
        public Model.CloudDisk.CloudFileInfoModel GetCloudFileInfo(string remotePath)
        {
            try
            {
                string           url    = "https://api.weipan.cn/2/metadata/sandbox";
                WebRequestHelper helper = new WebRequestHelper(url);
                var result           = helper.Get(url + remotePath + "?access_token=" + _accessToken);
                CloudFileInfoModel m = new CloudFileInfoModel();
                var fileInfo         = JsonHelper.DeserializeObject <SinaResponseFileInfoJsonEntity>(result);

                m.Bytes            = Convert.ToDouble(fileInfo.bytes);
                m.DiskType         = CloudDiskType.SINA;
                m.Path             = fileInfo.path;
                m.IsDir            = Convert.ToBoolean(fileInfo.is_dir);
                m.LastModifiedDate = Convert.ToDateTime(fileInfo.modified);
                m.MD5  = fileInfo.md5;
                m.SHA1 = fileInfo.sha1;
                if (fileInfo.contents != null)
                {
                    m.Contents = new List <CloudFileInfoModel>();
                    foreach (var oneDir in fileInfo.contents)
                    {
                        CloudFileInfoModel subDir = new CloudFileInfoModel();
                        subDir.Bytes            = Convert.ToDouble(oneDir.bytes);
                        subDir.Path             = oneDir.path;
                        subDir.IsDir            = Convert.ToBoolean(oneDir.is_dir);
                        subDir.LastModifiedDate = Convert.ToDateTime(oneDir.modified);
                        subDir.MD5  = oneDir.md5;
                        subDir.SHA1 = oneDir.sha1;

                        m.Contents.Add(subDir);
                    }
                }

                return(m);
            }
            catch (System.Net.WebException webEx)
            {
                HttpWebResponse errorResponse = webEx.Response as HttpWebResponse;
                if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    //
                    return(null);
                }
                //webEx.Status == System.Net.WebExceptionStatus.CacheEntryNotFound
                //throw webEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
        public virtual CallServiceResponseObj CallService(CallServiceRequestObj data)
        {
            var result = new CallServiceResponseObj();

            var url = data.EndpointMethod;

            log.Info(string.Format("Sending REST request to service: {0} {1}", data.RequestType, url));

            string headers          = string.Empty;
            var    headerCollection = new WebHeaderCollection();

            if (data.Headers != null)
            {
                foreach (var h in data.Headers)
                {
                    headers += h + " ";
                    headerCollection.Add(h.Key, h.Value);
                }
            }

            log.Info(string.Format("- using headers: {0}", headers));

            WebRequestHelper.WebResponse response = null;

            if (data.RequestType == "GET")
            {
                response = WebRequestHelper.Get(url, headerCollection, true);
            }
            else if (data.RequestType == "POST")
            {
                response = WebRequestHelper.Post(url, data.Body, headerCollection, true);
            }
            else if (data.RequestType == "DELETE")
            {
                response = WebRequestHelper.Delete(url, data.Body, headerCollection, true);
            }
            else if (data.RequestType == "PUT")
            {
                response = WebRequestHelper.Put(url, data.Body, headerCollection, true);
            }
            else
            {
                throw new Exception(string.Format("The request type {0} is not supported.", data.RequestType));
            }

            result.Body       = response.Body;
            result.StatusCode = (int)response.HttpStatusCode;
            return(result);
        }
Exemple #5
0
        public Model.CloudDisk.CloudFileInfoModel GetCloudFileInfo(string remotePath)
        {
            string url = "http://bcs.duapp.com/" + _bucketName;
            //if (remotePath == "/" || string.IsNullOrEmpty(remotePath))
            //{

            //}
            //else
            //{
            //    url += remotePath;
            //}
            string flag    = "MBO";
            string para    = "?sign=" + flag + ":" + _appKey + ":";
            string content = flag + "\n"
                             + "Method=GET" + "\n"
                             + "Bucket=" + _bucketName + "\n"
                             + "Object=/" + "\n";
            //+ "Object=" + remotePath + "\n";
            string sign = BaiduSignatureHelper.GetSignature(content, _appSecret);

            para = para + sign;
            WebRequestHelper helper = new WebRequestHelper(url);

            url = url + para;
            var           result = helper.Get(url);
            BaiduFileInfo info   = JsonHelper.DeserializeObject <BaiduFileInfo>(result);

            CloudFileInfoModel m = null;

            if (info != null)
            {
                foreach (BaiduObjectList obj in info.object_list)
                {
                    if (obj.Object == remotePath)
                    {
                        m       = new CloudFileInfoModel();
                        m.Bytes = Convert.ToDouble(obj.size);
                        m.IsDir = obj.is_dir == "1";
                        m.Path  = obj.Object;
                        m.MD5   = obj.content_md5;

                        break;
                    }
                }
            }
            return(m);
        }
        public WebRequestHelper.WebResponse MakeGenericCall(string url, string method, string body = null, WebHeaderCollection headers = null)
        {
            log.Info("Make generic call to ServiceRegistry");

            WebRequestHelper.WebResponse response = null;

            url = serviceRegistryBasePath + url;
            if (method == "GET")
            {
                response = WebRequestHelper.Get(url, headers, false);
            }
            else if (method == "POST")
            {
                response = WebRequestHelper.Post(url, body, headers: headers, UseCertificate: false);
            }

            return(response);
        }
Exemple #7
0
        public SingleCloudDiskCapacityModel GetCloudDiskCapacityInfo()
        {
            /*
             * string url = "https://pcs.baidu.com/rest/2.0/pcs/quota";
             * string para = "?method=info&access_token=" + _accessToken;
             * SingleCloudDiskCapacityModel m = new SingleCloudDiskCapacityModel();
             * WebRequestHelper helper = new WebRequestHelper(url);
             * var result = helper.Get(url + para);
             * XmlNode node = JsonHelper.DeserializeToXmlNode(result);
             * m.TotalByte = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("quota").InnerText);
             * var comsumed = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("used").InnerText);
             * m.TotalAvailableByte = m.TotalByte - comsumed;
             * return m;*/
            string url     = "http://bcs.duapp.com/?";
            string flag    = "MBO";
            string para    = "sign=" + flag + ":" + _appKey + ":";
            string content = flag + "\n"
                             + "Method=GET" + "\n"
                             + "Bucket=" + "\n"
                             + "Object=/" + "\n";
            string sign = BaiduSignatureHelper.GetSignature(content, _appSecret);

            para = para + sign;
            WebRequestHelper helper = new WebRequestHelper(url);
            var result = helper.Get(url + para);
            List <BaiduBucketInfo>       info = JsonHelper.DeserializeObject <List <BaiduBucketInfo> >(result);
            SingleCloudDiskCapacityModel m    = new SingleCloudDiskCapacityModel();

            if (info != null)
            {
                foreach (BaiduBucketInfo one in info)
                {
                    if (one.bucket_name == _bucketName)
                    {
                        m.TotalByte = Convert.ToDouble(info[0].total_capacity);
                        var comsumed = Convert.ToDouble(info[0].used_capacity);
                        m.TotalAvailableByte = m.TotalByte - comsumed;
                    }
                }
            }

            return(m);
        }
Exemple #8
0
 public Model.CloudDisk.SingleCloudDiskCapacityModel GetCloudDiskCapacityInfo()
 {
     try
     {
         string url = "https://api.weipan.cn/2/account/info";
         SingleCloudDiskCapacityModel m      = new SingleCloudDiskCapacityModel();
         WebRequestHelper             helper = new WebRequestHelper(url);
         var     result = helper.Get(url + "?access_token=" + _accessToken);
         XmlNode node   = JsonHelper.DeserializeToXmlNode(result);
         m.TotalByte = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("quota_info").SelectSingleNode("quota").InnerText);
         var comsumed = Convert.ToDouble(node.ChildNodes[0].SelectSingleNode("quota_info").SelectSingleNode("consumed").InnerText);
         m.TotalAvailableByte = m.TotalByte - comsumed;
         return(m);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public List <Organization> FindIdentties()
        {
            var result = new List <Organization>();

            var url      = _spisUrl + string.Format("/findIdentities");
            var response = WebRequestHelper.Get(url);

            var responseObj = JsonConvert.DeserializeObject <FindIdentitiesResponseObj>(response.Body);

            if (response.HttpStatusCode == HttpStatusCode.OK &&
                !string.IsNullOrEmpty(response.Body) &&
                response.Body.Length > 35)
            {
                foreach (var org in responseObj.Organizations)
                {
                    result.Add(org);
                }
            }

            return(result);
        }
        public WebRequestHelper.WebResponse MakeGenericCall(string url, string method, string body = null, WebHeaderCollection headers = null)
        {
            log.Info("Make generic call to IdentityRegistry");

            WebRequestHelper.WebResponse response = null;

            url = idRegistryBaseUrl + url;
            if (method == "GET")
            {
                response = WebRequestHelper.Get(url, headers, true);
            }
            else if (method == "POST")
            {
                response = WebRequestHelper.Post(url, body, headers: headers, UseCertificate: true);
            }

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new WebException(response.ErrorMessage);
            }

            return(response);
        }
        /// <summary>
        /// 通过OpenID获取微信用户信息
        /// </summary>
        /// <returns></returns>
        private WXUserInfo GetUserInfo(string openid, string ACCESS_TOKEN)
        {
            try
            {
                WxData data = new WxData();
                data.SetValue("access_token", ACCESS_TOKEN);
                data.SetValue("openid", openid);
                data.SetValue("lang", "zh_CN");
                string url = "https://api.weixin.qq.com/cgi-bin/user/info?" + data.ToUrl();

                //请求url以获取数据
                string result = WebRequestHelper.Get(url);
                //保存用户信息
                WXUserInfo wxuserinfo = JsonConvert.DeserializeObject <WXUserInfo>(result);
                DAL.Log.Instance.Write("请求:" + data.ToUrl() + ",返回:" + result, "获取微信用户信息");
                return(wxuserinfo);
            }
            catch (Exception ex)
            {
                DAL.Log.Instance.Write(ex.ToString(), "获取微信用户信息错误");
                throw new Exception(ex.ToString());
            }
        }
        public MessageEnvelope GetMessages(string dataId, int limitQuery, DateTime?fromTime, DateTime?toTime)
        {
            string url = string.Empty;

            if (fromTime == null)
            {
                url = _spisUrl + string.Format("/getMessage?limitQuery={0}&dataId={1}", limitQuery, Uri.EscapeDataString(dataId ?? string.Empty));
            }
            else
            {
                if (toTime == null)
                {
                    toTime = DateTime.MaxValue;
                }

                url = _spisUrl + string.Format("/getMessageInTimeIntervall?limitQuery={0}&dataId={1}&fromDate={2}&toDate={3}",
                                               limitQuery, Uri.EscapeDataString(dataId ?? string.Empty),
                                               Uri.EscapeDataString(fromTime.Value.ToString("yyyy-MM-dd HH:mm:ss")),
                                               Uri.EscapeDataString(toTime.Value.ToString("yyyy-MM-dd HH:mm:ss")));
            }

            var response = WebRequestHelper.Get(url);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                var deserializeSetting = new JsonSerializerSettings()
                {
                    DateFormatHandling = DateFormatHandling.IsoDateFormat,
                    NullValueHandling  = NullValueHandling.Include
                };
                var result = JsonConvert.DeserializeObject <MessageEnvelope>(response.Body, deserializeSetting);
                return(result);
            }

            MessageBox.Show(response.HttpStatusCode + " " + response.ErrorMessage);
            return(null);
        }
Exemple #13
0
        public ActionResult GetChartData()
        {
            DateTime      today        = DateTime.Today;
            JsonReturnObj jsonReturn   = new JsonReturnObj();
            List <string> hometownList = new List <string>()
            {
                //"Johor",
                //"Kedah",
                //"Kelantan",
                "Kuala Lumpur",
                "Labuan",
                //"Melaka",
                //"Negeri Sembilan",
                //"Pahang",
                //"Penang",
                //"Perak",
                //"Perlis",
                "Putrajaya",
                "Sabah",
                "Sarawak",
                //"Selangor",
                //"Terengganu"
            };

            try
            {
                //Get App Token
                string     appTokenURL  = $"https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET}&grant_type=client_credentials";
                FBAppToken appTokenObj  = JsonConvert.DeserializeObject <FBAppToken>(WebRequestHelper.Get(appTokenURL));
                string     access_token = appTokenObj.AccessToken;

                //Get list of test users
                string testUserURL         = $"https://graph.facebook.com/v3.2/{APP_ID}/accounts/test-users?access_token={access_token}";
                string testUsersJson       = WebRequestHelper.Get(testUserURL);
                TestUserQueryResult result = JsonConvert.DeserializeObject <TestUserQueryResult>(testUsersJson);
                if (result.Error != null)
                {
                    throw new Exception(result.Error);
                }

                //Get list of test users profile
                Random rnd = new Random();
                List <TestUserProfile> userProfileList = new List <TestUserProfile>();
                foreach (TestUser user in result.TestUserList)
                {
                    string          profileURL  = $"https://graph.facebook.com/v3.2/{user.Id}/?fields=id,name,birthday,gender,hometown&access_token={user.AccessToken}";
                    TestUserProfile userProfile = JsonConvert.DeserializeObject <TestUserProfile>(WebRequestHelper.Get(profileURL));

                    char[] genderCharArray = userProfile.Gender.ToCharArray();
                    genderCharArray[0] = char.ToUpper(genderCharArray[0]);
                    userProfile.Gender = new string(genderCharArray);

                    DateTime birthday = DateTime.ParseExact(userProfile.Birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    userProfile.BirthdayMYFormat = birthday.ToString("dd/MM/yyyy");
                    userProfile.Hometown         = hometownList[rnd.Next(hometownList.Count)];
                    userProfileList.Add(userProfile);
                }

                //Populate JSON data for barchart
                BarChartData   barChartData   = GetBarChartDataFromUserProfileList(userProfileList, today);
                RadarChartData radarChartData = GetRadarChartDataFromUserProfileList(userProfileList, hometownList);

                jsonReturn.BarChartData   = barChartData;
                jsonReturn.RadarChartData = radarChartData;

                jsonReturn.IsSuccess = true;
            }
            catch (Exception ex)
            {
                jsonReturn.IsSuccess = false;
                jsonReturn.ErrorMsg  = ex.Message;
            }
            return(Json(jsonReturn, "application/json"));
        }