Пример #1
0
        public static UploadFileInfo[] Upload(UserConfiguration userConfig, HTTP.FileContentData[] fileContentDatas)
        {
            if (userConfig != null)
            {
                Uri apiHost = ApiConfiguration.AuthenticationApiHost;

                string url = new Uri(apiHost, "files/upload/index.php").ToString();

                var postDatas = new NameValueCollection();
                postDatas["token"] = userConfig.SessionToken;
                postDatas["sender_id"] = UserManagement.SenderId.Get();

                var httpInfo = new HTTP.HTTPInfo();
                httpInfo.Url = url;
                httpInfo.ContentData = HTTP.PostContentData.FromNamedValueCollection(postDatas);
                httpInfo.FileData = fileContentDatas;

                string response = HTTP.POST(httpInfo);
                if (response != null)
                {
                    bool success = ApiError.ProcessResponse(response, "Upload File");
                    if (success)
                    {
                        var uploadFileInfos = JSON.ToType<List<UploadFileInfo>>(response);
                        if (uploadFileInfos != null)
                        {
                            return uploadFileInfos.ToArray();
                        }
                    }
                }
            }

            return null;
        }
Пример #2
0
        public static List<MessageInfo> Get(UserConfiguration userConfig, List<string> messageIds)
        {
            Uri apiHost = ApiConfiguration.AuthenticationApiHost;

            string url = new Uri(apiHost, "messages/get/index.php").ToString();

            string format = "{0}?token={1}&sender_id={2}{3}";

            string token = userConfig.SessionToken;
            string senderId = UserManagement.SenderId.Get();
            string devices = "";

            // List Message IDs to Get
            // If no Messages are listed then ALL Messages are retrieved
            if (messageIds != null)
            {
                string json = JSON.FromList<string>(messageIds);
                if (!string.IsNullOrEmpty(json))
                {
                    devices = "messages=" + json;
                }
            }

            url = string.Format(format, url, token, senderId, devices);

            var httpInfo = new HTTP.HTTPInfo();
            httpInfo.Url = url;
            httpInfo.MaxAttempts = 1;

            string response = HTTP.GET(httpInfo);
            if (response != null)
            {
                bool success = ApiError.ProcessResponse(response, "Get Messages");
                if (success)
                {
                    var messageInfos = JSON.ToType<List<MessageInfo>>(response);
                    if (messageInfos != null)
                    {
                        return messageInfos;
                    }
                }
            }

            return null;
        }
Пример #3
0
        private static void SendData(object o)
        {
            if (o != null)
            {
                var info = (SendDataInfo)o;

                var httpInfo = new HTTP.HTTPInfo();
                httpInfo.Url = info.Url;
                httpInfo.ContentData = HTTP.PostContentData.FromNamedValueCollection(info.Values);
                httpInfo.MaxAttempts = 2;
                httpInfo.Timeout = 2000;

                string response = HTTP.POST(httpInfo);
                if (!string.IsNullOrEmpty(response))
                {
                    ApiError.ProcessResponse(response, "Update Cloud Data : " + info.Url + " @ " + DateTime.Now.ToLongTimeString());
                }
            }
        }
Пример #4
0
        public static List<DeviceInfo> Get(UserConfiguration userConfig, List<string> uniqueIds, DateTime from, DateTime to, int timeout, string command)
        {
            Uri apiHost = ApiConfiguration.DataApiHost;

            string url = new Uri(apiHost, "data/get/index.php").ToString();

            string times = "&from=" + from.ToString("o") + "&to=" + to.ToString("o");

            string devices = "";

            // List Devices to Get data for
            // If no devices are listed then ALL devices are retrieved
            if (uniqueIds != null && uniqueIds.Count > 0)
            {
                var deviceItems = new List<DeviceListItem>();

                foreach (var uniqueId in uniqueIds) deviceItems.Add(new DeviceListItem(uniqueId));

                string json = JSON.FromList<DeviceListItem>(deviceItems);
                if (!string.IsNullOrEmpty(json))
                {
                    devices = "&devices=" + json;
                }
            }

            string cmd = "";
            if (command != null) cmd = "&command=" +command;

            // Create GET request parameters
            if (userConfig != null)
            {
                string format = "{0}?token={1}&sender_id={2}{3}{4}{5}";

                string token = userConfig.SessionToken;
                string senderId = UserManagement.SenderId.Get();

                url = string.Format(format, url, token, senderId, devices, cmd, times);
            }
            else
            {
                string format = "{0}?{1}{2}{3}";
                url = string.Format(format, url, devices, cmd, times);
            }

            // Setup HTTP Information for GET request
            var httpInfo = new HTTP.HTTPInfo();
            httpInfo.Url = url;
            httpInfo.Timeout = timeout;
            httpInfo.MaxAttempts = 1;

            string response = HTTP.GET(httpInfo);
            if (response != null)
            {
                bool success = ApiError.ProcessResponse(response, "Get Device Data");
                if (success)
                {
                    var deviceInfos = JSON.ToType<List<DeviceInfo>>(response);
                    if (deviceInfos != null)
                    {
                        return deviceInfos;
                    }
                }
            }

            return null;
        }