Dynamically change config setting kafka in C# - c#

I am very new to Apache Kafka. I work on C#.NET /Windows platform .
I was able to play with config settings for Kafka and send and receive message using Command prompt.
Using https://www.codeguru.com/csharp/.net/producer-and-consumer-for-kafka-in-.net-an-exploration.html
I ran the c# program and was able to Produce and Receive message.
Qn1: I am trying to read a json file and based on number of rows in json file , Is there a way of dynamically changing value of num.partitions value from C#?
Thanks
MR

I do not see num.partitions in that link
But sure, you could read a property file, or make a timer to close and re-create any producer or consumer object.
But while a producer or consumer is running, there is no straightforward way to re-configure its properties.
It doesn't look like the Kafka-Net library has been updated since 2016, you can rather use the confluent-dotnet-kafka client.

Related

Discord.net: Is it possible to send multiple files at once?

I am using Discord.net to log images in a channel on a Discord server. Most of the time I need to send a couple of images (4 or 5 on average) at once.
Since the Discord Desktop app allows you to send up to 10 files at once I was wondering if this can also be done using C#.
Currently, I am sending one message per image.
The code looks like this:
DiscordSocketClient client = new DiscordSocketClient();
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
When the Bot has started, this code runs:
DiscordSocketClient channel = client.GetChannel(channelId) as SocketTextChannel;
Finally, to send a file I run this:
channel.SendFileAsync(filepath, message); // Both filepath and message are strings.
This works, but when it sends, for example, five images, five messages are sent on discord.
It would be nice if I could send one message that has all of those images attached. (Just like in the Desktop app)
I know that I could use an Embed to send two images at once, but that way I would still be limited to two images per message. (One as Embed-image and one as Embed-thumbnail)
This is still not close to the 10 files that are possible in the app and, in addition to that, the images would not be displayed equally.
Another option would be to create a new, bigger image that combines all of the images I want to send. Then I could send this single image by saving it as a .png and then using the method that i have already implemented.
The problem with this is that this is a workaround, rather than a real solution to the problem, as I dont really like the idea of not having the images uploaded as individual files.
Tl dr:
Is there a way to send multiple files or images in a single message using Discord.net?
Thanks in advance!
You can use SendFilesAsync! You must update to the latest version of Discord.net, when installing via Nuget make sure you uninstall all Discord.net extensions such as Discord.Net.Commands before updating.
List<FileAttachment> filestosend = new List<FileAttachment>();
filestosend.Add(new FileAttachment(#"c:\file.png", "file.png", "file description"));
filestosend.Add(new FileAttachment(#"c:\file2.png", "file2.png", "file description"));
await channel.SendFilesAsync(filestosend, "text");
Documentation can be found here
Edit for clarity: do not confuse SendFileAsync with SendFilesAsync

How to catch LDAP Sync Info Message using Content Synchronization Operation

I am trying to retrieve the deleted UUIDs from a Openldap server using a .Net Core Console Application.
I was able to see that a Sync Info Message was indeed sent by my Openldap server and that it contained the UUIDS of the present entries by using a Perl script and dumping the whole response.
I set up a Openldap server with the syncprov Overlay (see my previous question Can't get deleted items from OpenLDAP Server using Content Synchronization Operation (syncrepl)).
After re-reading the RFC4533 multiple times and the OpenLdap Syncrepl documentation and analysing the response, with my current configuration (No Accesslog) it is impossible to retrieve deleted entries, only a list of present entries. They are contained in the Sync Info Message. I wish to retrieve the information anyway so I can make a delta between what is sent and what is on my client.
Do you know how to catch the message in C#?
I tried using the DirectoryServices.Protocols and the Novell.Directory.Ldap libraries (separately). I must have missed something but don't know what exactly...
I used the Novell Code sample (the SearchPersist one and adding the corresponding control) available at https://www.microfocus.com/documentation/edirectory-developer-documentation/ldap-libraries-for-c-sharp/.
I can retrieve added/modified entries but not the Sync Info Message containing the present entries.
By digging a bit into the Novell Library, I found some useful classes for decoding ASN1 Objects.
By using the following code I am able to determine the type of the Intermediate Sync Info Message.
var decoder = new LBERDecoder();
(Asn1Tagged)decoder.decode(intermediateResponse.getValue());`
Then, depending on the Tag I am able to decode the message (using the method .decode(valueToDecode))

How to directly read value from Windows Service with VB6?

How can I directly read a value from Windows Service with VB6?
I wrote a Windows Service with C# which generate a string and I want to read this value with VB6.
For example, Windows Service Application generate a string variable like this for each 10 second:
string id = "1422144";
after 10 second
string id = "2462778";
I want to read this values with VB6 each 10 second. I can read it from text file when I create and write this value to text with Windows Service but I don't want to create a text file. Thanks in advance.
To use MSMQ (Message Queue) approach (note, I've not checked this exhaustively so it's just to get started):
https://msdn.microsoft.com/en-us/library/ms973860.aspx
http://www.informit.com/articles/article.aspx?p=131272&seqNum=6
To create self-hosted OWIN Web Api 2.0 service, I'd recommend using TopShelf (I've done this myself, but too much overhead for just passing a simple string along):
https://codeopinion.com/self-host-asp-net-web-api-as-a-windows-service/
Other options:
Communicate via TCP/IP directly
Use a database (server updates, VB6 reads)
use compicated system of arduino-activated relays to cause mice to take particular paths in a maze, and detect their movements (note: not entirely serious)
Lots of things I've not thought of

Is it possible to change the device name programatically in Attachmate EXTRA?

I've written a win forms application that uses Attachmate EXTRA. The application itself works great but I was just notified that there is a need to be able to switch to different device names for the sessions. The names would be set before the sessions are launched and then the session would go through the connection process. The only way I can think to do this is create and save a separate session with each device name needed and go that route but I would like to be able to do this dynamically instead if possible.
I've tried doing this during debug to look at the object but have been unable to find a method or property to set.
After having a support ticket entered and getting confirmation, the only way to change the device name programatically is to open the .EDP file, replace the string with the new device name, save the file and then run that .EDP file.
Apparently their new application, Reflection, can handle these types of things with calls without making changes to the files.

Proxying Videos locally with a TCP Socket

I've been really interested in adding support for video podcasts to Media Browser.
I would like users to be able to navigate through the available video podcasts and stream them from the internets. That's really easy cause media player etc.. will happily play a file that lives in the cloud.
The problem is that I want cache these files locally so subsequent viewings of the same episode will not involve streaming and instead will play the local file.
So... I was thinking, why not host an HttpListener and as media player asks it for bits of the file, have the HttpListener download and store it locally. Next time a user plays the file we will already have portions of the file locally.
Does anyone know of example code that uses HttpListener for proxying?
EDIT
The idea would be only to proxy simple streamable content like MP3 or Mov.
The bounty will go to an actual implementation.
Here is the API I would like:
// will proxy a uri on the local port, if cacheFile exists it will resume the
// download from cacheFile.
// while the file is downloading it will be name cacheFile.partial, after the
// download is complete the file will be renamed to cacheFile.
// Example usage: ProxyFile("http://media.railscasts.com/videos/176_searchlogic.mov", 8000, #"c:\downloads\railscasts\176_searchlogic.mov")
//
// Directly after this call http://localhost:8000 will be the proxy stream, it will be playable locally.
void ProxyUri(Uri uri, int port, string cacheFile)
Edit 2
HttpListener is looking pretty unpromising I will probably need to do the work at a TCP socket level as HttpListeners seem to require the program runs as admin which is going to be really tricky.
I hadn't done anything with HttpListener before, so I thought this would be a nice little exercise to bring myself up to speed with it - and so it proved. I implemented it as a single ProxyListener class whose constructor takes the parameters of the ProxyUri function you specified. Once you obtain an instance, you start it listening (and potentially downloading) by calling its Start method. When you're done with it, call Cleanup.
There are one or two rough edges but basically it works as per your question. To test it, I built it up as a console application with a Program class which accepts input lines consisting of (uri, port, filename), space-separated, creates the ProxyListener instances and starts them. You can run this console application, type in a suitable line, and the downloader will start (printing out progress to console). Simultaneously you can e.g. fire up IE and fetch the file from the specified port, and you will be able to download it while the downloader is still working. The "uploader" progress will be printed to console, too.
I'm having a bit of trouble pasting it in here, maybe due to size (it's not that big, but bigger than the snippets you normally see here - the ProxyListener class is a tad under 200 lines). Does it sound interesting? If so, I'll post it to a pastebin and update this answer with a link.
Update: Posted as a gist.
Note that you will need Administrator privileges to run the program, since HttpListener requires this.
Update 2: Under certain circumstances, it is not necessary to have admin privileges to run HttpListener. See this link and this one. The idea is, if you can reserve an URL namespace during installation time, then the user does not have to have admin privileges if listening against that namespace.
Streaming was not designed to be saved, and also these protocols are very custom and very complex to implement, streaming sessions do lots of validation and synchronization which will be extremely difficult to imitate. Of course it is not an impossible task, but its fairly big task to do. Only other way is to read and save it as local media file, and use that as a reference. Because you can use windows media encoder to read stream and write stream data as local file, but it still may not allow you to do copy protected data.
Did you consider using HTTP proxy with caching features?
Like:
Apache httpd with mod_proxy and mod_cache
Squid
See also Web Cache # wikipedia
If you want your application to have such web cache component, I suggest you look for Web Cache implementation in .Net, and not code it from scratch.

Categories

Resources