private void Window_Loaded(object sender, RoutedEventArgs e) { ProjectionsState state = GetStateByProj4ProjectionParameters(proj4Parameters); if (state is CommonProjectionsState) { tabControl.SelectedIndex = 0; CommonProjectionsState commonProjectionsState = (CommonProjectionsState)state; commonProjectionViewModel.SelectedUnitType = commonProjectionsState.SelectedUnit; commonProjectionViewModel.SelectedProj4ProjectionParameters = commonProjectionsState.ProjectionParameters; commonProjectionViewModel.SelectedProjectionType = commonProjectionsState.SelectedProjection; commonProjectionViewModel.SelectedDatumType = commonProjectionsState.SelectedDatum; commonProjectionViewModel.SelectedZone = commonProjectionViewModel.SupportedZones[commonProjectionsState.SelectedZoneIndex]; } else if (state is CustomProjectionsState) { tabControl.SelectedIndex = 1; CustomProjectionsState customProjectionsState = (CustomProjectionsState)state; otherProjectionViewModel.SelectedProjectionType = customProjectionsState.SelectedSearchProjectionType; if (customProjectionsState.SelectedProj4ModelIndex > 0) { otherProjectionViewModel.SelectedProj4Model = otherProjectionViewModel.SearchedResult[customProjectionsState.SelectedProj4ModelIndex]; } if (otherProjectionViewModel.SelectedProj4Model != null) { otherProjectionViewModel.SelectedProj4Model.Proj4Parameter = customProjectionsState.ProjectionParameters; Proj4ParameterTextBox.Text = customProjectionsState.ProjectionParameters; otherProjection.SearchedResultListView.ScrollIntoView(otherProjectionViewModel.SelectedProj4Model); } } }
private static ProjectionsState GetStateByProj4ProjectionParameters(string proj4ProjectionParameters) { string xmlPathFileName = Path.Combine(GisEditor.InfrastructureManager.TemporaryPath, "Projections", "State.xml"); if (File.Exists(xmlPathFileName)) { XElement rootX = XElement.Load(xmlPathFileName); IEnumerable <XElement> statesX = rootX.Elements("state"); foreach (var item in statesX) { if (item.FirstAttribute.Value.Equals(proj4ProjectionParameters)) { XElement commonProjectionsStateX = item.Element("common"); XElement customProjectionsStateX = item.Element("custom"); if (commonProjectionsStateX != null) { string parameters = item.FirstAttribute.Value; string value = commonProjectionsStateX.Value; string[] values = value.Split(','); string projection = values[0]; string datum = values[1]; string zone = values[2]; string unit = values[3]; CommonProjectionsState state = new CommonProjectionsState(parameters); state.SelectedDatum = (DatumType)Enum.Parse(typeof(DatumType), datum); state.SelectedProjection = (ProjectionType)Enum.Parse(typeof(ProjectionType), projection); state.SelectedUnit = (UnitType)Enum.Parse(typeof(UnitType), unit); state.SelectedZoneIndex = int.Parse(zone); return(state); } else if (customProjectionsStateX != null) { string parameters = item.FirstAttribute.Value; string value = customProjectionsStateX.Value; string[] values = value.Split(','); string searchProjectionType = values[0]; string proj4Model = values[1]; CustomProjectionsState state = new CustomProjectionsState(parameters); state.SelectedSearchProjectionType = (SearchProjectionType)int.Parse(searchProjectionType); state.SelectedProj4ModelIndex = int.Parse(proj4Model); return(state); } } } } return(null); }