Ejemplo n.º 1
0
        private static bool CheckMonitoringEnabled()
        {
            MonitoringSessionController sessionController = new MonitoringSessionController();
            var session = sessionController.GetActiveSession();

            if (session == null)
            {
                return(false);
            }
            else
            {
                if (m_MonitoringSession == null)
                {
                    m_MonitoringSession = session;
                }
                else
                {
                    // Check if it is the same session or not
                    if (m_MonitoringSession.SessionId != session.SessionId)
                    {
                        Logger.LogCpuMonitoringVerboseEvent($"Reloading monitoring session as session has changed, old={m_MonitoringSession.SessionId}, new={session.SessionId}", m_MonitoringSession.SessionId);
                        m_MonitoringSession = session;
                        m_CpuMonitoring.InitializeMonitoring(m_MonitoringSession);
                    }
                }

                return(true);
            }
        }
Ejemplo n.º 2
0
        private IMonitoringSubProduct CreateMonitoringSubProduct(string rstFileName, string productIdentify, string subProductIdentify)
        {
            MonitoringSession        session        = new MonitoringSession(_session);
            IMonitoringProduct       monitorProduct = session.ChangeActiveProduct(productIdentify);
            IMonitoringSubProduct    subprd         = session.ChangeActiveSubProduct(subProductIdentify);
            RasterIdentify           rstIdentify    = new RasterIdentify(rstFileName);
            ExtractAlgorithmIdentify id             = new ExtractAlgorithmIdentify();

            id.Satellite = rstIdentify.Satellite;
            id.Sensor    = rstIdentify.Sensor;
            AlgorithmDef alg = subprd.Definition.GetAlgorithmDefByAlgorithmIdentify(id);

            if (alg == null)
            {
                PrintInfo("没有匹配的算法:" + "卫星" + rstIdentify.Satellite + ",传感器" + rstIdentify.Sensor);
                return(null);
            }
            subprd.ResetArgumentProvider(alg.Identify);
            subprd.ArgumentProvider.SetArg("AlgorithmName", alg.Identify);
            if (alg.Bands != null && alg.Bands.Length > 0)
            {
                MonitoringThemeFactory.SetBandArgs(subprd, rstIdentify.Satellite, rstIdentify.Sensor);
                foreach (BandDef band in alg.Bands)
                {
                    if (subprd.ArgumentProvider.GetArg(band.Identify).ToString() == "-1")
                    {
                        PrintInfo("从波段映射表获取\"" + band.Identify + "\"的波段序号失败,生成过程终止!");
                        return(null);
                    }
                }
            }
            TryHandleCustomArguments(subprd.ArgumentProvider, alg);
            return(subprd);
        }
Ejemplo n.º 3
0
        private static void StopMonitoringSession()
        {
            SessionMode sessionMode = SessionMode.Collect;
            string      sessionId   = "";

            if (m_MonitoringSession != null)
            {
                sessionMode = m_MonitoringSession.Mode;
                sessionId   = m_MonitoringSession.SessionId;
            }
            Logger.LogCpuMonitoringVerboseEvent($"Stopping a monitoring session", sessionId);

            MonitoringSessionController sessionController = new MonitoringSessionController();
            var sessionStopped = sessionController.StopMonitoringSession();

            if (!sessionStopped)
            {
                Logger.LogCpuMonitoringVerboseEvent($"Failed while stopping the session", sessionId);
                m_FailedStoppingSession = true;
            }
            else
            {
                var blobSasUri = m_MonitoringSession.BlobSasUri;
                m_MonitoringEnabled     = false;
                m_MonitoringSession     = null;
                m_FailedStoppingSession = false;
                if (sessionMode == SessionMode.CollectKillAndAnalyze && !string.IsNullOrWhiteSpace(sessionId))
                {
                    MonitoringSessionController controller = new MonitoringSessionController();
                    controller.AnalyzeSession(sessionId, blobSasUri);
                }
            }
        }
Ejemplo n.º 4
0
 private string TryGetExtractingArgInfos()
 {
     try
     {
         MonitoringSession mss = (_session.MonitoringSession as MonitoringSession);
         if (mss != null && mss.CurrentCanvasViewer != null && mss.CurrentCanvasViewer.ActiveObject != null)
         {
             IExtractingSession ess = mss.ExtractingSession;
             if (ess != null && mss.ActiveMonitoringProduct != null && mss.ActiveMonitoringSubProduct != null &&
                 ess.CurrentSubProduct != null && ess.CurrentSubProduct.ArgumentProvider != null &&
                 ess.CurrentSubProduct.ArgumentProvider.ArgNames != null)
             {
                 StringBuilder str = new StringBuilder();
                 str.AppendLine("参数信息");
                 foreach (string argname in ess.CurrentSubProduct.ArgumentProvider.ArgNames)
                 {
                     if (argname.IndexOf("CursorInfo:") != -1)
                     {
                         str.AppendLine("    " + argname.Replace("CursorInfo:", "") + " : " + ess.CurrentSubProduct.ArgumentProvider.GetArg(argname));
                     }
                 }
                 return(str.ToString());
             }
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
Ejemplo n.º 5
0
        public void UpdateData(Core.UI.ISmartSession smartSession)
        {
            this._smartSession = smartSession;
            MonitoringSession monitSession = _smartSession.MonitoringSession as MonitoringSession;
            ProductDef        productDef   = monitSession.ActiveMonitoringProduct.Definition;
            string            _identify    = productDef.Identify;

            _wDef = WorkspaceDefinitionFactory.GetWorkspaceDef(_identify);
            LoadData();
        }
Ejemplo n.º 6
0
        // POST: api/CpuMonitoring
        public HttpResponseMessage Post([FromBody] MonitoringSession session)
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                var submittedSession = monitoringController.CreateSession(session);
                return(Request.CreateResponse(HttpStatusCode.OK, session.SessionId));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - POST", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message));
            }
        }
Ejemplo n.º 7
0
        public override void Execute()
        {
            using (var session = new MonitoringSession("NuMon"))
            {
                Console.CancelKeyPress += (sender, args) =>
                {
                    session.Stop();
                    args.Cancel = true;
                };
                session.EnableProviders(RootAssembly, ProviderPattern, new TraceEventProviderOptions() { StacksEnabled = true });
                foreach (var provider in session.EnabledProviders)
                {
                    Console.WriteLine("Enabled Provider: {0}", provider.Name);
                }

                session.Subscribe(evt => Console.WriteLine("[{0}]({1}): {2}", evt.ProviderName, evt.EventName, evt.FormattedMessage));

                Console.WriteLine("Listening for events. Press Ctrl-C to stop");
                session.Run().Wait();
            }
            Console.WriteLine("Finished listening");
        }
        public async Task <MonitoringSession> GetNewSession(
            int profileId
            )
        {
            bool hasMonitorTagFilter = await _context.ProfilesTagSelection
                                       .AnyAsync(pts => pts.BindedProfileID == profileId &&
                                                 ProfileSelectedTagFlags.Monitor ==
                                                 (pts.Flags & ProfileSelectedTagFlags.Monitor));

            int monitoredNodesNum = hasMonitorTagFilter
                ? await _context.ProfilesTagSelection.AsNoTracking()
                                    .Where(pts => pts.BindedProfileID == profileId &&
                                           ProfileSelectedTagFlags.Monitor ==
                                           (pts.Flags & ProfileSelectedTagFlags.Monitor))
                                    .Include(pts => pts.Tag)
                                    .ThenInclude(t => t.Attachments)
                                    .ThenInclude(ta => ta.Node)
                                    .SelectMany(pts => pts.Tag.Attachments.Select(ta => ta.Node))
                                    .Where(n => n.OpenPing)
                                    .Select(n => n.ID)
                                    .Distinct()
                                    .CountAsync()
                : await _context.Nodes.CountAsync(n => n.OpenPing);

            MonitoringSession newSession = new MonitoringSession
            {
                ID = 0,
                CreatedByProfileID    = profileId,
                ParticipatingNodesNum = monitoredNodesNum,
                CreationTime          = JsDateTimeNow(),
                LastPulseTime         = 0,
            };

            _context.MonitoringSessions.Add(newSession);
            await _context.SaveChangesAsync();

            _context.Entry(newSession).State = EntityState.Detached;
            return(newSession);
        }
        public async Task <MonitoringPulseResult> SavePulseResult(
            int sessionId,
            MonitoringPulseResult pulseResult,
            IEnumerable <MonitoringMessage> messages
            )
        {
            pulseResult.CreationTime = JsDateTimeNow();
            MonitoringSession session = await _context.MonitoringSessions
                                        .Include(s => s.Pulses)
                                        .SingleAsync(s => s.ID == sessionId);

            //context.MonitoringPulses
            //    .Add(pulseResult);
            session.LastPulseTime = pulseResult.CreationTime;
            //await context.SaveChangesAsync();
            session.Pulses.Add(pulseResult);
            await _context.SaveChangesAsync();

            //foreach(MonitoringMessage message in messages) {
            //    context.MonitoringMessages.add
            //        .Add(message);
            //}
            //await context.SaveChangesAsync();
            MonitoringPulseResult pulseWithMessages = await _context.MonitoringPulses
                                                      .Include(p => p.Messages)
                                                      .SingleAsync(p => p.ID == pulseResult.ID);

            foreach (MonitoringMessage messageEntity in messages)
            {
                pulseWithMessages.Messages.Add(messageEntity);
            }

            await _context.SaveChangesAsync();

            _context.Entry(pulseWithMessages).State = EntityState.Detached;
            return(pulseWithMessages);
        }
Ejemplo n.º 10
0
 private string TryGetExtractingArea()
 {
     try
     {
         MonitoringSession mss = (_session.MonitoringSession as MonitoringSession);
         if (mss != null && mss.CurrentCanvasViewer != null && mss.CurrentCanvasViewer.ActiveObject != null)
         {
             IExtractingSession ess = mss.ExtractingSession;
             if (ess != null && mss.ActiveMonitoringProduct != null && mss.ActiveMonitoringSubProduct != null)
             {
                 IPixelIndexMapper extResult = ess.GetBinaryValuesMapper(mss.ActiveMonitoringProduct.Identify, mss.ActiveMonitoringSubProduct.Identify);
                 if (extResult != null)
                 {
                     string areaString = "0";
                     long   count      = extResult.Indexes.LongCount();
                     double area       = 0;
                     if (count != 0)
                     {
                         IRasterDataProvider raster = (mss.CurrentCanvasViewer.ActiveObject as RasterDrawing).DataProvider;
                         if (raster != null)
                         {
                             float  resolutionX = raster.ResolutionX;
                             float  resolutionY = raster.ResolutionY;
                             double piexArea    = 1;
                             if (raster.SpatialRef == null || (raster.SpatialRef != null && raster.SpatialRef.ProjectionCoordSystem == null))
                             {
                                 piexArea = MIF.Core.AreaCountHelper.CalcArea(extResult.CoordEnvelope.Center.X, extResult.CoordEnvelope.Center.Y, resolutionX, resolutionY);
                             }
                             else
                             {
                                 piexArea = resolutionX * resolutionY;
                             }
                             area = count * piexArea;//m²
                             if (area > 1000000 * 100)
                             {
                                 areaString = (area / 1000000).ToString("f2") + "(KM²)";//m²->km²
                             }
                             if (area > 1000000)
                             {
                                 areaString = (area / 1000000).ToString("f4") + "(KM²)";//m²->km²
                             }
                             else
                             {
                                 areaString = (int)area + "(M²)";
                             }
                         }
                     }
                     StringBuilder str = new StringBuilder();
                     str.AppendLine("判识信息");
                     str.AppendLine("    像元个数 : " + count);
                     str.AppendLine("    判识面积 : " + areaString);
                     return(str.ToString());
                 }
             }
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
        private static TestIDsSet AddTestDataSet(NtwkDBContext context)
        {
            var testProfile = new Profile
            {
                ID   = 0,
                Name = TestProfileName,
                StartMonitoringOnLaunch   = true,
                DepthMonitoring           = true,
                MonitoringStartHour       = 0,
                MonitoringSessionDuration = 24,
                MonitorInterval           = 10
            };

            context.Profiles.Add(testProfile);
            context.SaveChanges();

            // tags
            NodeTag[] testTags = Enumerable.Range(0, 3)
                                 .Select(i => new NodeTag
            {
                ID   = 0,
                Name = TagNames[i]
            }).ToArray();
            context.Tags.AddRange(testTags);
            context.SaveChanges();

            // nodes
            NtwkNode[] testNodes = new NtwkNode[3];
            {
                uint[] ips = new[]
                {
                    167837697u,
                    3232292602u,
                    167837697u
                };
                bool[] t = new[] { false, true, false };
                bool[] s = new[] { true, false, true };
                for (int i = 0; i < 3; i++)
                {
                    testNodes[i] = new NtwkNode
                    {
                        ID         = 0,
                        Parent     = null,
                        Name       = NodeNames[i],
                        ip         = ips[i],
                        OpenTelnet = t[i],
                        OpenSSH    = s[i],
                        OpenPing   = true
                    };
                }

                context.Nodes.Add(testNodes[0]);
                context.SaveChanges();
                testNodes[1].Parent = testNodes[0];
                context.Nodes.Add(testNodes[1]);
                context.Nodes.Add(testNodes[2]);
                context.SaveChanges();
            }


            CustomWebService[] testWebServices;
            {
                string[] wsStrings =
                {
                    "http://{node_ip}:8080",
                    "https://{node_ip}:{param1}"
                };
                string[] wsP1 = new[] { null, "Port" };
                testWebServices = Enumerable.Range(0, 2)
                                  .Select(i => new CustomWebService
                {
                    ID            = 0,
                    Name          = WebServicesNames[i],
                    ServiceStr    = wsStrings[i],
                    Parametr1Name = wsP1[i]
                }).ToArray();
                context.WebServices.AddRange(testWebServices);
                context.SaveChanges();
            }


            {
                //TagAttachments
                NodeTag[] t = new[]
                {
                    testTags[0], testTags[0], testTags[1], testTags[2]
                };
                NtwkNode[] n = new[]
                {
                    testNodes[0], testNodes[1], testNodes[1], testNodes[2]
                };
                context.TagAttachments.AddRange(Enumerable.Range(0, 4)
                                                .Select(i => new TagAttachment
                {
                    ID   = 0,
                    Tag  = t[i],
                    Node = n[i],
                })
                                                );
                context.SaveChanges();
            }


            {
                // WebServiceBindings
                CustomWebService[] s = new[]
                {
                    testWebServices[0], testWebServices[0],
                    testWebServices[1], testWebServices[1], testWebServices[1]
                };
                NtwkNode[] n = new[]
                {
                    testNodes[0], testNodes[1],
                    testNodes[0], testNodes[1], testNodes[2]
                };
                string[] p = new[]
                {
                    null, null,
                    "80", "55315", ""
                };
                context.WebServiceBindings.AddRange(Enumerable.Range(0, 5)
                                                    .Select(i => new CustomWsBinding
                {
                    ID      = 0,
                    Service = s[i],
                    Node    = n[i],
                    Param1  = p[i]
                })
                                                    );
                context.SaveChanges();
            }


            {
                // test monitoring session data
                MonitoringSession testSession = new MonitoringSession
                {
                    ID = 0,
                    CreatedByProfile      = testProfile,
                    ParticipatingNodesNum = 2,
                    CreationTime          = 1528359015,
                    LastPulseTime         = 1528360285,
                };
                MonitoringPulseResult[] pulses = new[]
                {
                    new MonitoringPulseResult
                    {
                        ID           = 0,
                        Responded    = 2,
                        Silent       = 0,
                        Skipped      = 0,
                        CreationTime = 1528359015
                    },
                    new MonitoringPulseResult
                    {
                        ID           = 0,
                        Responded    = 0,
                        Silent       = 1,
                        Skipped      = 1,
                        CreationTime = 1528360285
                    }
                };
                var monMessageForSecondPulse = new MonitoringMessage
                {
                    ID                    = 0,
                    MessageType           = MonitoringMessageType.DangerNoPingReturnedSkippedChildren,
                    MessageSourceNodeName = NodeNames[0],
                    NumSkippedChildren    = 0
                };
                context.MonitoringSessions.Add(testSession);
                context.MonitoringPulses.AddRange(pulses);
                context.SaveChanges();
                pulses[1] = context.MonitoringPulses
                            .Include(p => p.Messages)
                            .Single(p => p.ID == pulses[1].ID);
                testSession = context.MonitoringSessions
                              .Include(s => s.Pulses)
                              .Single(s => s.ID == testSession.ID);
                testSession.Pulses.Add(pulses[0]);
                testSession.Pulses.Add(pulses[1]);
                pulses[1].Messages.Add(monMessageForSecondPulse);
                context.SaveChanges();
            }

            TestIDsSet idsSet = new TestIDsSet
            {
                ProfileId      = testProfile.ID,
                WebServicesIDs = testWebServices.Select(s => s.ID).ToArray(),
                NodesIDs       = testNodes.Select(n => n.ID).ToArray(),
                TagsIDs        = testTags.Select(t => t.ID).ToArray(),
            };

            CreateClosuresForTestNodes(context, idsSet);
            return(idsSet);
        }