Exemplo n.º 1
0
        public static List <UserGroup> GetUserGroups(string ticket)
        {
            if (string.IsNullOrWhiteSpace(ticket))
            {
                throw new ArgumentNullException("ticket");
            }

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var request        = string.Format("ticket={0}", ticket);
            var response       = new RestServiceAgent().SendPostRequest(string.Format("{0}/{1}", restServiceUrl, "getUserGroups"), request);

            //Deserialize json response
            var jsonReader     = new JsonTextReader(new StringReader(response));
            var jObject        = JObject.Load(jsonReader);
            var jsonSerializer = new JsonSerializer();
            var responseObject = (GetUserGroupsResponse)jsonSerializer.Deserialize(new JTokenReader(jObject), typeof(GetUserGroupsResponse));

            if (responseObject.res == "ok")
            {
                return(responseObject.groups);
            }
            else
            {
                throw new RestResponseException(responseObject.errorDesc);
            }
        }
Exemplo n.º 2
0
        public static string Login(Credentials credentials)
        {
            if (!credentials.ContainCredententials())
            {
                throw new ArgumentException("Invalid credentials");
            }

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var request        = string.Format("emailAddress={0}&password={1}", credentials.UserName, credentials.Password);
            var response       = new RestServiceAgent().SendPostRequest(string.Format("{0}/{1}", restServiceUrl, "login"), request);

            //Deserialize json response
            var jsonReader     = new JsonTextReader(new StringReader(response));
            var jObject        = JObject.Load(jsonReader);
            var jsonSerializer = new JsonSerializer();
            var responseObject = (LoginResponse)jsonSerializer.Deserialize(new JTokenReader(jObject), typeof(LoginResponse));

            if (responseObject.res == "ok")
            {
                return(responseObject.ticket);
            }
            else
            {
                throw new RestResponseException(responseObject.errorDesc);
            }
        }
Exemplo n.º 3
0
        public static FileUpload UploadFile(string ticket, string groupId, string folderId,
                                            string fileId, FileInfo fileInfo, bool saveAsNewVersion)
        {
            if (string.IsNullOrWhiteSpace(ticket))
            {
                throw new ArgumentNullException("ticket");
            }

            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException("groupId");
            }

            if (string.IsNullOrWhiteSpace(folderId))
            {
                throw new ArgumentNullException("folderId");
            }

            if (IsFileLocked(fileInfo))
            {
                throw new ArgumentException("fileInfo");
            }

            var requestParams = new Dictionary <string, string>();

            requestParams.Add("ticket", ticket);
            requestParams.Add("groupId", groupId);
            requestParams.Add("folderId", folderId);
            requestParams.Add("versionId", fileId);
            requestParams.Add("filename", fileInfo.Name);
            requestParams.Add("newVersion", saveAsNewVersion.ToString());

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var response       = new RestServiceAgent().SendPostRequest(string.Format("{0}/{1}", restServiceUrl, "fileUpload"),
                                                                        requestParams, fileInfo, "file");

            //Deserialize json response
            var jsonReader         = new JsonTextReader(new StringReader(response));
            var jObject            = JObject.Load(jsonReader);
            var jsonSerializer     = new JsonSerializer();
            var fileUploadResponse = (FileUploadResponse)jsonSerializer.Deserialize(new JTokenReader(jObject), typeof(FileUploadResponse));

            if (fileUploadResponse.res == "ok")
            {
                var fileUpload = new FileUpload()
                {
                    nodeId       = fileUploadResponse.nodeId,
                    modifiedTime = fileUploadResponse.modifiedTime
                };

                return(fileUpload);
            }
            else
            {
                throw new RestResponseException(fileUploadResponse.errorDesc);
            }
        }
Exemplo n.º 4
0
        public static List <FileFolder> GetFilesFolders(string ticket, string groupId, string parentFolderId)
        {
            if (string.IsNullOrWhiteSpace(ticket))
            {
                throw new ArgumentNullException("ticket");
            }

            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException("groupId");
            }

            var folders          = new List <FileFolder>();
            var firstResult      = 0;
            var maxResults       = 99;
            var responseComplete = false;
            var response         = string.Empty;
            var jsonSerializer   = new JsonSerializer();
            var jsonReader       = (JsonTextReader)null;
            var jObject          = (JObject)null;
            var responseObject   = (GetFilesFoldersResponse)null;

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var request        = string.Format("ticket={0}&groupId={1}&parentNodeId={2}&includeFolders=true&includeFiles=true", ticket, groupId, parentFolderId);

            do
            {
                response       = new RestServiceAgent().SendPostRequest(string.Format("{0}/{1}", restServiceUrl, "getFilesFolders"), string.Format("{0}&firstResult={1}&maxResults={2}", request, firstResult, maxResults));
                jsonReader     = new JsonTextReader(new StringReader(response));
                jObject        = JObject.Load(jsonReader);
                responseObject = (GetFilesFoldersResponse)jsonSerializer.Deserialize(new JTokenReader(jObject), typeof(GetFilesFoldersResponse));

                if (responseObject.res == "ok")
                {
                    if (responseObject.filesfolders.Count > 0)
                    {
                        folders.AddRange(responseObject.filesfolders);
                    }
                    else
                    {
                        responseComplete = true;
                    }
                }
                else
                {
                    throw new RestResponseException(responseObject.errorDesc);
                }

                firstResult += maxResults++;
                maxResults  += 99;
            }while (!responseComplete);

            return(folders);
        }
Exemplo n.º 5
0
        public static bool DownloadFile(string ticket, string fileId, string filePath)
        {
            if (string.IsNullOrWhiteSpace(ticket))
            {
                throw new ArgumentNullException("ticket");
            }

            if (string.IsNullOrWhiteSpace(fileId))
            {
                throw new ArgumentNullException("fileId");
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var request        = string.Format("{0}/{1}", ticket, fileId);
            var response       = new RestServiceAgent().SendGetRequest(string.Format("{0}/{1}/{2}", restServiceUrl, "viewDocument", request));

            if (response == null || response.Length == 0)
            {
                return(false);
            }

            try
            {
                var responseFile = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                response.Position = 0;
                response.CopyTo(responseFile);
                response.Close();
                responseFile.Flush();
                responseFile.Close();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public static bool RenameFileFolder(string ticket, string groupId, string fileFolderId, string title)
        {
            if (string.IsNullOrWhiteSpace(ticket))
            {
                throw new ArgumentNullException("ticket");
            }

            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException("groupId");
            }

            if (string.IsNullOrWhiteSpace(fileFolderId))
            {
                throw new ArgumentNullException("fileFolderId");
            }

            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentNullException("title");
            }

            var restServiceUrl = ConfigurationManager.GetValue(Resources.RestServiceUrlKey);
            var request        = string.Format("ticket={0}&groupId={1}&itemId={2}&title={3}", ticket, groupId, fileFolderId, title);
            var response       = new RestServiceAgent().SendPostRequest(string.Format("{0}/{1}", restServiceUrl, "renameFileFolder"), request);

            //Deserialize response
            var jsonReader     = new JsonTextReader(new StringReader(response));
            var jObject        = JObject.Load(jsonReader);
            var jsonSerializer = new JsonSerializer();
            var responseObject = (CreateFolderResponse)jsonSerializer.Deserialize(new JTokenReader(jObject), typeof(CreateFolderResponse));

            if (responseObject.res == "ok")
            {
                return(true);
            }
            else
            {
                throw new RestResponseException(responseObject.errorDesc);
            }
        }