Example #1
0
        static public Stream downloadIcon(VmosoSession session, String iconKey, String userKey)
        {
            String         url     = session.Host + "/dl/" + Uri.EscapeUriString(iconKey) + "." + userKey + "/temp";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.UserAgent = session.GetApiClient().Configuration.UserAgent;
            request.Headers.Add("X-CV-Authorization", session.GetAuthorizationHeader());

            WebResponse resp = null;

            try
            {
                resp = request.GetResponse();
                Stream respStream = resp.GetResponseStream();

                byte[]       buffer = new byte[16 * 1024];
                MemoryStream ms     = new MemoryStream();
                int          read;
                while ((read = respStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                respStream.Close();
                return(ms);
            } catch (Exception)
            {
                return(null);
            }
        }
Example #2
0
        private static HttpWebResponse PostForm(VmosoSession session, string postUrl, string userAgent, string contentType, byte[] formData)
        {
            HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;

            if (request == null)
            {
                throw new NullReferenceException("request is not a http request");
            }

            // Set up the request properties.
            request.Method          = "POST";
            request.ContentType     = contentType;
            request.UserAgent       = userAgent;
            request.CookieContainer = new CookieContainer();
            request.ContentLength   = formData.Length;

            request.Headers.Add("X-CV-Authorization", session.GetAuthorizationHeader());

            // Send the form data to the request.
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(formData, 0, formData.Length);
                requestStream.Close();
            }

            return(request.GetResponse() as HttpWebResponse);
        }
Example #3
0
        static public Model.FileRecord uploadFile(VmosoSession session, String filePath, String title, String description, bool dominantActivity)
        {
            try {
                String url       = session.Host + "/up/file";
                String userAgent = session.GetApiClient().Configuration.UserAgent;

                WebClient client = new WebClient();
                client.Headers.Add("X-CV-Authorization", session.GetAuthorizationHeader());
                client.Headers.Add("User-Agent", userAgent);

                byte[]  response   = client.UploadFile(url, filePath);
                var     jsonString = System.Text.Encoding.Default.GetString(response);
                dynamic dynObj     = JsonConvert.DeserializeObject(jsonString);
                var     file       = dynObj[0];

                String fileName       = file.name;
                String fileDownloadId = file.fileDownloadId;
                String mimeType       = file.mimeType;
                int    fileSize       = file.filesize;

                FileRecord fr = new FileRecord();
                fr.Type               = "file";
                fr.Name               = title;
                fr.Description        = description;
                fr.Filename           = "1";
                fr.Originalfilename   = fileName;
                fr.SiteSelected       = "1";
                fr.FilestoreDirRoot   = "1";
                fr.FilestoreFilestore = fileDownloadId;
                fr.Mimetype           = mimeType;
                fr.Filesize           = fileSize;
                fr.Downloadable       = "1";
                fr.Simpletype         = "1";
                fr.DvaultItemFlag     = "1";
                fr.DvaultItemStatus   = "1";
                fr.BvrevVersion       = 1;
                fr.BvrevLastUpdater   = 1;
                fr.Trashed            = "0";

                FileApi fileApi = new FileApi(session.GetApiClient());

                CreateFileInput createFileInput = new CreateFileInput(fr, dominantActivity, null);

                CreateFileResult createFileResult = fileApi.CreateFile(createFileInput);
                if (createFileResult.Hdr.Rc == 0)
                {
                    return(createFileResult.File);
                }
                else
                {
                    throw new Exception("Error uploading file. Rc=" + createFileResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Error uploading file", ex);
            }
        }
Example #4
0
        public static HttpWebResponse MultipartFormDataPost(VmosoSession session, string postUrl, string userAgent, Dictionary <string, object> postParameters)
        {
            string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
            string contentType      = "multipart/form-data; boundary=" + formDataBoundary;

            byte[] formData = GetMultipartFormData(postParameters, formDataBoundary);

            return(PostForm(session, postUrl, userAgent, contentType, formData));
        }
Example #5
0
        static public Model.FileRecord uploadNewVersion(VmosoSession session, String fileKey, String filePath)
        {
            try
            {
                FileApi        fileApi        = new FileApi(session.GetApiClient());
                ViewFileResult viewFileResult = fileApi.ViewFile(fileKey);
                if (viewFileResult.Hdr.Rc == 0)
                {
                    FileRecord fileRecord = viewFileResult.File;

                    String url       = session.Host + "/up/file";
                    String userAgent = session.GetApiClient().Configuration.UserAgent;

                    WebClient client = new WebClient();
                    client.Headers.Add("X-CV-Authorization", session.GetAuthorizationHeader());
                    client.Headers.Add("User-Agent", userAgent);

                    byte[]  response   = client.UploadFile(url, filePath);
                    var     jsonString = System.Text.Encoding.Default.GetString(response);
                    dynamic dynObj     = JsonConvert.DeserializeObject(jsonString);
                    var     file       = dynObj[0];

                    String fileName       = file.name;
                    String fileDownloadId = file.fileDownloadId;
                    String mimeType       = file.mimeType;
                    int    fileSize       = file.filesize;

                    fileRecord.FilestoreFilestore = fileDownloadId;
                    fileRecord.Filesize           = fileSize;

                    UpdateFileInput  updateFileInput  = new UpdateFileInput(fileRecord, null);
                    UpdateFileResult updateFileResult = fileApi.UpdateFile(fileKey, updateFileInput);
                    if (updateFileResult.Hdr.Rc == 0)
                    {
                        return(updateFileResult.Updated);
                    }
                    else
                    {
                        throw new Exception("Error updating file. Rc=" + viewFileResult.Hdr.Rc);
                    }
                }
                else
                {
                    throw new Exception("Error getting file. Rc=" + viewFileResult.Hdr.Rc);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error uploading new version", ex);
            }
        }
Example #6
0
        static public Stream downloadFile(VmosoSession session, String fileKey, String fileName)
        {
            String         url     = session.Host + "/dl/" + fileKey + "/" + Uri.EscapeUriString(fileName);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.UserAgent = session.GetApiClient().Configuration.UserAgent;
            request.Headers.Add("X-CV-Authorization", session.GetAuthorizationHeader());

            WebResponse resp       = request.GetResponse();
            Stream      respStream = resp.GetResponseStream();

            byte[]       buffer = new byte[16 * 1024];
            MemoryStream ms     = new MemoryStream();
            int          read;

            while ((read = respStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            respStream.Close();
            return(ms);
        }