示例#1
0
 public void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
 {
     try
     {
         loadService.Load(false, false);
     }
     catch
     {
         loadService.ClearAll();
     }
 }
示例#2
0
        public bool ShowImportDialog(Action <string> openAction)
        {
            if (packageLoaded)
            {
                System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show(LocalizationLocator.MobileLocalization.ImportWarning, "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning);

                if (dialogResult != System.Windows.Forms.DialogResult.Yes)
                {
                    return(false);
                }
            }


            var openFileDialog = new OpenFileDialog
            {
                CheckFileExists  = true,
                CheckPathExists  = true,
                Filter           = "EMSGE (*.emsge)|*.emsge",
                InitialDirectory = Environment.CurrentDirectory,
                Multiselect      = false,
                Title            = LocalizationLocator.MobileLocalization.Import
            };
            string importPath = Properties.Settings.Default.ImportFolderPath;

            if (!string.IsNullOrEmpty(importPath) && Directory.Exists(importPath))
            {
                openFileDialog.InitialDirectory = importPath;
            }
            if ((bool)openFileDialog.ShowDialog())
            {
                FileInfo file = new FileInfo(openFileDialog.FileName);
                Properties.Settings.Default.ImportFolderPath = file.Directory.FullName;
                Properties.Settings.Default.Save();

                OnImportStart(new EventArgs());
                //Mouse.OverrideCursor = Cursors.Wait;
                Loggers.TechLogger.Info("Importing File: " + openFileDialog.FileName);
                try
                {
                    openAction(openFileDialog.FileName);
                }
                catch (EmsgException ex)
                {
                    OnImportFinished(new EventArgs());
                    //Mouse.OverrideCursor = null;
                    Loggers.TechLogger.ErrorException(ex.Message, ex);
                    loadService.ClearAll();
                    messageBoxService.Information(ex.Message);
                    return(false);
                }
                catch (Exception ex)
                {
                    //Mouse.OverrideCursor = null;
                    OnImportFinished(new EventArgs());
                    Loggers.TechLogger.ErrorException(ex.Message, ex);
                    loadService.ClearAll();
                    messageBoxService.Information(LocalizationLocator.MobileLocalization.ImportError);
                    return(false);
                }

                //Mouse.OverrideCursor = null;
                OnImportFinished(new EventArgs());
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        public void Export(string file, bool exportAll)
        {
            FileHelper.TryDeleteFiles(new DirectoryInfo(clientConfigurationProvider.ExportPackageFolderPath));


            ClientPackageDescriptor mdescriptor = new ClientPackageDescriptor();
            ServerPackageDescriptor sdescriptor = GetWorkingSeverpackageDescriptor();


            if (exportAll)
            {
                mdescriptor.CheckOutsGISInspektionsroutenList = sdescriptor.CheckOutsGISInspektionsroutenList;
                mdescriptor.Inspektionsrouten = sdescriptor.Inspektionsrouten;
            }
            else
            {
                //mdescriptor.CheckOutsGISInspektionsroutenList = sdescriptor.CheckOutsGISInspektionsroutenList.Where(kvp => kvp.Value == layerService.getActiveInspektionsroute()).ToList();
                //mdescriptor.Inspektionsrouten = sdescriptor.Inspektionsrouten.Where(kvp => kvp.Key == layerService.getActiveInspektionsroute()).ToList();
                mdescriptor.CheckOutsGISInspektionsroutenList = sdescriptor.CheckOutsGISInspektionsroutenList.Where(kvp => kvp.Value == formService.GetActiveInspektionsRoute()).ToList();
                mdescriptor.Inspektionsrouten = sdescriptor.Inspektionsrouten.Where(kvp => kvp.Key == formService.GetActiveInspektionsRoute()).ToList();
            }

            mdescriptor.CurrentCulture = sdescriptor.CurrentCulture;


            mdescriptor.Version = PackageVersioner.GetClientPackageVersion();

            string tempExportDirectory = Path.Combine(clientConfigurationProvider.ExportPackageFolderPath, Guid.NewGuid().ToString());

            EnsurePackageFolder(tempExportDirectory);
            DTOContainer dtoContainer = exportService.Export(tempExportDirectory, exportAll);

            string[] allfilePaths = Directory.GetFiles(tempExportDirectory, "*",
                                                       SearchOption.AllDirectories);



            var dtofileNames = allfilePaths.Where(p => Path.GetExtension(p) == ".model");

            mdescriptor.FileCount.Add(new XMLKeyValuePair <string, int>(".model", dtofileNames.Count()));

            var fileNames = dtofileNames;

            XmlSerializer xmlSerializer           = new XmlSerializer(typeof(ClientPackageDescriptor));
            Stream        packageDescriptorStream = new MemoryStream();

            xmlSerializer.Serialize(packageDescriptorStream, mdescriptor);
            packageDescriptorStream.Seek(0, 0);


            try
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                using (var zipFile = new ZipFile(file))
                {
                    zipFile.AddFiles(fileNames, false, string.Empty);
                    zipFile.AddEntry(FileNameConstants.ClientPackageDescriptorFileName, packageDescriptorStream);
                    zipFile.Save(file);
                }

                if (exportAll)
                {
                    //Delete the Inspektionsrouten entries in the Packagedescriptor lying in the Working Dir (CurrentTemporaryFolder),
                    //OnApplicationExiting there is a Save (copy WorkingDir to PackageDir =>If there are no Inspektionsrouten, then the PackageDir will be deleted)

                    var descriptor = GetSeverpackageDescriptor(Directory.GetFiles(clientConfigurationProvider.CurrentTemporaryFolder, FileNameConstants.ServerPackageDescriptorFileName,
                                                                                  SearchOption.AllDirectories).SingleOrDefault());
                    descriptor.Inspektionsrouten.Clear();
                    xmlSerializer           = new XmlSerializer(typeof(ServerPackageDescriptor));
                    packageDescriptorStream = new System.IO.FileStream(Path.Combine(clientConfigurationProvider.CurrentTemporaryFolder, FileNameConstants.ServerPackageDescriptorFileName), FileMode.Create, FileAccess.ReadWrite);
                    xmlSerializer.Serialize(packageDescriptorStream, descriptor);
                    packageDescriptorStream.Close();

                    loadService.ClearAll(true);
                }
                else
                {
                    foreach (var dto in dtoContainer.DataTransferObjects)
                    {
                        dtoService.DeleteDTO(dto.Id);
                    }


                    //Delete the to be exported Inspektionsroute in the Shape Files

                    //Delete the Inspektionsrouten entries in the Packagedescriptor lying in the Working Dir (CurrentTemporaryFolder)
                    var descriptor = GetSeverpackageDescriptor(Directory.GetFiles(clientConfigurationProvider.CurrentTemporaryFolder, FileNameConstants.ServerPackageDescriptorFileName,
                                                                                  SearchOption.AllDirectories).SingleOrDefault());



                    descriptor.Inspektionsrouten.Remove(descriptor.Inspektionsrouten.Where(ir => ir.Key == formService.GetActiveInspektionsRoute()).SingleOrDefault());
                    descriptor.CheckOutsGISInspektionsroutenList.Remove(descriptor.CheckOutsGISInspektionsroutenList.Where(ir => ir.Value == formService.GetActiveInspektionsRoute()).SingleOrDefault());


                    xmlSerializer           = new XmlSerializer(typeof(ServerPackageDescriptor));
                    packageDescriptorStream = new System.IO.FileStream(Path.Combine(clientConfigurationProvider.CurrentTemporaryFolder, FileNameConstants.ServerPackageDescriptorFileName), FileMode.Create, FileAccess.ReadWrite);
                    xmlSerializer.Serialize(packageDescriptorStream, descriptor);
                    packageDescriptorStream.Close();



                    //Delete the Inspektionsroute from the Dictionary for displaying
                    //all changes to an Observable Collection must be done by the same Thread it was created by, becaus of Thread Affinity
                    Action action = new Action(() => { loadService.InspektionsroutenDictionary.Remove(loadService.InspektionsroutenDictionary.Where(ir => ir.Key == formService.GetActiveInspektionsRoute()).SingleOrDefault()); });
                    Application.Current.Dispatcher.Invoke(action);
                    if (descriptor.Inspektionsrouten.IsEmpty())
                    {
                        loadService.ClearAll(true);
                    }



                    //Let Map know about the export
                    IEnumerable <AchsenSegmentDTO>        achsenSegmente = dtoService.Get <AchsenSegmentDTO>();
                    IEnumerable <StrassenabschnittGISDTO> strabs         = dtoService.Get <StrassenabschnittGISDTO>();
                    IEnumerable <ZustandsabschnittGISDTO> zabs           = dtoService.Get <ZustandsabschnittGISDTO>();

                    string achsString  = geoJsonService.GenerateGeoJsonStringFromEntities(achsenSegmente);
                    string strabString = geoJsonService.GenerateGeoJsonStringFromEntities(strabs);
                    string zabString   = geoJsonService.GenerateGeoJsonStringFromEntities(zabs);

                    DataChangedEventArgs args = new DataChangedEventArgs();
                    args.AchsenGeoJson = achsString;
                    args.StrabsGeoJson = strabString;
                    args.ZabsGeoJson   = zabString;
                    sdescriptor.LayerConfig.ForEach(c => c.BasePath = clientConfigurationProvider.TileFolder);
                    args.LayerInfo = sdescriptor.LayerConfig;
                    args.ActiveInspectionRouteId = formService.GetActiveInspektionsRoute();
                    MobileLocalization localization = LocalizationLocator.MobileLocalization;
                    foreach (var propertyInfo in typeof(MobileLocalization).GetProperties())
                    {
                        if (propertyInfo.CanRead)
                        {
                            args.MobileLocalization.Add(propertyInfo.Name, propertyInfo.GetValue(localization, null).ToString());
                        }
                    }
                    string[] sldPaths;
                    if (clientConfigurationProvider.UseLocalFiles)
                    {
                        sldPaths = Directory.GetFiles(".\\Mobile\\style\\sld", "*.sld", SearchOption.TopDirectoryOnly);
                    }
                    else
                    {
                        sldPaths = Directory.GetFiles(Path.Combine(clientConfigurationProvider.MobilePackageFolder, "style\\sld"), "*.sld", SearchOption.TopDirectoryOnly);
                    }

                    string[] sldcontent = new string[sldPaths.Length];
                    int      i          = 0;
                    foreach (string sldpath in sldPaths)
                    {
                        StringBuilder sb = new StringBuilder();
                        using (StreamReader sr = new StreamReader(sldpath))
                        {
                            String line;
                            while ((line = sr.ReadLine()) != null)
                            {
                                sb.AppendLine(line);
                            }
                        }
                        sldcontent[i] = sb.ToString();
                    }
                    args.Slds = sldcontent;
                    formService.OnDataChanged(args);
                }

                messageBoxService.Information(LocalizationLocator.MobileLocalization.SuccessfullExport);
            }
            catch (EmsgException ex)
            {
                Loggers.TechLogger.ErrorException(ex.Message, ex);
                messageBoxService.Information(ex.Message);
            }
            catch (Exception ex)
            {
                Loggers.TechLogger.ErrorException(ex.Message, ex);
                messageBoxService.Information(LocalizationLocator.MobileLocalization.ExportError);
            }
        }