Пример #1
0
        /// <summary>
        /// Rebuild the factory
        /// </summary>
        protected override void RebuildFactory()
        {
            NetGraphBuilder       builder = new NetGraphBuilder();
            ClientEndpointFactory client  = builder.AddClient("Client", Guid.NewGuid());

            client.Hidden = true;
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            server.Hidden = true;

            SwitchNodeFactory outputSwitch = CreateBaseGraph(builder, server, client, false);
            SwitchNodeFactory inputSwitch  = CreateBaseGraph(builder, client, server, true);

            AddStates(builder, outputSwitch, inputSwitch, client, server);

            NetGraphFactory factory = builder.Factory;

            factory.Properties.Add(_metaName, _defaultState);

            if (_factory == null)
            {
                _factory = factory;
            }
            else
            {
                _factory.UpdateGraph(factory);
            }

            Dirty = true;
        }
Пример #2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public NetGraphDocument()
     : base()
 {
     _nodes = new BaseNodeConfig[0];
     _lines = new LineConfig[0];
     _properties = new Dictionary<string, string>();
     _factory = new NetGraphFactory();
     _lockObject = new object();
 }
Пример #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="filter">The filter which checks for a match</param>
 /// <param name="factory">The graph factory to create on match</param>
 /// <param name="layers">The binding layers for the graph</param>
 /// <param name="selectionPath">Selection path to act as a discriminator</param>
 /// <param name="isolatedGraph">Whether to isolate the graph, only sharing global meta</param>
 /// <param name="filterId">The ID of the filter</param>        
 public LayerSectionFilter(IDataFrameFilter filter, NetGraphFactory factory, INetworkLayerFactory[] layers, string selectionPath, bool isolatedGraph, Guid filterId)
 {
     Filter = filter;
     Factory = factory;
     Layers = layers;
     SelectionPath = selectionPath;
     FilterId = filterId;
     IsolatedGraph = isolatedGraph;
 }
Пример #4
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public NetGraphDocument()
     : base()
 {
     _nodes      = new BaseNodeConfig[0];
     _lines      = new LineConfig[0];
     _properties = new Dictionary <string, string>();
     _factory    = new NetGraphFactory();
     _lockObject = new object();
 }
Пример #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="filter">The filter which checks for a match</param>
 /// <param name="factory">The graph factory to create on match</param>
 /// <param name="layers">The binding layers for the graph</param>
 /// <param name="selectionPath">Selection path to act as a discriminator</param>
 /// <param name="isolatedGraph">Whether to isolate the graph, only sharing global meta</param>
 /// <param name="filterId">The ID of the filter</param>
 public LayerSectionFilter(IDataFrameFilter filter, NetGraphFactory factory, INetworkLayerFactory[] layers, string selectionPath, bool isolatedGraph, Guid filterId)
 {
     Filter        = filter;
     Factory       = factory;
     Layers        = layers;
     SelectionPath = selectionPath;
     FilterId      = filterId;
     IsolatedGraph = isolatedGraph;
 }
        /// <summary>
        /// Convert a netgraph to a simple dot diagram
        /// </summary>
        /// <param name="netgraph">The netgraph to convert</param>
        /// <returns>The graph as a dot diagram</returns>
        public static string ToDot(NetGraphFactory netgraph)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("digraph netgraph {{").AppendLine();
            builder.AppendLine("rankdir=LR;");
            foreach (var node in netgraph.Nodes.Select(n => n.Factory))
            {
                List <string> attrs = new List <string>();
                if (!String.IsNullOrWhiteSpace(node.Label))
                {
                    attrs.Add(String.Format("label=\"{0}\"", node.Label));
                }

                if (node is ServerEndpointFactory)
                {
                    attrs.Add("ordering=out");
                    attrs.Add("rank=min");
                }
                else if (node is ClientEndpointFactory)
                {
                    attrs.Add("ordering=in");
                    attrs.Add("rank=max");
                }
                else
                {
                    attrs.Add("shape=box");
                }

                if (!node.Enabled)
                {
                    attrs.Add("style=dotted");
                }

                if (attrs.Count > 0)
                {
                    builder.AppendFormat("{0} [{1}];", FormatId(node.Id), String.Join(",", attrs)).AppendLine();
                }
            }

            foreach (var edge in netgraph.Lines)
            {
                builder.AppendFormat("{0} -> {1}", FormatId(edge.SourceNode), FormatId(edge.DestNode));
                if (!String.IsNullOrWhiteSpace(edge.PathName))
                {
                    builder.AppendFormat(" [label=\"{0}\"]", edge.PathName);
                }
                builder.AppendLine(";");
            }

            builder.AppendLine("}");

            return(builder.ToString());
        }
Пример #7
0
        private void AddStates(NetGraphBuilder builder, SwitchNodeFactory outputSwitch, SwitchNodeFactory inputSwitch,
                               BaseNodeFactory outputNode, BaseNodeFactory inputNode)
        {
            foreach (StateGraphEntry entry in _entries)
            {
                BaseNodeFactory currentInput  = inputSwitch;
                BaseNodeFactory currentOutput = outputSwitch;
                NetGraphFactory graph         = entry.Graph == null?NetGraphBuilder.CreateDefaultProxyGraph(entry.StateName) : entry.Graph.Factory;

                LayerSectionMasterNodeFactory masterNode = new LayerSectionMasterNodeFactory(String.Format("{0} {1}", entry.StateName,
                                                                                                           GetDirection(false)), Guid.NewGuid(), Guid.NewGuid());

                masterNode.DefaultMode = LayerSectionNodeDefaultMode.PassFrame;
                masterNode.Direction   = LayerSectionGraphDirection.ServerToClient;

                builder.AddNode(masterNode);
                builder.AddNode(masterNode.SlaveFactory);

                LayerSectionFilterFactory[] filters = new LayerSectionFilterFactory[1];

                LayerSectionFilterFactory filter = new LayerSectionFilterFactory();

                filter.GraphFactory   = graph;
                filter.LayerFactories = entry.GetLayerFactories();
                filter.SelectionPath  = "";
                filter.FilterFactory  = DataFrameFilterFactory.CreateDummyFactory();
                filter.IsolatedGraph  = false;

                masterNode.LayerFactories = new LayerSectionFilterFactory[1] {
                    filter
                };

                masterNode.SlaveFactory.Hidden = true;

                builder.AddLine(outputSwitch, masterNode, entry.StateName);
                builder.AddLine(inputSwitch, masterNode.SlaveFactory, entry.StateName);

                if (entry.LogPackets)
                {
                    currentOutput = AddLog(builder, entry, masterNode, false);
                    currentInput  = AddLog(builder, entry, masterNode.SlaveFactory, true);
                }
                else
                {
                    currentOutput = masterNode;
                    currentInput  = masterNode.SlaveFactory;
                }

                builder.AddLine(currentOutput, outputNode, null);
                builder.AddLine(currentInput, inputNode, null);
            }
        }
Пример #8
0
        /// <summary>
        /// Create the netgraph for a connection
        /// </summary>
        /// <param name="factory">The netgraph factory</param>
        /// <param name="meta">Current meta data</param>
        /// <param name="properties">Property bag</param>
        /// <returns>The created graph</returns>
        private NetGraph CreateNetGraph(NetGraphFactory factory, MetaDictionary meta, PropertyBag properties)
        {
            NetGraph g = factory == null?_factory.Create(_logger, null, _globalMeta, meta, properties) : factory.Create(_logger, null, _globalMeta, meta, properties);

            if (g != null)
            {
                g.LogPacketEvent  += new EventHandler <LogPacketEventArgs>(log_AddLogPacket);
                g.EditPacketEvent += new EventHandler <EditPacketEventArgs>(edit_InputReceived);
                g.GraphShutdown   += new EventHandler(graph_GraphShutdown);
            }

            return(g);
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void RebuildFactory()
        {
            List <NetGraphFactory.GraphNodeEntry> graphNodes = new List <NetGraphFactory.GraphNodeEntry>();
            List <NetGraphFactory.GraphLineEntry> graphLines = new List <NetGraphFactory.GraphLineEntry>();
            HashSet <Guid> createdNodes = new HashSet <Guid>();

            if (_factory == null)
            {
                _factory = new NetGraphFactory();
            }

            if (_nodes != null)
            {
                foreach (BaseNodeConfig node in _nodes)
                {
                    if (!createdNodes.Contains(node.Id))
                    {
                        BaseNodeFactory   factory      = node.CreateFactory();
                        ILinkedNodeConfig linkedConfig = node as ILinkedNodeConfig;

                        if ((linkedConfig != null) && (linkedConfig.LinkedNode != null))
                        {
                            BaseNodeFactory linked = linkedConfig.CreateFactory(factory);

                            createdNodes.Add(linkedConfig.LinkedNode.Id);
                            graphNodes.Add(new NetGraphFactory.GraphNodeEntry(linked));
                        }

                        graphNodes.Add(new NetGraphFactory.GraphNodeEntry(factory));

                        createdNodes.Add(node.Id);
                    }
                }
            }

            if (_lines != null)
            {
                foreach (LineConfig line in _lines)
                {
                    graphLines.Add(new NetGraphFactory.GraphLineEntry(line.SourceNode.Id, line.DestNode.Id, line.BiDirection, line.PathName, line.WeakPath));
                }
            }

            _factory.Nodes = graphNodes.ToArray();
            _factory.Lines = graphLines.ToArray();

            foreach (KeyValuePair <string, string> pair in _properties)
            {
                _factory.Properties.Add(pair.Key, pair.Value);
            }
        }
Пример #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="config">Configuration for the server</param>
        public FullHttpProxyServer(HttpProxyServerConfig config, Logger logger)
            : base(logger)
        {
            _config = config;

            NetGraphBuilder builder = new NetGraphBuilder();

            ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid());
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            DirectNodeFactory nop = builder.AddNode(new DirectNodeFactory("NOP", Guid.NewGuid()));

            builder.AddLines(client, nop, server, client);

            _factory = builder.Factory;
        }
Пример #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="config">Configuration for the server</param>
        public FullHttpProxyServer(HttpProxyServerConfig config, Logger logger)
            : base(logger)
        {
            _config = config;

            NetGraphBuilder builder = new NetGraphBuilder();

            ClientEndpointFactory client = builder.AddClient("Client", Guid.NewGuid());
            ServerEndpointFactory server = builder.AddServer("Server", Guid.NewGuid());

            DirectNodeFactory nop = builder.AddNode(new DirectNodeFactory("NOP", Guid.NewGuid()));

            builder.AddLines(client, nop, server, client);

            _factory = builder.Factory;
        }
Пример #12
0
        /// <summary>
        /// Create the netgraph for a connection
        /// </summary>
        /// <param name="factory">The netgraph factory</param>
        /// <param name="meta">Current meta data</param>
        /// <param name="properties">Property bag</param>
        /// <returns>The created graph</returns>
        private NetGraph CreateNetGraph(NetGraphFactory factory, MetaDictionary meta, PropertyBag properties)
        {
            NetGraph g = factory == null?_factory.Create(_logger, null, _globalMeta, meta, properties) : factory.Create(_logger, null, _globalMeta, meta, properties);

            if (g != null)
            {
                g.LogPacketEvent  += new EventHandler <LogPacketEventArgs>(log_AddLogPacket);
                g.EditPacketEvent += new EventHandler <EditPacketEventArgs>(edit_InputReceived);
                g.GraphShutdown   += new EventHandler(graph_GraphShutdown);

                // Add service to provider
                g.ServiceProvider.RegisterService(typeof(ProxyNetworkService), this);
                g.ServiceProvider.RegisterService(typeof(CredentialsManagerService), _credentialManager);
            }

            return(g);
        }
Пример #13
0
        /// <summary>
        /// Create the test graph container
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <param name="globals">Global meta</param>
        /// <returns>The new test graph container</returns>
        public override TestDocument.TestGraphContainer CreateTestGraph(Utils.Logger logger, MetaDictionary globals)
        {
            NetGraphFactory factory = _document.Factory;

            ClientEndpointFactory[] clients = factory.GetNodes <ClientEndpointFactory>();
            ServerEndpointFactory[] servers = factory.GetNodes <ServerEndpointFactory>();

            if ((clients.Length == 0) || (servers.Length == 0))
            {
                throw new ArgumentException("Graph must have a one client and one server endpoint to perform a test");
            }

            Guid inputNode  = _clientToServer ? clients[0].Id : servers[0].Id;
            Guid outputNode = _clientToServer ? servers[0].Id : clients[0].Id;

            NetGraph graph = factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection"));

            return(new TestDocument.TestGraphContainer(graph, graph.Nodes[inputNode], graph.Nodes[outputNode]));
        }
Пример #14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="listener"></param>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        /// <param name="globalMeta"></param>
        /// <param name="proxyServer"></param>
        /// <param name="proxyClient"></param>
        /// <param name="filters"></param>
        /// <param name="defaultTimeout"></param>
        /// <param name="afterdata"></param>
        public ProxyNetworkService(INetworkListener listener, NetGraphFactory factory, Logger logger,
                                   MetaDictionary globalMeta,
                                   ProxyServer proxyServer, ProxyClient proxyClient, ProxyFilter[] filters, int defaultTimeout, bool afterdata)
        {
            _packetLog = new List <LogPacket>(1000);
            _logger    = logger;
            Listener   = listener;

            _factory        = factory;
            _connections    = new List <ConnectionEntry>();
            _globalMeta     = globalMeta;
            _history        = new List <ConnectionHistoryEntry>();
            _subServices    = new List <ProxyNetworkService>();
            DefaultBinding  = NetworkLayerBinding.Default;
            _proxyClient    = proxyClient;
            _proxyServer    = proxyServer;
            _filters        = filters;
            _defaultTimeout = defaultTimeout;
            _afterData      = afterdata;
        }
Пример #15
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Name of the factory</param>
        /// <param name="factory">Factory</param>
        /// <param name="direction">Direction of graph</param>        
        /// <param name="containerGraph">The parent graph</param>
        /// <param name="logger">The logger to use</param>
        /// <param name="stateDictionary">Forwarded state dictionary</param>
        /// <param name="linked">If true then we are creating a linked master node</param>
        public NetGraphContainerNode(string name, NetGraphFactory factory,  
            GraphDirection direction, NetGraph containerGraph, Logger logger, 
            Dictionary<string, object> stateDictionary, bool linked)
        {
            var clients = factory.GetNodes<ClientEndpointFactory>();
            var servers = factory.GetNodes<ServerEndpointFactory>();

            if ((clients.Length > 0) && (servers.Length > 0))
            {
                Guid outputNode = direction == GraphDirection.ClientToServer
                    ? servers[0].Id : clients[0].Id;
                Guid inputNode = direction == GraphDirection.ClientToServer
                    ? clients[0].Id : servers[0].Id;

                if (linked)
                {
                    _graph = factory.Create(name, logger, containerGraph, containerGraph.GlobalMeta,
                        containerGraph.Meta, containerGraph.ConnectionProperties);
                }
                else
                {
                    _graph = factory.CreateFiltered(name, logger, containerGraph, containerGraph.GlobalMeta,
                        containerGraph.Meta, inputNode, containerGraph.ConnectionProperties, stateDictionary);
                }

                _graph.BindEndpoint(outputNode, new EventDataAdapter(this));

                _inputNode = (PipelineEndpoint)_graph.Nodes[inputNode];
                _inputNode.Hidden = true;

                _outputNode = (PipelineEndpoint)_graph.Nodes[outputNode];
                _outputNode.Hidden = true;
            }
            else
            {
                throw new ArgumentException(CANAPE.Properties.Resources.NetGraphContainerNode_InvalidGraph);
            }
        }
Пример #16
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Name of the factory</param>
        /// <param name="factory">Factory</param>
        /// <param name="direction">Direction of graph</param>
        /// <param name="containerGraph">The parent graph</param>
        /// <param name="logger">The logger to use</param>
        /// <param name="stateDictionary">Forwarded state dictionary</param>
        /// <param name="linked">If true then we are creating a linked master node</param>
        public NetGraphContainerNode(string name, NetGraphFactory factory,
                                     GraphDirection direction, NetGraph containerGraph, Logger logger,
                                     Dictionary <string, object> stateDictionary, bool linked)
        {
            var clients = factory.GetNodes <ClientEndpointFactory>();
            var servers = factory.GetNodes <ServerEndpointFactory>();

            if ((clients.Length > 0) && (servers.Length > 0))
            {
                Guid outputNode = direction == GraphDirection.ClientToServer
                    ? servers[0].Id : clients[0].Id;
                Guid inputNode = direction == GraphDirection.ClientToServer
                    ? clients[0].Id : servers[0].Id;

                if (linked)
                {
                    _graph = factory.Create(name, logger, containerGraph, containerGraph.GlobalMeta,
                                            containerGraph.Meta, containerGraph.ConnectionProperties);
                }
                else
                {
                    _graph = factory.CreateFiltered(name, logger, containerGraph, containerGraph.GlobalMeta,
                                                    containerGraph.Meta, inputNode, containerGraph.ConnectionProperties, stateDictionary);
                }

                _graph.BindEndpoint(outputNode, new EventDataAdapter(this));

                _inputNode        = (PipelineEndpoint)_graph.Nodes[inputNode];
                _inputNode.Hidden = true;

                _outputNode        = (PipelineEndpoint)_graph.Nodes[outputNode];
                _outputNode.Hidden = true;
            }
            else
            {
                throw new ArgumentException(CANAPE.Properties.Resources.NetGraphContainerNode_InvalidGraph);
            }
        }
Пример #17
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="packetLog"></param>
        /// <param name="listener"></param>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        /// <param name="globalMeta"></param>
        /// <param name="history"></param>
        /// <param name="credentials"></param>
        /// <param name="proxyServer"></param>
        /// <param name="proxyClient"></param>
        /// <param name="filters"></param>
        /// <param name="defaultTimeout"></param>
        /// <param name="afterdata"></param>
        public ProxyNetworkService(IList <LogPacket> packetLog, INetworkListener listener, NetGraphFactory factory, Logger logger,
                                   MetaDictionary globalMeta, IList <ConnectionHistoryEntry> history, IDictionary <SecurityPrincipal, ICredentialObject> credentials,
                                   ProxyServer proxyServer, ProxyClient proxyClient, ProxyFilter[] filters, int defaultTimeout, bool afterdata)
        {
            _packetLog = packetLog;
            _logger    = logger;
            Listener   = listener;

            _factory           = factory;
            _connections       = new List <ConnectionEntry>();
            _globalMeta        = globalMeta;
            _history           = history;
            _subServices       = new List <ProxyNetworkService>();
            DefaultBinding     = NetworkLayerBinding.Default;
            _credentials       = new Dictionary <SecurityPrincipal, ICredentialObject>(credentials);
            _credentialManager = new CredentialsManagerService();
            _credentialManager.ResolveCredentials += _credentialManager_ResolveCredentials;
            _proxyClient    = proxyClient;
            _proxyServer    = proxyServer;
            _filters        = filters;
            _defaultTimeout = defaultTimeout;
            _afterData      = afterdata;
        }
Пример #18
0
        /// <summary>
        /// Create the netgraph for a connection
        /// </summary>
        /// <param name="factory">The netgraph factory</param>
        /// <param name="meta">Current meta data</param>
        /// <param name="properties">Property bag</param>
        /// <returns>The created graph</returns>
        private NetGraph CreateNetGraph(NetGraphFactory factory, MetaDictionary meta, PropertyBag properties)
        {
            NetGraph g = factory == null ? _factory.Create(_logger, null, _globalMeta, meta, properties) : factory.Create(_logger, null, _globalMeta, meta, properties);
            if (g != null)
            {
                g.LogPacketEvent += new EventHandler<LogPacketEventArgs>(log_AddLogPacket);
                g.EditPacketEvent += new EventHandler<EditPacketEventArgs>(edit_InputReceived);
                g.GraphShutdown += new EventHandler(graph_GraphShutdown);

                // Add service to provider
                g.ServiceProvider.RegisterService(typeof(ProxyNetworkService), this);
                g.ServiceProvider.RegisterService(typeof(CredentialsManagerService), _credentialManager);
            }

            return g;
        }
Пример #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="guid"></param>
 /// <param name="label"></param>
 /// <param name="factory"></param>
 /// <param name="direction"></param>
 public NetGraphContainerNodeFactory(string label, Guid guid, NetGraphFactory factory, NetGraphContainerNode.GraphDirection direction)
     : base(label, guid)
 {
     Direction = direction;
     Factory = factory;
 }
Пример #20
0
        /// <summary>
        /// Connect client
        /// </summary>
        /// <param name="baseAdapter"></param>
        /// <param name="connProperties"></param>
        /// <returns></returns>
        public NetGraph ConnectClient(IDataAdapter baseAdapter, PropertyBag connProperties)
        {
            IDataAdapter   server     = null;
            IDataAdapter   client     = null;
            ProxyToken     token      = null;
            NetGraph       graph      = null;
            NetGraph       retGraph   = null;
            MetaDictionary meta       = new MetaDictionary();
            PropertyBag    properties = new PropertyBag("Properties");

            try
            {
                properties.AddBag(connProperties);

                token = _proxyServer.Accept(baseAdapter, meta, _globalMeta, this);

                if (token != null)
                {
                    token = FilterToken(token);
                    if (token.Status == NetStatusCodes.Success)
                    {
                        ProxyClient proxyClient = token.Client ?? _proxyClient;

                        if (token.Bind)
                        {
                            client = proxyClient.Bind(token, _logger, meta, _globalMeta, properties.AddBag("Client"));
                        }
                        else
                        {
                            client = proxyClient.Connect(token, _logger, meta, _globalMeta, properties.AddBag("Client"));
                        }

                        server = _proxyServer.Complete(token, meta, _globalMeta, this, client);

                        if ((token.Status == NetStatusCodes.Success) && (client != null))
                        {
                            NetGraphFactory factory = token.Graph != null ? token.Graph : _factory;

                            token.PopulateBag(properties.AddBag("Token"));

                            // Negotiate SSL or other bespoke encryption mechanisms
                            if (token.Layers != null)
                            {
                                foreach (INetworkLayer layer in token.Layers)
                                {
                                    layer.Negotiate(ref server, ref client, token, _logger, meta,
                                                    _globalMeta, properties, DefaultBinding);
                                }
                            }

                            var clients = factory.GetNodes <ClientEndpointFactory>();
                            var servers = factory.GetNodes <ServerEndpointFactory>();

                            if ((clients.Length > 0) && (servers.Length > 0))
                            {
                                graph = CreateNetGraph(factory, meta, properties);

                                graph.BindEndpoint(clients[0].Id, client);
                                graph.BindEndpoint(servers[0].Id, server);
                                if (token.NetworkDescription != null)
                                {
                                    graph.NetworkDescription = token.NetworkDescription;
                                }
                                else
                                {
                                    graph.NetworkDescription = String.Format("{0} <=> {1}",
                                                                             server.Description, client.Description);
                                }

                                PropertyBag networkService = properties.AddBag("NetworkService");

                                networkService.AddValue("ClientId", clients[0].Id);
                                networkService.AddValue("ServerId", servers[0].Id);
                                networkService.AddValue("ClientAdapter", client);
                                networkService.AddValue("ServerAdapter", server);
                                networkService.AddValue("Token", token);

                                graph.Start();

                                OnNewConnection(graph);

                                retGraph = graph;
                            }
                            else
                            {
                                _logger.LogError(CANAPE.Net.Properties.Resources.ProxyNetworkService_InvalidGraph);
                            }
                        }
                    }
                    else
                    {
                        _logger.LogVerbose(CANAPE.Net.Properties.Resources.ProxyNetworkService_ConnectionFiltered);
                        server = _proxyServer.Complete(token, meta, _globalMeta, this, client);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
            finally
            {
                if (retGraph == null)
                {
                    try
                    {
                        if (graph != null)
                        {
                            ((IDisposable)graph).Dispose();
                        }
                        if (server != null)
                        {
                            server.Dispose();
                        }
                        if (client != null)
                        {
                            client.Dispose();
                        }
                        if (token != null)
                        {
                            token.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.SystemLogger.LogException(ex);
                    }
                }
            }

            return(retGraph);
        }
Пример #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 public StateGraphDocument()
 {
     _entries = new List<StateGraphEntry>();
     _factory = new NetGraphFactory();
     _metaName = "REPLACE ME";
 }
Пример #22
0
 /// <summary>
 /// Constructor
 /// </summary>
 public StateGraphDocument()
 {
     _entries  = new List <StateGraphEntry>();
     _factory  = new NetGraphFactory();
     _metaName = "REPLACE ME";
 }
Пример #23
0
        /// <summary>
        /// 
        /// </summary>
        protected virtual void RebuildFactory()
        {
            List<NetGraphFactory.GraphNodeEntry> graphNodes = new List<NetGraphFactory.GraphNodeEntry>();
            List<NetGraphFactory.GraphLineEntry> graphLines = new List<NetGraphFactory.GraphLineEntry>();
            HashSet<Guid> createdNodes = new HashSet<Guid>();

            if (_factory == null)
            {
                _factory = new NetGraphFactory();
            }

            if(_nodes != null)
            {
                foreach (BaseNodeConfig node in _nodes)
                {
                    if (!createdNodes.Contains(node.Id))
                    {
                        BaseNodeFactory factory = node.CreateFactory();
                        ILinkedNodeConfig linkedConfig = node as ILinkedNodeConfig;

                        if ((linkedConfig != null) && (linkedConfig.LinkedNode != null))
                        {
                            BaseNodeFactory linked = linkedConfig.CreateFactory(factory);

                            createdNodes.Add(linkedConfig.LinkedNode.Id);
                            graphNodes.Add(new NetGraphFactory.GraphNodeEntry(linked));
                        }

                        graphNodes.Add(new NetGraphFactory.GraphNodeEntry(factory));

                        createdNodes.Add(node.Id);
                    }
                }
            }

            if(_lines != null)
            {
                foreach (LineConfig line in _lines)
                {
                    graphLines.Add(new NetGraphFactory.GraphLineEntry(line.SourceNode.Id, line.DestNode.Id, line.BiDirection, line.PathName, line.WeakPath));
                }
            }

            _factory.Nodes = graphNodes.ToArray();
            _factory.Lines = graphLines.ToArray();

            foreach (KeyValuePair<string, string> pair in _properties)
            {
                _factory.Properties.Add(pair.Key, pair.Value);
            }
        }
Пример #24
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="packetLog"></param>
        /// <param name="listener"></param>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        /// <param name="globalMeta"></param>
        /// <param name="history"></param>
        /// <param name="credentials"></param>
        /// <param name="proxyServer"></param>
        /// <param name="proxyClient"></param>
        /// <param name="filters"></param>
        /// <param name="defaultTimeout"></param>
        /// <param name="afterdata"></param>
        public ProxyNetworkService(IList<LogPacket> packetLog, INetworkListener listener, NetGraphFactory factory, Logger logger, 
            MetaDictionary globalMeta, IList<ConnectionHistoryEntry> history, IDictionary<SecurityPrincipal, ICredentialObject> credentials, 
            ProxyServer proxyServer, ProxyClient proxyClient, ProxyFilter[] filters, int defaultTimeout, bool afterdata)
        {
            _packetLog = packetLog;
            _logger = logger;
            Listener = listener;

            _factory = factory;
            _connections = new List<ConnectionEntry>();
            _globalMeta = globalMeta;
            _history = history;
            _subServices = new List<ProxyNetworkService>();
            DefaultBinding = NetworkLayerBinding.Default;
            _credentials = new Dictionary<SecurityPrincipal, ICredentialObject>(credentials);
            _credentialManager = new CredentialsManagerService();
            _credentialManager.ResolveCredentials += _credentialManager_ResolveCredentials;
            _proxyClient = proxyClient;
            _proxyServer = proxyServer;
            _filters = filters;
            _defaultTimeout = defaultTimeout;
            _afterData = afterdata;
        }
Пример #25
0
 /// <summary>
 /// Constructor which takes an existing factory
 /// </summary>
 /// <param name="factory">The factory</param>
 public NetGraphBuilder(NetGraphFactory factory)
 {
     _graphFactory = factory;
 }