Exemplo n.º 1
0
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (FileName.Text != "")
            {
                if (FileType.SelectedIndex == 0)
                {
                    Result = CreateFileResult.TextFile;
                }

                if (FileType.SelectedIndex == 1)
                {
                    Result = CreateFileResult.HtmlFile;
                }

                AppVar.FileNameEdit = FileName.Text;
                if (CheckBoxFileNow.IsChecked == true)
                {
                    CreateFileNow = true;
                }
                else
                {
                    CreateFileNow = false;
                }
            }
            else
            {
                Result = CreateFileResult.CreateFailed;
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Upload file to Parse
        /// </summary>
        /// <param name="parseFile">The file to upload. Its Name and Url properties will be updated upon success.</param>
        /// <returns></returns>
        public ParseFile CreateFile(ParseFile parseFile)
        {
            string           responseString = UploadFileToParse(parseFile.LocalPath, parseFile.ContentType);
            CreateFileResult cor            = JsonConvert.DeserializeObject <CreateFileResult>(responseString);

            parseFile.Url  = cor.url;
            parseFile.Name = cor.name;
            return(parseFile);
        }
Exemplo n.º 4
0
        public async Task <CreateFileResult> WriteImageFileAsync(string file, Bitmap bmp, ImageCodecInfo codec, EncoderParameters encoderParameters)
        {
            try
            {
                await Task.Run(() => bmp.Save(Path.Combine(fileSystemPath, file), codec, encoderParameters));

                return(CreateFileResult.Success(file));
            }
            catch (Exception e)
            {
                return(CreateFileResult.Failed(e.Message));
            }
        }
Exemplo n.º 5
0
        public static CreateFileResult CreateFileOrOverwrite(string path, string content)
        {
            var result = new CreateFileResult
            {
                FileExisted = File.Exists(path),
                Success     = true
            };

            try
            {
                if (result.FileExisted)
                {
                    File.Delete(path);
                }
                else
                {
                    //let's make sure directory exist first
                    var dir = new FileInfo(path).Directory.FullName;
                    Directory.CreateDirectory(dir);
                }

                // Create the file.
                using (FileStream fs = File.Create(path))
                {
                    Byte[] info = new UTF8Encoding(true).GetBytes(content);
                    // Add some information to the file.
                    fs.Write(info, 0, info.Length);
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                AppendToFile(_logFilePath, ex.Message);
            }

            return(result);
        }
Exemplo n.º 6
0
 private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Result = CreateFileResult.CreateFailed;
 }