예제 #1
0
        /// <summary>
        /// Execute send
        /// </summary>
        /// <param name="routesConfigs">Sent routes config collection</param>
        public void Execute(ICollection <SentRouteConfig> routesConfigs)
        {
            // Set page status to "Sending routes..."
            _app.MainWindow.StatusBar.SetStatus(_page, Properties.Resources.SendingRoutes);

            // Get properties to export
            IList <string> propertyNames = new List <string>(Order.GetPropertyNames(_app.Project.CapacitiesInfo,
                                                                                    _app.Project.OrderCustomPropertiesInfo, _app.Geocoder.AddressFields));;

            int totalSended              = 0;
            int totalSendedSuccessfully  = 0;
            List <MessageDetail> details = new List <MessageDetail>();

            // List of all selected route's export warning messages.
            List <string> exportWarningMessages = new List <string>();

            foreach (SentRouteConfig sendedRouteConfig in routesConfigs)
            {
                // If route checked to be exported - export it
                if (sendedRouteConfig.IsChecked)
                {
                    GrfExportResult exportWarnings = new GrfExportResult();

                    bool result = _ProcessSendedRouteConfig(sendedRouteConfig.Route, details,
                                                            propertyNames, ref exportWarnings);

                    // Increase total sent routes counrer
                    totalSended++;

                    // Increase successfully sent routes counter
                    if (result)
                    {
                        totalSendedSuccessfully++;
                    }

                    // If there was messages during export then add unique
                    // route's export result messages to list of export results warning messages.
                    foreach (string message in exportWarnings.Warnings)
                    {
                        if (!exportWarningMessages.Contains(message))
                        {
                            exportWarningMessages.Add(message);
                        }
                    }
                }
            }

            // Show result in message window.
            _ShowResults(totalSended, totalSendedSuccessfully, exportWarningMessages, details);
        }
예제 #2
0
        /// <summary>
        /// Make send
        /// </summary>
        /// <param name="route">Route for sending</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <returns>Error message</returns>
        private string _DoSend(Route route, IList <string> selectedPropertyNames, ref GrfExportResult exportResult)
        {
            string message = string.Empty;

            // Generate filename
            DateTime routeDate = route.StartTime.Value.Date;
            string   filename  = string.Format(FILENAME_FORMAT, routeDate.ToString("yyyyMMdd"),
                                               route.Name, DateTime.Now.ToString("yyyyMMdd_HHmmss"));

            // Add extention to filename
            filename += (_grfExporterConfig.RouteGrfCompression) ? GZExt : GRFExt;

            // Get mobile device
            MobileDevice mobileDevice = route.Driver.MobileDevice;

            if (mobileDevice == null)
            {
                mobileDevice = route.Vehicle.MobileDevice;
            }

            // React on empty mobile device
            if (mobileDevice == null)
            {
                string errorMessage = Properties.Resources.MobileDeviceEmpty;
                throw new SettingsException(errorMessage);
            }

            // Do send depends on sync type
            switch (mobileDevice.SyncType)
            {
            case SyncType.ActiveSync:
                exportResult = _SendToActiveSync(route, filename, selectedPropertyNames, mobileDevice);
                message      = string.Format(Properties.Resources.SuccessfullySentToDevice,
                                             route.Name, mobileDevice.Name);
                break;

            case SyncType.EMail:
                exportResult = _SendToEMail(route, filename, selectedPropertyNames, mobileDevice);
                message      = string.Format(Properties.Resources.SuccessfullyMailed,
                                             route.Name, mobileDevice.EmailAddress);
                break;

            case SyncType.Folder:
                exportResult = _SendToFolder(route, filename, selectedPropertyNames, mobileDevice);
                message      = string.Format(Properties.Resources.SuccessfullySentToFolder,
                                             route.Name, mobileDevice.SyncFolder);
                break;

            case SyncType.None:
            {
                // React on empty sync type
                string errorMessage = (mobileDevice == route.Driver.MobileDevice) ?
                                      Properties.Resources.SyncTypeNotSelectedForDriverDevice :
                                      Properties.Resources.SyncTypeNotSelectedForVehicleDevice;
                throw new SettingsException(errorMessage);
            }

            default:
            {
                throw new SettingsException(Properties.Resources.SyncTypeIsNotSupported);
            }
            }

            return(message);
        }
예제 #3
0
        /// <summary>
        /// Process sending route
        /// </summary>
        /// <param name="route">Sent route</param>
        /// <param name="details">Results message details</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <returns>True if successfully sent</returns>
        private bool _ProcessSendedRouteConfig(Route route, IList <MessageDetail> details,
                                               IList <string> selectedPropertyNames, ref GrfExportResult exportResult)
        {
            bool   result  = false;
            Link   link    = null;
            string message = string.Empty;

            try
            {
                message = _DoSend(route, selectedPropertyNames, ref exportResult);
                result  = true;
            }
            catch (SettingsException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, ex.Message);
            }
            catch (IOException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, ex.Message);
            }
            catch (InvalidOperationException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, ex.Message);
            }
            catch (UnauthorizedAccessException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, ex.Message);
            }
            catch (SmtpException ex)
            {
                Logger.Error(ex);
                string innerMessage = Properties.Resources.MailConnectionError;
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, innerMessage);
            }
            catch (MailerSettingsException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                                        route.Name, ex.Message);

                link = new Link(Properties.Resources.ExportToNavigatorLink,
                                ExportToNavigatorPreferencesPagePath, LinkType.Page);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                if (ex is AuthenticationException || ex is CommunicationException)
                {
                    string service = (string)_app.FindResource("ServiceNameRouting");
                    message = AddServiceMessageWithDetail(service, ex);

                    if (ex is AuthenticationException)
                    {
                        link = new Link((string)_app.FindResource("LicencePanelText"),
                                        ESRI.ArcLogistics.App.Pages.PagePaths.LicensePagePath, LinkType.Page);
                    }
                }
                else
                {
                    string innerMessage = Properties.Resources.UnknownError;
                    message = string.Format(Properties.Resources.SendingFailed,
                                            route.Name, innerMessage);
                }
            }

            MessageDetail messageDetail;

            // If route sent successfully - add information details
            // If route was not sent - add error details
            if (result)
            {
                messageDetail = new MessageDetail(MessageType.Information, message);
            }
            else
            {
                if (link == null)
                {
                    messageDetail = new MessageDetail(MessageType.Error, message);
                }
                else
                {
                    messageDetail = new MessageDetail(MessageType.Error, message, link);
                }
            }

            details.Add(messageDetail);

            return(result);
        }