Exemple #1
0
        public void Load(string path, bool overwriteMobile = true, bool overwriteTiles = true)
        {
            Loggers.PerformanceLogger.Debug("Loading package from {0} started.", path);
            FileHelper.TryDeleteFiles(new DirectoryInfo(clientConfigurationProvider.TemporaryFolderPath));

            ClearAll();

            DirectoryInfo pathInfo = new DirectoryInfo(path);
            IEnumerable <DirectoryInfo> directoriesToCopy = pathInfo.GetDirectories().Where(di => di.Name != FileNameConstants.TileFolderName && di.Name != FileNameConstants.MobilePackageFolderName);
            IEnumerable <FileInfo>      filesToCopy       = pathInfo.EnumerateFiles();

            clientConfigurationProvider.CurrentTemporaryFolder = Path.Combine(clientConfigurationProvider.TemporaryFolderPath, Guid.NewGuid().ToString());
            foreach (DirectoryInfo dirinfo in directoriesToCopy)
            {
                FileHelper.CopyAll(dirinfo, new DirectoryInfo(clientConfigurationProvider.CurrentTemporaryFolder));
            }

            foreach (FileInfo fileinfo in filesToCopy)
            {
                fileinfo.CopyTo(Path.Combine(clientConfigurationProvider.CurrentTemporaryFolder, fileinfo.Name), true);
            }
            string[] allfilePaths = Directory.GetFiles(clientConfigurationProvider.CurrentTemporaryFolder, "*",
                                                       SearchOption.AllDirectories);
            var filePathsDTO = allfilePaths.Where(p => Path.GetExtension(p) == ".model");

            var filePathPackageDescriptor = allfilePaths.Where(p => Path.GetFileName(p) == FileNameConstants.ServerPackageDescriptorFileName).SingleOrDefault();

            PackageDescriptor = GetServerPackageDescriptor(filePathPackageDescriptor);

            Loggers.PerformanceLogger.Debug("Package consistency check started.");
            foreach (var filecount in PackageDescriptor.FileCount)
            {
                if (!((Directory.GetFiles(path, "*" + filecount.Key, SearchOption.AllDirectories).Count(s => s.EndsWith(filecount.Key))) == filecount.Value))
                {
                    throw new IncompletePackageException();
                }
            }
            Loggers.PerformanceLogger.Debug("Package consistency check finished.");

            DirectoryInfo tileDirectory = new DirectoryInfo(Path.Combine(path, FileNameConstants.TileFolderName));

            if (tileDirectory.Exists && overwriteTiles || (tileDirectory.Exists && !Directory.Exists(clientConfigurationProvider.TileFolder)))
            {
                FileHelper.CopyAll(tileDirectory, new DirectoryInfo(clientConfigurationProvider.TileFolder), (int progress, string text) => { this.progressService.Update(LocalizationLocator.MobileLocalization.CreateMapCache, progress); });
            }
            DirectoryInfo mobileDirectory = new DirectoryInfo(Path.Combine(path, FileNameConstants.MobilePackageFolderName));

            if ((mobileDirectory.Exists && overwriteMobile) || (mobileDirectory.Exists && !Directory.Exists(clientConfigurationProvider.MobilePackageFolder)))
            {
                FileHelper.CopyAll(mobileDirectory, new DirectoryInfo(clientConfigurationProvider.MobilePackageFolder));
                this.OnMobileChanged();
            }

            //all changes to an Observable Collection must be done by the same Thread it was created by, becaus of Thread Affinity
            Func <ObservableCollection <XMLKeyValuePair <Guid, string> > > func = new Func <ObservableCollection <XMLKeyValuePair <Guid, string> > >(PackageDescriptor.GetObservableCollection);

            InspektionsroutenDictionary = (ObservableCollection <XMLKeyValuePair <Guid, string> >)Application.Current.Dispatcher.Invoke(func);

            OnPackageDescriptorChanged(EventArgs.Empty);

            Loggers.PerformanceLogger.Debug("Loading Vector-Data started.");

            dtoService.LoadFile();

            //Vectorlayers
            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;
            PackageDescriptor.LayerConfig.ForEach(c => c.BasePath = clientConfigurationProvider.TileFolder);
            args.LayerInfo = PackageDescriptor.LayerConfig;
            args.ActiveInspectionRouteId = InspektionsroutenDictionary.First().Key;
            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();
                i++;
            }
            args.Slds = sldcontent;
            formService.OnDataChanged(args);
            Loggers.PerformanceLogger.Debug("Loading Vector-Data finished.");
            Loggers.PerformanceLogger.Debug("Package loaded");
            OnPackageLoaded();
        }
Exemple #2
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);
            }
        }