Example #1
0
 private async Task ReceivedRequestSystemData(ConnectorMessage.RequestSystemData message)
 {
     try
     {
         HttpWebRequest reqInfo = WebRequest.CreateHttp($"{BASE_URL}api-v1/system?systemName={message.SystemName}&showId=1&showCoordinates=1&showPermit=1&showInformation=0&showPrimaryStar=1");
         reqInfo.Timeout = 5000;
         HttpWebResponse respInfo = (await reqInfo.GetResponseAsync()) as HttpWebResponse;
         string          dataInfo = respInfo.GetContent();
         if ((String.IsNullOrWhiteSpace(dataInfo)) || (dataInfo == "[]") || (respInfo.StatusCode == HttpStatusCode.NotFound))
         {
             this.uiMessenger.Tell(new UiMessengerMessage.Publish(new NoSystemData(message.SystemName)));
             return;
         }
         Responses.SystemReq objInfo;
         try
         {
             objInfo = JsonConvert.DeserializeObject <Responses.SystemReq>(dataInfo);
         }
         catch (Exception ex)
         {
             log.Error($"Failed to deserialize EDSM systemdata for {message.SystemName} ({dataInfo.Length} chars): {ex.Message}");
             throw;
         }
         HttpWebRequest reqBodies = WebRequest.CreateHttp($"{BASE_URL}api-system-v1/bodies?systemName={message.SystemName}");
         reqBodies.Timeout = 5000;
         HttpWebResponse     respBodies = (await reqBodies.GetResponseAsync()) as HttpWebResponse;
         string              dataBodies = respBodies.GetContent();
         Responses.BodiesReq objBodies;
         try
         {
             objBodies = JsonConvert.DeserializeObject <Responses.BodiesReq>(dataBodies);
         }
         catch (Exception ex)
         {
             log.Error($"Failed to deserialize EDSM bodiesdata for {message.SystemName} ({dataBodies.Length} chars): {ex.Message}");
             throw;
         }
         List <BodyData> bodies = new List <BodyData>();
         foreach (var b in objBodies.Bodies)
         {
             bodies.Add(new BodyData(b.Id64, b.Name, b.BodyId, b.Discovery?.Commander, b.TerraformingState));
         }
         SystemData systemData = new SystemData(objInfo.Name, bodies.ToImmutableArray());
         this.uiMessenger.Tell(new UiMessengerMessage.Publish(systemData));
     }
     catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout)
     {
         log.Warning($"Timeout while getting system data for {message.SystemName}");
     }
     catch (Exception ex)
     {
         log.Error(ex, $"Failed to get EDSM data for {message.SystemName}");
     }
 }
Example #2
0
 private void ReceivedCollect(CollectorMessage.Collect message)
 {
     foreach (string sourceFolder in this.sourceFolders)
     {
         string[] files = Directory.GetFiles(sourceFolder, "*.png").Concat(Directory.GetFiles(sourceFolder, "*.jpg")).ToArray();
         foreach (string file in files)
         {
             try
             {
                 string sourceName     = Path.GetFileNameWithoutExtension(file);
                 string sourceExt      = Path.GetExtension(file);
                 string targetName     = $"{sourceName}.{sourceExt}";
                 int    idx            = 0;
                 string targetFullname = Path.Combine(this.destinationFolder, targetName);
                 while (File.Exists(targetFullname))
                 {
                     targetName     = $"{sourceName}.{idx:D3}.{sourceExt}";
                     targetFullname = Path.Combine(this.destinationFolder, targetName);
                     idx++;
                 }
                 File.Move(file, targetFullname);
                 this.processor.Tell(new CollectorMessage.Success(targetFullname));
             }
             catch (Exception ex)
             {
                 log.Error(ex, "Failed to move '{0}' to collection destination", file);
             }
         }
     }
 }
Example #3
0
        private void CreateCollector()
        {
            if (!this.config.Services.CollectScreenshots)
            {
                return;                                           // collecting deactivated
            }
            if (String.IsNullOrWhiteSpace(this.config.Locations.FolderScreenshotsElite) && String.IsNullOrWhiteSpace(this.config.Locations.FolderScreenshotsSteam))
            {
                return;                                                                                                                                                     // no folder from where we could collect
            }
            if (String.IsNullOrWhiteSpace(this.config.Locations.FolderCollectedScreenshots))
            {
                log.Error("Cannot collect screenshots, no collection folder specified!");
                return;
            }
            List <string> collectionSources = new List <string>();

            if (!String.IsNullOrWhiteSpace(this.config.Locations.FolderScreenshotsElite))
            {
                collectionSources.Add(this.config.Locations.FolderScreenshotsElite);
            }
            if (!String.IsNullOrWhiteSpace(this.config.Locations.FolderScreenshotsSteam))
            {
                collectionSources.Add(this.config.Locations.FolderScreenshotsSteam);
            }
            this.collector = Context.ActorOf(Props.Create(() => new Screenshots.CollectorActor(Self, collectionSources.ToImmutableArrayOrEmpty(), this.config.Locations.FolderCollectedScreenshots)));
            this.collector.Tell(new Screenshots.CollectorMessage.Init());
        }
Example #4
0
 private void ReceivedConvert(BitmapConverterMessage.Convert message)
 {
     string[] targetFiles = Directory.GetFiles(this.folder, this.filefilter);
     log.Info("Found {0} files to convert ({1})", targetFiles.Length, this.filefilter);
     // note: we could use child actors to do the actual conversion and a pool router to limit the concurrency of that - but I guess we only process screenshots of one player actually ;)
     foreach (var targetFile in targetFiles)
     {
         try
         {
             string converterFilename = Path.ChangeExtension(targetFile, "png");
             using (var image = Image.FromFile(targetFile))
             {
                 if (File.Exists(converterFilename))
                 {
                     log.Warning("Skipping to convert {0} because it seems to already exist!", targetFile);
                     continue;
                 }
                 image.Save(converterFilename, ImageFormat.Png);
                 log.Info("Saved: {0}", converterFilename);
             }
             File.Delete(targetFile);
             this.processor.Tell(new BitmapConverterMessage.SuccessNotification(converterFilename));
         }
         catch (Exception ex)
         {
             log.Error(ex, "Failed to convert: {0}", targetFile);
             this.processor.Tell(new BitmapConverterMessage.FailureNotification(ex.Message, targetFile));
         }
     }
 }
 private void ReceivedProcessLine(ReaderMessage.ProcessLine message)
 {
     log.Debug("Parsing new line");
     try
     {
         JObject o         = JObject.Parse(message.Line);
         string  tsText    = o["timestamp"].Value <string>();
         string  eventText = o["event"].Value <string>();
         if (String.IsNullOrWhiteSpace(tsText))
         {
             throw new Exception("Timestamp missing");
         }
         if (String.IsNullOrWhiteSpace(eventText))
         {
             throw new Exception("Eventtype missing");
         }
         Event @event = Event.Unknown;
         if (!Enum.TryParse <Event>(eventText, out @event))
         {
             log.Warning($"Event '{eventText}' not supported (yet)");
             @event = Event.Unknown;
         }
         DateTime timestamp = DateTime.Parse(tsText, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
         Entry    entry     = CreateEntryFor(o, timestamp, @event);
         if (entry == null)
         {
             return;
         }
         this.connector.Tell(new ConnectorMessage.JournalEntry(entry));
     }
     catch (Exception ex)
     {
         log.Error(ex, $"Failed to parse new line (index {message.Index} in {message.SourceFile})");
         this.connector.Tell(new ReaderMessage.ProcessError(message.Line, $"Failed to parse line index {message.Index} in '{message.SourceFile}': {ex.Message}"));
     }
 }
Example #6
0
 public override void ExceptionCaught(IChannelHandlerContext ctx, Exception cause)
 {
     _log.Error(cause, "Channel {0} caught exception", ctx.Channel);
     ctx.FireExceptionCaught(cause);
 }
Example #7
0
 public void Error(string format, params object[] args)
 => _logger.Error(format, args);