コード例 #1
0
ファイル: TestProcessViewModel.cs プロジェクト: pasha369/Quiz
        private void InitQuestions(List <Question> questions)
        {
            foreach (var questionItem in questions)
            {
                QuestionModel questionModel = new QuestionModel();
                questionModel.QuestionText = questionItem.QuestionText;
                foreach (var variantItem in questionItem.Variants)
                {
                    var variant = new VariantModel();
                    if (variantItem.Type == "Image")
                    {
                        FileTransferClient fileTransfer = new FileTransferClient();

                        TransferedImage img  = fileTransfer.DownloadImage(variantItem.ImageUri);
                        var             path = SaveImage(img.data, img.Filename);
                        variant.ImageUri = path;
                        variant.Type     = variantItem.Type;
                    }
                    else
                    {
                        variant.VariantText = variantItem.VariantText;
                    }
                    questionModel.Variants.Add(variant);
                }
                _questions.Add(questionModel);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        private void ExecuteTransfer(string param, out string retValue)
        {
            retValue = "Res=ArgumentException";

            if (!string.IsNullOrEmpty(param))
            {
                string[] paths = param.Split(' ');
                if (paths.Length == 2)
                {
                    string[] array = paths[1].Split('@');
                    int      index = 0;

                    if (array[0].StartsWith("machine"))
                    {
                        try
                        {
                            index = Int32.Parse(array[0].Substring("machine".Length));

                            FileTransferClient client = new FileTransferClient(NetUtil.GetStationIp(index - 1));
                            if (FileTransferClient.TRANSFER_ERROR_NONE == client.Upload(paths[0], array[1]))
                            {
                                retValue = "Res=Pass";
                            }
                            else
                            {
                                retValue = "Res=Fail";
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
コード例 #4
0
        private async void ConnectToServer(object sender, RoutedEventArgs e)
        {
            if (isClientConnected)
            {
                client.Close();
                ClientStatus.Text    = "Status: Niepołączony";
                SendBtn.IsEnabled    = false;
                ClientConBtn.Content = "Połącz";
                isClientConnected    = false;
            }
            else
            {
                try
                {
                    isClientConnected    = true;
                    client               = new FileTransferClient(ClientAddress.Text, Convert.ToInt32(ClientPort.Text));
                    ClientStatus.Text    = "Status: Łączenie...";
                    ClientConBtn.Content = "Przerwij";
                    await client.ConnectAsync();

                    ClientStatus.Text = "Status: Połączony";
                    SendBtn.IsEnabled = true;
                }
                catch (Exception)
                {
                    ClientStatus.Text    = "Status: Niepołączony";
                    SendBtn.IsEnabled    = false;
                    ClientConBtn.Content = "Połącz";
                    isClientConnected    = false;
                }
            }
        }
コード例 #5
0
        private void ClientForm_Load(object sender, EventArgs e)
        {
            m_clientId = ConfigurationManager.AppSettings.Get("clientId").ToInt32();
            string configServiceAddress       = ConfigurationManager.AppSettings.Get("ConfigServiceAddress");
            string configServicePort          = ConfigurationManager.AppSettings.Get("ConfigServicePort");
            string configStreamingServicePort = ConfigurationManager.AppSettings.Get("ConfigStreamingServicePort");
            string configRipServicePort       = ConfigurationManager.AppSettings.Get("ConfigRipServicePort");

            string useConfig = ConfigurationManager.AppSettings.Get("UseConfig");


            ClientIdTextBox.Text = m_clientId.ToString();
            IPTextBox.Text       = configServiceAddress;
            PortTextBox.Text     = configServicePort;

            m_serviceAddress       = configServiceAddress;
            m_servicePort          = configServicePort;
            m_streamingServicePort = configStreamingServicePort;
            m_ripServicePort       = configRipServicePort;

            ClientManager.Instance.ServerDisconnectEvent += ServerDisconnect;
            RipDataFileTransferClient.Instance().ServerDisconnectEvent += RipServerDisconnect;
            m_ftClient = new FileTransferClient();
            m_ftClient.ServerDisconnectEvent += FTServerDisconnect;
        }
コード例 #6
0
ファイル: TestProcessViewModel.cs プロジェクト: pasha369/Quiz
        private void InitQuestions(List<Question> questions)
        {
            foreach (var questionItem in questions)
            {
                QuestionModel questionModel = new QuestionModel();
                questionModel.QuestionText = questionItem.QuestionText;
                foreach (var variantItem in questionItem.Variants)
                {
                    var variant = new VariantModel();
                    if(variantItem.Type == "Image")
                    {
                        FileTransferClient fileTransfer = new FileTransferClient();

                        TransferedImage img = fileTransfer.DownloadImage(variantItem.ImageUri);
                        var path = SaveImage(img.data, img.Filename);
                        variant.ImageUri = path;
                        variant.Type = variantItem.Type;
                    }
                    else
                    {
                        variant.VariantText = variantItem.VariantText;                    
                    }
                    questionModel.Variants.Add(variant);
                }
                _questions.Add(questionModel);
            }
        }
コード例 #7
0
        /// <summary>
        /// 测试完成后,调用此接口,用来记录测试结果
        /// </summary>
        /// <param name="sn"></param>
        public static void Record(string sn)
        {
            InitResultList();

            foreach (FlowItem flowItem in FlowControl.Instance.FlowItemList)
            {
                if (flowItem.IsFinished() && !flowItem.Item.Property.Disable && !flowItem.Item.Property.Hide)
                {
                    ResultInfo info = new ResultInfo();
                    info.Key   = flowItem.Name;
                    info.Value = RestoreCmdResult(flowItem.SpecValueList);
                    resultList_.Add(info);
                }
            }

            if (resultList_.Count > 0)
            {
                string filename = @"d:\DataFragment\" + sn + "_" + NetUtil.GetStationIndex();
                using (StreamWriter sw = new StreamWriter(filename))
                {
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(writer, resultList_);
                    }
                }

                ThreadPool.QueueUserWorkItem(delegate
                {
                    FileTransferClient client = new FileTransferClient(NetUtil.GetStationIp(AppInfo.STATION_SERVER));
                    client.Upload(filename, filename);
                });
            }
        }
コード例 #8
0
 /// <summary>Creates a new instance of <see cref="TeamSpeakClient"/> using the provided host TCP port.</summary>
 /// <param name="hostName">The host name of the remote server.</param>
 /// <param name="port">The TCP port of the Query API server.</param>
 /// <param name="keepAliveInterval">The Timespan used to use on the internal keep alive wait.</param>
 public TeamSpeakClient(string hostName, int port, bool useKeepAlive = false, TimeSpan?keepAliveInterval = null)
 {
     //Added 'this' for my clarity.
     this.useInternalKeepAlive = useKeepAlive;
     this.KeepAliveInterval    = keepAliveInterval;
     this.Client = new QueryClient(hostName, port);
     this._fileTransferClient = new FileTransferClient(hostName);
 }
コード例 #9
0
 public IFACertificateService(IConfiguration configuration,
                              FileTransferClient fileTransferClient,
                              CertificatesRepository certificatesRepository)
 {
     _configuration          = configuration;
     _fileTransferClient     = fileTransferClient;
     _certificatesRepository = certificatesRepository;
 }
コード例 #10
0
        private void OnWatchedFileChange(object state)
        {
            Console.WriteLine("OnWatchedFileChange");

            string             srcfilename  = @"C:\TRT_Camera_Tester_Picture\test result\result.txt";
            string             destfilename = @"d:\DataFragment\result_" + NetUtil.GetStationIndex() + ".txt";
            FileTransferClient client       = new FileTransferClient(NetUtil.GetStationIp(AppInfo.STATION_SERVER));

            client.Upload(srcfilename, destfilename);
        }
 public CoverLetterTemplateService(FilePerister filePerister,
                                   FileTransferClient fileTransferClient,
                                   DocumentTemplateDataStream documentTemplateDataStream,
                                   CertificatesRepository certificatesRepository)
 {
     _filePerister               = filePerister;
     _fileTransferClient         = fileTransferClient;
     _documentTemplateDataStream = documentTemplateDataStream;
     _certificatesRepository     = certificatesRepository;
 }
コード例 #12
0
 public IFACertificateService(
     BlobContainerHelper initialiseContainer,
     IAggregateLogger aggregateLogger,
     FileTransferClient fileTransferClient,
     IWebConfiguration webConfiguration)
 {
     _initialiseContainer = initialiseContainer;
     _aggregateLogger     = aggregateLogger;
     _fileTransferClient  = fileTransferClient;
     _webConfiguration    = webConfiguration;
 }
コード例 #13
0
 public CoverLetterService(
     IAggregateLogger aggregateLogger,
     FileTransferClient fileTransferClient,
     DocumentTemplateDataStream documentTemplateDataStream,
     BlobContainerHelper initialiseContainer)
 {
     _aggregateLogger            = aggregateLogger;
     _fileTransferClient         = fileTransferClient;
     _documentTemplateDataStream = documentTemplateDataStream;
     _initialiseContainer        = initialiseContainer;
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: merkator2160/Study
        private static void FileWatcher_Created(Object sender, FileSystemEventArgs e)
        {
            FileTransferResponse response = null;

            try
            {
                if (!IsFileLocked(e.FullPath))
                {
                    var startAt     = DateTime.Now;
                    var createdFile = new FileTransferRequest()
                    {
                        FileName = e.Name,
                        Content  = File.ReadAllBytes(e.FullPath)
                    };

                    response = new FileTransferClient().Put(createdFile);

                    if (response.ResponseStatus != "Successful")
                    {
                        MoveToFailedFolder(e);
                    }
                    else
                    {
                        if (File.Exists(e.FullPath))
                        {
                            File.Delete(e.FullPath);
                        }
                    }

                    Console.WriteLine(response.ResponseStatus + " at: " + DateTime.Now.Subtract(startAt));
                    new Logger().Create(e.Name, DateTime.Now, response.ResponseStatus, response.Message);
                }
            }
            catch (CommunicationException ex)
            {
                MoveToFailedFolder(e);
                Console.WriteLine(ex.Message);
                new Logger().Create(e.Name, DateTime.Now, "Error", ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (response != null)
                {
                    new Logger().Create(e.Name, DateTime.Now, response.ResponseStatus, response.Message);
                }
                else
                {
                    new Logger().Create(e.Name, DateTime.Now, "Error", ex.Message);
                }
            }
        }
コード例 #15
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);
        }
コード例 #16
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);
                    }
                }
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: SitamMatt/Telekom_Labs
        static void Main(string[] args)
        {
            string text    = "Hello World";                            // tekst do zakodowania
            var    encoded = Telekom.Encoding.Huffman.Encode(text);    // zakodowanie
            var    decoded = Telekom.Encoding.Huffman.Decode(encoded); // odkowowanie

            Console.WriteLine(text == decoded);

            // praca z gniazdami
            var server = new FileTransferServer("127.0.0.1", 5678);
            var client = new FileTransferClient("127.0.0.1", 5678);
            var t1     = server.AcceptAsync();
            var t2     = client.ConnectAsync();

            Task.WaitAll(t2, t1);
            var t3 = client.SendAsync(@"E:\filename.txt");

            Thread.Sleep(5000);
            var t4 = server.ReceiveAsync(@"E:\file.txt");

            Task.WaitAll(t4, t3);
        }
コード例 #18
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);
            }
        }
コード例 #19
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);
                
            }
        }
コード例 #20
0
        private static void DownloadFirstFileInCurrentChannel(QueryClient queryClient, string targetDirectory)
        {
            // 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 the first file in the current channel
            FileTransferFileEntry firstFile = new FtGetFileListCommand(channelId, "/").Execute(queryClient).Values.FirstOrDefault();

            // initialize the file transfer to get the server file transfer key
            FtInitDownloadCommandResponse ftInitDownloadResponse = new FtInitDownloadCommand(randomClientId, "/" + firstFile.Name, firstFile.ChannelId, 0).Execute(queryClient);

            // calculate the target file path
            string fileName       = firstFile.Name.Substring(firstFile.Name.LastIndexOf("/", StringComparison.Ordinal) + 1);
            string targetFilePath = Path.Combine(targetDirectory, fileName);

            // 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, ftInitDownloadResponse.FileTransferPort ?? 30033);

            // download the file synchron
            transferClient.DownloadFile(ftInitDownloadResponse.FileTransferKey, ftInitDownloadResponse.FileSize.Value, targetFilePath);
        }
コード例 #21
0
ファイル: EntryBlock.xaml.cs プロジェクト: Dekkee/LavaAxe
 private void btnClose_Click(object sender, RoutedEventArgs e)
 {
     IFileTransfer fileHost = new FileTransferClient();
     if (fileHost.DeleteFile(Source.FileName))
         parent.Children.Remove(this);
 }
コード例 #22
0
 /// <summary>Creates a new instance of <see cref="TeamSpeakClient"/> using the provided host TCP port.</summary>
 /// <param name="hostName">The host name of the remote server.</param>
 /// <param name="port">The TCP port of the Query API server.</param>
 public TeamSpeakClient(string hostName, int port)
 {
     Client = new QueryClient(hostName, port);
     _fileTransferClient = new FileTransferClient(hostName);
 }
コード例 #23
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;
        }
コード例 #24
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);
            }
        }
コード例 #25
0
ファイル: MainWindow.xaml.cs プロジェクト: Dekkee/LavaAxe
        public void Show(LavaUser user)
        {
            this.Title = user.UserName;
            this.Show();

            currentUser = user;

            LoadingScreen.LoadingScreen loadingScreen = new LoadingScreen.LoadingScreen();
            loadingScreen.Show();

            // Open document
            var LoadingThread = new BackgroundWorker();
            //Запуск процесса десереализации в фоновом потоке
            LoadingThread.DoWork += (s, args) =>
            {
                try
                {
                    IFileTransfer fileHost = new FileTransferClient();

                    string[] fileList = fileHost.GetFileList(user.UserName);
                    if (fileList == null)
                        throw new Exception("Error. File list in null");

                    foreach (var file in fileList)
                    {
                        //Получаем файл. Расшифровываем. Парсим.
                        entrys.Deserialize(file, CryptoLibrary.decrypt28147cfb(user.MasterKey, GetFile(fileHost, file)));
                    }
                }
                catch (Exception ex)
                {
                    args.Result = ex.Message;
                }
            };
            LoadingThread.RunWorkerCompleted += (s, e) =>
            {
                if (e.Result != null)
                    MessageBox.Show(loadingScreen, e.Result.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                loadingScreen.Close();
            };
            LoadingThread.RunWorkerAsync();
        }