Пример #1
0
        /// <summary>
        /// Send GRF by E-Mail
        /// </summary>
        /// <param name="route">Route to export</param>
        /// <param name="filename">GRF Filename</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <param name="mobileDevice">Mobile device</param>
        private GrfExportResult _SendToEMail(Route route, string filename, IList <string> selectedPropertyNames, MobileDevice mobileDevice)
        {
            string filePath = "";

            try
            {
                if (string.IsNullOrEmpty(mobileDevice.EmailAddress))
                {
                    throw new SettingsException(Properties.Resources.MailAddressEmpty);
                }

                string tempFolderPath = Environment.GetEnvironmentVariable("TEMP");
                filePath = Path.Combine(tempFolderPath, filename);

                DateTime routeDate = route.StartTime.Value.Date;

                var exportResults = GrfExporter.ExportToGRF(filePath, route, _app.Project, _app.Geocoder,
                                                            _app.Solver, selectedPropertyNames, _grfExporterConfig.RouteGrfCompression);

                // Fill E-Mail message
                string subject = string.Format(Properties.Resources.GRFLetterSubjectFormat,
                                               route.Vehicle.Name, routeDate.ToString("yyyyMMdd"));
                string[] attachments = new string[1];
                attachments[0] = filePath;

                // Try to send E-Mail message
                if (_mailer == null)
                {
                    if (_mailerException != null)
                    {
                        throw _mailerException;
                    }
                    else
                    {
                        try
                        {
                            _mailer = new Mailer(_grfExporterConfig);
                        }
                        catch (Exception ex)
                        {
                            _mailerException = ex;
                            throw;
                        }
                    }
                }

                _mailer.Send(mobileDevice.EmailAddress, mobileDevice.EmailAddress, subject, "", attachments, filePath);

                return(exportResults);
            }
            finally
            {
                _DeleteFile(filePath);
            }
        }
Пример #2
0
        /// <summary>
        /// Save GRF file to folder
        /// </summary>
        /// <param name="route">Route to export</param>
        /// <param name="filename">GRF Filename</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <param name="mobileDevice">Mobile device</param>
        private GrfExportResult _SendToFolder(Route route, string filename, IList <string> selectedPropertyNames, MobileDevice mobileDevice)
        {
            if (string.IsNullOrEmpty(mobileDevice.SyncFolder))
            {
                throw new SettingsException(Properties.Resources.FolderPathEmpty);
            }

            string filePath = Path.Combine(mobileDevice.SyncFolder, filename);

            return(GrfExporter.ExportToGRF(filePath, route, _app.Project, _app.Geocoder, _app.Solver,
                                           selectedPropertyNames, _grfExporterConfig.RouteGrfCompression));
        }
Пример #3
0
        /// <summary>
        /// Send GRF to device via active sync
        /// </summary>
        /// <param name="route">Route to export</param>
        /// <param name="filename">GRF filename</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <param name="mobileDevice">Mobile device</param>
        private GrfExportResult _SendToActiveSync(Route route, string filename, IList <string> selectedPropertyNames, MobileDevice mobileDevice)
        {
            if (string.IsNullOrEmpty(mobileDevice.ActiveSyncProfileName))
            {
                throw new SettingsException(Properties.Resources.ActiveSyncProfileEmpty);
            }

            // Try to find device name in registry
            string deviceKeyPath = _FindDeviceKeyPath(mobileDevice);
            bool   deviceFound   = deviceKeyPath.Length > 0;

            string syncPath = string.Empty;

            if (deviceFound)
            {
                string syncDeviceKeyPath = Path.Combine(deviceKeyPath, MobileDevice.PARTNER_SYNC_PATH);

                RegistryKey partnerRegKey = Registry.CurrentUser.OpenSubKey(syncDeviceKeyPath);

                // Get synchronization path for device
                syncPath = (string)partnerRegKey.GetValue(MobileDevice.BRIEFCASEPATH);
                if (string.IsNullOrEmpty(syncPath))
                {
                    string message = string.Format(Properties.Resources.SyncPathAbsent,
                                                   mobileDevice.ActiveSyncProfileName);
                    throw new SettingsException(message);
                }

                if (syncPath[0] == '\\')
                {
                    syncPath = syncPath.Remove(0, 1);
                }
            }
            else
            {
                string message = string.Format(Properties.Resources.DeviceNotFound,
                                               mobileDevice.ActiveSyncProfileName);
                throw new SettingsException(message);
            }

            string documentsFolder    = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string deviceSyncFullPath = Path.Combine(documentsFolder, syncPath);
            string filePath           = Path.Combine(deviceSyncFullPath, filename);

            return(GrfExporter.ExportToGRF(filePath, route, _app.Project, _app.Geocoder,
                                           _app.Solver, selectedPropertyNames, false));
        }