示例#1
0
        void IJob.DoJob(Operation operation)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Einsatznummer: {0}", operation.OperationNumber).AppendLine();
            sb.AppendFormat("Einsatzort: {0}", operation.GetDestinationLocation());

            // Send notification via each growl sender
            _growlSender.ForEach(gs =>
            {
                try
                {
                    gs.SendNotification(this, "Neuer Alarm!", sb.ToString());
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Could not send Growl notification! See log for information.");
                    Logger.Instance.LogException(this, ex);
                }
            });
        }
示例#2
0
        private void SetContentToLatestAlarm(Operation operation)
        {
            // TODO: Find a more elegant way than just switching the panels' visibility!
            pnlProgress.Visible = false;
            pnlAlarm.Visible = true;
            pnlNoAlarm.Visible = false;

            // TODO
            tcOperationNumber.Text = operation.OperationNumber;
            tcTimestamp.Text = operation.Timestamp.ToLocalTime().ToString();
            tcDestinationLocation.Text = operation.GetDestinationLocation().ToString();
            tcKeyword.Text = operation.Keyword;
            tcMessenger.Text = operation.Messenger;
            tcComment.Text = operation.Comment;

            LoadOperationRouteImage(operation);
        }
        private byte[] DownloadRoutePlan(Operation operation)
        {
            PropertyLocation source = GetFDLocation();
            if (!source.IsMeaningful)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, Resources.RoutePlanningSourceLocationNotMeaningful, source);
                return null;
            }

            PropertyLocation destination = operation.GetDestinationLocation();
            if (!operation.GetDestinationLocation().IsMeaningful)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, Resources.DestinationLocationIsUnknown);
                return null;
            }

            Logger.Instance.LogFormat(LogType.Trace, this, Resources.DownloadRoutePlanBegin, destination.ToString());

            Stopwatch sw = Stopwatch.StartNew();
            try
            {
                byte[] imageBuffer = GoogleMapsProvider.GetRouteImage(source, destination);

                sw.Stop();

                if (imageBuffer == null)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Resources.DownloadRoutePlanFailed);
                }
                else
                {
                    Logger.Instance.LogFormat(LogType.Trace, this, Resources.DownloadRoutePlanSuccess, sw.ElapsedMilliseconds);
                }

                return imageBuffer;
            }
            catch (Exception ex)
            {
                sw.Stop();
                Logger.Instance.LogFormat(LogType.Error, this, Resources.DownloadRoutePlanError);
                Logger.Instance.LogException(this, ex);
            }

            return null;
        }
        /// <summary>
        /// Downloads the route planning info if it is enabled and the location datas are meaningful enough.
        /// </summary>
        /// <param name="operation"></param>
        private void DownloadRoutePlan(Operation operation)
        {
            if (!AlarmWorkflowConfiguration.Instance.DownloadRoutePlan)
            {
                return;
            }

            // Get start address and check if it is meaningful enough (if not then bail out)
            PropertyLocation source = AlarmWorkflowConfiguration.Instance.FDInformation.Location;
            if (!source.IsMeaningful)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Cannot download route plan because the location information for this fire department is not meaningful enough: '{0}'. Please fill the correct address!", source);
                return;
            }

            // Get destination address and check if it is meaningful enough (if not then bail out)
            PropertyLocation destination = operation.GetDestinationLocation();
            if (!operation.GetDestinationLocation().IsMeaningful)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Destination location is unknown! Cannot download route plan!");
            }
            else
            {
                Logger.Instance.LogFormat(LogType.Trace, this, "Downloading route plan to destination '{0}'...", destination.ToString());

                Stopwatch sw = Stopwatch.StartNew();
                try
                {
                    Image image = _routePlanProvider.GetRouteImage(source, destination);

                    if (image != null)
                    {
                        // Save the image as PNG
                        using (MemoryStream ms = new MemoryStream())
                        {
                            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                            operation.RouteImage = ms.ToArray();
                        }
                    }

                    sw.Stop();

                    if (operation.RouteImage == null)
                    {
                        Logger.Instance.LogFormat(LogType.Warning, this, "The download of the route plan did not succeed. Please check the log for information!");
                    }
                    else
                    {
                        Logger.Instance.LogFormat(LogType.Trace, this, "Downloaded route plan in '{0}' milliseconds.", sw.ElapsedMilliseconds);
                    }
                }
                catch (Exception ex)
                {
                    sw.Stop();
                    Logger.Instance.LogFormat(LogType.Error, this, "An error occurred while trying to download the route plan! The image will not be available.");
                    Logger.Instance.LogException(this, ex);
                }
            }
        }