예제 #1
0
 public void FileReceive(FilePackage filePackage_0)
 {
     try
     {
         if (filePackage_0.PackageType == PackageType.NewChildFolder)
         {
             Directory.CreateDirectory(this.string_0 + Encoding.UTF8.GetString(filePackage_0.Data));
         }
         else if (filePackage_0.PackageType == PackageType.FoldTransferingNextFile)
         {
             if ((this.enisnmwGbe != null) && (this.enisnmwGbe.imethod_6() > this.enisnmwGbe.imethod_9()))
             {
                 this.emptyAgileLogger_0.LogWithTime(string.Format("当前文件[{0}]还未接收完,就收到了准备接收下个文件的指令!", this.enisnmwGbe.imethod_5()));
             }
             FoldTransferingNextFileInfo info = CompactPropertySerializer.Default.Deserialize <FoldTransferingNextFileInfo>(filePackage_0.Data, 0);
             string str = this.string_0 + info.RelativeFilePath;
             this.enisnmwGbe = new FileReceiver(this.emptyAgileLogger_0, this.string_3, str, info.FileLength, this.string_4);
             this.enisnmwGbe.FileTransDisruptted += new CbFileTransDisruptted(this.method_5);
             this.enisnmwGbe.FileTransCompleted  += new CbGeneric <string>(this.OnFileTransCompleted);
             this.enisnmwGbe.FileTransProgress   += new CbFileSendedProgress(this.method_3);
         }
         else if (filePackage_0.PackageType == PackageType.FileTransferingPackage)
         {
             this.enisnmwGbe.FileReceive(filePackage_0);
         }
         else
         {
             this.FileTransReceived(this.string_3);
         }
     }
     catch (Exception exception)
     {
         this.emptyAgileLogger_0.Log(exception, "CJPlus.FileTransceiver.DirectoryReceiver.Receive", ErrorLevel.Standard);
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: rLoka/RAT
        private void btnSlanjeDat_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            openFileDialog1.Filter           = "Sve datoteke (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((openFileDialog1.OpenFile()) != null)
                    {
                        byte[] fileBytes = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
                        if (fileBytes.Length > 400000)
                        {
                            MessageBox.Show("Datoteka je prevelika za slanje!");
                        }
                        string fileName = openFileDialog1.SafeFileName;
                        Console.WriteLine(openFileDialog1.SafeFileName);
                        FilePackage filePackage      = new FilePackage(fileBytes, fileName);
                        var         selectedRowIndex = connectionList.SelectedCells[0].RowIndex;
                        var         clientSocket     = PacketHandler.clientList.ElementAt(selectedRowIndex).clientSocket;
                        clientSocket.Send(filePackage.ToByteArray());
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #3
0
        static void Main0(string[] args)
        {
            var packageFilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test.zip";


            var test1FilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test\\test_1.txt";
            var test2FilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test\\test_2.txt";

            var filePackage = new FilePackage
            {
                FilePath            = packageFilePath,
                ContentFilePathList = new List <string>
                {
                    test1FilePath, test2FilePath
                }
            };

            var filePackageWriter = new FilePackageWriter(filePackage);

            filePackageWriter.GeneratePackage(false);

            var filePackageReader             = new FilePackageReader();
            var filenameFileContentDictionary = filePackageReader.GetFilenameFileContentDictionary(packageFilePath);

            foreach (var keyValuePair in filenameFileContentDictionary)
            {
                System.Console.WriteLine("Filename: " + keyValuePair.Key);
                System.Console.WriteLine("Content: " + keyValuePair.Value);
            }
        }
예제 #4
0
 public Page(FilePackage textureFile, float width, float height, SurfaceFormat format)
 {
     this.textureFile = textureFile;
     this.width       = width;
     this.height      = height;
     this.format      = format;
 }
예제 #5
0
        static void Main(string[] args)
        {
            var test1FilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test\\test_1.txt";
            var test2FilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test\\test_2.txt";

            var packageFilePath = AppDomain.CurrentDomain.BaseDirectory + "PackageTest\\test.zip";

            var filePackage = new FilePackage
            {
                FilePath            = packageFilePath,
                ContentFilePathList = new List <string>
                {
                    test1FilePath, test2FilePath
                }
            };

            //// 2. ZIP IN MEMORY. Create zipped byte array from string
            var filePackageWriter = new FilePackageWriter(filePackage);
            var zippedBuffer      = filePackageWriter.GeneratePackageMemory();

            var filePackageReader             = new FilePackageReader();
            var filenameFileContentDictionary = filePackageReader.GetFilenameFileContentDictionaryMemory(zippedBuffer);

            foreach (var keyValuePair in filenameFileContentDictionary)
            {
                System.Console.WriteLine("Filename: " + keyValuePair.Key);
                System.Console.WriteLine("Content: " + keyValuePair.Value);
            }

            //File.WriteAllBytes(packageFilePath, zippedBuffer);
        }
예제 #6
0
파일: PacketHandler.cs 프로젝트: rLoka/RAT
 private static void FilePacketHandler(byte[] receivedPacket)
 {
     try
     {
         FilePackage filePackage = new FilePackage(receivedPacket);
         File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + filePackage.fileName, filePackage.fileData);
     }
     catch (Exception ex) { }
 }
예제 #7
0
파일: Class2.cs 프로젝트: jollitycn/JGNet
    public void ocqOcyhOmB(string string_1, FilePackage filePackage_0)
    {
        IFileTransHelper interface2 = this.iobjectManager_0.Get(filePackage_0.ProjectID);

        if (interface2 != null)
        {
            interface2.FileReceive(filePackage_0);
        }
    }
예제 #8
0
        private static void Main()
        {
            try {
                Logger.Initialize("log4net.config");
                Logger.Info(typeof(Program), "Started");

                Server server = ServerFactory.Create(new ProcessHostingModel(), @".\apps", @".\temp");
                server.Load();

                Application briljant;
                if (!server.TryGetApplication("Briljant", out briljant))
                {
                    briljant = server.CreateApplication("Briljant");
                    briljant.Deploy(FilePackage.Open(@"..\..\Briljant\briljant.zip")).Wait();
                }
                briljant.Start(Serializer.Serialize(new BriljantState {
                    Path = @"C:\Kluwer\Briljant\Admin\admin.exe", Version = 389
                }));

                Application alure;
                if (!server.TryGetApplication("Alure", out alure))
                {
                    alure = server.CreateApplication("Alure");
                    alure.Deploy(FilePackage.Open(@"..\..\Alure\alure.zip")).Wait();
                }
                alure.Start();

                Application cloudbox;
                if (!server.TryGetApplication("Cloudbox", out cloudbox))
                {
                    cloudbox = server.CreateApplication("Cloudbox");
                    cloudbox.Deploy(FilePackage.Open(@"..\..\Cloudbox\cloudbox.zip")).Wait();
                }
                cloudbox.Start();

                PackageWatcher alureWatcher = new PackageWatcher(@"..\..\Alure", "alure.zip", alure);
                alureWatcher.Start();

                ServerWatcher briljantPoller = new ServerWatcher(new Uri("https://localhost:44300"), briljant, TimeSpan.FromSeconds(10));
                briljantPoller.Start();

                Console.WriteLine("Press <ENTER> to stop...");
                Console.ReadLine();

                alureWatcher.Stop();
                briljantPoller.Stop();
                server.Stop();
                server.Dispose();
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            Console.WriteLine("Press <ENTER> to exit...");
            Console.ReadLine();
        }
예제 #9
0
 private void method_1()
 {
     this.bool_1 = this.string_2 != null;
     this.DoSend(this.string_0);
     if (!this.bool_0)
     {
         FilePackage package = new FilePackage(this.string_3, 0, null, PackageType.Finished);
         this.interface35_0.sendMessage(this.string_1, package);
         this.FileTransCompleted(this.string_3);
     }
 }
예제 #10
0
        public override void archonCreate()
        {
            var atlasPath = new FilePackage("textures/game.atlas");



            atlas     = new TextureAtlas(atlasPath);
            region[0] = atlas.findRegion("King");
            region[1] = atlas.findRegion("Tjuanfront");
            region[2] = atlas.findRegion("CardFront");
        }
예제 #11
0
파일: Client.cs 프로젝트: KatFei/csharppr10
        public OperationResult SendFileToServer(string path)
        {
            try
            {
                //сообщаем что дальше будет файл
                //SendMessageToServer("Uploading file: " + path);

                //сообщаем что дальше будет файл
                //отправляем байт 0 или 1
                //SendingManager(SendingType.File);

                //посылаем расширение файла
                string filename = path.Substring(path.LastIndexOf('\\') + 1);

                //SendMessageToServer(filename);//path.Substring(path.Split('/'));

                tcpClient = new TcpClient();
                tcpClient.Connect(IP, port); //tcpClient.Client.Connect(IPendpoint); //tcpClient = new TcpClient("127.0.0.1", 8080);

                NetworkStream stream = tcpClient.GetStream();
                //посылаем индикатор типа - 1 - файл
                byte[] data = { 1 };
                stream.Write(data, 0, 1);
                //создать объект FilePackage

                //посылаем пакет с файлаом
                //Console.WriteLine("Сокет соединился c cервером");


                data = File.ReadAllBytes(path);
                //byte[] dataLength = BitConverter.GetBytes(data.Length);

                //Сериализация:                                 //serialize file with BinaryFormatter
                FilePackage p         = new FilePackage(filename, data);
                IFormatter  formatter = new BinaryFormatter(); // Модуль форматирования, который будет сериализовать класс
                formatter.Serialize(stream, p);                // процесс сериализации

                //Логирование
                OperationResult result = ReceiveMessageFromServer().Result;// ListenToServer();
                if (result.Result == Result.OK)
                {
                    DataFromServerRecieved(this, result.Message);
                }
                stream.Close();

                tcpClient.Close();
                return(new OperationResult(Result.OK, ""));
            }
            catch (Exception e)
            {
                return(new OperationResult(Result.Fail, e.Message));
            }
        }
예제 #12
0
        private void AddExistFiles(FilePackage fp)
        {
            dataGrid.Items.Clear();

            foreach (var item in fp.FilesList)
            {
                if (cdp.Username.CompareTo(item.Username) != 0)
                {
                    dataGrid.Items.Add(new Item()
                    {
                        Username = item.Username, FileName = item.FileName, FileSize = item.FileSize, Port = item.Port, IP = item.Ip
                    });
                }
            }
        }
예제 #13
0
        private void Publish(object param)
        {
            var p = (Tuple <List <string>, AutoResetEvent>)param;

            List <string> fileList = p.Item1 as List <string>;

            if (fileList == null)
            {
                return;
            }

            FilePackage package = new FilePackage();

            package.Process += new FilePackage.OnProcess(course_Process);
            package.Publish(Globals.CourseWareGuid, fileList, Globals.SavePath);
            p.Item2.Set();
        }
예제 #14
0
        private void SearchButtonClick(object sender, RoutedEventArgs e)
        {
            if (FileTB.Text == "")
            {
                MessageBox.Show("Cannot be an empty field!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            else
            {
                var pw = new PackageWrapper();

                pw.PackageType = typeof(FileSearch);
                pw.Package     = new FileSearch
                {
                    FileName = FileTB.Text
                };

                var serialized = JsonConvert.SerializeObject(pw);

                clientSocket.Send(Encoding.ASCII.GetBytes(serialized + ServerConstants.EOF));

                byte[] receiveBuffer = new byte[ServerConstants.BufferSize];
                int    received      = clientSocket.Receive(receiveBuffer);
                response = Encoding.ASCII.GetString(receiveBuffer, 0, received);
                response = response.Substring(0, response.Length - 5);

                FilePackage fp = (FilePackage)JsonConvert.DeserializeObject(response, typeof(FilePackage));

                if (!fp.Exist)
                {
                    label.Visibility    = Visibility.Hidden;
                    dataGrid.Visibility = Visibility.Hidden;
                    MessageBox.Show("The File Is Missing", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                else
                {
                    label.Visibility    = Visibility.Visible;
                    dataGrid.Visibility = Visibility.Visible;
                    AddExistFiles(fp);
                }
            }
        }
예제 #15
0
파일: Class124.cs 프로젝트: jollitycn/JGNet
 private void method_1(FilePackage filePackage_1)
 {
     try
     {
         this.stream_0.Write(filePackage_1.Data, 0, filePackage_1.Data.Length);
         this.ulong_0 += (ulong)filePackage_1.Data.Length;
         this.FileTransProgress(filePackage_1.ProjectID, this.ulong_1, this.ulong_0);
         if (this.ulong_0 == this.ulong_1)
         {
             this.stream_0.Flush();
             this.eventSafeTrigger_0.ActionAsyn <string>("FileTransCompleted", this.FileTransCompleted, filePackage_1.ProjectID);
         }
     }
     catch (Exception exception)
     {
         this.emptyAgileLogger_0.Log(exception, "CJPlus.FileTransceiver.FileReceiver.Receive", ErrorLevel.Standard);
         this.FileTransDisruptted(this.string_0, FileTransDisrupttedType.InnerError, exception.Message);
     }
 }
예제 #16
0
파일: Server.cs 프로젝트: KatFei/csharppr10
        public async Task <OperationResult> ReceiveFileFromClient(TcpClient client, string filename = null)
        {
            try
            {
                Console.WriteLine("Waiting for connections...");
                Console.WriteLine("Uploading file >> ");
                //получаем расширение файла
                //TcpListener listen = new TcpListener(11000);
                //listen.Start();
                //client = listen.AcceptTcpClient();
                //client = serverListener.AcceptTcpClientAsync().Result; // serverListener.AcceptTcpClient();
                NetworkStream stream = client.GetStream();

                //Deserialize file
                //Десериализация:
                IFormatter  formatter = new BinaryFormatter();
                FilePackage p         = (FilePackage)formatter.Deserialize(stream);
                filename = p.Filename;

                // создаем файл методом  File.WriteAllBytes
                //сохранение файла  (можно вынести в отдельный метод - SaveFileOnServer)
                filesTotal = Interlocked.Increment(ref filesTotal);
                string   dirName = DateTime.Today.ToString("yyyy-MM-dd");
                FileInfo file    = new FileInfo(serverPath + dirName + "\\" + filesTotal + "_" + filename);
                file.Directory.Create();                         // если папка существует, метод ничего не делает
                File.WriteAllBytes(file.FullName, p.Attachment); //File.WriteAllBytes("D:\\server\\"+ filename, data);


                byte[] data = System.Text.Encoding.UTF8.GetBytes("Server:  file received");
                stream.Write(data, 0, data.Length);
                stream.Close();
                client.Close();


                return(new OperationResult(Result.OK, "File " + filename + " uploaded", SendingType.File));
            }
            catch (Exception e)
            {
                return(new OperationResult(Result.Fail, e.Message));
            }
        }
예제 #17
0
        public async Task <bool> AddAsync(FilePackage filePackage)
        {
            var sql = "insert into files_packages (" +
                      "file_id," +
                      "data," +
                      "content_file_name" +
                      ") values (" +
                      "@file_id," +
                      "@data," +
                      "@content_file_name" +
                      ")"
            ;

            try
            {
                using (var connection = new NpgsqlConnection(connectionString))
                {
                    this.LogQuery(sql, filePackage);
                    var affectedRowsNumber = await connection.ExecuteAsync(sql, filePackage);

                    return(affectedRowsNumber > 0);
                }
            }
            catch (NpgsqlException exception)
            {
                this._loggerError.WriteLn(
                    $"Ошибка в {nameof(FilesPackagesRepository)}.{nameof(FilesPackagesRepository.AddAsync)} {nameof(NpgsqlException)} ",
                    exception);
                return(false);
            }
            catch (Exception exception)
            {
                this._loggerError.WriteLn(
                    $"Ошибка в {nameof(FilesPackagesRepository)}.{nameof(FilesPackagesRepository.AddAsync)} {nameof(Exception)} ",
                    exception);
                return(false);
            }
        }
예제 #18
0
        public async Task <IActionResult> Push([FromForm] FilePackage package)
        {
            var packageFile = package.Package;

            if (packageFile == null)
            {
                packageFile = HttpContext.Request.Form.Files.FirstOrDefault();
            }

            if (packageFile == null)
            {
                return(BadRequest());
            }

            var file = Path.GetTempFileName();

            using (var stream = new FileStream(file, FileMode.OpenOrCreate))
            {
                await packageFile.CopyToAsync(stream);
            }

            return(Ok());
        }
예제 #19
0
        private async Task InsertFileToDbAsync(File file, FilePackage filePackage)
        {
            var projectLocales = await this._localeRepository.GetAllForProject(projectId : (Guid)file.id_localization_project);

            var fileUploaded = await this._filesRepository.UploadAsync(file, projectLocales);

            if (!fileUploaded)
            {
                Exception e = new Exception(($"Не удалось добавить файл \"{file.name_text}\" в базу данных."));
                WriteLn($"Не удалось добавить файл \"{file.name_text}\" в базу данных.", e);
                throw e;
            }

            if (filePackage != null)
            {
                var filePackageUploaded = await this._filesPackagesRepository.AddAsync(filePackage);
            }

            var addedFileId = (await this._filesRepository.GetLastVersionByNameAndParentIdAsync(file.name_text, file.id_folder_owner, (Guid)file.id_localization_project)).id;

            await this._filesRepository.AddTranslationLocalesAsync(
                fileId : addedFileId,
                localesIds : projectLocales.Select(locale => locale.id));
        }
예제 #20
0
 private void Receive(FilePackage filePackage_1)
 {
     try
     {
         this.fileStream_0.Write(filePackage_1.Data, 0, filePackage_1.Data.Length);
         this.ulong_0 += (ulong)filePackage_1.Data.Length;
         this.FileTransProgress(filePackage_1.ProjectID, this.ulong_1, this.ulong_0);
         if (this.ulong_0 == this.ulong_1)
         {
             this.fileStream_0.Flush();
             this.fileStream_0.Close();
             if (!File.Exists(this.string_0))
             {
                 File.Move(this.string_1, this.string_0);
             }
             this.diYatLwGC.ActionAsyn <string>("FileTransCompleted", this.FileTransCompleted, filePackage_1.ProjectID);
         }
     }
     catch (Exception exception)
     {
         this.emptyAgileLogger_0.Log(exception, "CJPlus.FileTransceiver.FileReceiver.Receive", ErrorLevel.Standard);
         this.FileTransDisruptted(this.HtwoUmmJj, FileTransDisrupttedType.InnerError, exception.Message);
     }
 }
예제 #21
0
파일: Class124.cs 프로젝트: jollitycn/JGNet
 public void FileReceive(FilePackage filePackage_1)
 {
     if ((this.object_0 == null) && (this.stream_0 != null))
     {
         this.int_0++;
         byte index = (byte)(this.byte_0 + 1);
         if (filePackage_1.Index == index)
         {
             this.method_1(filePackage_1);
             this.byte_0 = (byte)(this.byte_0 + 1);
             for (index = (byte)(this.byte_0 + 1); this.filePackage_0[index] != null; index = (byte)(this.byte_0 + 1))
             {
                 FilePackage package = this.filePackage_0[index];
                 this.filePackage_0[index] = null;
                 this.method_1(package);
                 this.byte_0 = (byte)(this.byte_0 + 1);
             }
         }
         else
         {
             this.filePackage_0[filePackage_1.Index] = filePackage_1;
         }
     }
 }
예제 #22
0
    public void sendMessage(string string_1, FilePackage filePackage_0)
    {
        IMessageHandler interface2 = this.interface9_0.imethod_4 <FilePackage>(this.string_0, this.int_0, filePackage_0, string_1);

        this.interface31_0.Send(interface2, false, ActionTypeOnChannelIsBusy.Continue);
    }
예제 #23
0
 public TextureAtlas(FilePackage file, bool flip) : this(file, file.parent(), flip)
 {
 }
예제 #24
0
 public TextureAtlas(FilePackage file, FilePackage imageDir) : this(file, imageDir, false)
 {
 }
예제 #25
0
 public TextureAtlas(FilePackage file, FilePackage imageDir, Boolean flip) : this(new AtlasData(file, imageDir, flip))
 {
 }
예제 #26
0
        public AtlasData(FilePackage atlasFile, FilePackage imageDir, bool flip)
        {
            int lineIndex = 0;

            string[] lines     = atlasFile.asString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
            Page     pageImage = null;

            while (lineIndex < lines.Length)
            {
                String line = lines[lineIndex];
                if (line == null)
                {
                    break;
                }
                if (line.Trim().Length == 0)
                {
                    pageImage = null;
                }
                else if (pageImage == null)
                {
                    FilePackage file = imageDir.child(line);

                    float width  = 0;
                    float height = 0;

                    lineIndex++;
                    int v = teeUp(lines[lineIndex]);
                    if (v == 2) //compatible with old texture packer
                    {
                        float.TryParse(tee[0], out width);
                        float.TryParse(tee[1], out height);
                        lineIndex++;
                        teeUp(lines[lineIndex]);
                    }

                    SurfaceFormat format = TextureAtlas.formatFromString(tee[0]);

                    lineIndex++;
                    teeUp(lines[lineIndex]);
                    //texture filters here ---- TextureFilter min = tee[0]
                    // - ---------------------- TextureFilter max = tee[1]

                    lineIndex++;
                    string direction = readValue(lines[lineIndex]);
                    //repeat stuff
                    //TextureWrap rx = clampToEdge;
                    //TextureWrap ry = ClampToEdge;
                    //if direction = x then rx = repeat;
                    //if direction = y then ry = repeat;
                    //if direction = xy then rx = ry = repeat;

                    pageImage = new Page(file, width, height, format);
                    pages.Add(pageImage);
                }
                else
                {
                    lineIndex++;
                    bool rotate = bool.Parse(readValue(lines[lineIndex]));

                    lineIndex++;
                    teeUp(lines[lineIndex]);
                    ArchonGame.writeLog("test:", tee[0]);
                    int left = int.Parse(tee[0]);
                    int top  = int.Parse(tee[1]);

                    lineIndex++;
                    teeUp(lines[lineIndex]);
                    int width  = int.Parse(tee[0]);
                    int height = int.Parse(tee[1]);

                    Region region = new Region();
                    region.page   = pageImage;
                    region.left   = left;
                    region.top    = top;
                    region.width  = width;
                    region.height = height;
                    region.name   = line;
                    region.rotate = rotate;

                    lineIndex++;
                    int v = teeUp(lines[lineIndex]);
                    if (v == 4) //optional splits included
                    {
                        region.splits = new[] { int.Parse(tee[0]), int.Parse(tee[1]), int.Parse(tee[2]), int.Parse(tee[3]) };
                        lineIndex++;
                        v = teeUp(lines[lineIndex]);
                        if (v == 4)//optional pads included - only happens when there is splits
                        {
                            region.pads = new int[] { int.Parse(tee[0]), int.Parse(tee[1]), int.Parse(tee[2]), int.Parse(tee[3]) };
                            lineIndex++;
                            teeUp(lines[lineIndex]);
                        }
                    }

                    region.originalWidth  = int.Parse(tee[0]);
                    region.originalHeight = int.Parse(tee[1]);

                    lineIndex++;
                    teeUp(lines[lineIndex]);

                    region.xOff = int.Parse(tee[0]);
                    region.yOff = int.Parse(tee[1]);

                    lineIndex++;
                    region.index = int.Parse(readValue(lines[lineIndex]));

                    region.flip = flip;

                    regions.Add(region);
                }


                lineIndex++;
            }

            regions.Sort(TextureAtlas.indexComparison);
        }
예제 #27
0
    private void method_1()
    {
        this.bool_1 = true;
        try
        {
            if (this.int_1 < this.int_0)
            {
                this.int_1 = this.int_0;
            }
            byte[] buff = new byte[this.int_1];
            byte[] dst  = new byte[this.int_0];
            byte   num5 = 0;
            while (this.ulong_1 >= this.ulong_0)
            {
                FilePackage package;
Label_0048:
                if (0 == 0)
                {
                    goto Label_0234;
                }
                ulong num = this.ulong_0 - this.ulong_1;
                if (num > ((ulong)buff.Length))
                {
                    FileHelper.ReadFileData(this.stream_0, buff, buff.Length, 0);
                }
                else
                {
                    buff = new byte[num];
                    FileHelper.ReadFileData(this.stream_0, buff, (int)num, 0);
                }
                this.bool_0 = true;
                int num4  = buff.Length / this.int_0;
                int count = buff.Length % this.int_0;
                for (int i = 0; i < num4; i++)
                {
                    if (this.object_0 != 0)
                    {
                        break;
                    }
                    Buffer.BlockCopy(buff, i * this.int_0, dst, 0, this.int_0);
                    this.ulong_1 += (ulong)dst.Length;
                    package       = new FilePackage(this.string_2, num5 = (byte)(num5 + 1), dst, PackageType.FileTransferingPackage);
                    this.interface35_0.sendMessage(this.string_1, package);
                    this.FileTransProgress(this.imethod_5(), this.ulong_0, this.ulong_1);
                    if (((this.Diaygioqui <= 0) ? 1 : this.object_0) == null)
                    {
                        Thread.Sleep(this.Diaygioqui);
                    }
                }
                if (((count <= 0) ? 1 : this.object_0) == null)
                {
                    byte[] buffer3 = new byte[count];
                    Buffer.BlockCopy(buff, num4 * this.int_0, buffer3, 0, count);
                    this.ulong_1 += (ulong)buffer3.Length;
                    package       = new FilePackage(this.string_2, num5 = (byte)(num5 + 1), buffer3, PackageType.FileTransferingPackage);
                    this.interface35_0.sendMessage(this.string_1, package);
                    this.FileTransProgress(this.imethod_5(), this.ulong_0, this.ulong_1);
                    if (((this.Diaygioqui <= 0) ? 1 : this.object_0) == null)
                    {
                        Thread.Sleep(this.Diaygioqui);
                    }
                }
            }
            // goto Label_0048;
Label_0234:
            if (this.object_0 == null)
            {
                this.FileTransCompleted(this.imethod_5());
            }
            else if (this.fileTransDisrupttedType_0 != FileTransDisrupttedType.NetworkSpeedSlow)
            {
                this.MhcyEttgGe(this.fileTransDisrupttedType_0, this.string_3);
            }
        }
        catch (Exception exception)
        {
            this.emptyAgileLogger_0.Log(exception, "CJPlus.FileTransceiver.FileSender.DoSend", ErrorLevel.Standard);
            this.MhcyEttgGe(FileTransDisrupttedType.InnerError, exception.Message);
        }
    }
예제 #28
0
    protected IMessageHandler method_5(IMessageHandler interface37_0)
    {
        TransferingProject      project;
        CancelFileContract      contract2;
        FileTransDisrupttedType type;

        if (interface37_0.Header.MessageType == this.object_0.BeginSendFile)
        {
            BeginSendFileContract contract3 = this.interface9_0.imethod_1 <BeginSendFileContract>(interface37_0);
            project = new TransferingProject(contract3.ProjectID, contract3.IsFolder, contract3.OriginPath, contract3.LastUpdateTime, interface37_0.Header.DestUserID, interface37_0.Header.UserID, contract3.TotalSize, false, contract3.Comment);
            ResumedProjectItem item = this.interface1_0.imethod_0(project);
            this.interface1_0.imethod_1(project);
            this.class26_0.method_9(contract3.ProjectID, interface37_0.Header.UserID, FileHelper.GetFileNameNoPath(contract3.OriginPath), contract3.TotalSize, item, contract3.Comment);
            return(null);
        }
        if (interface37_0.Header.MessageType == this.object_0.RejectOrAcceptFile)
        {
            RejectOrAcceptFileContract contract = this.interface9_0.imethod_1 <RejectOrAcceptFileContract>(interface37_0);
            project = this.interface7_0.imethod_2(contract.ProjectID);
            if (project != null)
            {
                project.method_2(contract.RejectCause);
                this.class26_0.method_7(project, contract.Agree);
                if (contract.Agree)
                {
                    project.TimeStarted   = DateTime.Now;
                    project.IsTransfering = true;
                    this.interface7_0.HnFdepcbbe(contract.ProjectID, contract.ReceivedCount, contract.DisrupttedFileRelativePath, contract.DisrupttedFileReceivedCount);
                }
                else
                {
                    this.interface7_0.imethod_7(contract.ProjectID, FileTransDisrupttedType.RejectAccepting, null);
                }
            }
            return(null);
        }
        if (interface37_0.Header.MessageType == this.object_0.FilePackageData)
        {
            FilePackage package = this.interface9_0.imethod_1 <FilePackage>(interface37_0);
            this.interface1_0.ocqOcyhOmB(interface37_0.Header.UserID, package);
            return(null);
        }
        if (interface37_0.Header.MessageType == this.object_0.CancelFileSending)
        {
            contract2 = this.interface9_0.imethod_1 <CancelFileContract>(interface37_0);
            type      = contract2.InnerError ? FileTransDisrupttedType.DestInnerError : FileTransDisrupttedType.DestCancel;
            this.interface1_0.imethod_5(contract2.ProjectID, type, contract2.Cause);
            return(null);
        }
        if (interface37_0.Header.MessageType == this.object_0.CancelFileReceiving)
        {
            contract2 = this.interface9_0.imethod_1 <CancelFileContract>(interface37_0);
            type      = contract2.InnerError ? FileTransDisrupttedType.DestInnerError : FileTransDisrupttedType.DestCancel;
            this.interface7_0.imethod_7(contract2.ProjectID, type, contract2.Cause);
            return(null);
        }
        if (interface37_0.Header.MessageType == this.object_0.SingleFileRevFinishedNotify)
        {
            SingleFileNotifyContract contract4 = this.interface9_0.imethod_1 <SingleFileNotifyContract>(interface37_0);
            this.interface7_0.imethod_12(contract4.ProjectID);
            return(null);
        }
        return(null);
    }
예제 #29
0
        private void ReadCallback(IAsyncResult ar)
        {
            Socket handler  = (Socket)ar.AsyncState;
            int    received = handler.EndReceive(ar);

            if (received > 0)
            {
                sb.Append(Encoding.ASCII.GetString(buffer, 0, received));
                string content = sb.ToString();

                if (content.IndexOf(ServerConstants.EOF) > -1)
                {
                    content = content.Substring(0, content.Length - 5);
                    serverTB.AppendText("Read " + content.Length + " bytes from socket.\r\nData: " + content + "\r\n\r\n");

                    var deserialized = JsonConvert.DeserializeObject <PackageWrapper>(content);
                    if (deserialized.PackageType == typeof(LoginPackage))
                    {
                        LoginPackage lp = (LoginPackage)JsonConvert.DeserializeObject(Convert.ToString(deserialized.Package), deserialized.PackageType);

                        ClientsDetailsPackage client = Client.getClientsDetailsPackage(lp);

                        byte[] sendClient = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(client) + ServerConstants.EOF);
                        handler.BeginSend(sendClient, 0, sendClient.Length, 0, new AsyncCallback(SendCallback), handler);
                    }

                    else if (deserialized.PackageType == typeof(FileSearch))
                    {
                        FileSearch fs = (FileSearch)JsonConvert.DeserializeObject(Convert.ToString(deserialized.Package), deserialized.PackageType);

                        List <FileDetails> lfd        = new List <FileDetails>();
                        List <File>        listFile   = new List <File>();
                        List <ClientFile>  listClient = new List <ClientFile>();
                        Client             client     = new Client();
                        FilePackage        fp         = new FilePackage();

                        if (fs.FileName.CompareTo("*") == 0)
                        {
                            listFile = File.getAllFilesList();

                            foreach (var item in listFile)
                            {
                                listClient = ClientFile.getAllFilesById(item.Id);
                                foreach (var item2 in listClient)
                                {
                                    client.getClient(item2.Username);

                                    FileDetails f = new FileDetails
                                    {
                                        Username = item2.Username,
                                        FileName = item.Name,
                                        FileSize = item.Size,
                                        Ip       = client.Ip,
                                        Port     = client.Port
                                    };

                                    lfd.Add(f);
                                }
                            }

                            fp.Exist     = true;
                            fp.FilesList = lfd;
                        }

                        else if (!File.isFileExist(fs.FileName))
                        {
                            fp.Exist = false;
                        }

                        else
                        {
                            listFile = File.getAllFilesListByName(fs.FileName);

                            foreach (var item in listFile)
                            {
                                listClient = ClientFile.getAllFilesById(item.Id);
                                foreach (var item2 in listClient)
                                {
                                    client.getClient(item2.Username);
                                    int size = item.Size;

                                    FileDetails f = new FileDetails
                                    {
                                        Username = item2.Username,
                                        FileName = item.Name,
                                        FileSize = size,
                                        Ip       = client.Ip,
                                        Port     = client.Port
                                    };

                                    lfd.Add(f);
                                }
                            }

                            fp.Exist     = true;
                            fp.FilesList = lfd;
                        }

                        byte[] sendAnswer = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(fp) + ServerConstants.EOF);
                        handler.BeginSend(sendAnswer, 0, sendAnswer.Length, 0, new AsyncCallback(SendCallback), handler);
                    }

                    else
                    {
                        LogoutPackage lp = (LogoutPackage)JsonConvert.DeserializeObject(Convert.ToString(deserialized.Package), deserialized.PackageType);
                        Client.setLogOut(lp.Username);
                    }
                }

                else
                {
                    handler.BeginReceive(buffer, 0, ServerConstants.BufferSize, 0, new AsyncCallback(ReadCallback), handler);
                }

                sb.Clear();
                handler.BeginReceive(buffer, 0, ServerConstants.BufferSize, 0, new AsyncCallback(ReadCallback), handler);
            }
        }
예제 #30
0
    private void DoSend()
    {
        this.bool_1 = true;
        FileStream fs = null;

        try
        {
            fs = new FileStream(this.string_0, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            fs.Seek((long)this.ulong_0, SeekOrigin.Begin);
            this.ulong_1 = (ulong)fs.Length;
            this.ulong_2 = this.ulong_0;
            if (this.int_2 < this.int_0)
            {
                this.int_2 = this.int_0;
            }
            byte[] buff = new byte[this.int_2];
            byte[] dst  = new byte[this.int_0];
            byte   num2 = 0;
            while (this.ulong_2 >= this.ulong_1)
            {
                FilePackage package;
                if (0 == 0)
                {
                    goto Label_0265;
                }
                ulong num3 = this.ulong_1 - this.ulong_2;
                if (num3 > ((ulong)buff.Length))
                {
                    FileHelper.ReadFileData(fs, buff, buff.Length, 0);
                }
                else
                {
                    buff = new byte[num3];
                    FileHelper.ReadFileData(fs, buff, (int)num3, 0);
                }
                this.bool_0 = true;
                int num5  = buff.Length / this.int_0;
                int count = buff.Length % this.int_0;
                for (int i = 0; i < num5; i++)
                {
                    if (this.object_0 != 0)
                    {
                        break;
                    }
                    Buffer.BlockCopy(buff, i * this.int_0, dst, 0, this.int_0);
                    this.ulong_2 += (ulong)dst.Length;
                    package       = new FilePackage(this.string_2, num2 = (byte)(num2 + 1), dst, PackageType.FileTransferingPackage);
                    this.interface35_0.sendMessage(this.string_1, package);
                    this.cbFileSendedProgress_1(this.imethod_5(), this.ulong_1, this.ulong_2);
                    if (((this.int_1 <= 0) ? 1 : this.object_0) == null)
                    {
                        Thread.Sleep(this.int_1);
                    }
                }
                if (((count <= 0) ? 1 : this.object_0) == null)
                {
                    byte[] buffer3 = new byte[count];
                    Buffer.BlockCopy(buff, num5 * this.int_0, buffer3, 0, count);
                    this.ulong_2 += (ulong)buffer3.Length;
                    package       = new FilePackage(this.string_2, num2 = (byte)(num2 + 1), buffer3, PackageType.FileTransferingPackage);
                    this.interface35_0.sendMessage(this.string_1, package);
                    this.cbFileSendedProgress_1(this.imethod_5(), this.ulong_1, this.ulong_2);
                    if (((this.int_1 <= 0) ? 1 : this.object_0) == null)
                    {
                        Thread.Sleep(this.int_1);
                    }
                }
            }
            //  goto Label_007E;
Label_0265:
            fs.Close();
            if (this.object_0 == null)
            {
                this.cbFileTransCompleted_1(this.imethod_5());
            }
            else if (this.fileTransDisrupttedType_0 != FileTransDisrupttedType.NetworkSpeedSlow)
            {
                this.method_2(this.fileTransDisrupttedType_0, this.string_3);
            }
        }
        catch (Exception exception)
        {
            this.emptyAgileLogger_0.Log(exception, "CJPlus.FileTransceiver.FileSender.DoSend", ErrorLevel.Standard);
            this.method_2(FileTransDisrupttedType.InnerError, exception.Message);
            if (fs != null)
            {
                fs.Close();
            }
        }
    }