public void StartClient(Socket clientSocket) { networkStreamIn = new NetworkStream(clientSocket); networkStreamOut = new NetworkStream(clientSocket); //TODO create an action for logging in etc, and have the action processor manage it while (!isLoggedIn) { ClientID = Receive(networkStreamIn); logger.Info("ConnectionToClient received name: " + ClientID); if (database.KeyExists($"{ElementType.CHANNEL}:" + ClientID)) { // TODO change this to an object to send back, should be handled by above todo Send("\nName already exist, choose again:"); } else { actionProcessor.Process(new CreateAction(ClientID, ElementType.CHANNEL, $"{ClientID}")); isLoggedIn = true; database.SetAdd("loggedIn", ClientID); } } Thread receiveThread = new Thread(ReceiveLoop); receiveThread.Start(); }
public static void DoPreProcessing() { string commandFile = @"E:\SourceCode\40copoka\DPP\Source\UnitTests\CommandLineAction.UnitTest\Output\CommandLineAction.UnitTest.exe"; var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsCore.RunCommandLine }; var prm = new IActionParam[] { action, new ActionParam <string>() { ParamName = ActionParamNamesCore.PathToFile, Value = commandFile }, new ActionParam <string>() { ParamName = ActionParamNamesCore.DataValue, Value = string.Empty }, new ActionParam <ActionProcessCommandLineDelegate>() { ParamName = ActionParamNamesCore.OutputDataReceivedDelegate, Value = OnOutputCommandLine }, new ActionParam <ActionProcessCommandLineDelegate>() { ParamName = ActionParamNamesCore.ErrorDataReceivedDelegate, Value = OnErrorCommandLine } }; var procc = new ActionProcessor(prm); var res = procc.Process <StringActionResult>(); }
public void Process() { var gotCalled = false; var ap = new ActionProcessor <int>(async(i) => { gotCalled = true; return(await Task.FromResult <bool>(true)); }); ap.Process(0).Wait(); Assert.IsTrue(gotCalled); }
public virtual void Process(TPacket packet) { Check.Require(packet != null); if (FilterProcessor != null) { FilterProcessor.Process(packet); } if (packet.HasError) { return; } if (ActionProcessor != null) { ActionProcessor.Process(packet); } }
public void CopySrtmRasterToStoreage(IEnumerable <string> rasterFiles, bool replaceExisted) { if (rasterFiles == null) { throw new FileLoadException("Srtm files were not defined"); } var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.demCopyRaster.ToString() }; var prm = new IActionParam[] { action, new ActionParam <IEnumerable <string> >() { ParamName = ActionParameters.Files, Value = rasterFiles.ToArray() }, new ActionParam <bool>() { ParamName = ActionParameters.ReplaceOnExists, Value = replaceExisted }, new ActionParam <ResterStorageTypesEnum>() { ParamName = ActionParameters.ResterStorageType, Value = ResterStorageTypesEnum.Srtm }, }; var procc = new ActionProcessor(prm); var res = procc.Process <CopyRasterResult>(); foreach (var line in res.Result.Log) { log.InfoEx(line); } if (res.Result.CopoedFiles.Count() != rasterFiles.Count()) { throw new FormatException("Not all SRTM files were coppied"); } }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("You should define at least 3 parameters"); return; } var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.bsp.ToString() }; var prm = new List <IActionParam> { action, new ActionParam <string>() { ParamName = ActionParameters.FeatureClass, Value = args[0] }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = args[1] }, new ActionParam <string>() { ParamName = ActionParameters.DataWorkSpace, Value = args[2] }, new ActionParam <string>() { ParamName = ActionParameters.OutGraphName, Value = args.Length > 3 ? args[3] : null } }; var procc = new ActionProcessor(prm); var res = procc.Process <StringActionResult>(); Console.WriteLine(res.Result); }
public void GenerateProfile(string profileSource, IEnumerable <ILine> profileLines) { string profileSourceName = GdbAccess.Instance.AddProfileLinesToCalculation(profileLines); var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.bsp.ToString() }; string sdtnow = MilSpace.DataAccess.Helper.GetTemporaryNameSuffix(); var resuTable = $"{MilSpaceConfiguration.ConnectionProperty.TemporaryGDBConnection}\\StackProfile{sdtnow}"; var profileLineFeatureClass = GdbAccess.Instance.GetProfileLinesFeatureClass(profileSourceName); var prm = new List <IActionParam> { action, new ActionParam <string>() { ParamName = ActionParameters.FeatureClass, Value = profileLineFeatureClass }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = profileSource }, new ActionParam <string>() { ParamName = ActionParameters.DataWorkSpace, Value = resuTable }, new ActionParam <string>() { ParamName = ActionParameters.OutGraphName, Value = "" } }; var procc = new ActionProcessor(prm); var res = procc.Process <BoolResult>(); if (!res.Result) { if (res.Exception != null) { throw res.Exception; } //TODO: Log error throw new Exception(res.ErrorMessage); } //Teke the table and import the data try { ITable profiletable = GdbAccess.Instance.GetProfileTable($"StackProfile{sdtnow}"); IQueryFilter queryFilter = new QueryFilter() { WhereClause = "OBJECTID > 0" }; ICursor featureCursor = profiletable.Search(queryFilter, true); IRow profileRow; int distanceFld = profiletable.FindField(FIRST_DIST_Field); int zFld = profiletable.FindField(FIRST_Z_Field); int idFld = profiletable.FindField(LINE_ID_Field); List <ProfileSurface> profileSurfaces = new List <ProfileSurface>(); ProfileSession session = new ProfileSession() { ProfileSurface = profileSurfaces.ToArray() }; Dictionary <int, List <ProfileSurfacePoint> > surface = new Dictionary <int, List <ProfileSurfacePoint> >(); while ((profileRow = featureCursor.NextRow()) != null) { int lineId = Convert.ToInt32(profileRow.Value[idFld]); List <ProfileSurfacePoint> points; if (!surface.ContainsKey(lineId)) { points = new List <ProfileSurfacePoint>(); surface.Add(lineId, points); } else { points = surface[lineId]; } points.Add(new ProfileSurfacePoint { Distance = (double)profileRow.Value[distanceFld], Z = (double)profileRow.Value[zFld] }); } //TODO: Clean memo using Marhsaling IRow session.ProfileSurface = surface.Select(r => new ProfileSurface { LineId = r.Key, ProfileSurfacePoints = r.Value.ToArray() } ).ToArray(); XmlSerializer serializer = new XmlSerializer(typeof(ProfileSession)); TextWriter writer = new StreamWriter(@"E:\SourceCode\Copoka\Tmp\temp.xml"); serializer.Serialize(writer, session); writer.Close(); writer.Dispose(); } catch (Exception ex) { //TODO: Log error throw ex; } }
public ProfileSession GenerateProfile( string profileSource, IEnumerable <IPolyline> profileLines, ProfileSettingsTypeEnum profileSettingsTypeEnum, int sessionId, string sessionName) { string profileSourceName = GdbAccess.Instance.AddProfileLinesToCalculation(profileLines); var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.bsp.ToString() }; string sdtnow = MilSpace.DataAccess.Helper.GetTemporaryNameSuffix(); var resuTable = $"{MilSpaceConfiguration.ConnectionProperty.TemporaryGDBConnection}\\StackProfile{sdtnow}"; var profileLineFeatureClass = GdbAccess.Instance.GetProfileLinesFeatureClass(profileSourceName); var prm = new List <IActionParam> { action, new ActionParam <string>() { ParamName = ActionParameters.FeatureClass, Value = profileLineFeatureClass }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = profileSource }, new ActionParam <string>() { ParamName = ActionParameters.DataWorkSpace, Value = resuTable }, new ActionParam <string>() { ParamName = ActionParameters.OutGraphName, Value = "" } }; var procc = new ActionProcessor(prm); var res = procc.Process <BoolResult>(); if (!res.Result) { if (res.Exception != null) { throw res.Exception; } //TODO: Log error throw new Exception(res.ErrorMessage); } //Take the table and import the data ISpatialReference currentSpatialreference = profileLines.First().SpatialReference; try { ITable profiletable = GdbAccess.Instance.GetProfileTable($"StackProfile{sdtnow}"); IFeatureClass lines = GdbAccess.Instance.GetCalcProfileFeatureClass(profileSourceName); IQueryFilter queryFilter = new QueryFilter() { WhereClause = WhereAllRecords }; ICursor featureCursor = profiletable.Search(queryFilter, true); IRow profileRow; int distanceFld = profiletable.FindField(FIRST_DIST_Field); int zFld = profiletable.FindField(FIRST_Z_Field); int idFld = profiletable.FindField(LINE_ID_Field); List <ProfileSurface> profileSurfaces = new List <ProfileSurface>(); ProfileSession session = new ProfileSession() { ProfileSurfaces = profileSurfaces.ToArray(), ProfileLines = GetProfileLines(lines).ToArray(), SessionId = sessionId, SessionName = sessionName, DefinitionType = profileSettingsTypeEnum }; Dictionary <int, List <ProfileSurfacePoint> > surface = new Dictionary <int, List <ProfileSurfacePoint> >(); int curLine = -1; IPolyline line = null; IPoint firstPoint = null; while ((profileRow = featureCursor.NextRow()) != null) { int lineId = Convert.ToInt32(profileRow.Value[idFld]); var profileLine = session.ProfileLines.FirstOrDefault(l => l.Id == lineId); if (profileLine == null) { throw new MilSpaceProfileLineNotFound(lineId, profileLineFeatureClass); } List <ProfileSurfacePoint> points; if (!surface.ContainsKey(lineId)) { points = new List <ProfileSurfacePoint>(); surface.Add(lineId, points); } else { points = surface[lineId]; } if (curLine != lineId) { curLine = lineId; line = lines.GetFeature(profileLine.Id).Shape as IPolyline; firstPoint = line.FromPoint; } var profilePoint = EsriTools.GetPointFromAngelAndDistance(firstPoint, profileLine.Angel, (double)profileRow.Value[distanceFld]); profilePoint.Project(EsriTools.Wgs84Spatialreference); points.Add(new ProfileSurfacePoint { Distance = (double)profileRow.Value[distanceFld], Z = (double)profileRow.Value[zFld], X = profilePoint.X, Y = profilePoint.Y }); } //TODO: Clean memo using Marhsaling IRow session.ProfileSurfaces = surface.Select(r => new ProfileSurface { LineId = r.Key, ProfileSurfacePoints = r.Value.ToArray() } ).ToArray(); //Write to DB if (!MilSpaceProfileFacade.SaveProfileSession(session)) { return(null); } return(session); } catch (MilSpaceDataException ex) { //TODO: Log error throw ex; } catch (Exception ex) { //TODO: Log error throw ex; } }
public ProfileSession GenerateProfile( string profileSource, IEnumerable <IPolyline> profileLines, ProfileSettingsTypeEnum profileSettingsTypeEnum, int sessionId, string sessionName, double observHeight, string azimuthes) { string profileSourceName = GdbAccess.Instance.AddProfileLinesToCalculation(profileLines); var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.bsp.ToString() }; string sdtnow = MilSpace.DataAccess.Helper.GetTemporaryNameSuffix(); var resuTable = $"{MilSpaceConfiguration.ConnectionProperty.TemporaryGDBConnection}\\StackProfile{sdtnow}"; var profileLineFeatureClass = GdbAccess.Instance.GetProfileLinesFeatureClass(profileSourceName); var prm = new List <IActionParam> { action, new ActionParam <string>() { ParamName = ActionParameters.FeatureClass, Value = profileLineFeatureClass }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = profileSource }, new ActionParam <string>() { ParamName = ActionParameters.DataWorkSpace, Value = resuTable }, new ActionParam <string>() { ParamName = ActionParameters.OutGraphName, Value = "" } }; var procc = new ActionProcessor(prm); var res = procc.Process <BoolResult>(); if (!res.Result) { if (res.Exception != null) { throw res.Exception; } //TODO: Log error throw new Exception(res.ErrorMessage); } //Take the table and import the data ISpatialReference currentSpatialreference = profileLines.First().SpatialReference; try { string tempTableName = $"StackProfile{sdtnow}"; ITable profiletable = GdbAccess.Instance.GetProfileTable(tempTableName); IFeatureClass lines = GdbAccess.Instance.GetCalcProfileFeatureClass(profileSourceName); IQueryFilter queryFilter = new QueryFilter() { WhereClause = WhereAllRecords }; ICursor featureCursor = profiletable.Search(queryFilter, true); IRow profileRow; int distanceFld = profiletable.FindField(FIRST_DIST_Field); int zFld = profiletable.FindField(FIRST_Z_Field); int idFld = profiletable.FindField(LINE_ID_Field); List <ProfileSurface> profileSurfaces = new List <ProfileSurface>(); ProfileSession session = new ProfileSession() { ProfileSurfaces = profileSurfaces.ToArray(), ProfileLines = GetProfileLines(lines).ToArray(), SessionId = sessionId, SessionName = sessionName, DefinitionType = profileSettingsTypeEnum, ObserverHeight = observHeight, SurfaceLayerName = profileSource, CreatedBy = Environment.UserName, CreatedOn = DateTime.Now, Shared = false, Azimuth = azimuthes }; Dictionary <int, List <ProfileSurfacePoint> > surface = new Dictionary <int, List <ProfileSurfacePoint> >(); int curLine = -1; IPolyline line = null; IEnumerable <IPoint> verticesCache; Dictionary <IPoint, ProfileSurfacePoint> mapProfilePointToVertex = new Dictionary <IPoint, ProfileSurfacePoint>(); Dictionary <IPoint, double> mapProfilePointToDistance = new Dictionary <IPoint, double>(); ProfileLine profileLine = null; verticesCache = new IPoint[0]; int pointsCount = 0; while ((profileRow = featureCursor.NextRow()) != null) { int lineId = Convert.ToInt32(profileRow.Value[idFld]); pointsCount++; if (!session.ProfileLines.Any(l => l.Id == lineId)) { throw new MilSpaceProfileLineNotFound(lineId, profileLineFeatureClass); } List <ProfileSurfacePoint> points; if (!surface.ContainsKey(lineId)) { points = new List <ProfileSurfacePoint>(); surface.Add(lineId, points); } else { points = surface[lineId]; } if (curLine != lineId) // data for new line { curLine = lineId; profileLine = session.ProfileLines.FirstOrDefault(l => l.Id == lineId); line = lines.GetFeature(profileLine.Id).Shape as IPolyline; verticesCache = line.Vertices(); mapProfilePointToVertex.ToList().ForEach(v => { if (!v.Value.IsEmpty) { v.Value.isVertex = true; } }); mapProfilePointToVertex = verticesCache.ToDictionary(k => k, t => new ProfileSurfacePoint()); mapProfilePointToDistance = verticesCache.ToDictionary(k => k, t => - 1.0); } //Returns the point with Origin (Taken from firstPoint) Spatial reference //var profilePointSource = EsriTools.GetPointFromAngelAndDistance(firstPoint, profileLine.Angel, (double)profileRow.Value[distanceFld]); //var profilePoint = profilePointSource.CloneWithProjecting(); // Try to define if this point is close to a vertex double distance = (double)profileRow.Value[distanceFld]; ProfileSurfacePoint newSurface = new ProfileSurfacePoint { Distance = distance, Z = (double)profileRow.Value[zFld], //X = profilePoint.X, //Y = profilePoint.Y }; IPoint point = new Point(); line.QueryPoint(esriSegmentExtension.esriNoExtension, newSurface.Distance, false, point); IProximityOperator proximity = point as IProximityOperator; foreach (var vertx in verticesCache) { var profilePoint = mapProfilePointToVertex[vertx]; if (mapProfilePointToDistance[vertx] == 0)// profilePoint.isVertex) { continue; } double localDistance = proximity.ReturnDistance(vertx); if (mapProfilePointToDistance[vertx] == -1 || mapProfilePointToDistance[vertx] > localDistance) { mapProfilePointToDistance[vertx] = localDistance; mapProfilePointToVertex[vertx] = newSurface; if (localDistance == 0) { newSurface.isVertex = true; } } } var projected = point.CloneWithProjecting(); newSurface.X = projected.X; newSurface.Y = projected.Y; points.Add(newSurface); } mapProfilePointToVertex.ToList().ForEach(v => { if (!v.Value.IsEmpty) { v.Value.isVertex = true; } }); //Delete temp table form the GDB GdbAccess.Instance.DeleteTemporarSource(tempTableName, profileSourceName); Marshal.ReleaseComObject(featureCursor); //TODO: Clean memo using Marhsaling IRow session.ProfileSurfaces = surface.Select(r => new ProfileSurface { LineId = r.Key, ProfileSurfacePoints = r.Value.ToArray() } ).ToArray(); return(session); } catch (MilSpaceCanotDeletePrifileCalcTable ex) { //TODO: Log error throw ex; } catch (MilSpaceDataException ex) { //TODO: Log error throw ex; } catch (Exception ex) { //TODO: Log error throw ex; } }
public static VisibilityTask Generate( IFeatureClass obervationPoints, IEnumerable <int> pointsToExport, IFeatureClass obervationStations, IEnumerable <int> stationsToExport, string sourceDem, VisibilityCalculationResultsEnum culcResults, string taskName, string taskId, VisibilityCalcTypeEnum calculationType, IMap currentMap, short visibilityPercent, bool showAllResults = true) { logger.InfoEx("> Generate START. Visiblility result {2} using DEM {0} from observation points {1}" .InvariantFormat(sourceDem, obervationPoints, taskId)); CurrentMap = currentMap; //Target dataset name string nameOfTargetDataset = taskId; var calcTask = new VisibilityTask { Id = nameOfTargetDataset, Name = taskName, ReferencedGDB = MilSpaceConfiguration.ConnectionProperty.TemporaryGDBConnection, CalculatedResults = (int)culcResults, UserName = Environment.UserName, CalculationType = calculationType, Surface = sourceDem }; calcTask = VisibilityZonesFacade.AddVisibilityTask(calcTask); OnGenerationStarted.Invoke(true, calcTask.Id); if (calcTask == null) { throw new MilSpaceVisibilityCalcFailedException("Cannot save visibility session"); } var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.vblt.ToString() }; var prm = new List <IActionParam> { action, new ActionParam <IFeatureClass>() { ParamName = ActionParameters.FeatureClass, Value = obervationPoints }, new ActionParam <IFeatureClass>() { ParamName = ActionParameters.FeatureClassX, Value = obervationStations }, new ActionParam <int[]>() { ParamName = ActionParameters.FilteringPointsIds, Value = pointsToExport.ToArray() }, new ActionParam <int[]>() { ParamName = ActionParameters.FilteringStationsIds, Value = stationsToExport.ToArray() }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = sourceDem }, new ActionParam <VisibilityCalculationResultsEnum>() { ParamName = ActionParameters.Calculationresults, Value = culcResults }, new ActionParam <string>() { ParamName = ActionParameters.OutputSourceName, Value = nameOfTargetDataset }, new ActionParam <VisibilityTask>() { ParamName = ActionParameters.Session, Value = calcTask }, new ActionParam <short>() { ParamName = ActionParameters.VisibilityPercent, Value = visibilityPercent }, new ActionParam <bool>() { ParamName = ActionParameters.ShowAllResults, Value = showAllResults } }; var procc = new ActionProcessor(prm); VisibilityZonesFacade.StarthVisibilitySession(calcTask); var res = procc.Process <VisibilityCalculationResult>(); calcTask = res.Result.Session; if (res.Result.CalculationMessages != null && res.Result.CalculationMessages.Count() > 0) { foreach (var calcRes in res.Result.CalculationMessages) { //Here should be checked if the results match with session.CalculatedResults //logger.InfoEx($"The result layer {calcRes} was successfully composed in {calcTask.ReferencedGDB}"); } } if (res.Exception != null) { VisibilityZonesFacade.UpdateVisibilityTask(calcTask); throw res.Exception; } else { VisibilityZonesFacade.FinishVisibilityTask(calcTask); VisibilityZonesFacade.AddVisibilityResults(calcTask.GetVisibilityResults(false)); } if (!string.IsNullOrWhiteSpace(res.ErrorMessage)) { throw new MilSpaceVisibilityCalcFailedException(res.ErrorMessage); } return(calcTask); }