/// <summary> /// Recieve data from client, update it and retrun /// </summary> /// <param name="data">Recieved data</param> /// <returns>Updated data</returns> public byte[] RecieveAndSend(byte[] data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } try { Configuration = new DirectoryCloneConfiguration(data); mainClient = CreateFileClient(); var sessionMap = $"{DateTime.Now.ToBinary()}_Map.xml"; mainClient.LoadFile(sessionMap, "Map.xml"); DirectoryUnmapper.Client = mainClient; using (var mapStream = File.OpenRead(sessionMap)) { DirectoryUnmapper.CreateDirectoryByMap(mapStream, Configuration.TargetDirectory); } } catch (Exception ex) { using (var exeptionStream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(exeptionStream, ex); return exeptionStream.ToArray(); } } return new byte[] {0}; }
public void StartCloneAsync(DirectoryCloneConfiguration cloneConfiguration) { if (cloneConfiguration == null) { throw new ArgumentNullException(nameof(cloneConfiguration)); } StatusChanged += () => ((IServiceHandler) this).StartCloneAsync(cloneConfiguration); ((IServiceHandler) this).StartCloneAsync(cloneConfiguration); }
public void StartCloneAsync(DirectoryCloneConfiguration cloneConfiguration) { var cloneThread = new Thread(((IServiceHandler) this).StartClone); cloneThread.Start(cloneConfiguration); }
public void StartClone(DirectoryCloneConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (Status != ServiceHandlerStatus.Ready) { return; } lock (mainClientLockObject) { Status = ServiceHandlerStatus.Busy; var result = mainClient.SendAndRecieve(new byte[] {0}, configuration.ToBytes()); if (result.Length > 1) { MessageBox.Show("Service error!"); //Status = ServiceHandlerStatus.Error; //using (var exceptionStream = new MemoryStream(result)) //{ // exceptionStream.Write(result, 0, result.Length); // using (var leftoverStream = mainClient.ReceiveUntilEndStream()) // { // exceptionStream.Write(leftoverStream.ToArray(),0,(int) leftoverStream.Length); // } // var formatter = new BinaryFormatter(); // var exception = formatter.Deserialize(exceptionStream) as Exception; // if (exception != null) // throw new ServiceException(exception,Ip); //} } Status = ServiceHandlerStatus.Complete; } }
private void InitializeClone(object sender, DoWorkEventArgs doWorkEventArgs) { OnStatusChanged("Creating cloning directory map..."); DirectoryMapper.CreateDirectoryMapFile(sessionSetting.SourcePath); OnStatusChanged("Creating clone configuration for services..."); directoryCloneConfiguration = CreateConfiguration(sessionSetting); OnStatusChanged("Starting file server..."); fileServer = new FileServer(sessionSetting.SourcePath, sessionSetting.FileServerPort, startNow: true); OnStatusChanged("Load selected group information..."); serviceHandlerComposite = new ServiceHandlerComposite (MachineCompositHandler.ReadComposit(sessionSetting.SelectedGroup), SettingsHandler.ServicePort); serviceHandlerComposite.StatusChanged += ServiceHandlerStatusChanged; OnStatusChanged("Starting timers..."); RunTimers(); OnStatusChanged("Complete"); }