コード例 #1
0
ファイル: DeviceController.cs プロジェクト: CBWJ/GlsunView
        public ActionResult Edit(Device device, HttpPostedFileBase iconFile)
        {
            var  json      = new JsonResult();
            User loginUser = null;

            try
            {
                string iconFileName = "";
                if (iconFile != null)
                {
                    iconFileName = SaveIcon(iconFile);
                }
                using (var ctx = new GlsunViewEntities())
                {
                    loginUser = (from u in ctx.User
                                 where u.ULoginName == HttpContext.User.Identity.Name
                                 select u).FirstOrDefault();
                    var deviceModify = ctx.Device.Find(device.ID);

                    deviceModify.DName       = device.DName;
                    deviceModify.DAddress    = device.DAddress;
                    deviceModify.DPort       = device.DPort;
                    deviceModify.DType       = device.DType;
                    deviceModify.DIcon       = device.DIcon;
                    deviceModify.DProtocal   = device.DProtocal;
                    deviceModify.CoordinateX = device.CoordinateX;
                    deviceModify.CoordinateY = device.CoordinateY;
                    deviceModify.Remark      = device.Remark;
                    deviceModify.EditorID    = loginUser.ID;
                    deviceModify.EditingTime = DateTime.Now;
                    deviceModify.MFID        = device.MFID;

                    if (!string.IsNullOrWhiteSpace(iconFileName))
                    {
                        deviceModify.DIcon = iconFileName;
                        device.DIcon       = iconFileName;
                    }
                    ctx.SaveChanges();
                }
                var data = new TopologyNode
                {
                    ID      = device.ID,
                    Name    = device.DName,
                    Address = device.DAddress,
                    Icon    = device.DIcon,
                    X       = device.CoordinateX.Value,
                    Y       = device.CoordinateY.Value
                };
                json.Data = new { Code = "", Data = data, Message = "保存成功" };
                //日志记录
                _topoLogger.Record(loginUser, "修改设备", "", "成功", "", device.ID, device.DName, "设备");
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = device, Message = ex.Message };
                //日志记录
                _topoLogger.Record(loginUser, "修改设备", "", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备");
            }
            return(json);
        }
コード例 #2
0
ファイル: DeviceController.cs プロジェクト: CBWJ/GlsunView
        public ActionResult Create(Device device, HttpPostedFileBase iconFile)
        {
            var  json      = new JsonResult();
            User loginUser = null;

            try
            {
                string iconFileName = "";
                if (iconFile != null)
                {
                    iconFileName = SaveIcon(iconFile);
                }
                using (var ctx = new GlsunViewEntities())
                {
                    loginUser = (from u in ctx.User
                                 where u.ULoginName == HttpContext.User.Identity.Name
                                 select u).FirstOrDefault();
                    var newDevice = device.CopyProperty();
                    newDevice.CreatorID    = loginUser.ID;
                    newDevice.CreationTime = DateTime.Now;
                    if (string.IsNullOrWhiteSpace(newDevice.DIcon))
                    {
                        newDevice.DIcon = iconFileName;
                    }
                    ctx.Device.Add(newDevice);
                    ctx.SaveChanges();
                    device.ID    = newDevice.ID;
                    device.DIcon = newDevice.DIcon;
                }
                var data = new TopologyNode
                {
                    ID      = device.ID,
                    Name    = device.DName,
                    Address = device.DAddress,
                    Icon    = device.DIcon,
                    X       = device.CoordinateX.Value,
                    Y       = device.CoordinateY.Value
                };
                json.Data = new { Code = "", Data = data, Message = "保存成功" };
                //日志记录
                _topoLogger.Record(loginUser, "添加设备", "", "成功", "", device.ID, device.DName, "设备");
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = device, Message = ex.Message };
                //日志记录
                _topoLogger.Record(loginUser, "添加设备", "", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备");
            }
            return(json);
        }
コード例 #3
0
ファイル: DeviceController.cs プロジェクト: CBWJ/GlsunView
        public ActionResult Rename(int id, string name)
        {
            //序列化有外键约束的EF实体对象会报错
            var          json      = new JsonResult();
            TopologyNode node      = null;
            User         loginUser = null;
            Device       device    = null;

            try
            {
                using (var ctx = new GlsunViewEntities())
                {
                    loginUser = (from u in ctx.User
                                 where u.ULoginName == HttpContext.User.Identity.Name
                                 select u).FirstOrDefault();
                    var deviceModify = ctx.Device.Find(id);
                    device = deviceModify.CopyProperty();
                    if (deviceModify != null)
                    {
                        deviceModify.DName       = name;
                        deviceModify.EditorID    = loginUser.ID;
                        deviceModify.EditingTime = DateTime.Now;
                        node = new TopologyNode
                        {
                            ID      = deviceModify.ID,
                            Name    = deviceModify.DName,
                            Address = deviceModify.DAddress,
                            Icon    = deviceModify.DIcon,
                            X       = deviceModify.CoordinateX.Value,
                            Y       = deviceModify.CoordinateY.Value
                        };
                        ctx.SaveChanges();
                    }
                }
                json.Data = new { Code = "", Data = node, Message = "重命名成功" };
                //日志记录
                _topoLogger.Record(loginUser, "修改设备", "重命名", "成功", "", device.ID, device.DName, "设备");
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = node, Message = ex.Message };
                //日志记录
                _topoLogger.Record(loginUser, "修改设备", "重命名", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备");
            }
            return(json);
        }
コード例 #4
0
        public void FindClosestElement()
        {
            using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
                using (Topology topology = geodatabase.OpenDataset <Topology>("Backcountry_Topology"))
                {
                    // Build a topology graph using the extent of the topology dataset.

                    topology.BuildGraph(topology.GetExtent(), (topologyGraph) =>
                    {
                        MapPoint queryPointViaCampsites12 = null;

                        using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12))
                        {
                            queryPointViaCampsites12 = campsites12.GetShape() as MapPoint;
                        }

                        double searchRadius = 1.0;

                        TopologyElement topologyElementViaCampsites12 = topologyGraph.FindClosestElement <TopologyElement>(queryPointViaCampsites12, searchRadius);

                        System.Diagnostics.Debug.Assert(topologyElementViaCampsites12 != null, "There should be a topology element corresponding to 'queryPointViaCampsites12' within the 'searchRadius' units.");

                        IReadOnlyList <FeatureInfo> parentFeatures = topologyElementViaCampsites12.GetParentFeatures();

                        Console.WriteLine("The parent features that spawn 'topologyElementViaCampsites12' are:");
                        foreach (FeatureInfo parentFeature in parentFeatures)
                        {
                            Console.WriteLine($"\t{parentFeature.FeatureClassName}; OID: {parentFeature.ObjectID}");
                        }

                        TopologyNode topologyNodeViaCampsites12 = topologyGraph.FindClosestElement <TopologyNode>(queryPointViaCampsites12, searchRadius);

                        if (topologyNodeViaCampsites12 != null)
                        {
                            // There exists a TopologyNode nearest to the query point within searchRadius units.
                        }

                        TopologyEdge topologyEdgeViaCampsites12 = topologyGraph.FindClosestElement <TopologyEdge>(queryPointViaCampsites12, searchRadius);

                        if (topologyEdgeViaCampsites12 != null)
                        {
                            // There exists a TopologyEdge nearest to the query point within searchRadius units.
                        }
                    });
                }
        }
コード例 #5
0
        /// <summary>Print a console message describing a received event notification</summary>
        /// <param name="topologyEvent">the received event</param>
        /// <param name="type">a string describing the type of event notification</param>
        private void WriteEvent(TopologyEvent topologyEvent, string type)
        {
            TopologyDriver driver = topologyEvent.getDriver();
            string         s1     = "none";

            if (driver != null)
            {
                s1 = driver.getDisplayName();
            }
            TopologyNode node = topologyEvent.getNodeOrPeer();
            string       s2   = "none";

            if (node != null)
            {
                s2 = node.getDisplayName();
            }
            Console.WriteLine("[.Net] dispatcher: topology event '" + type + "' for driver=" + s1 + " and node=" + s2);
        }
コード例 #6
0
        private void AddBranchToPartialTopology(PresentationDescriptor presentationDescriptor, int iStream)
        {
            SharpDX.Bool     isSelected;
            StreamDescriptor streamDescriptor;

            presentationDescriptor.GetStreamDescriptorByIndex(iStream, out isSelected, out streamDescriptor);
            if (isSelected)
            {
                TopologyNode sourceNode = CreateSourceStreamNode(presentationDescriptor, streamDescriptor);
                //var resource = videoTexture.QueryInterface<SharpDX.DXGI.Resource>();
                //var sharedTex = _device.OpenSharedResource<Texture2D>(resource.SharedHandle)
                TopologyNode outputNode = CreateOutputNode(streamDescriptor, videoHwnd);

                topology.AddNode(sourceNode);
                topology.AddNode(outputNode);
                sourceNode.ConnectOutput(0, outputNode, 0);
            }
        }
コード例 #7
0
 /// <summary>
 /// Add new stations to a new factory with a new production line.
 /// </summary>
 public void AddNewStations(List <string> opcUriList)
 {
     foreach (string opcUri in opcUriList)
     {
         try
         {
             ContosoTopologyNode newProductionLine = GetOrAddNewProductionLine();
             StationDescription  desc = new StationDescription();
             desc.Name        = opcUri;
             desc.Description = _newStationName;
             desc.OpcUri      = opcUri;
             Station station = new Station(desc);
             station.Location = newProductionLine.Location;
             TopologyNode node = station as TopologyNode;
             AddChild(newProductionLine.Key, node);
             UpdateAllKPIAndOEEPerfItems();
         }
         catch
         {
             Trace.TraceError("Failed to add station {0} to topology", opcUri);
         }
     }
 }
コード例 #8
0
        private static void ExploreTopologyGraph(Geodatabase geodatabase, Topology topology)
        {
            // Build a topology graph using the extent of the topology dataset.

            topology.BuildGraph(topology.GetExtent(), (topologyGraph) =>
            {
                // To visualize where the query point is, see "QueryPoint.PNG" in the "..\Data" folder.

                Feature featureViaTrailPoints66 = GetFeature(geodatabase, "Trail_Points", 66);

                try
                {
                    MapPoint queryPointViaTrailPoints66 = featureViaTrailPoints66.GetShape() as MapPoint;
                    double searchRadius = 1.0;

                    TopologyNode topologyNodeViaTrailPoints66 = topologyGraph.FindClosestElement <TopologyNode>(queryPointViaTrailPoints66, searchRadius);

                    System.Diagnostics.Debug.Assert(topologyNodeViaTrailPoints66 != null, "There should be a topology node corresponding to 'queryPointViaTrailPoints66' within the 'searchRadius' units.");

                    IReadOnlyList <FeatureInfo> parentFeatures = topologyNodeViaTrailPoints66.GetParentFeatures();
                    Console.WriteLine("***************************************************************************");
                    Console.WriteLine("The parent features that spawn 'topologyNodeViaTrailPoints66' are:");
                    foreach (FeatureInfo parentFeature in parentFeatures)
                    {
                        Console.WriteLine($"\t{parentFeature.FeatureClassName}; OID: {parentFeature.ObjectID}");
                    }

                    IReadOnlyList <TopologyEdge> allEdgesConnectedToNodeViaTrailPoints66 = topologyNodeViaTrailPoints66.GetEdges();

                    foreach (TopologyEdge edge in allEdgesConnectedToNodeViaTrailPoints66)
                    {
                        IReadOnlyList <FeatureInfo> parents = edge.GetParentFeatures();
                        System.Diagnostics.Debug.Assert(parents.Count == 1, "The edge should have only 1 corresponding parent feature.");
                        FeatureInfo parentFeature = parents[0];

                        // To determine whether the edge's "from node" is coincident with "topologyNodeViaTrailPoints66".

                        bool fromNodeIsCoincidentWithNodeViaTrailPoints66 = edge.GetFromNode() == topologyNodeViaTrailPoints66;

                        // To determine whether the edge's "to node" is coincident with "topologyNodeViaTrailPoints66".

                        bool toNodeIsCoincidentWithNodeViaTrailPoints66 = edge.GetToNode() == topologyNodeViaTrailPoints66;

                        if (fromNodeIsCoincidentWithNodeViaTrailPoints66)
                        {
                            Console.WriteLine($"The [{parentFeature.FeatureClassName},{parentFeature.ObjectID}] edge's FromNode is coincident with 'topologyNodeViaTrailPoints66'.");
                        }

                        if (toNodeIsCoincidentWithNodeViaTrailPoints66)
                        {
                            Console.WriteLine($"The [{parentFeature.FeatureClassName},{parentFeature.ObjectID}] edge's ToNode is coincident with 'topologyNodeViaTrailPoints66'.");
                        }

                        // Get only polygon features lying to the left of this edge if available (specified by the "boundedByEdge" optional argument).

                        IReadOnlyList <FeatureInfo> leftParentFeatures = edge.GetLeftParentFeatures();

                        if (leftParentFeatures.Count == 0)
                        {
                            // There are no polygon features lying to the left of this edge; get the set of polygon features that cover this edge.

                            Console.WriteLine("The set of polygon features that cover this edge:");

                            leftParentFeatures = edge.GetLeftParentFeatures(false);
                        }
                        else
                        {
                            Console.WriteLine("The set of polygon features lying to the left of this edge (i.e., left parent polygon features bounded by this edge):");
                        }

                        foreach (FeatureInfo leftParentFeature in leftParentFeatures)
                        {
                            Console.WriteLine($"\t{leftParentFeature.FeatureClassName}; OID: {leftParentFeature.ObjectID}");

                            // To get additional information from the parent feature (e.g., shape, globalID), use leftParentFeature.GetFeature().
                        }

                        // Get only polygon features lying to the right of this edge if available (specified by the "boundedByEdge" optional argument).

                        IReadOnlyList <FeatureInfo> rightParentFeatures = edge.GetRightParentFeatures();

                        if (rightParentFeatures.Count != 0)
                        {
                            Console.WriteLine("The set of polygon features lying to the right of this edge (i.e., right parent polygon features bounded by this edge):");

                            foreach (FeatureInfo rightParentFeature in rightParentFeatures)
                            {
                                Console.WriteLine($"\t{rightParentFeature.FeatureClassName}; OID: {rightParentFeature.ObjectID}");
                            }
                        }
                    }
                }
                finally
                {
                    if (featureViaTrailPoints66 != null)
                    {
                        featureViaTrailPoints66.Dispose();
                    }
                }
            });
        }
コード例 #9
0
        public void Load(object customSource)
        {
            Close();
            AfterClose();
            if (Hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException();
            }
            Trace.WriteLine("HwndRenderSession::Load()");

            MediaSource            source = null;
            Topology               topo   = null;
            PresentationDescriptor pdesc  = null;

            try {
                // Create MediaSource(check argument)
                source = ComObject.As <MediaSource>(Marshal.GetIUnknownForObject(customSource)); // GetIUnknownForObject adds reference count
                // Create MediaSession
                MediaFactory.CreateMediaSession(null, out _mediaSession);
                _callback = new MediaSessionCallback(_mediaSession, OnMediaEvent);
                // Create Topology
                MediaFactory.CreateTopology(out topo);

                // Get PresentationDescriptor from MediaSource
                source.CreatePresentationDescriptor(out pdesc);
                // Connect each stream
                for (var i = 0; i < pdesc.StreamDescriptorCount; i++)
                {
                    RawBool isSelected;
                    using (var sdesc = pdesc.GetStreamDescriptorByIndex(i, out isSelected)) {
                        if (!isSelected)
                        {
                            continue;
                        }

                        Activate     renderer = null;
                        TopologyNode srcnode  = null;
                        TopologyNode outnode  = null;
                        try {
                            // Renderer
                            if (sdesc.MediaTypeHandler.MajorType == MediaTypeGuids.Video)
                            {
                                MediaFactory.CreateVideoRendererActivate(Hwnd, out renderer);
                            }
                            else if (sdesc.MediaTypeHandler.MajorType == MediaTypeGuids.Audio)
                            {
                                MediaFactory.CreateAudioRendererActivate(out renderer);
                            }
                            else
                            {
                                // not supported
                                continue;
                            }
                            // Source Node
                            MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out srcnode);
                            srcnode.Set(TopologyNodeAttributeKeys.Source, source);
                            srcnode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, pdesc);
                            srcnode.Set(TopologyNodeAttributeKeys.StreamDescriptor, sdesc);
                            // Output Node
                            MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outnode);
                            outnode.Object = renderer;

                            // Connect
                            topo.AddNode(srcnode);
                            topo.AddNode(outnode);
                            srcnode.ConnectOutput(0, outnode, 0);
                        } finally {
                            srcnode?.Dispose();
                            outnode?.Dispose();
                            renderer?.Dispose();
                        }
                    }
                }
                // Set to session
                _mediaSession.SetTopology(SessionSetTopologyFlags.None, topo);
            } catch {
                Close();
                AfterClose();
                throw;
            } finally {
                pdesc?.Dispose();
                topo?.Dispose();
                source?.Dispose();
            }
        }
コード例 #10
0
        public void ExploreTopologyGraph()
        {
            using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
                using (Topology topology = geodatabase.OpenDataset <Topology>("Backcountry_Topology"))
                {
                    // Build a topology graph using the extent of the topology dataset.

                    topology.BuildGraph(topology.GetExtent(), (topologyGraph) =>
                    {
                        using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12))
                        {
                            IReadOnlyList <TopologyNode> topologyNodesViaCampsites12 = topologyGraph.GetNodes(campsites12);

                            TopologyNode topologyNodeViaCampsites12 = topologyNodesViaCampsites12[0];

                            IReadOnlyList <TopologyEdge> allEdgesConnectedToNodeViaCampsites12 = topologyNodeViaCampsites12.GetEdges();
                            IReadOnlyList <TopologyEdge> allEdgesConnectedToNodeViaCampsites12CounterClockwise = topologyNodeViaCampsites12.GetEdges(false);

                            System.Diagnostics.Debug.Assert(allEdgesConnectedToNodeViaCampsites12.Count == allEdgesConnectedToNodeViaCampsites12CounterClockwise.Count);

                            foreach (TopologyEdge edgeConnectedToNodeViaCampsites12 in allEdgesConnectedToNodeViaCampsites12)
                            {
                                TopologyNode fromNode = edgeConnectedToNodeViaCampsites12.GetFromNode();
                                TopologyNode toNode   = edgeConnectedToNodeViaCampsites12.GetToNode();

                                bool fromNodeIsTheSameAsTopologyNodeViaCampsites12 = (fromNode == topologyNodeViaCampsites12);
                                bool toNodeIsTheSameAsTopologyNodeViaCampsites12   = (toNode == topologyNodeViaCampsites12);

                                System.Diagnostics.Debug.Assert(fromNodeIsTheSameAsTopologyNodeViaCampsites12 || toNodeIsTheSameAsTopologyNodeViaCampsites12,
                                                                "The FromNode *or* ToNode of each edge connected to 'topologyNodeViaCampsites12' should be the same as 'topologyNodeViaCampsites12' itself.");

                                IReadOnlyList <FeatureInfo> leftParentFeaturesBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetLeftParentFeatures();
                                foreach (FeatureInfo featureInfo in leftParentFeaturesBoundedByEdge)
                                {
                                    System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));
                                    System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);
                                    EnsureShapeIsNotEmpty(featureInfo);
                                }

                                IReadOnlyList <FeatureInfo> leftParentFeaturesNotBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetLeftParentFeatures(false);
                                foreach (FeatureInfo featureInfo in leftParentFeaturesNotBoundedByEdge)
                                {
                                    System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));
                                    System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);
                                    EnsureShapeIsNotEmpty(featureInfo);
                                }

                                IReadOnlyList <FeatureInfo> rightParentFeaturesBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetRightParentFeatures();
                                foreach (FeatureInfo featureInfo in rightParentFeaturesBoundedByEdge)
                                {
                                    System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));
                                    System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);
                                    EnsureShapeIsNotEmpty(featureInfo);
                                }

                                IReadOnlyList <FeatureInfo> rightParentFeaturesNotBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetRightParentFeatures(false);
                                foreach (FeatureInfo featureInfo in rightParentFeaturesNotBoundedByEdge)
                                {
                                    System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));
                                    System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);
                                    EnsureShapeIsNotEmpty(featureInfo);
                                }
                            }
                        }
                    });
                }
        }