static void Main(string[] args) { LogMessage("Application started."); var factory = new ConnectionFactory() { HostName = "localhost" }; using var connection = factory.CreateConnection(); using var channel = connection.CreateModel(); LogMessage("Connected to RabbitMq."); using var system = ActorSystem.Create("downloader-system"); LogMessage("Enter the name of the system."); var systemId = Console.ReadLine().Replace(' ', '-'); var supervisorName = $"downloader-supervisor-{systemId}"; LogMessage($"Creating supervisor node '{supervisorName}'..."); var downloaderSupervisor = system.ActorOf(SupervisorActor.Props(systemId), supervisorName); var downloaderName = $"downloader-{systemId}"; LogMessage($"Registering downloader with name '{downloaderName}'..."); downloaderSupervisor.Tell(new RegisterDownloader(systemId, downloaderName)); var messageBusListener = new MessageBusSubscriberListener <DownloadRun>(channel, ExchangeName); var subscription = messageBusListener.Subscribe(OnNext, OnError, OnCompleted); Console.ReadLine(); subscription.Dispose(); channel.Dispose(); connection.Dispose(); void OnNext(Message <DownloadRun> message) => downloaderSupervisor.Tell(message.Body); void OnError(Exception ex) => Console.WriteLine($"Something terrible has happened! {ex.ToString()}"); void OnCompleted() => Console.WriteLine($"Supervisor actor for system {systemId} is no longer subscribed to messages."); void LogMessage(string message) => Console.WriteLine($"[{DateTimeOffset.Now}] {message}"); }
static void Main(string[] args) { string exchangeName = "queueLink"; Random rand = new Random(); ConnectionFactory factory = new ConnectionFactory() { HostName = "localhost", UserName = "******", Password = "******" }; using var connection = factory.CreateConnection(); using var channel = connection.CreateModel(); MessageBusSubscriberListener <UpdateInformation> listener = new MessageBusSubscriberListener <UpdateInformation>(channel, exchangeName); Console.WriteLine($"[*] Waiting for messages ..."); var subscriber = listener.Subscribe(OnNext, OnError, OnCompleted); Console.ReadLine(); subscriber.Dispose(); connection.Close(); channel.Close(); //SubMethods void OnNext(Message <UpdateInformation> message) { string Json = string.Empty; Uri informationUrl = new Uri(message.Body.InformationEndPoint); Uri downloadUrl = new Uri(message.Body.DownloadEndPoint); Console.WriteLine($"[*] Message Received."); Console.WriteLine("[*] Grabbing the launch file"); try { //getting file information from server using WebClient client = new WebClient(); var json = client.DownloadString(informationUrl); FIleInformation fileInfo = JsonConvert.DeserializeObject <FIleInformation>(json); Console.WriteLine("[*][-] Got information from server."); string baseFolder = @$ "C:\setups"; string downloadFile = Path.Combine(baseFolder, message.Body.Id, fileInfo.Version, fileInfo.Name); Directory.CreateDirectory(Path.GetDirectoryName(downloadFile)); //downloading file from server client.DownloadFile(downloadUrl, downloadFile); Console.WriteLine("[*] Starting launcher downloaded from server."); Process newProc = new Process(); newProc.StartInfo.FileName = downloadFile; newProc.Start(); } catch (Exception) { throw; } } void OnError(Exception ex) => Console.WriteLine($"Error occured, on delivery. :: {ex.Message}"); void OnCompleted() => Console.WriteLine("Subscription Disposed."); }