/// <summary> /// 创建连接 /// </summary> public void CreateConnection() { InitComm();//初始化通信 clientObj.WcfService = baseServiceClient; //string serverConfig = null; baseServiceClient.Open(); //AddMessageHeader(baseServiceClient.InnerDuplexChannel as IContextChannel, "", (() => //{ clientObj.ClientID = baseServiceClient.CreateClient(clientObj.ClientName, PluginName, BeginIdentify);//创建连接获取ClientID if (ServerConfigRequestState == false) { //重新获取服务端配置,如:是否压缩Json、是否加密Json //serverConfig = baseServiceClient.MiddlewareConfig(); serverConfig = JsonConvert.DeserializeObject <ServerConfigObject>(baseServiceClient.GetServerConfig()); ServerConfigRequestState = true; } //})); if (serverConfig != null) { if (serverConfig.IsHeartbeat) { //开启发送心跳 if (timer == null) { StartTimer(); } else { timer.Start(); } } else { if (timer != null) { timer.Stop(); } } } //if (backConfig != null) //{ // backConfig(IsMessage, MessageTime); //} //if (createconnAction != null) //{ // createconnAction(); //} }
/// <summary> /// 客户端连接对象需要从服务端获取的配置 /// </summary> /// <returns></returns> public static string GetServerConfig() { ServerConfigObject config = new ServerConfigObject(); config.Identify = WcfGlobal.Identify; config.HostName = WcfGlobal.HostName; config.IsToken = WcfGlobal.IsToken; config.IsHeartbeat = true; //写死,不通过配置 ClientManage.IsHeartbeat; config.HeartbeatTime = ClientManage.HeartbeatTime; config.IsMessage = true; //写死 ClientManage.IsMessage; config.MessageTime = 3; //写死 ClientManage.MessageTime; config.IsCompressJson = WcfGlobal.IsCompressJson; config.IsEncryptionJson = WcfGlobal.IsEncryptionJson; config.SerializeType = (int)WcfGlobal.serializeType; return(JsonConvert.SerializeObject(config)); }
private void SaveFile(string filename, ServerConfigObject configObject) { try { using (StreamWriter stream = new StreamWriter(filename)) { string json = JsonConvert.SerializeObject(configObject, Formatting.Indented); stream.Write(json); stream.Flush(); } } catch (IOException e) { log.Error($"Unable to create new file {filename}: {e}!"); } log.Info("Created new server settings file from defaults."); }
private void ReadFile(string filename) { try { using (StreamReader stream = new StreamReader(filename)) { string json = stream.ReadToEnd(); _configObject = JsonConvert.DeserializeObject <ServerConfigObject>(json); stream.Close(); } } catch (FileNotFoundException) { log.Error($"{filename} does not exist. Creating."); SaveFile(filename, _configObject); } catch (IOException e) { log.Error($"Unable to load configuration file {filename}: {e}!"); } log.Debug($"Loaded settings file {filename}"); }
/// <summary> /// 发送心跳 /// 为心跳单独创建一个通道 /// </summary> /// <returns></returns> private bool Heartbeat() { //DuplexBaseServiceClient _wcfService = clientObj.WcfService; if (clientObj.WcfService.State == CommunicationState.Closed || clientObj.WcfService.State == CommunicationState.Faulted) { ReConnection(false);//连接服务主机失败,重连 } try { bool ret = false; //string serverConfig = null; // AddMessageHeader(_wcfService.InnerDuplexChannel as IContextChannel, "", (() => //{ ret = clientObj.WcfService.Heartbeat(clientObj.ClientID); if (ServerConfigRequestState == false) { //重新获取服务端配置,如:是否压缩Json、是否加密Json serverConfig = JsonConvert.DeserializeObject <ServerConfigObject>(clientObj.WcfService.GetServerConfig()); ServerConfigRequestState = true; } //})); if (serverConfig != null) { //if (backConfig != null) // backConfig(IsMessage, MessageTime); if (serverConfig.IsHeartbeat) { //开启发送心跳 if (timer == null) { StartTimer(); } else { timer.Start(); } } else { if (timer != null) { timer.Stop(); } } } if (ret == false)//表示服务主机关闭过,丢失了clientId,必须重新创建连接 { //ReConnection(false);//连接服务主机失败,重连 clientObj.WcfService.Abort(); CreateConnection(); //MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "上级中间件已丢失客户端信息,重新创建客户端连接成功!"); } return(ret); } catch (Exception err) { //MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "上级中间件失去连接!\n" + clientObj.PluginName + "\n" + err.Message); ServerConfigRequestState = false; //ReConnection(false);//连接服务主机失败,重连 return(false); } }
public void LoadSettings() { _settingDb = _configRepository.GetConfigObject(); }
/// <summary> /// ASYNC: calculates the results of the point cloud and returns a result package; throws OnResultPackageEvent when done, OnErrorEvent when an error occured /// </summary> /// <param name="pInputCloud">the input cloud</param> /// <param name="pAlgorithm">the algorithm to chose</param> /// <param name="pSettings">the configuration object</param> public void calculateResults(PointCloud pInputCloud, ServerConfigObject pConfig) { _CancelTokenSource = new CancellationTokenSource(); Log.LogManager.updateAlgorithmStatus("Start Calculation Service"); Task <ScanResultPackage> t = new Task <ScanResultPackage>(() => { //remove calibrated planes pInputCloud.removePlaneFromPointcloud(pConfig.serverAlgorithmConfig.calibratedPlanes, pConfig.serverAlgorithmConfig.planar_ThresholdDistance); this.OnNewPointPicturesEvent(pInputCloud.pictures); //remove calibrated objects pInputCloud.removePointcloudsFromPointCloud(pConfig.serverAlgorithmConfig.calibratedObjects, pConfig.serverAlgorithmConfig.euclidean_ExtractionRadius); this.OnNewPointPicturesEvent(pInputCloud.pictures); //remove noise via euclidean cluster extraction, discard too small ones List <PointCloud> pointCloudList = EuclideanClusterExtraction.calculateEuclideanClusterExtraction(pInputCloud, pConfig.serverAlgorithmConfig.euclidean_ExtractionRadius, _CancelTokenSource.Token); pointCloudList.RemoveAll(pcl => pcl.delaunayVolume < pConfig.serverAlgorithmConfig.euclidean_MinimumVolume); if (pointCloudList.Count == 0) { throw new Exception("No valid point clouds found!"); } //calculate items in result package _CancelTokenSource.Token.ThrowIfCancellationRequested(); ScanResultPackage resultPack = new ScanResultPackage(); PlaneModel floorPlane = pConfig.serverAlgorithmConfig.calibratedPlanes.Find(pl => pl.isFloor); //create concav and convex areas List <IntermediateScanResultPackage> intermediateResultList = Algorithm.PlanarVolumeCalculation.CalculateIntermediateScanresults(pointCloudList, floorPlane, pConfig.serverAlgorithmConfig.downsamplingFactor, pConfig.serverAlgorithmConfig.concav_angleThreshold); //sum up convex and concav volume resultPack.convexScannedAlgorithmVolume = 0d; resultPack.concavScannedAlgorithmVolume = 0d; foreach (IntermediateScanResultPackage p in intermediateResultList) { resultPack.convexScannedAlgorithmVolume += p.convexPlaneArea * p.averageHeight; resultPack.concavScannedAlgorithmVolume += p.concavPlaneArea * p.averageHeight; } //calculate best fit for container matching, check first if container calibration exist, aggregate result resultPack.containerResults = null; resultPack.estimatedPayloadVolume = 0; if (pConfig.calibratedContainers.Count > 0) { List <ContainerCalculation.tModel> bestFitSolutions = ContainerCalculation.CalculateBestFitSolutions(intermediateResultList, pConfig.calibratedContainers); resultPack.containerResults = new List <ScanResultPackage.ContainerResult>(); //go through the best fit solution for every point cloud foreach (ContainerCalculation.tModel p in bestFitSolutions) { foreach (Post_knv_Server.CalculationService.ContainerCalculation.tContainerModel m in p.containerResults) { //check if container exists in containerResults, if not add, if yes, just add if (resultPack.containerResults.Exists(q => q.containerType == m.containerType)) { resultPack.containerResults.Find(q => q.containerType == m.containerType).amount += m.amountOfContainers; } else { ScanResultPackage.ContainerResult res = new ScanResultPackage.ContainerResult(); res.containerType = m.containerType; res.amount = m.amountOfContainers; resultPack.containerResults.Add(res); } //add container volume resultPack.estimatedPayloadVolume += m.containerType.containerVolume * m.amountOfContainers; } } //accumulate rating resultPack.containerAccuracy = bestFitSolutions.Average(i => i.pRating); //estimate payload resultPack.estimatedPayloadVolume = resultPack.concavScannedAlgorithmVolume - resultPack.estimatedPayloadVolume; } //create results resultPack.timestamp = DateTime.Now; resultPack.algorithmUsed = pConfig.serverAlgorithmConfig.useAlgorithm; resultPack.numberOfClouds = pointCloudList.Count; resultPack.numberOfPoints = pointCloudList.Sum(p => p.count); resultPack.scannedDelaunayVolume = pointCloudList.Sum(p => p.delaunayVolume); resultPack.amountOfKinectsDataRequested = pInputCloud.ConfigObject.clientRequestObject.amountOfKinectsInRequest; return(resultPack); }, _CancelTokenSource.Token); //task finishing t.ContinueWith(calculationFinishedSuccessfully, TaskContinuationOptions.OnlyOnRanToCompletion); t.ContinueWith(exceptionHandler, TaskContinuationOptions.OnlyOnFaulted); t.Start(); }