public void Concatenates_Duplicate_Items() { // Arrange var k0 = Rnd.Str; var k1 = Rnd.Str; var v0 = Rnd.Str; var v1 = Rnd.Str; var v2 = Rnd.Str; var items = new[] { new KeyValuePair <string, string>(k0, v0), new KeyValuePair <string, string>(k0, v1), new KeyValuePair <string, string>(k1, v2) }; // Act var result = new MetaDictionary(items); // Assert Assert.Collection(result, x => { Assert.Equal(k0, x.Key); Assert.Equal($"{v0};{v1}", x.Value); }, x => { Assert.Equal(k1, x.Key); Assert.Equal(v2, x.Value); } ); }
/// <summary> /// Create the data endpoint /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globalMeta">Global meta dictionary</param> /// <param name="meta">Meta dictionary</param> /// <returns></returns> public override IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta) { IDataEndpoint ret = Script.Container.GetInstance(ClassName) as IDataEndpoint; if (ret == null) { throw new NetServiceException(CANAPE.Documents.Properties.Resources.ScriptDataEndpointFactory_InvalidType); } ServerConfig config = (ServerConfig)Config; foreach (KeyValuePair <string, string> pair in config.Properties) { meta[pair.Key] = pair.Value; } ret.Meta = meta; ret.GlobalMeta = globalMeta; if (ret is IPersistNode) { IPersistNode persist = ret as IPersistNode; persist.SetState(config.GetConfig(), logger); } return(ret); }
public void SetDictionaryValues(MetaDictionary <MetaValue, MetaValue> metaValues) { this.dictionaryKeys = metaValues.GetKeys(); this.dictionaryValues = metaValues.GetValues(this.dictionaryKeys); this.Enabled = (this.dictionaryValues.Count > 0); this.RefreshData(); }
/// <summary> /// Connect socket. /// </summary> /// <param name="token">The proxy token (ignored).</param> /// <param name="logger">The logger object.</param> /// <param name="meta">Connection meta-data.</param> /// <param name="globalMeta">Global meta-data.</param> /// <param name="properties">Properties for the connection.</param> /// <returns>The connected data adapater.</returns> public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties) { IDataAdapter adapter = null; try { Socket socket = new Socket(_endPoint.AddressFamily, SocketType.Stream, _protocolType); socket.Connect(_endPoint); NetUtils.PopulateBagFromSocket(socket, properties); adapter = new StreamSocketDataAdapter(socket); } catch (SocketException ex) { logger.LogException(ex); token.Status = NetStatusCodes.ConnectFailure; } catch (IOException ex) { logger.LogException(ex); token.Status = NetStatusCodes.ConnectFailure; } return(adapter); }
public async Task Meta_Contains_Key_Single_Item_Found_Sets_ValueObj_Returns_True() { // Arrange var term = new Term(); var terms = new[] { term }; var db = Substitute.For <IWpDb>(); var unitOfWork = Substitute.For <IUnitOfWork>(); var key = Rnd.Str; var meta = new MetaDictionary { { key, Rnd.Lng.ToString() } }; var queryTerms = Substitute.For <IQueryTerms>(); queryTerms.ExecuteAsync <Term>(db, unitOfWork, Arg.Any <GetTermsOptions>()).Returns(terms); var field = new Test(queryTerms, key); // Act var result = await field.HydrateAsync(db, unitOfWork, meta, true); // Assert result.AssertTrue(); Assert.Same(term, field.ValueObj); }
private CANAPEProject() { _documents = new Dictionary <string, IDocumentObject>(); _properties = new Dictionary <string, string>(); _defaultClient = new IpProxyClientFactory(); _globalMeta = new MetaDictionary(); }
public async Task Meta_Contains_Key_Multiple_Terms_Found_Returns_None_With_MultipleTermsFoundMsg() { // Arrange var t0 = new Term(); var t1 = new Term(); var terms = new[] { t0, t1 }; var db = Substitute.For <IWpDb>(); var unitOfWork = Substitute.For <IUnitOfWork>(); var key = Rnd.Str; var value = Rnd.Lng; var meta = new MetaDictionary { { key, value.ToString() } }; var queryTerms = Substitute.For <IQueryTerms>(); queryTerms.ExecuteAsync <Term>(db, unitOfWork, Arg.Any <GetTermsOptions>()).Returns(terms); var field = new Test(queryTerms, key); // Act var result = await field.HydrateAsync(db, unitOfWork, meta, true); // Assert var none = result.AssertNone().AssertType <MultipleTermsFoundMsg>(); Assert.Equal(value.ToString(), none.Value); }
/// <summary> /// /// </summary> /// <param name="token"></param> /// <param name="client"></param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns></returns> public override IDataAdapter Complete(ProxyToken token, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service, IDataAdapter client) { SocksProxyToken socksToken = (SocksProxyToken)token; if (IsSupported(socksToken.Version)) { if (socksToken.Version == 4) { return(HandleSocksV4Response(socksToken)); } else if (socksToken.Version == 5) { return(HandleSocksV5Response(socksToken)); } else { // We shouldn't get here throw new InvalidOperationException(CANAPE.Net.Properties.Resources.SocksProxyServer_IsSupportedError); } } else { _logger.LogError(CANAPE.Net.Properties.Resources.SocksProxyServer_UnsupportedTokenVersion, socksToken.Version); } return(null); }
/// <summary> /// Extended match syntax, can use details from a graph and node /// </summary> /// <param name="frame">The data frame to select off</param> /// <param name="globalMeta">The global meta</param> /// <param name="meta">The meta</param> /// <param name="node">The current node</param> /// <param name="properties">The property bag</param> /// <param name="uuid">The uuid for private meta names</param> /// <returns>True if the filter matches</returns> public bool IsMatch(DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, Guid uuid, BasePipelineNode node) { bool ret = true; foreach (IDataFrameFilter filter in _filters) { ret = filter.IsMatch(frame, meta, globalMeta, properties, uuid, node); if (_matchAll) { if (!ret) { break; } } else { if (ret) { break; } } } if (Invert) { return(!ret); } else { return(ret); } }
/// <summary> /// Method to create the data endpoint /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globalMeta">Global meta dictionary</param> /// <param name="meta">Meta dictionary</param> /// <returns>The data endpoint</returns> public override IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta) { IDataEndpoint server = null; ConstructorInfo ci = _type.GetConstructor(new [] { typeof(Logger) }); if (ci != null) { server = (IDataEndpoint)ci.Invoke(new [] { logger }); } else { ci = _type.GetConstructor(new Type[0]); if (ci == null) { throw new NetServiceException("Can not find an appropriate constructor for endpoint"); } server = (IDataEndpoint)ci.Invoke(new object[0]); } server.Meta = meta; server.GlobalMeta = globalMeta; if (Config != null) { IPersistNode persist = server as IPersistNode; if (persist != null) { persist.SetState(Config, logger); } } return server; }
public string Execute(Base data, string path) { Repository repository = (Repository)data; this.path = path; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } MetaDictionary <MetaClass, MetaList <MetaValue> > values = repository.Values; string fullPath; MetaList <MetaValue> metaValues; foreach (KeyValuePair <MetaClass, MetaList <MetaValue> > pair in values) { this._lsIds = 0; metaValues = pair.Value; if (metaValues.Count > 0) { fullPath = path + "/" + pair.Key.GetNameWithModule("/") + ".lsb"; this.createFilePath(fullPath); this.writer = new FileStream(fullPath, FileMode.Create); this.dump((byte)1); this.dump((byte)0); this.dump(metaValues); this.writer.Close(); } } return("Code generation was successful."); }
/// <summary> /// Build a NetGraph object from the nodes /// </summary> /// <param name="name">The name of the graph</param> /// <param name="logger">A logger object</param> /// <param name="parent">The parent graph, null if not available</param> /// <param name="globalMeta">Global meta dictionary</param> /// <param name="meta">Local meta dictionary</param> /// <param name="connectionProperties">Properties for connection</param> /// <returns>The constructed NetGraph</returns> public NetGraph Create(string name, Logger logger, NetGraph parent, MetaDictionary globalMeta, MetaDictionary meta, PropertyBag connectionProperties) { lock (_lockObject) { return(CreateGraph(name, logger, parent, globalMeta, meta, _nodes, _lines, _props, connectionProperties, new Dictionary <string, object>())); } }
public bool IsMatch(DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, Guid uuid, BasePipelineNode node) { switch (_arrity) { case 1: return(_filterFunc(frame)); case 2: return(_filterFunc(frame, meta)); case 3: return(_filterFunc(frame, meta, globalMeta)); case 4: return(_filterFunc(frame, meta, globalMeta, properties)); case 5: return(_filterFunc(frame, meta, globalMeta, properties, uuid)); case 6: return(_filterFunc(frame, meta, globalMeta, properties, uuid, node)); default: break; } return(false); }
/// <summary> /// Accept connection (just returns a default token) /// </summary> /// <param name="adapter">The server adapter</param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns>The proxy token</returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = new PassThroughToken(adapter); token.Layers = _layers.CreateLayers(_logger); return token; }
public async Task Meta_Contains_Key_Multiple_Terms_Found_Returns_None_With_MultipleTermsFoundMsg() { // Arrange var a0 = new Attachment(); var a1 = new Attachment(); var attachments = new[] { a0, a1 }; var db = Substitute.For <IWpDb>(); var unitOfWork = Substitute.For <IUnitOfWork>(); var key = Rnd.Str; var value = Rnd.Lng; var meta = new MetaDictionary { { key, value.ToString() } }; var queryPosts = Substitute.For <IQueryPosts>(); queryPosts.ExecuteAsync <Attachment>(db, unitOfWork, Arg.Any <GetPostsOptions>()).Returns(attachments); var field = new TestCustomField(queryPosts, key); // Act var result = await field.HydrateAsync(db, unitOfWork, meta, true); // Assert var none = result.AssertNone().AssertType <MultipleAttachmentsFoundMsg>(); Assert.Equal(value.ToString(), none.Value); }
public async Task Meta_Contains_Key_Single_Item_Found_Sets_ValueObj_Properties_Returns_True() { // Arrange var attachment = new Attachment(); var urlPath = Rnd.Str; attachment.Meta.Add(Constants.Attachment, urlPath); var info = Rnd.Str; attachment.Meta.Add(Constants.AttachmentMetadata, "s:6:\"" + info + "\";"); var attachments = new[] { attachment }; var db = Substitute.For <IWpDb>(); var unitOfWork = Substitute.For <IUnitOfWork>(); var key = Rnd.Str; var meta = new MetaDictionary { { key, Rnd.Lng.ToString() } }; var queryPosts = Substitute.For <IQueryPosts>(); queryPosts.ExecuteAsync <Attachment>(db, unitOfWork, Arg.Any <GetPostsOptions>()).Returns(attachments); var field = new TestCustomField(queryPosts, key); // Act var result = await field.HydrateAsync(db, unitOfWork, meta, true); // Assert result.AssertTrue(); Assert.Equal(urlPath, field.ValueObj.UrlPath); Assert.Contains(info, field.ValueObj.Info); }
public async Task Meta_Contains_Key_Single_Item_Found_Sets_ValueObj_Returns_True() { // Arrange var attachment = new Attachment(); var attachments = new[] { attachment }; var db = Substitute.For <IWpDb>(); var unitOfWork = Substitute.For <IUnitOfWork>(); var key = Rnd.Str; var meta = new MetaDictionary { { key, Rnd.Lng.ToString() } }; var queryPosts = Substitute.For <IQueryPosts>(); queryPosts.ExecuteAsync <Attachment>(db, unitOfWork, Arg.Any <GetPostsOptions>()).Returns(attachments); var field = new TestCustomField(queryPosts, key); // Act var result = await field.HydrateAsync(db, unitOfWork, meta, true); // Assert result.AssertTrue(); Assert.Same(attachment, field.ValueObj); }
/// <summary> /// Accept connection (just returns a default token) /// </summary> /// <param name="adapter">The server adapter</param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns>The proxy token</returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = new PassThroughToken(adapter); token.Layers = _layers.CreateLayers(_logger); return(token); }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { FixedProxyToken token = new FixedProxyToken(_address, _hostName, _port, _clientType, _ipv6, adapter); token.Layers = _layers.CreateLayers(_logger); return(token); }
private void dump(MetaDictionary <MetaValue, MetaValue> metaValues) { MetaList <MetaValue> keys = metaValues.GetKeys(); MetaList <MetaValue> values = metaValues.GetValues(keys); this.dump(keys); this.dump(values); }
private void RunTest() { Logger logger = eventLogControl.Logger; MetaDictionary globals = new MetaDictionary(); EventWaitHandle endEvent = new EventWaitHandle(false, EventResetMode.ManualReset); try { CancellationTokenSource tokenSource = new CancellationTokenSource(); using (TestDocument.TestGraphContainer testGraph = Document.CreateTestGraph(logger, globals)) { testGraph.Graph.LogPacketEvent += new EventHandler <LogPacketEventArgs>(log_AddLogPacket); testGraph.Graph.EditPacketEvent += new EventHandler <EditPacketEventArgs>(Graph_EditPacketEvent); LogPacket[] packets = Document.GetInputPackets(); using (QueuedDataAdapter inputAdapter = new QueuedDataAdapter(tokenSource.Token)) { foreach (LogPacket p in packets) { inputAdapter.Enqueue(p.Frame.CloneFrame()); } inputAdapter.StopEnqueue(); testGraph.Graph.BindEndpoint(testGraph.Output.Uuid, new EventDataAdapter(endEvent)); testGraph.Graph.BindEndpoint(testGraph.Input.Uuid, inputAdapter); IPipelineEndpoint inputEndpoint = testGraph.Input as IPipelineEndpoint; inputEndpoint.Start(); // Sleep up to 100 seconds if (!endEvent.WaitOne(100000)) { logger.LogError("Test did not finish after 100 seconds"); tokenSource.Cancel(); } } } } catch (EndOfStreamException) { // End of stream } catch (ThreadAbortException) { } catch (ObjectDisposedException) { } finally { if (endEvent != null) { endEvent.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = null; if (_config.SslConfig.Enabled) { IDataAdapter client = null; INetworkLayer ssl = new TlsNetworkLayer(_config.SslConfig); ssl.Negotiate(ref adapter, ref client, null, _logger, null, null, new PropertyBag("Root"), NetworkLayerBinding.Server); } if (adapter is HttpProxyDataAdapter) { HttpProxyDataAdapter proxyAdapter = (HttpProxyDataAdapter)adapter; token = new FullHttpProxyToken(proxyAdapter.Url.Host, proxyAdapter.Url.Port); token.State.Add("adapter", adapter); } else { DataAdapterToStream stm = new DataAdapterToStream(adapter); DataReader reader = new DataReader(stm); try { HttpRequestHeader header = HttpParser.ReadRequestHeader(reader, false, _logger); if (HandleProxyAuthentication(reader, stm, ref header)) { // We just have a connect if (header.IsConnect) { token = HandleConnect(header, stm); } else { token = HandleOtherRequest(header, stm, service); } } } catch (HttpStreamParserException ex) { _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidRequest, ex.Message); // TODO: Put in some decent error codes ReturnResponse(null, 400, "Bad Request", "GET", HttpVersion.Version11, stm); } catch (EndOfStreamException) { token = null; } } return(token); }
/// <summary> /// Constructor /// </summary> public NetServiceDocument() : base() { _packets = new LogPacketCollection(); _globalMeta = new MetaDictionary(); _history = new ConnectionHistory(); _credentials = new Dictionary <SecurityPrincipal, ICredentialObject>(); SetupCollections(); }
public override string RenderOGPMeta(IOGPSiteMeta siteMeta, IOGPPageData ogpPageData) { ogpPageData = GetPageMetaMerger().MergeMetaData( ogpPageData,siteMeta); var metas = new MetaDictionary("og:"); metas.Add("type","article"); metas.Add("site_name",siteMeta.SiteName); AppendTitleImageUrl(metas,ogpPageData); AppendOptionalMeta(metas,ogpPageData); return metas.ToMetaTagString(); }
public Repository(Model model) : base() { this.model = model; this.values = new MetaDictionary <MetaClass, MetaList <MetaValue> >(); this.visibleClasses = new MetaList <MetaClass>(model.LeafClasses); foreach (MetaClass metaClass in this.visibleClasses) { this.values[metaClass] = new MetaList <MetaValue>(); } }
/// <summary> /// Create the data endpoint /// </summary> /// <param name="logger">Logger</param> /// <param name="meta">Metadata</param> /// <param name="globalMeta">Global metadata</param> /// <returns></returns> public IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta) { T server = new T() { Logger = logger, Meta = meta, GlobalMeta = globalMeta }; server.SetState(Config, logger); return(server); }
/// <summary> /// Handles the Click event of the LinkButtonRemove control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void LinkButtonRemove_Click(object sender, System.EventArgs e) { System.Web.UI.WebControls.ListItem li = DicSingleValueCtrl.SelectedItem; if (li != null) { DicSingleValueCtrl.Items.Remove(li); //if (li.Value != "-1") { MetaDictionary dictionary = MetaDictionary.Load(MDContext, AttributeId); dictionary.Delete(int.Parse(li.Value)); } } }
/// <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); }
private void BindData() { //foreach(string item in MetaField.DictionaryItems.Values) //{ // MetaMultiValueCtrl.Items.Add(new ListItem(item, item)); //} if (this.IsPostBack && DictionaryItemsTable != null) { MetaMultiValueCtrl.DataSource = DictionaryItemsTable; MetaMultiValueCtrl.DataBind(); } else { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id", typeof(int)), new DataColumn("Value", typeof(string)) }); MetaDictionary dictionary = MetaField.Dictionary; if (dictionary != null) { foreach (MetaDictionaryItem item in dictionary) { DataRow row = dt.NewRow(); row["Id"] = item.Id; row["Value"] = item.Value; dt.Rows.Add(row); } } DictionaryItemsTable = dt; this.MetaMultiValueCtrl.DataSource = dt; this.MetaMultiValueCtrl.DataBind(); } //if(MetaField.Value!=null) //foreach(string str in (string[])MetaField.Value) //{ // Util.CommonHelper.SelectListItem(MetaMultiValueCtrl, str, false); //} if (MetaObject != null) { MetaDictionaryItem[] items = MetaObject.GetDictionaryItems(MetaField); foreach (MetaDictionaryItem item in items) { ManagementHelper.SelectListItem(MetaMultiValueCtrl, item.Id, false); } } }
/// <summary> /// Connect to the required service with the token /// </summary> /// <param name="token">The token recevied from proxy</param> /// <param name="globalMeta">The global meta</param> /// <param name="logger">The logger</param> /// <param name="meta">The meta</param> /// <param name="properties">Property bag to add any information to</param> /// <param name="credmgr">Credentials manager</param> /// <returns>The connected data adapter</returns> public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { IpProxyToken iptoken = token as IpProxyToken; if ((iptoken != null) && IsFiltered(iptoken)) { return base.Connect(token, logger, meta, globalMeta, properties, credmgr); } else { token.Status = NetStatusCodes.Blocked; return null; } }
public override string RenderOGPMeta(IOGPSiteMeta siteMeta, IOGPPageData ogpPageData) { ogpPageData = GetPageMetaMerger().MergeMetaData(ogpPageData, siteMeta); var metas = new MetaDictionary("twitter:"); metas.Add("card","summary"); if (siteMeta is ITwitterCardSiteMeta) { var twitterSiteMeta = (ITwitterCardSiteMeta)siteMeta; metas.Add("site",twitterSiteMeta.Site); } AppendTitleImageUrl(metas,ogpPageData); metas.Add("description", ogpPageData.Description); return metas.ToMetaTagString(); }
/// <summary> /// Select a single node /// </summary> /// <param name="path">The path to select</param> /// <param name="frame">The data frame to select off</param> /// <param name="globalMeta">Global meta</param> /// <param name="meta">Meta</param> /// <param name="properties">PropertyBag</param> /// <param name="uuid">Uuid to use for private values</param> /// <param name="node">The current node</param> /// <returns>The first selected node or null if not found</returns> public static DataNode SelectSingleNode(string path, DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, Guid uuid, BasePipelineNode node) { DataNode[] nodes = SelectNodes(path, frame, meta, globalMeta, properties, uuid, node); if (nodes.Length > 0) { return nodes[0]; } else { return null; } }
private MetaDictionaryItem findDictionaryItem(string value, string DestFieldName) { MetaField field = MetaField.Load(this.Context, DestFieldName); MetaDictionary dictionary = field.Dictionary; foreach (MetaDictionaryItem item in dictionary) { if (String.Compare(value, item.Value, true) == 0) { return(item); } } return(null); }
/// <summary> /// Connect to the required service with the token /// </summary> /// <param name="token">The token recevied from proxy</param> /// <param name="globalMeta">The global meta</param> /// <param name="logger">The logger</param> /// <param name="meta">The meta</param> /// <param name="properties">Property bag to add any information to</param> /// <returns>The connected data adapter</returns> public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties) { IpProxyToken iptoken = token as IpProxyToken; if ((iptoken != null) && IsFiltered(iptoken)) { return(base.Connect(token, logger, meta, globalMeta, properties)); } else { token.Status = NetStatusCodes.Blocked; return(null); } }
private void dump(MetaDictionary <MetaValue, MetaValue> metaValues) { this.dump(metaValues.Count); if (metaValues.Count > 0) { this.dump((uint)2); MetaList <MetaValue> keys = metaValues.GetKeys(); MetaList <MetaValue> values = metaValues.GetValues(keys); this.dump(this._getLS2Type(keys[0].Type, true)); this.dump(this._getLS2Type(values[0].Type, true)); this.dump(keys); this.dump(values); } }
/// <summary> /// Extended match syntax, can use details from a graph and node /// </summary> /// <param name="frame">The data frame to select off</param> /// <param name="globalMeta">The global meta</param> /// <param name="meta">Meta</param> /// <param name="node">The current node</param> /// <param name="properties">Property bag</param> /// <param name="uuid">The uuid for private names</param> /// <returns>True if the filter matches</returns> public bool IsMatch(DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, Guid uuid, BasePipelineNode node) { bool match = false; DataNode[] nodes = GeneralUtils.SelectNodes(Path, frame, meta, globalMeta, properties, uuid, node); match = OnMatch(nodes); if (Invert) { return !match; } else { return match; } }
/// <summary> /// Bind to the required service with the token /// </summary> /// <param name="token">The token recevied from proxy</param> /// <param name="globalMeta">The global meta</param> /// <param name="logger">The logger</param> /// <param name="meta">The meta</param> /// <param name="properties">Property bag to add any information to</param> /// <param name="credmgr">Credentials manager</param> /// <returns>The connected data adapter</returns> public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { IDataAdapter adapter = null; IpProxyToken iptoken = token as IpProxyToken; if (iptoken != null) { if (iptoken.ClientType == IpProxyToken.IpClientType.Tcp) { adapter = BindTcp(iptoken, logger, properties); } else { throw new ArgumentException(CANAPE.Net.Properties.Resources.IpProxyClient_InvalidTokenType); } } return adapter; }
/// <summary> /// Default constructor /// </summary> /// <param name="globalMeta">Global meta data</param> /// <param name="logger">Logger</param> /// <param name="meta">Local meta data</param> /// <param name="parent">Parent graph if available</param> /// <param name="properties">A property bag associated with this connection</param> public NetGraph(Logger logger, NetGraph parent, MetaDictionary globalMeta, MetaDictionary meta, PropertyBag properties) { Nodes = new Dictionary<Guid, BasePipelineNode>(); if (meta == null) { Meta = new MetaDictionary(); } else { Meta = meta; } Properties = new ConcurrentDictionary<string, string>(); ConnectionProperties = properties; GlobalMeta = globalMeta; Uuid = Guid.NewGuid(); if (logger != null) { Logger = logger; } else { Logger = Logger.GetSystemLogger(); } NetworkDescription = "Unknown"; Name = String.Empty; Parent = parent; Created = DateTime.Now; CreatedTicks = new TimeSpan(DateTime.UtcNow.Ticks); if (parent == null) { ServiceProvider = new CANAPEServiceProvider(); } else { ServiceProvider = parent.ServiceProvider; } }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = null; TcpClientDataAdapter tcpAdapter = adapter as TcpClientDataAdapter; if (_config.SslConfig.Enabled) { IDataAdapter client = null; INetworkLayer ssl = new SslNetworkLayer(_config.SslConfig); ssl.Negotiate(ref adapter, ref client, null, _logger, null, null, new PropertyBag("Root"), NetworkLayerBinding.Server); } DataAdapterToStream stm = new DataAdapterToStream(adapter); DataReader reader = new DataReader(stm); try { HttpRequestHeader header = HttpParser.ReadRequestHeader(reader, false, _logger); token = HandleOtherRequest(header, stm, tcpAdapter); } catch (HttpStreamParserException ex) { _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidRequest, ex.Message); // TODO: Put in some decent error codes ReturnResponse(null, 400, "Bad Request", "GET", HttpVersion.Version11, stm); } catch (EndOfStreamException) { token = null; } return token; }
public void SetDictionaryValues(MetaDictionary<MetaValue, MetaValue> metaValues) { this.dictionaryKeys = metaValues.GetKeys(); this.dictionaryValues = metaValues.GetValues(this.dictionaryKeys); this.Enabled = (this.dictionaryValues.Count > 0); this.RefreshData(); }
public void SetData(IRefreshable owner, Repository repository, MetaType metaType1, MetaType metaType2, MetaDictionary<MetaValue, MetaValue> metaValues) { this.owner = owner; this.repository = repository; this.type1 = metaType1; this.type2 = metaType2; this.dictionaryKeys = metaValues.GetKeys(); this.dictionaryValues = metaValues.GetValues(this.dictionaryKeys); this.vlVariables.ClearData(); this.vlVariables.SetData(this, this.repository, this.type2); this.vlVariables.SetValue(this.dictionaryValues.Count > 0 ? this.dictionaryValues[0] : null); }
/// <summary> /// Method to constructor the test graph /// </summary> /// <param name="logger"></param> /// <param name="globals"></param> /// <returns></returns> public abstract TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals);
public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { return new DataEndpointAdapter(_factory.Create(logger, meta, globalMeta), logger); }
/// <summary> /// Complete the client connection, just returns the original adapter /// </summary> /// <param name="token">The proxy token</param> /// <param name="client"></param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns>The data adapter</returns> public override IDataAdapter Complete(ProxyToken token, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service, IDataAdapter client) { PassThroughToken passToken = (PassThroughToken)token; IDataAdapter adapter = passToken.Adapter; if (token.Status != NetStatusCodes.Success) { return null; } else { // Set to null to prevent Dispose being called passToken.Adapter = null; return adapter; } }
protected void AppendTitleImageUrl(MetaDictionary dic, IOGPPageData page) { dic.Add("title",page.Title); dic.Add("image",page.Image); dic.Add("url",page.Url); }
public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { return new SerialPortDataAdapter(_config.Create()); }
/// <summary> /// Method to create the data endpoint /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globalMeta">Global meta dictionary</param> /// <param name="meta">Meta dictionary</param> /// <returns>The data endpoint</returns> public abstract IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta);
/// <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"), _credentialManager); } else { client = proxyClient.Connect(token, _logger, meta, _globalMeta, properties.AddBag("Client"), _credentialManager); } 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.Close(); } if (client != null) { client.Close(); } if (token != null) { token.Dispose(); } } catch (Exception ex) { Logger.GetSystemLogger().LogException(ex); } } } return retGraph; }
/// <summary> /// Extended match syntax, can use details from a graph and node /// </summary> /// <param name="frame">The data frame to select off</param> /// <param name="globalMeta">The global meta</param> /// <param name="meta">The meta</param> /// <param name="node">The current node</param> /// <param name="properties">The property bag</param> /// <param name="uuid">The uuid for private meta names</param> /// <returns>True if the filter matches</returns> public bool IsMatch(DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, Guid uuid, BasePipelineNode node) { bool ret = true; foreach (IDataFrameFilter filter in _filters) { ret = filter.IsMatch(frame, meta, globalMeta, properties, uuid, node); if (_matchAll) { if (!ret) { break; } } else { if (ret) { break; } } } if (Invert) { return !ret; } else { return ret; } }
/// <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; }
/// <summary> /// /// </summary> /// <param name="server"></param> /// <param name="client"></param> /// <param name="token"></param> /// <param name="logger"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="properties"></param> /// <param name="defaultBinding"></param> public void Negotiate(ref IDataAdapter server, ref IDataAdapter client, ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, NetworkLayerBinding defaultBinding) { if (defaultBinding == NetworkLayerBinding.Default) { defaultBinding = NetworkLayerBinding.ClientAndServer; } if (Binding != NetworkLayerBinding.Default) { defaultBinding = Binding; } if ((defaultBinding & NetworkLayerBinding.Server) == NetworkLayerBinding.Server) { server = new HttpRequestDataAdapter(server, logger, this); } if ((defaultBinding & NetworkLayerBinding.Client) == NetworkLayerBinding.Client) { client = new HttpResponseDataAdapter(client, logger, this); } }
/// <summary> /// Create the test graph /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globals">The global meta</param> /// <returns>The new test graph container</returns> /// <exception cref="ArgumentException">Throw if script invalid</exception> public override TestGraphContainer CreateTestGraph(Logger logger, MetaDictionary globals) { if (String.IsNullOrWhiteSpace(_config.ClassName)) { throw new ArgumentException(CANAPE.Documents.Properties.Resources.ScriptTestDocument_MustProvideClassname); } NetGraphBuilder builder = new NetGraphBuilder(); ServerEndpointFactory server = builder.AddServer("server", Guid.NewGuid()); DynamicNodeFactory node = builder.AddNode((DynamicNodeFactory)_config.CreateFactory()); LogPacketNodeFactory log = builder.AddLog("Test Network", Guid.NewGuid(), new ColorValue(0xFF, 0xFF, 0xFF, 0xFF), "Entry", false); ClientEndpointFactory client = builder.AddClient("client", Guid.NewGuid()); builder.AddLine(server, node, null); builder.AddLine(node, log, null); builder.AddLine(log, client, null); NetGraph graph = builder.Factory.Create(logger, null, globals, new MetaDictionary(), new PropertyBag("Connection")); return new TestGraphContainer(graph, graph.Nodes[server.Id], graph.Nodes[client.Id]); }
protected void AppendOptionalMeta(MetaDictionary dic, IOGPPageData page) { dic.Add("description",page.Description); dic.Add("locale",page.Locale); }
/// <summary> /// Connect the client /// </summary> /// <param name="token">The proxy token</param> /// <param name="logger">The proxy logger instance</param> /// <param name="meta">The proxy meta data</param> /// <param name="globalMeta">The proxy global meta data</param> /// <param name="properties">The proxy property bag</param> /// <param name="credmgr">Credentials manager</param> /// <returns>The connected adapter</returns> public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { IDataAdapter ret = null; for (int i = 0; i < _clients.Length; ++i) { ret = _clients[i].Connect(token, logger, meta, globalMeta, properties, credmgr); if (ret != null) { break; } } if ((ret == null) && (token.Status == NetStatusCodes.Success)) { ret = new IpProxyClient().Connect(token, logger, meta, globalMeta, properties, credmgr); } return ret; }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { DataAdapterToStream stm = new DataAdapterToStream(adapter); return HandleConnectRequest(stm); }
public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr) { return null; }
/// <summary> /// /// </summary> /// <param name="token"></param> /// <param name="client"></param> /// <param name="globalMeta"></param> /// <param name="meta"></param> /// <param name="service"></param> /// <returns></returns> public override IDataAdapter Complete(ProxyToken token, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service, IDataAdapter client) { SocksProxyToken socksToken = (SocksProxyToken)token; if (IsSupported(socksToken.Version)) { if (socksToken.Version == 4) { return HandleSocksV4Response(socksToken); } else if (socksToken.Version == 5) { return HandleSocksV5Response(socksToken); } else { // We shouldn't get here throw new InvalidOperationException(CANAPE.Net.Properties.Resources.SocksProxyServer_IsSupportedError); } } else { _logger.LogError(CANAPE.Net.Properties.Resources.SocksProxyServer_UnsupportedTokenVersion, socksToken.Version); } return null; }
/// <summary> /// Create the data endpoint /// </summary> /// <param name="logger">The logger to use</param> /// <param name="globalMeta">Global meta dictionary</param> /// <param name="meta">Meta dictionary</param> /// <returns></returns> public override IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta) { IDataEndpoint ret = Script.Container.GetInstance(ClassName) as IDataEndpoint; if (ret == null) { throw new NetServiceException(CANAPE.Documents.Properties.Resources.ScriptDataEndpointFactory_InvalidType); } ServerConfig config = (ServerConfig)Config; foreach (KeyValuePair<string, string> pair in config.Properties) { meta[pair.Key] = pair.Value; } ret.Meta = meta; ret.GlobalMeta = globalMeta; if (ret is IPersistNode) { IPersistNode persist = ret as IPersistNode; persist.SetState(config.GetConfig(), logger); } return ret; }
/// <summary> /// Connect to the required service with the token /// </summary> /// <param name="token">The token recevied from proxy</param> /// <param name="globalMeta">The global meta</param> /// <param name="logger">The logger</param> /// <param name="meta">The meta</param> /// <param name="properties">Property bag to add any information to</param> /// <param name="credmgr">Credentials manager</param> /// <returns>The connected data adapter</returns> public abstract IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr);
/// <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]); }