private void ClearSchadenData()
        {
            foreach (var schadengruppeDto in schadengruppeDtos)
            {
                dtoService.DeleteDTO(schadengruppeDto);
            }

            foreach (var schadendetailDto in schadendetailDtos)
            {
                dtoService.DeleteDTO(schadendetailDto);
            }
        }
Exemplo n.º 2
0
        public void Save()
        {
            if (zustandsabschnittGisDto.MassnahmenvorschlagFahrbahnDTO == null)
            {
                zustandsabschnittGisDto.MassnahmenvorschlagFahrbahnDTO = new MassnahmenvorschlagDTO();
            }

            zustandsabschnittGisDto.MassnahmenvorschlagFahrbahnDTO.Dringlichkeit = Dringlichkeit;
            zustandsabschnittGisDto.MassnahmenvorschlagFahrbahnDTO.Typ           = Massnahmenvorschlag;

            if (IsManuel)
            {
                zustandsabschnittGisDto.Zustandsindex   = Zustandsindex ?? 0;
                zustandsabschnittGisDto.Erfassungsmodus = ZustandsErfassungsmodus;

                dtoService.CreateOrReplaceDTO(zustandsabschnittGisDto);

                //Clear Schadendetails
                var schadengruppeDtos = dtoService.Get <SchadengruppeDTO>().Where(sg => sg.ZustandsabschnittId == zustandsabschnittGisDto.Id).ToList();
                foreach (var schadengruppeDto in schadengruppeDtos)
                {
                    dtoService.DeleteDTO(schadengruppeDto);
                }

                var schadendetailDtos = dtoService.Get <SchadendetailDTO>().Where(sd => sd.ZustandsabschnittId == zustandsabschnittGisDto.Id).ToList();
                foreach (var schadendetailDto in schadendetailDtos)
                {
                    dtoService.DeleteDTO(schadendetailDto);
                }
            }
            else
            {
                zustandFahrbahnWindowViewModel.Save();
            }

            HasNoChanges = true;
        }
Exemplo n.º 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);
            }
        }