Пример #1
0
        public static double GetSlowest(string Name)
        {
            RunCount kvp = AllStopwatches[Name];

            kvp.RunResults.Sort();
            return(kvp.RunResults[(int)(kvp.RunResults.Count * 0.9)]);
        }
Пример #2
0
        public static double GetNanoSeconds(string Name, int loopCount)
        {
            RunCount kvp = AllStopwatches[Name];

            kvp.RunResults.Sort();
            return(kvp.RunResults[kvp.RunResults.Count >> 1] * 1000000000.0 / loopCount);
        }
Пример #3
0
        public static double GetAverage(string Name)
        {
            RunCount kvp = AllStopwatches[Name];

            kvp.RunResults.Sort();
            return(kvp.RunResults[kvp.RunResults.Count >> 1]);
        }
Пример #4
0
        public void Execute(Process process)
        {
            var logger = _logger ?? new NLogPipelineLogger(SlugifyTransform.Slugify(Cfg));

            if (process.OutputIsConsole())
            {
                logger.SuppressConsole();
            }

            if (RunCount % 3 == 0)
            {
                if (_checkMemory)
                {
                    CheckMemory(process, logger);
                }
                else
                {
                    var context = new PipelineContext(logger, process);
                    context.Info($"Process has run {RunCount} time{RunCount.Plural()}.");
                }
            }

            using (var scope = DefaultContainer.Create(process, logger, Options.PlaceHolderStyle)) {
                try {
                    scope.Resolve <IProcessController>().Execute();
                } catch (Exception ex) {
                    var context = scope.Resolve <IContext>();
                    context.Error(ex.Message);
                    context.Logger.Clear();

                    new LibaryVersionChecker(context).Check();
                }
            }
            ++RunCount;
        }
Пример #5
0
        //public bool AddRecord(Recording rec) {
        //    lock (_writerLock) {
        //        if (_setWriter == null) {
        //            var file = "index.lst";
        //            var path = System.IO.Path.Combine(BaseDirectory, WorkingDirectory, file);

        //            try {
        //                _setWriter = new RecordSetWriter(path);
        //            } catch (Exception) {
        //                return false;
        //            }
        //        }

        //        _setWriter.AddRecord(rec);
        //        return true;
        //    }
        //}

        public bool Run()
        {
            if (State == Status.Running)
            {
                return(true);
            }

            var workingDirRel = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());

            WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);

            while (System.IO.Directory.Exists(WorkingDirectory))
            {
                RunCount++;
                workingDirRel    = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());
                WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);
            }

            // 1. Hole Liste von Device Nodes
            var devNodes = Nodes.Where(HasNoInputConnections);

            // 2. Erstelle Queue mit Verknüpfungszielen
            var nodeQueue = new Queue <Node>();

            devNodes.ForEach(nodeQueue.Enqueue);

            var visited = new List <Node>();

            try {
                BFS(
                    nodeQueue,
                    visited,
                    (node) => {
                    if (!node.PrepareProcessing())
                    {
                        throw new OperationCanceledException();
                    }
                },
                    NodesReachableByOutput
                    );
            } catch (OperationCanceledException) {
                return(false);
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine($"Graph.Run Exception: {e}");
                return(false);
            }

            OsClock.Start();
            SynchronizeClock(TimeStamp.Zero());

            _processor = new GraphProcessor(this);
            _processor.Start();

            Nodes.ForEach(n => n.StartProcessing());

            State = Status.Running;

            return(true);
        }
Пример #6
0
        public static ITimer Start(string name, bool runGC = false)
        {
            if (!AllStopwatches.ContainsKey(name))
            {
                AllStopwatches.Add(name, new RunCount());
            }
            if (runGC)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            RunCount sw = AllStopwatches[name];

            sw.SW.Restart();
            return(sw);
        }
Пример #7
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (DisplayName.Length != 0)
            {
                hash ^= DisplayName.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (encryptionSpec_ != null)
            {
                hash ^= EncryptionSpec.GetHashCode();
            }
            if (BlobStoragePathPrefix.Length != 0)
            {
                hash ^= BlobStoragePathPrefix.GetHashCode();
            }
            if (RunCount != 0)
            {
                hash ^= RunCount.GetHashCode();
            }
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (updateTime_ != null)
            {
                hash ^= UpdateTime.GetHashCode();
            }
            hash ^= Labels.GetHashCode();
            if (Etag.Length != 0)
            {
                hash ^= Etag.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        /// <summary>
        /// Set a mask on the gp object to buffer the output to the specified distance
        /// </summary>
        /// <param name="workspace">IFeatureWorkspace</param>
        /// <param name="geomList">List of geometries to create the mask</param>
        /// <param name="gp">IGeoProcessor2</param>
        private string SetGPMask(IFeatureWorkspace workspace, List <IGeometry> geomList, IGeoProcessor2 gp, string fcName)
        {
            IFeatureClass maskFc = CreateMaskFeatureClass(workspace, fcName + "_" + RunCount.ToString());

            foreach (IGeometry geom in geomList)
            {
                //create a new point feature
                IFeature ipFeature = maskFc.CreateFeature();
                ipFeature.Shape = geom;
                ipFeature.Store();
            }
            IDataset ds   = (IDataset)maskFc;
            string   path = ds.Workspace.PathName + "\\" + ds.BrowseName;

            gp.SetEnvironmentValue("mask", path);

            return(path);
        }
Пример #9
0
        public bool Run()
        {
            if (State == Status.Running)
            {
                return(true);
            }

            var workingDirRel = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());

            WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);

            while (System.IO.Directory.Exists(WorkingDirectory))
            {
                RunCount++;
                workingDirRel    = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());
                WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);
            }

            try {
                if (!Nodes.All(n => n.PrepareProcessing()))
                {
                    return(false);
                }
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine($"Graph.Run Exception: {e}");
                return(false);
            }

            OsClock.Start();
            Nodes.ForEach(n => n.StartProcessing());

            State = Status.Running;

            foreach (var dev in _devices)
            {
                if (HasActivePorts(dev) && !dev.StartSampling())
                {
                    Stop();
                    return(false);
                }
            }

            return(true);
        }
Пример #10
0
        private static void CheckMemory(Process process, IPipelineLogger logger)
        {
            if (string.IsNullOrEmpty(process.MaxMemory))
            {
                return;
            }

            var context = new PipelineContext(logger, process);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            var bytes = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64.Bytes();

            if (bytes.Megabytes > MaxBytes.Megabytes)
            {
                if (MaxBytes.Megabytes > 0.0)
                {
                    context.Warn($"Process memory has increased from {MaxBytes.Megabytes:#.0} to {bytes.Megabytes:#.0}.");
                }
                MaxBytes = bytes;
            }

            var maxMemory = ByteSize.Parse(process.MaxMemory);

            if (maxMemory.CompareTo(bytes) < 0)
            {
                context.Error($"Process exceeded {maxMemory.Megabytes:#.0} Mb. Current memory is {bytes.Megabytes:#.0} Mb!");
                context.Error($"Process is exiting after running {RunCount} time{RunCount.Plural()}.");
                Environment.Exit(1);
            }
            else
            {
                context.Info($"Process is using {bytes.Megabytes:#.0} Mb of it's max {maxMemory.Megabytes:#.0} Mb allowed.");
                context.Info($"Process has run {RunCount} time{RunCount.Plural()}.");
            }
        }
        /// <summary>
        /// Where all of the work is done.  Override from TabBaseViewModel
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                //base.CreateMapElement();

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                // Determine if selected surface is projected or geographic
                ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                var    geoDataset   = surfaceLayer as IGeoDataset;
                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption);
                    return;
                }

                if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
                    return;
                }

                using (ComReleaser oComReleaser = new ComReleaser())
                {
                    // Create feature workspace
                    IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace");

                    StartEditOperation((IWorkspace)workspace);

                    // Create feature class
                    IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString());

                    double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                    double finalSurfaceOffset  = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType);

                    double conversionFactor     = GetConversionFactor(SelectedSurfaceSpatialRef);
                    double convertedMinDistance = MinDistance * conversionFactor;
                    double convertedMaxDistance = MaxDistance * conversionFactor;
                    double finalMinDistance     = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType);
                    double finalMaxDistance     = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType);

                    double finalLeftHorizontalFOV  = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType);
                    double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType);
                    double finalBottomVerticalFOV  = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType);
                    double finalTopVerticalFOV     = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType);

                    // Out radius geometries
                    List <IGeometry> radius2GeomList   = new List <IGeometry>();
                    List <IGeometry> radius1_2GeomList = new List <IGeometry>();
                    List <IGeometry> donutGeomList     = new List <IGeometry>();

                    foreach (var observerPoint in ObserverAddInPoints)
                    {
                        // Create buffer geometries for final Min/Max distance
                        ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator;
                        IGeometry            geom = topologicalOperator.Buffer(finalMaxDistance);
                        radius2GeomList.Add(geom);
                        radius1_2GeomList.Add(geom);
                        if (finalMinDistance > 0)
                        {
                            IGeometry geom2 = topologicalOperator.Buffer(finalMinDistance);

                            ITopologicalOperator eraseTopo  = geom as ITopologicalOperator;
                            IGeometry            erasedGeom = eraseTopo.Difference(geom2);
                            donutGeomList.Add(erasedGeom);
                        }
                        else
                        {
                            radius1_2GeomList.Add(geom);
                        }

                        double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                        //create a new point feature
                        IFeature ipFeature = pointFc.CreateFeature();

                        // Set the field values for the feature
                        SetFieldValues(finalObserverOffset, finalSurfaceOffset, finalMinDistance, finalMaxDistance, finalLeftHorizontalFOV,
                                       finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature);

                        if (double.IsNaN(z1))
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        //Create shape
                        IPoint point = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        };
                        ipFeature.Shape = point;
                        ipFeature.Store();
                    }

                    IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
                    fd.Create(pointFc, null, "OBJECTID");

                    StopEditOperation((IWorkspace)workspace);

                    try
                    {
                        ILayer layer     = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                        string layerPath = GetLayerPath(layer);

                        IFeatureLayer ipFeatureLayer = new FeatureLayerClass();
                        ipFeatureLayer.FeatureClass = pointFc;

                        IDataset ipDataset    = (IDataset)pointFc;
                        string   outputFcName = ipDataset.BrowseName + "_output";
                        string   strPath      = ipDataset.Workspace.PathName + "\\" + ipDataset.BrowseName;
                        string   outPath      = ipDataset.Workspace.PathName + "\\" + outputFcName;

                        IVariantArray parameters = new VarArrayClass();
                        parameters.Add(layerPath);
                        parameters.Add(strPath);
                        parameters.Add(outPath);

                        esriLicenseStatus status = GetSpatialAnalystLicense();
                        if (status == esriLicenseStatus.esriLicenseUnavailable || status == esriLicenseStatus.esriLicenseFailure ||
                            status == esriLicenseStatus.esriLicenseNotInitialized || status == esriLicenseStatus.esriLicenseNotLicensed ||
                            status == esriLicenseStatus.esriLicenseUnavailable)
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        IGeoProcessor2 gp = new GeoProcessorClass();

                        gp.AddOutputsToMap = false;

                        // Add a mask to buffer the output to selected distance
                        SetGPMask(workspace, radius2GeomList, gp, "radiusMask");

                        object oResult = gp.Execute("Visibility_sa", parameters, null);
                        IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;

                        ComReleaser.ReleaseCOMObject(gp);
                        gp = null;
                        GC.Collect();

                        // Add buffer geometries to the map
                        foreach (IGeometry geom in radius1_2GeomList)
                        {
                            var color = new RgbColorClass()
                            {
                                Blue = 255
                            } as IColor;
                            AddGraphicToMap(geom, color, true);
                        }

                        IRasterLayer outputRasterLayer = new RasterLayerClass();
                        outputRasterLayer.CreateFromFilePath(outPath);

                        string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, donutGeomList);

                        IFeatureClass finalFc = workspace.OpenFeatureClass(fcName);

                        IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
                        outputFeatureLayer.FeatureClass = finalFc;

                        //Add it to a map if the layer is valid.
                        if (outputFeatureLayer != null)
                        {
                            // set the renderer
                            IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc);
                            IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer;
                            geoLayer.Renderer = featRend;
                            geoLayer.Name     = "RLOS_Visibility_" + RunCount.ToString();

                            // Set the layer transparency
                            IDisplayFilterManager      filterManager = (IDisplayFilterManager)outputFeatureLayer;
                            ITransparencyDisplayFilter filter        = new TransparencyDisplayFilter();
                            filter.Transparency         = 80;
                            filterManager.DisplayFilter = filter;

                            ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
                            map.AddLayer((ILayer)outputFeatureLayer);

                            IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope;
                            ZoomToExtent(envelope);
                        }

                        RunCount += 1;
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                    }

                    //Reset(true);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
            }
            finally
            {
                IsRunning = false;
            }
        }