Example #1
0
        /// <summary>
        /// Отправка файла на сервер
        /// </summary>
        /// <param name="settingName">название настройки</param>
        /// <param name="Continue">продолжить с момента разрыва</param>
        public void UploadFileToServer(string settingName)
        {
            Logger logger = LogManager.GetCurrentClassLogger();

            logger.Debug(settingName + ": Начало отправки файла на сервер");
            var baseConfig = GetBaseConfig(settingName);
            ChannelFactory <IFileTransfer> factory;

            SetCurrentStatus(settingName, Job.SendFileToServer, JobStatus.Process);
            OnExchangeProcess(GetCurrentStatus(settingName));

            Status remoteStatus = RemoteGetCurrentStatus(settingName);

            if (remoteStatus.jobStatus == JobStatus.Error && remoteStatus.description.Contains("Не найдена настройка"))
            {
                throw new Exception(remoteStatus.description);
            }

            //закорем поток после передачи
            using (FileData sendData = new FileData()){
                sendData.settingName    = settingName;
                sendData.fileByteStream = GetCompressFileStream(settingName);

                //попробуем загрузить из файла конфигурации
                try{
                    factory = new ChannelFactory <IFileTransfer>("IFileTransfer");
                }
                catch {
                    //если нет то создаем вручную

                    NetTcpBinding streamBinding = new NetTcpBinding(SecurityMode.None);
                    streamBinding.CloseTimeout           = TimeSpan.FromHours(0.5);
                    streamBinding.OpenTimeout            = TimeSpan.FromHours(0.5);
                    streamBinding.SendTimeout            = TimeSpan.FromHours(13);
                    streamBinding.TransferMode           = TransferMode.Buffered;
                    streamBinding.MaxReceivedMessageSize = 429496729;

                    EndpointAddress endpointAdress = new EndpointAddress(config.HostSetting.Protocol + @"://" + baseConfig.ServerAdress + "/FileTransfer");
                    factory = new ChannelFactory <IFileTransfer>(streamBinding, endpointAdress);
                }

                IFileTransfer channel = factory.CreateChannel();
                if (remoteStatus.currentPosInFile > 0)
                {
                    sendData.fileByteStream.Seek(remoteStatus.currentPosInFile, SeekOrigin.Begin);
                }

                channel.UploadFile(sendData);
                factory.Close();
            }

            logger.Debug(settingName + ": Конец отправки файла на сервер");
            SetCurrentStatus(settingName, Job.SendFileToServer, JobStatus.Complite, "", 0);
            OnExchangeProcess(GetCurrentStatus(settingName));
        }