コード例 #1
0
        private string UploadImg()
        {
            string path = string.Empty;

            FileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                var filename = openFileDialog.FileName;

                var           name         = openFileDialog.SafeFileName;
                IFileTransfer fileTransfer = new FileTransferClient();
                byte[]        imgData;

                using (var ms = new MemoryStream())
                {
                    Image img = Image.FromFile(filename);
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

                    imgData = ms.ToArray();
                }

                path = fileTransfer.UploadFile(imgData, name);
            }
            return(path);
        }
コード例 #2
0
        private static void UploadFileToCurrentChannel(QueryClient queryClient, string sourceFilePath)
        {
            // get the channel we're currenlty in
            uint channelId = new WhoAmICommand().Execute(queryClient).ChannelId;

            // create a rondom id for the file transfer
            uint randomClientId = (uint)_randomForFileClientTransferId.Next(1, 10000);

            // get only the filename
            FileInfo sourceFileInfo = new FileInfo(sourceFilePath);

            // initialize the file transfer to get the server file transfer key
            FtInitUploadCommandResponse ftInitUploadCommandResponse = new FtInitUploadCommand(randomClientId, "/" + sourceFileInfo.Name, channelId, (ulong)sourceFileInfo.Length, true, false).Execute(queryClient);

            // create the file transfer cleint with the host of the query client and the port we got from the init download response
            FileTransferClient transferClient = new FileTransferClient(queryClient.Host, ftInitUploadCommandResponse.FileTransferPort ?? 30033);

            // upload the file synchron
            transferClient.UploadFile(ftInitUploadCommandResponse.FileTransferKey, (ulong)sourceFileInfo.Length, sourceFileInfo.FullName);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: Dekkee/LavaAxe
        public void SaveAll()
        {
            foreach (EntryBlock entry in spData.Children)
            {
                if (entry.isModified)
                {
                    byte[] encrypted = CryptoLibrary.encrypt28147cfb(currentUser.MasterKey, entry.Source.Serialize());
                    IFileTransfer clientUpload = new FileTransferClient();
                    RemoteFileInfo uploadRequestInfo = new RemoteFileInfo();

                    using (MemoryStream stream = new MemoryStream(encrypted))
                    {
                        uploadRequestInfo.FileName = entry.Source.FileName;
                        uploadRequestInfo.Length = encrypted.Length;
                        uploadRequestInfo.FileByteStream = stream;
                        clientUpload.UploadFile(uploadRequestInfo);
                    }
                }
            }
        }
コード例 #4
0
ファイル: TestEdit.xaml.cs プロジェクト: pasha369/Quiz
        private void btnAddImage_Click(object sender, RoutedEventArgs e)
        {
            FileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == true)
            {
                var filename = openFileDialog.FileName;

                var name = openFileDialog.SafeFileName;
                IFileTransfer fileTransfer = new FileTransferClient();
                byte[] imgData;

                using (var ms = new MemoryStream())
                {
                    Image img = Image.FromFile(filename);
                    img.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
                    
                    imgData = ms.ToArray();
                }

                var path = fileTransfer.UploadFile(imgData, name);
                
            }
        }
コード例 #5
0
        private void btnAddImage_Click(object sender, RoutedEventArgs e)
        {
            FileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                var filename = openFileDialog.FileName;

                var           name         = openFileDialog.SafeFileName;
                IFileTransfer fileTransfer = new FileTransferClient();
                byte[]        imgData;

                using (var ms = new MemoryStream())
                {
                    Image img = Image.FromFile(filename);
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

                    imgData = ms.ToArray();
                }

                var path = fileTransfer.UploadFile(imgData, name);
            }
        }
コード例 #6
0
ファイル: TestEditViewModel.cs プロジェクト: pasha369/Quiz
        private string UploadImg()
        {
            string path = string.Empty;

            FileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == true)
            {
                var filename = openFileDialog.FileName;

                var name = openFileDialog.SafeFileName;
                IFileTransfer fileTransfer = new FileTransferClient();
                byte[] imgData;

                using (var ms = new MemoryStream())
                {
                    Image img = Image.FromFile(filename);
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

                    imgData = ms.ToArray();
                }

                path = fileTransfer.UploadFile(imgData, name);
                
            }
            return path;
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: Dekkee/LavaAxe
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            IFileTransfer proxy = new FileTransferClient();
            RemoteFileInfo uploadRequestInfo = new RemoteFileInfo();

            Entry entry = new Entry(entrys, "Name", "", "");
            byte[] bEntry = entry.Serialize();

            string path = proxy.AddNewFile(currentUser.UserName, bEntry);
            if (path == null || path == "")
            {
                return;
            }

            entrys.Deserialize(path, bEntry);
            byte[] encrypted = CryptoLibrary.encrypt28147cfb(currentUser.MasterKey, entry.Serialize());

            using (MemoryStream stream = new MemoryStream(encrypted))
            {
                uploadRequestInfo.FileName = path;
                uploadRequestInfo.Length = encrypted.Length;
                uploadRequestInfo.FileByteStream = stream;
                proxy.UploadFile(uploadRequestInfo);
            }
        }