private bool HasNonHeaderParts(IDictionary <string, string> request) { var templateParts = new MapOf( new FilteredDictionary((key, value) => !key.StartsWith(HEADER_KEY_PREFIX), this.template ) ); var requestParts = new FilteredDictionary((key, value) => !key.StartsWith(HEADER_KEY_PREFIX), request ); var applies = true; foreach (var templatePart in templateParts.Keys) { var matches = new FilteredDictionary((key, value) => key == templatePart && value() == templateParts[templatePart], requestParts ); if (new LengthOf(matches.Keys).Value() == 0) { applies = false; break; } } return(applies); }
/// <summary> /// Read configuration (form) (partition & collection) /// </summary> /// <param name="root">Config</param> /// <returns>true if successfull, false for stopping the connector in error</returns> public override bool OnLoadConfig(XDoc root) { //initialize properties channelMatcher = new PatternMatcher("Channels", "Channels", 20); token = ""; users = new MapOf <JsonObject>(); //read configuration (collection & partition) url = Connector.CurrentConfig.Value("slack/url"); token = Connector.CurrentConfig.Value("slack/token"); channelMatcher.IncludedPattern.SetText(Connector.CurrentConfig.ValueList("slack/ChannelIncluded")); channelMatcher.ExcludedPattern.SetText(Connector.CurrentConfig.ValueList("slack/ChannelExcluded")); indexMessages = Connector.CurrentConfig.ValueBoo("slack/indexMessages", true); indexFiles = Connector.CurrentConfig.ValueBoo("slack/indexFiles", true); if (Str.IsEmpty(url) || Str.IsEmpty(token)) { Sys.LogError("URL or Token is empty"); return(false); } //Notify that this connector supports the realtime mode Connector.RealTimeSupported = true; return(true); }
public void HasFormParams() { var expected = new MapOf( "key1", "value1", "key2", "value2" ); Assert.Equal( expected["key1"], new FormResponse( new FkWire(req => new Response.Of( new FormParams(expected) ) ) )["key1"] ); Assert.Equal( expected["key2"], new FormResponse( new FkWire(req => new Response.Of( new FormParams(expected) ) ) )["key2"] ); }
public void HasFormData() { var expected = new MapOf( "key1", "value1", "key2", "value2" ); Assert.Equal( expected["key1"], new FormParams.Of( new FormResponse.Of(expected) )["key1"] ); Assert.Equal( expected["key2"], new FormParams.Of( new FormResponse.Of(expected) )["key2"] ); }
/// <summary> /// All known namespaces in the scope. /// </summary> /// <param name="scope">scope to look in</param> /// <returns>map of namespaces prefix=uri</returns> public IDictionary <string, string> GetNamespacesInScope(XmlNamespaceScope scope) { IDictionary <string, string> result = new Dictionary <string, string>(); foreach (var kvp in this.map) { if (scope != XmlNamespaceScope.ExcludeXml || (kvp.Key != XMLNS_ATTRIBUTE && kvp.Key != XML_NS_PREFIX) ) { result.Add(kvp.Key, kvp.Value); } } foreach (var ctx in this.contexts) { IEnumerable <KeyValuePair <string, string> > namespaces = ctx.Value().GetNamespacesInScope(scope); result = new MapOf <string, string>(result, namespaces); } return(result); }
/// <summary> /// Starting point of the Generic Connector for the collection /// </summary> /// <returns>true if succeded otherwise false</returns> public override bool OnGenericIndexCollection() { bool ok = true; users = new MapOf <JsonObject>(); //put all users info in cache JsonObject response = slackGet("users.list") as JsonObject; if (response == null || (response != null && !response.ValueBoo("ok"))) { Sys.LogError(Json.Serialize(response)); return(false); } if (response != null) { JsonArray members = response.GetAsArray("members"); if (members != null) { for (int i = 0; i < members.EltCount(); i++) { JsonObject user = members.Elt(i) as JsonObject; //Add user object in cache users.Add(user.GetValue("id"), user); } } } //index channels response = slackGet("conversations.list") as JsonObject; if (response == null || (response != null && !response.ValueBoo("ok"))) { Sys.LogError(Json.Serialize(response)); return(false); } if (response != null) { JsonArray channels = response.GetAsArray("channels"); if (channels != null) { for (int i = 0; i < channels.EltCount(); i++) { JsonObject channel = channels.Elt(i) as JsonObject; string Name = channel.GetValue("name"); //check if included/excluded from conf if (channelMatcher.IsExcluded(Name)) { continue; } //Index the Channel if (indexMessages) { ok &= IndexChannelMessages(Name, channel); } if (indexFiles) { ok &= IndexChannelFiles(Name, channel); } } } } return(ok); }