Example #1
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var d = e.Data;

            try {
                var json = (JObject)JsonConvert.DeserializeObject(d);
                if (json["type"] != null)
                {
                    var type = (string)json["type"];
                    switch (type)
                    {
                    case "config":
                        var variable = (string)json["variable"];
                        var value    = (string)json["value"];
                        UIConsole.Debug($"Received config change request of {variable} to {value}");
                        EventMaster.Post(EventTypes.ConfigChangeEvent, new ConfigChangeEventData {
                            Name = variable, Value = value
                        });
                        break;

                    case "dirlist":
                        var path = (string)json["path"];
                        UIConsole.Debug($"Received request for listing folder {path}");
                        if (dh != null)
                        {
                            var list = dh.ListDir(path);
                            var dl   = new DirList(list);
                            Send(dl.toJSON());
                        }
                        break;

                    case "configList":
                        var configList = ProgConfig.GetConfig();
                        UIConsole.Debug("Received request for listing config.");
                        try {
                            var cl = new ConfigEntryModel(configList);
                            Send(cl.toJSON());
                        } catch (Exception ex) {
                            UIConsole.Error($"Error serializing configList: {ex}");
                        }
                        break;
                    }
                }
            } catch (Exception) {
                UIConsole.Debug($"Received invalid message from ws client: {d}");
            }
        }
Example #2
0
        public void parseBytes(byte[] data)
        {
            try {
                int scid = ((data[0] & 0x3F) << 2) | ((data[1] & 0xC0) >> 6);
                int vcid = (data[1] & 0x3F);
                int vcnt = (data[2] << 16 | data[3] << 8 | data[4]);

                // UIConsole.Log($"Satellite ID: {scid}");

                EventMaster.Post(EventTypes.FrameEvent, new FrameEventData {
                    ChannelID = vcid, PacketNumber = vcnt
                });

                if (vcid != FILL_VCID)
                {
                    resetMutex.WaitOne();
                    lock (demuxers) {
                        if (!demuxers.ContainsKey(vcid))
                        {
                            UIConsole.Log($"I don't have a demuxer for VCID {vcid}. Creating...");
                            demuxers.Add(vcid, new Demuxer(this));
                        }
                    }
                    recordMutex.WaitOne();
                    if (RecordToFile)
                    {
                        try {
                            fStream.Write(data, 0, data.Length);
                        } catch (Exception e) {
                            UIConsole.Error($"Error writting demuxdump file: {e}");
                        }
                    }
                    recordMutex.ReleaseMutex();
                    demuxers[vcid].ParseBytes(data);
                    resetMutex.ReleaseMutex();
                }
            } catch (Exception e) {
                CrashReport.Report(e);
                throw e;
            }
        }
Example #3
0
        public static void DefaultHandler(string filename, XRITHeader fileHeader)
        {
            string dir       = Path.GetDirectoryName(filename);
            string ofilename = fileHeader.Filename ?? Path.GetFileName(filename);

            // Workarround for multi-segment HRIT
            if (fileHeader.Product.ID == (int)NOAAProductID.GOES16_ABI)
            {
                if (fileHeader.SegmentIdentificationHeader != null && fileHeader.SegmentIdentificationHeader.MaxSegments > 1)
                {
                    string baseName = Path.GetFileNameWithoutExtension(ofilename);
                    string ext      = Path.GetExtension(ofilename);
                    string fileH    = fileHeader.SegmentIdentificationHeader.Sequence.ToString("D2");
                    string imageId  = fileHeader.SegmentIdentificationHeader.ImageID.ToString();
                    ofilename = $"{baseName}-img{imageId}-seg{fileH}{ext}";
                }
            }

            string f = PacketManager.FixFileFolder(dir, ofilename, fileHeader.Product, fileHeader.SubProduct);

            if (
                (fileHeader.Product.ID == (int)NOAAProductID.DCS && SkipDCS) ||
                (fileHeader.Product.ID == (int)NOAAProductID.EMWIN && SkipEMWIN) ||
                (fileHeader.Product.ID == (int)NOAAProductID.HRIT_EMWIN && SkipEMWIN) ||
                (fileHeader.Product.ID == (int)NOAAProductID.WEATHER_DATA && SkipWeatherData)
                )
            {
                try {
                    File.Delete(filename);
                } catch (IOException e) {
                    UIConsole.Error(String.Format("Error deleting file {0}: {1}", Path.GetFileName(filename), e));
                }
                return;
            }

            if (File.Exists(f))
            {
                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string ext       = Path.GetExtension(f);
                string append    = String.Format("--dup-{0}{1}", timestamp, ext);
                f = f.Replace(String.Format("{0}", ext), append);
            }

            UIConsole.Log($"New {fileHeader.ToNameString()}");

            /*if (fileHeader.SubProduct.Name != "Unknown") {
             *  UIConsole.Log($"New {fileHeader.Product.Name} - {fileHeader.SubProduct.Name}");
             * } else {
             *  UIConsole.Log($"New {fileHeader.Product.Name}");
             * }*/

            EventMaster.Post(EventTypes.NewFileEvent, new NewFileReceivedEventData {
                Name     = Path.GetFileName(ofilename),
                Path     = ofilename,
                Metadata =
                {
                    { "product",      fileHeader.Product.Name             },
                    { "subProduct",   fileHeader.SubProduct.Name          },
                    { "productId",    fileHeader.Product.ID.ToString()    },
                    { "subProductId", fileHeader.SubProduct.ID.ToString() }
                }
            });

            try {
                File.Move(filename, f);
            } catch (IOException e) {
                UIConsole.Error(String.Format("Error moving file {0} to {1}: {2}", filename, f, e));
            }
        }
Example #4
0
        public HeadlessMain()
        {
            AppDomain.CurrentDomain.UnhandledException += CrashReport.DefaultExceptionHandler;
            ManageConfig();

            EventMaster.On(EventTypes.ConfigChangeEvent, d => {
                var data = (ConfigChangeEventData)d.Data;
                ProgConfig.UpdateProperty(data.Name, data.Value);
                EventMaster.Post("configSaved", data.Name);
                SetConfigVars();
            });

            SetConfigVars();

            var fdFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_FULLDISK);
            var xxFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_AREA_OF_INTEREST);
            var nhFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_NORTHERN);
            var shFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_SOUTHERN);
            var usFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.INFRARED_UNITEDSTATES);
            var fmFolder  = PacketManager.GetFolderByProduct(NOAAProductID.GOES16_ABI, (int)ScannerSubProduct.NONE);
            var unkFolder = PacketManager.GetFolderByProduct(NOAAProductID.GOES13_ABI, (int)ScannerSubProduct.NONE); // Same for any unknown ABI

            FDImageManager  = new ImageManager(fdFolder, "Full Disk");
            XXImageManager  = new ImageManager(xxFolder, "Area of Interest");
            NHImageManager  = new ImageManager(nhFolder, "Northern Hemisphere");
            SHImageManager  = new ImageManager(shFolder, "Southern Hemisphere");
            USImageManager  = new ImageManager(usFolder, "United States");
            FMImageManager  = new ImageManager(fmFolder, "FM1");
            UNKImageManager = new ImageManager(unkFolder, "Unknown");

            FDImageManager.InitMapDrawer();
            XXImageManager.InitMapDrawer();
            NHImageManager.InitMapDrawer();
            SHImageManager.InitMapDrawer();
            USImageManager.InitMapDrawer();
            FMImageManager.InitMapDrawer();
            UNKImageManager.InitMapDrawer();

            directoryHandler = new DirectoryHandler(FileHandler.FinalFileFolder, "/data");

            mtx = new Mutex();
            cn  = new Connector();

            demuxManager = new DemuxManager {
                RecordToFile = ProgConfig.RecordIntermediateFile
            };
            cn.StatisticsAvailable += data => {
                mtx.WaitOne();
                statistics = data;
                mtx.ReleaseMutex();

                if (ProgConfig.SaveStatistics)
                {
                    ThreadPool.QueueUserWorkItem((a) => StatisticsManager.Update(new DBStatistics {
                        SCID                  = data.scid,
                        VCID                  = data.vcid,
                        PacketNumber          = (long)data.packetNumber,
                        VitErrors             = data.vitErrors,
                        FrameBits             = data.frameBits,
                        RSErrors0             = data.rsErrors [0],
                        RSErrors1             = data.rsErrors [1],
                        RSErrors2             = data.rsErrors [2],
                        RSErrors3             = data.rsErrors [3],
                        SignalQuality         = data.signalQuality,
                        SyncCorrelation       = data.syncCorrelation,
                        PhaseCorrection       = data.phaseCorrection,
                        LostPackets           = (long)data.lostPackets,
                        AverageVitCorrections = data.averageVitCorrections,
                        AverageRSCorrections  = data.averageRSCorrections,
                        DroppedPackets        = (long)data.droppedPackets,
                        SyncWord              =
                            $"{data.syncWord[0]:X02}{data.syncWord[1]:X02}{data.syncWord[2]:X02}{data.syncWord[3]:X02}",
                        FrameLock = data.frameLock > 0,
                    }));
                }

                stModel.Refresh(statistics);
                httpsv.WebSocketServices.Broadcast(stModel.toJSON());
            };

            cn.ChannelDataAvailable       += demuxManager.parseBytes;
            cn.ConstellationDataAvailable += data => {
                var cm = new ConstellationModel(data);
                if (httpsv.IsListening)
                {
                    httpsv.WebSocketServices.Broadcast(cm.toJSON());
                }
            };

            statistics = new Statistics_st();
            stModel    = new StatisticsModel(statistics);
            UIConsole.Log("Headless Main Created");
            UIConsole.Log($"HTTP Server at port {ProgConfig.HTTPPort}");
            httpsv = new HttpServer(ProgConfig.HTTPPort)
            {
                RootPath = Path.GetFullPath(Path.Combine(".", "web"))
            };

            httpsv.OnGet += HandleHTTPGet;
            httpsv.AddWebSocketService("/mainws", () => new WSHandler {
                dh = directoryHandler
            });

            UIConsole.MessageAvailable += (data) => {
                var cm = new ConsoleModel(data.Priority.ToString(), data.Message);
                if (httpsv.IsListening)
                {
                    httpsv.WebSocketServices["/mainws"].Sessions.Broadcast(cm.toJSON());
                }

                messageListMutex.WaitOne();
                if (messageList.Count >= MAX_CACHED_MESSAGES)
                {
                    messageList.RemoveAt(0);
                }
                messageList.Add(data);
                messageListMutex.ReleaseMutex();
            };
        }
Example #5
0
 static EventMaster()
 {
     Master = new EventMaster();
 }
Example #6
0
        public static string DumpFile(string filename, XRITHeader fileHeader, string newExt, bool forceErase = false)
        {
            string dir = Path.GetDirectoryName(filename);
            string f   = FixFileFolder(dir, fileHeader.Filename, fileHeader.Product, fileHeader.SubProduct);

            f = f.Replace(".lrit", "." + newExt);

            if (
                FileHandler.SkipEMWIN && fileHeader.Product.ID == (int)NOAAProductID.HRIT_EMWIN ||
                FileHandler.SkipWeatherData && f.Contains(WeatherDataFolder)
                )
            {
                try {
                    File.Delete(filename);
                } catch (Exception) {
                    // Do nothing, file doesn't exists
                }
                return(null);
            }

            if (File.Exists(f))
            {
                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string ext       = Path.GetExtension(f);
                string append    = String.Format("--dup-{0}{1}", timestamp, ext);
                f = f.Replace(String.Format("{0}", ext), append);
            }

            UIConsole.Log($"New {fileHeader.ToNameString()}");

            /*
             * if (fileHeader.SubProduct.Name != "Unknown") {
             *  UIConsole.Log(String.Format("New {0} - {1} ({2})", fileHeader.Product.Name, fileHeader.SubProduct.Name, fileHeader.Filename));
             * } else {
             *  UIConsole.Log(String.Format("New {0} ({1})", fileHeader.Product.Name, fileHeader.Filename));
             * }*/

            FileStream fs = File.OpenRead(filename);

            fs.Seek(fileHeader.PrimaryHeader.HeaderLength, SeekOrigin.Begin);
            FileStream os = File.OpenWrite(f);

            byte[] buffer = new Byte[1024];
            int    bytesRead;

            while ((bytesRead = fs.Read(buffer, 0, 1024)) > 0)
            {
                os.Write(buffer, 0, bytesRead);
            }

            fs.Close();
            os.Close();

            if (f.Contains(".zip"))
            {
                UIConsole.Log(String.Format("Extracting Zip File {0}", Path.GetFileName(f)));
                ExtractZipFile(f);
            }
            else
            {
                EventMaster.Post(EventTypes.NewFileEvent, new NewFileReceivedEventData {
                    Name     = fileHeader.Filename,
                    Path     = f,
                    Metadata =
                    {
                        { "product",      fileHeader.Product.Name             },
                        { "subProduct",   fileHeader.SubProduct.Name          },
                        { "productId",    fileHeader.Product.ID.ToString()    },
                        { "subProductId", fileHeader.SubProduct.ID.ToString() }
                    }
                });
            }
            if (!forceErase)
            {
                // Keep the original lrit file
                File.Move(filename, f.Replace("." + newExt, ".lrit"));
                return(f.Replace("." + newExt, ".lrit"));
            }
            else
            {
                try {
                    File.Delete(filename);
                } catch (Exception) {
                    // Do nothing, file doesn't exists
                }
                return(null);
            }
        }
Example #7
0
        public static void ExtractZipFile(string zipfile)
        {
            try {
                string basepath = Path.GetDirectoryName(zipfile);

                using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipfile))) {
                    ZipEntry theEntry;
                    while ((theEntry = s.GetNextEntry()) != null)
                    {
                        string directoryName = Path.GetDirectoryName(theEntry.Name);
                        string fileName      = Path.GetFileName(theEntry.Name);
                        string baseFileName  = Path.GetFileName(theEntry.Name);

                        directoryName = Path.Combine(basepath, directoryName);

                        if (directoryName.Length > 0)
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        fileName = Path.Combine(directoryName, fileName);

                        if (fileName != String.Empty)
                        {
                            int count = 1;
                            while (File.Exists(fileName))
                            {
                                fileName = String.Format("{0}__{1}{2}", Path.GetFileNameWithoutExtension(baseFileName), count, Path.GetExtension(baseFileName));
                                fileName = Path.Combine(directoryName, fileName);
                                if (count == 1000)
                                {
                                    count = 0;
                                    break;
                                }
                                count++;
                            }

                            UIConsole.Debug($"Saving file {Path.GetFileName(fileName)}");

                            using (FileStream streamWriter = File.Create(fileName)) {
                                const int MAXSIZE   = 40 * 1024 * 1024;
                                int       size      = 2048;
                                int       readBytes = 0;
                                byte[]    data      = new byte[2048];
                                while (readBytes < MAXSIZE)
                                {
                                    size       = s.Read(data, 0, data.Length);
                                    readBytes += size;
                                    if (size > 0)
                                    {
                                        streamWriter.Write(data, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            EventMaster.Post(EventTypes.NewFileEvent, new NewFileReceivedEventData {
                                Name     = Path.GetFileName(fileName),
                                Path     = fileName,
                                Metadata =
                                {
                                    { "product", "ZIP FILE" },
                                    { "zipFile", zipfile    },
                                }
                            });
                        }
                    }
                }
            } catch (Exception e) {
                UIConsole.Error(String.Format("Error extracting file {0}: {1}", Path.GetFileName(zipfile), e));
            }

            try {
                File.Delete(zipfile);
            } catch (Exception) {
            }
        }
Example #8
0
        void ThreadLoop()
        {
            try {
                while (running)
                {
                    organizer.Update();
                    var data  = organizer.GroupData;
                    var clist = data.ToList();
                    foreach (var z in clist)
                    {
                        var mData = z.Value;
                        if (!running)
                        {
                            break;
                        }
                        string ImageName = string.Format("{0}-{1}-{2}", z.Key, mData.SatelliteName, mData.RegionName);
                        if (!mData.IsProcessed)
                        {
                            try {
                                if (ImageManager.GenerateVisible && mData.Visible.IsComplete && mData.Visible.MaxSegments != 0 && !mData.IsVisibleProcessed)
                                {
                                    string ofilename = Path.Combine(folder, GenFilename(mData.SatelliteName, mData.RegionName, "VIS", z.Key, mData.Visible.Segments [mData.Visible.FirstSegment]));
                                    if (File.Exists(ofilename))
                                    {
                                        UIConsole.Debug($"Skipping generating Visible for {Path.GetFileName(ofilename)}. Image already exists.");
                                        mData.IsVisibleProcessed = true;
                                    }
                                    else
                                    {
                                        UIConsole.Debug(string.Format("Starting Generation of Visible for {0}.", Path.GetFileName(ofilename)));
                                        var bmp = ImageTools.GenerateFullImage(mData.Visible, mData.CropImage);
                                        if (GenerateMapOverlays || GenerateLatLonOverlays || GenerateLabels)
                                        {
                                            if (SaveNonOverlay)
                                            {
                                                string orgFileName = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(ofilename)}-original.png");
                                                bmp.Save(orgFileName, ImageFormat.Png);
                                            }
                                            UIConsole.Debug(string.Format("Generating Overlays Visible for {0}.", Path.GetFileName(ofilename)));
                                            GenerateImageOverlay(ref bmp, mData, mData.Visible);
                                        }
                                        bmp.Save(ofilename, ImageFormat.Png);
                                        bmp.Dispose();
                                        UIConsole.Log($"New Visible Image: {Path.GetFileName(ofilename)}");
                                        EventMaster.Post("newFile", new NewFileReceivedEventData()
                                        {
                                            Name     = Path.GetFileName(ofilename),
                                            Path     = ofilename,
                                            Metadata =
                                            {
                                                { "channel", "visible" }, {
                                                    "satelliteName",
                                                    mData.SatelliteName
                                                },{
                                                    "regionName",
                                                    mData.RegionName
                                                },{
                                                    "timestamp",
                                                    z.Key.ToString()
                                                }
                                            }
                                        });
                                    }
                                    mData.IsVisibleProcessed = true;
                                    mData.Visible.OK         = true;
                                }
                                else if (mData.Visible.MaxSegments == 0)
                                {
                                    mData.IsVisibleProcessed = true;
                                    mData.Visible.OK         = true;
                                }

                                if (ImageManager.GenerateInfrared && mData.Infrared.IsComplete && mData.Infrared.MaxSegments != 0 && !mData.IsInfraredProcessed)
                                {
                                    string ofilename = Path.Combine(folder, GenFilename(mData.SatelliteName, mData.RegionName, "IR", z.Key, mData.Infrared.Segments [mData.Infrared.FirstSegment]));
                                    if (File.Exists(ofilename))
                                    {
                                        UIConsole.Debug($"Skipping generating Infrared for {Path.GetFileName(ofilename)}. Image already exists.");
                                    }
                                    else
                                    {
                                        UIConsole.Debug($"Starting Generation of Infrared for {Path.GetFileName(ofilename)}.");
                                        var bmp = ImageTools.GenerateFullImage(mData.Infrared, mData.CropImage);
                                        if (GenerateMapOverlays || GenerateLatLonOverlays || GenerateLabels)
                                        {
                                            if (SaveNonOverlay)
                                            {
                                                string orgFileName = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(ofilename)}-original.png");
                                                bmp.Save(orgFileName, ImageFormat.Png);
                                            }
                                            UIConsole.Debug(string.Format("Generating Overlays Infrared for {0}.", Path.GetFileName(ofilename)));
                                            GenerateImageOverlay(ref bmp, mData, mData.Infrared);
                                        }
                                        bmp.Save(ofilename, ImageFormat.Png);
                                        bmp.Dispose();
                                        UIConsole.Log($"New Infrared Image: {Path.GetFileName(ofilename)}");
                                        EventMaster.Post("newFile", new NewFileReceivedEventData()
                                        {
                                            Name     = Path.GetFileName(ofilename),
                                            Path     = ofilename,
                                            Metadata =
                                            {
                                                { "channel", "infrared" }, {
                                                    "satelliteName",
                                                    mData.SatelliteName
                                                },{
                                                    "regionName",
                                                    mData.RegionName
                                                },{
                                                    "timestamp",
                                                    z.Key.ToString()
                                                }
                                            }
                                        });
                                    }
                                    mData.IsInfraredProcessed = true;
                                    mData.Infrared.OK         = true;
                                }
                                else if (mData.Infrared.MaxSegments == 0)
                                {
                                    mData.IsInfraredProcessed = true;
                                    mData.Infrared.OK         = true;
                                }

                                if (ImageManager.GenerateWaterVapour && mData.WaterVapour.IsComplete && mData.WaterVapour.MaxSegments != 0 && !mData.IsWaterVapourProcessed)
                                {
                                    string ofilename = Path.Combine(folder, GenFilename(mData.SatelliteName, mData.RegionName, "WV", z.Key, mData.WaterVapour.Segments [mData.WaterVapour.FirstSegment]));
                                    if (File.Exists(ofilename))
                                    {
                                        UIConsole.Debug($"Skipping generating Water Vapour for {Path.GetFileName(ofilename)}. Image already exists.");
                                    }
                                    else
                                    {
                                        UIConsole.Debug($"Starting Generation of Water Vapour for {Path.GetFileName(ofilename)}.");
                                        var bmp = ImageTools.GenerateFullImage(mData.WaterVapour, mData.CropImage);
                                        if (GenerateMapOverlays || GenerateLatLonOverlays || GenerateLabels)
                                        {
                                            if (SaveNonOverlay)
                                            {
                                                string orgFileName = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(ofilename)}-original.png");
                                                bmp.Save(orgFileName, ImageFormat.Png);
                                            }
                                            UIConsole.Debug(string.Format("Generating Overlays WaterVapour for {0}.", Path.GetFileName(ofilename)));
                                            GenerateImageOverlay(ref bmp, mData, mData.WaterVapour);
                                        }
                                        bmp.Save(ofilename, ImageFormat.Png);
                                        bmp.Dispose();
                                        UIConsole.Log($"New Water Vapour Image: {Path.GetFileName(ofilename)}");
                                        EventMaster.Post("newFile", new NewFileReceivedEventData()
                                        {
                                            Name     = Path.GetFileName(ofilename),
                                            Path     = ofilename,
                                            Metadata =
                                            {
                                                { "channel", "watervapour" }, {
                                                    "satelliteName",
                                                    mData.SatelliteName
                                                },{
                                                    "regionName",
                                                    mData.RegionName
                                                },{
                                                    "timestamp",
                                                    z.Key.ToString()
                                                }
                                            }
                                        });
                                    }
                                    mData.IsWaterVapourProcessed = true;
                                    mData.WaterVapour.OK         = true;
                                }
                                if (GenerateFalseColor && !mData.IsFalseColorProcessed && ImageTools.CanGenerateFalseColor(mData))
                                {
                                    string filename = GenFilename(
                                        mData.SatelliteName,
                                        mData.RegionName,
                                        "FSCLR",
                                        z.Key,
                                        mData.Visible.Segments [mData.Visible.FirstSegment]
                                        .Replace("VS", "FC")
                                        .Replace("VIS", "FC")
                                        );
                                    filename = Path.Combine(folder, filename);

                                    if (File.Exists(filename))
                                    {
                                        UIConsole.Debug($"Skipping generating FLSCLR for {Path.GetFileName(filename)}. Image already exists.");
                                    }
                                    else
                                    {
                                        UIConsole.Debug($"Starting Generation of FSLCR for {Path.GetFileName(filename)}.");
                                        var bmp = ImageTools.GenerateFalseColor(mData);
                                        if (GenerateMapOverlays || GenerateLatLonOverlays || GenerateLabels)
                                        {
                                            if (SaveNonOverlay)
                                            {
                                                string orgFileName = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(filename)}-original.png");
                                                bmp.Save(orgFileName, ImageFormat.Png);
                                            }
                                            UIConsole.Debug(string.Format("Generating Overlays False Colour for {0}.", Path.GetFileName(filename)));
                                            GenerateImageOverlay(ref bmp, mData, mData.Visible);  // Using visible coordinates
                                        }
                                        bmp.Save(filename, ImageFormat.Png);
                                        bmp.Dispose();
                                        UIConsole.Log($"New False Colour Image: {Path.GetFileName(filename)}");
                                        EventMaster.Post("newFile", new NewFileReceivedEventData()
                                        {
                                            Name     = Path.GetFileName(filename),
                                            Path     = filename,
                                            Metadata =
                                            {
                                                { "channel", "filename" }, {
                                                    "satelliteName",
                                                    mData.SatelliteName
                                                },{
                                                    "regionName",
                                                    mData.RegionName
                                                },{
                                                    "timestamp",
                                                    z.Key.ToString()
                                                }
                                            }
                                        });
                                    }
                                    mData.IsFalseColorProcessed = true;
                                }
                                if (GenerateOtherImages && !mData.IsOtherDataProcessed && mData.OtherData.Count > 0)
                                {
                                    mData.OtherData.Keys.ToList().ForEach(k => {
                                        var gd = mData.OtherData [k];
                                        if (gd.IsComplete && gd.MaxSegments != 0 && !gd.OK)
                                        {
                                            string ofilename = GenFilename(mData.SatelliteName, mData.RegionName, gd.Code, gd.Timestamp, gd.Segments [0]);
                                            ofilename        = Path.Combine(folder, ofilename);

                                            if (File.Exists(ofilename))
                                            {
                                                UIConsole.Debug($"Skipping generating {Path.GetFileName(ofilename)}. Image already exists.");
                                            }
                                            else
                                            {
                                                UIConsole.Debug($"Starting Generation of {Path.GetFileName(ofilename)}.");
                                                var bmp = ImageTools.GenerateFullImage(gd, false);
                                                if (GenerateMapOverlays || GenerateLatLonOverlays || GenerateLabels)
                                                {
                                                    if (SaveNonOverlay)
                                                    {
                                                        string orgFileName = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(ofilename)}-original.png");
                                                        bmp.Save(orgFileName, ImageFormat.Png);
                                                    }
                                                    UIConsole.Debug(string.Format("Generating Overlays for {0}.", Path.GetFileName(ofilename)));
                                                    GenerateImageOverlay(ref bmp, mData, gd);
                                                }
                                                bmp.Save(ofilename, ImageFormat.Png);
                                                bmp.Dispose();
                                                UIConsole.Log($"New Image: {Path.GetFileName(ofilename)}");
                                                EventMaster.Post("newFile", new NewFileReceivedEventData()
                                                {
                                                    Name     = Path.GetFileName(ofilename),
                                                    Path     = ofilename,
                                                    Metadata = { {
                                                                     "channel",
                                                                     "otherimages"
                                                                 },{
                                                                     "satelliteName",
                                                                     mData.SatelliteName
                                                                 },{
                                                                     "regionName",
                                                                     mData.RegionName
                                                                 },{
                                                                     "timestamp",
                                                                     z.Key.ToString()
                                                                 } }
                                                });
                                            }
                                            gd.OK = true;
                                        }
                                    });
                                }
                                else if (mData.OtherData.Count == 0)
                                {
                                    if (mData.ReadyToMark)
                                    {
                                        mData.IsOtherDataProcessed = true;
                                    }
                                }

                                if (mData.ReadyToMark)
                                {
                                    mData.IsProcessed =
                                        (!GenerateFalseColor || (GenerateFalseColor && mData.IsFalseColorProcessed)) &&
                                        (!GenerateVisible || (GenerateVisible && mData.IsVisibleProcessed)) &&
                                        (!GenerateInfrared || (GenerateInfrared && mData.IsInfraredProcessed)) &&
                                        (!GenerateWaterVapour || (GenerateWaterVapour && mData.IsWaterVapourProcessed)) &&
                                        (!GenerateOtherImages || (GenerateOtherImages && mData.IsOtherDataProcessed));
                                }

                                if (mData.Timeout)
                                {
                                    // Timeout completing, so let's erase the files.
                                    mData.ForceComplete();
                                }

                                if (EraseFiles)
                                {
                                    TryEraseGroupDataFiles(z.Key, mData);
                                }
                            } catch (SystemException e) {
                                UIConsole.Error($"Error processing image (SysExcpt) {ImageName}: {e}");
                                mData.RetryCount++;
                                if (mData.RetryCount == ImageManager.MaxRetryCount)
                                {
                                    mData.IsProcessed = true;
                                }
                            } catch (Exception e) {
                                UIConsole.Error($"Error processing image {ImageName}: {e}");
                                mData.RetryCount++;
                                if (mData.RetryCount == ImageManager.MaxRetryCount)
                                {
                                    mData.IsProcessed = true;
                                }
                            }
                        }
                    }

                    Thread.Sleep(200);
                }
            } catch (Exception e) {
                CrashReport.Report(e);
                throw e;
            }
        }