Exemple #1
0
        public void TiffConverterTest_Split()
        {
            string[] fileEntries = Directory.GetFiles(@"D:\Imagery\");
            int      counter     = 0;

            foreach (var file in fileEntries)
            {
                if (file.Contains(".tif"))
                {
                    counter++;
                    if (counter > 100)
                    {
                        break;
                    }
                    var byteRay = TiffConverter.Split(file, 10);
                }
            }
        }
Exemple #2
0
        private void faxStart(Model.Printer printer, FinishedEventArgs e)
        {
            try
            {
                faxPrintFinished = false;
                faxPageIndex     = 0;

                var printDoc = new PrintDocument();
                if (Path.GetExtension(e.Einsatz.FaxPath).ToLower() == ".txt")
                {
                    faxText = new List <string>();
                    using (var _streamReader = new StreamReader(e.Einsatz.FaxPath, Encoding.GetEncoding(1252)))
                    {
                        while (_streamReader.Peek() >= 0)
                        {
                            faxText.Add(_streamReader.ReadLine());
                        }
                    }

                    printDoc.PrintPage += faxPrinter_PrintPageText;
                }
                else
                {
                    faxImages           = TiffConverter.TiffToBitmapList(e.Einsatz.FaxPath);
                    printDoc.PrintPage += faxPrinter_PrintPageImages;
                }

                printDoc.PrinterSettings.PrinterName = printer.PrinterName;
                printDoc.EndPrint += faxPrinter_StreamDispose;
                printDoc.Print();
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                faxPrintFinished = true;
            }
        }
Exemple #3
0
        private void faxService_EinsatzCreated(object sender, EinsatzCreatedEventArgs e)
        {
            if (e == null || e.Einsatz == null)
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var _message     = new Message();
                    _message.Subject = Settings.Default.MailOutput_Subject;

                    //Empfänger
                    _message.Recivers = new List <User>();
                    _message.Recivers.AddRange(_business.GetUserWithFaxMessageServiceMailOn().ToList());

                    //Nachricht
                    _message.Text = "EINSATZDATEN:" + Environment.NewLine;
                    if (!string.IsNullOrEmpty(e.Einsatz.Schlagwort))
                    {
                        _message.Text += "Schlagwort: " + e.Einsatz.Schlagwort + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Stichwort))
                    {
                        _message.Text += "Stichwort: " + e.Einsatz.Stichwort + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Objekt))
                    {
                        _message.Text += "Objekt: " + e.Einsatz.Objekt + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Straße))
                    {
                        _message.Text += "Straße: " + e.Einsatz.Straße + " " + e.Einsatz.Hausnummer +
                                         Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Ort))
                    {
                        _message.Text += "Ort: " + e.Einsatz.Ort + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Abschnitt))
                    {
                        _message.Text += "Abschnitt: " + e.Einsatz.Abschnitt + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Kreuzung))
                    {
                        _message.Text += "Kreuzung: " + e.Einsatz.Kreuzung + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Station))
                    {
                        _message.Text += "Station: " + e.Einsatz.Station + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(e.Einsatz.Bemerkung))
                    {
                        _message.Text += "Bemerkung: " + e.Einsatz.Bemerkung + Environment.NewLine;
                    }

                    _message.Text += Environment.NewLine;
                    _message.Text += Environment.NewLine;
                    _message.Text += "EINSATZMITTEL:" + Environment.NewLine;
                    foreach (var _vehicle in e.Einsatz.Einsatzmittel)
                    {
                        _message.Text += _vehicle.Name + Environment.NewLine;
                    }

                    _message.Text  += Environment.NewLine;
                    _message.Text  += Environment.NewLine;
                    var coordinaten = e.Einsatz.KoordinatenWGS84();
                    if (coordinaten != null)
                    {
                        var nfi = new NumberFormatInfo {
                            NumberDecimalSeparator = "."
                        };
                        var googleMapsUrl =
                            $"https://www.google.com/maps/search/?api=1&query={coordinaten.Latitude.ToString(nfi)},{coordinaten.Longitude.ToString(nfi)}";
                        _message.Text += $"ROUTE: {Environment.NewLine}{googleMapsUrl}" + Environment.NewLine;
                    }
                    else if (!string.IsNullOrEmpty(e.Einsatz.Straße) && !string.IsNullOrEmpty(e.Einsatz.Hausnummer) &&
                             !string.IsNullOrEmpty(e.Einsatz.Ort))
                    {
                        var googleMapsQuery = $"{e.Einsatz.Straße} {e.Einsatz.Hausnummer}, {e.Einsatz.Ort}";
                        var googleMapsUrl   =
                            $"https://www.google.com/maps/search/?api=1&query={HttpUtility.UrlEncode(googleMapsQuery)}";
                        _message.Text += $"ROUTE: {Environment.NewLine}{googleMapsUrl}" + Environment.NewLine;
                    }

                    //Start to send mail without attachment
                    sendMail(_message);


                    //Empfänger
                    _message.Recivers = new List <User>();
                    _message.Recivers.AddRange(_business.GetUserWithFaxMessageServiceFaxOn().ToList());

                    //Add Faximage as attachment
                    var _attachmentPath = e.Einsatz.FaxPath;
                    if (Path.GetExtension(e.Einsatz.FaxPath).ToLower() == ".tif")
                    {
                        _attachmentPath =
                            $"{Settings.Default.WorkingFolder}\\Temp\\ALARMFAX_PNG_{e.Einsatz.AlarmTime.ToString("yyyy-MM-dd_HH-mm-ss")}.png";
                        TiffConverter.SaveTiffAsImage(e.Einsatz.FaxPath, _attachmentPath);
                    }

                    _message.AttachmentPath = _attachmentPath;

                    //Start to send mail with attachment
                    sendMail(_message);
                }
                catch (Exception ex)
                {
                    ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                    {
                        Methode = MethodBase.GetCurrentMethod(),
                        Error   = ex
                    });
                }
            });
        }
        protected override void Process()
        {
            using (var unit = GetUnitOfWork())
            {
                var thumbs    = unit.Scope.Repository <ThumbnailGenerator>().GetAll().ToList();
                var tumbTypes = GetConfiguration().AppSettings.Settings["ThumbTypeIDs"].Value.Split(',').Select(x => int.Parse(x));
                var mediaPath = ConfigurationManager.AppSettings["FTPMediaDirectory"];
                var thumbPath = Path.Combine(mediaPath, ConfigurationManager.AppSettings["FTPMediaProductThumbDirectory"]);

                var productImages = unit.Scope.Repository <ProductMedia>().GetAll(x => tumbTypes.Contains(x.TypeID) && x.MediaPath != null).ToList();

                thumbs.ForEach(thumb =>
                {
                    var destinationPath = Path.Combine(thumbPath, thumb.ThumbnailGeneratorID.ToString());

                    if (!Directory.Exists(Path.Combine(destinationPath, "Products")))
                    {
                        Directory.CreateDirectory(Path.Combine(destinationPath, "Products"));
                    }

                    int width  = thumb.Width;
                    int heigth = thumb.Height;

                    int couterProduct = 0;
                    int logCount      = 0;
                    int totalProducts = productImages.Count;
                    log.DebugFormat("Found {0} media items to process for thumb generator {1}", totalProducts, thumb.Description);

                    productImages.ForEach(media =>
                    {
                        couterProduct++;
                        logCount++;
                        if (logCount == 50)
                        {
                            log.DebugFormat("Media Processed : {0}/{1}", couterProduct, totalProducts);
                            logCount = 0;
                        }

                        try
                        {
                            var pathToLook = Path.Combine(mediaPath, media.MediaPath);

                            var ext                 = Path.GetExtension(pathToLook).ToLower();
                            var isTiff              = (ext == ".tiff" || ext == ".tif");
                            FileInfo inf            = new FileInfo(pathToLook);
                            var destinationFilePath = Path.Combine(destinationPath, inf.Name);

                            ProductMediaTumbnail productThumb = unit.Scope.Repository <ProductMediaTumbnail>().GetSingle(x => x.MediaID == media.MediaID && x.ThumbnailGeneratorID == thumb.ThumbnailGeneratorID);

                            if (System.IO.File.Exists(pathToLook) && (productThumb == null || !File.Exists(destinationFilePath) || System.IO.File.GetLastWriteTime(pathToLook) > System.IO.File.GetLastWriteTime(destinationFilePath)))
                            {
                                if (!File.Exists(destinationFilePath))
                                {
                                    using (Image img = Image.FromFile(pathToLook))
                                    {
                                        if (isTiff)
                                        {
                                            TiffConverter converter = new TiffConverter(Path.Combine(pathToLook));
                                            converter.WriteTo(destinationFilePath.Replace(ext, ".png"), width, heigth);
                                        }
                                        else
                                        {
                                            var image = ImageUtility.GetFixedSizeImage(img, width > 0 ? width : img.Width, heigth > 0 ? heigth : img.Height, true, Color.White);
                                            image.Save(destinationFilePath.Replace(ext, ".png"), System.Drawing.Imaging.ImageFormat.Png);
                                        }
                                    }
                                }

                                if (productThumb == null)
                                {
                                    productThumb = new ProductMediaTumbnail()
                                    {
                                        MediaID = media.MediaID,
                                        ThumbnailGeneratorID = thumb.ThumbnailGeneratorID,
                                        Path = Path.Combine(thumb.ThumbnailGeneratorID.ToString(), inf.Name.Replace(ext, ".png"))
                                    };

                                    unit.Scope.Repository <ProductMediaTumbnail>().Add(productThumb);
                                    unit.Save();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Fail to Generate thumb for " + media.MediaPath, ex);
                        }
                    });
                });
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/png";

            bool   networkDrive = false;
            string drive        = ConfigurationManager.AppSettings["FTPMediaDirectory"].ToString();

            //string drive = @"\\SOL\Company_Shares\Database Backup";
            bool.TryParse(ConfigurationManager.AppSettings["IsNetworkDrive"], out networkDrive);

            string destinationPath = drive;

            if (networkDrive)
            {
                NetworkDrive oNetDrive = new NetworkDrive();
                try
                {
                    destinationPath      = @"H:\";
                    destinationPath      = Path.Combine(destinationPath, "Concentrator");
                    oNetDrive.LocalDrive = "H:";
                    oNetDrive.ShareName  = drive;
                    oNetDrive.MapDrive("Diract", "Concentrator01");
                    //oNetDrive.MapDrive();
                }
                catch (Exception err)
                {
                    //log.Error("Invalid network drive", err);
                }
                oNetDrive = null;
            }

            var mediaPath = context.Request.Params["MediaPath"];
            //var dir = ConfigurationManager.AppSettings["FTPMediaDirectory"].ToString();

            int width = -1;

            if (context.Request.Params["width"] != null)
            {
                int.TryParse(context.Request.Params["width"], out width);
            }

            int heigth = -1;

            if (context.Request.Params["height"] != null)
            {
                int.TryParse(context.Request.Params["height"], out heigth);
            }

            var pathToLook = Path.Combine(destinationPath, mediaPath);

            var ext    = Path.GetExtension(pathToLook).ToLower();
            var isTiff = (ext == ".tiff" || ext == ".tif");

            using (Image img = Image.FromFile(pathToLook))
            {
                if (isTiff)
                {
                    TiffConverter converter = new TiffConverter(Path.Combine(destinationPath, mediaPath));
                    converter.WriteTo(context.Response.OutputStream, width, heigth);
                }
                else
                {
                    var image = ImageUtility.GetFixedSizeImage(img, width > 0 ? width : img.Width, heigth > 0 ? heigth : img.Height, true);
                    image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }