/// <summary> /// Constructor /// </summary> /// <param name="resId">The given resource, whose dependencies we want to re-point</param> /// <param name="resSvc">The resource service</param> public RepointerDialog(ResourceIdentifier resId, IResourceService resSvc) : this() { _resSvc = resSvc; txtSource.Text = resId.ToString(); this.ResourceType = resId.ResourceType; var dependents = resSvc.EnumerateResourceReferences(resId.ToString()); lstAffectedResources.DataSource = dependents.ResourceId; }
object UpdateConfigurationDocument(BackgroundWorker worker, DoWorkEventArgs e, params object[] args) { GdalConfigurationDocument conf = (GdalConfigurationDocument)args[0]; IServerConnection conn = (IServerConnection)args[1]; string [] toAdd = args[2] as string[]; string [] toRemove = args[3] as string[]; bool isAlias = (bool)args[4]; worker.ReportProgress(0, Strings.UpdatingConfiguration); int total = toAdd.Length + toRemove.Length; int unit = (total / 100); int progress = 0; var result = new UpdateConfigResult() { Added = new List<string>(), Removed = new List<string>() }; //Remove first foreach (var remove in toRemove) { string dir = null; if (isAlias) { dir = remove.Substring(0, remove.LastIndexOf("\\")); //NOXLATE } else { dir = Path.GetDirectoryName(remove); } var loc = FindLocation(conf, dir); if (null != loc) { string f = isAlias ? remove.Substring(remove.LastIndexOf("\\") + 1) : Path.GetFileName(remove); //NOXLATE loc.RemoveItem(f); result.Removed.Add(remove); if (loc.Items.Length == 0) conf.RemoveLocation(loc); } progress += unit; worker.ReportProgress(progress, string.Format(Strings.ProcessedItem, remove)); } //Then add foreach (var add in toAdd) { string dir = null; if (isAlias) { int idx = add.LastIndexOf("/"); //NOXLATE if (idx >= 0) dir = add.Substring(0, idx); else dir = add.Substring(0, add.LastIndexOf("%") + 1); //NOXLATE } else { dir = Path.GetDirectoryName(add); } var loc = conf.AddLocation(dir); //Create a temp feature source to attempt interrogation of extents var values = new NameValueCollection(); values["DefaultRasterFileLocation"] = add; //NOXLATE var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.Gdal", values); //NOXLATE var resId = new ResourceIdentifier("Session:" + conn.SessionID + "//" + Guid.NewGuid() + ".FeatureSource"); //NOXLATE fs.ResourceID = resId.ToString(); conn.ResourceService.SaveResource(fs); var scList = fs.GetSpatialInfo(false); var raster = new GdalRasterItem(); if (isAlias) { int idx = add.LastIndexOf("/"); //NOXLATE if (idx >= 0) raster.FileName = add.Substring(add.LastIndexOf("/") + 1); //NOXLATE else raster.FileName = add.Substring(add.LastIndexOf("%") + 1); //NOXLATE } else { raster.FileName = Path.GetFileName(add); } if (scList.SpatialContext.Count > 0) { raster.MinX = Convert.ToDouble(scList.SpatialContext[0].Extent.LowerLeftCoordinate.X, CultureInfo.InvariantCulture); raster.MinY = Convert.ToDouble(scList.SpatialContext[0].Extent.LowerLeftCoordinate.Y, CultureInfo.InvariantCulture); raster.MaxX = Convert.ToDouble(scList.SpatialContext[0].Extent.UpperRightCoordinate.X, CultureInfo.InvariantCulture); raster.MaxY = Convert.ToDouble(scList.SpatialContext[0].Extent.UpperRightCoordinate.Y, CultureInfo.InvariantCulture); } else { raster.MinX = -10000000; raster.MinY = -10000000; raster.MaxX = 10000000; raster.MaxY = 10000000; } loc.AddItem(raster); result.Added.Add(Path.Combine(dir, raster.FileName)); progress += unit; worker.ReportProgress(progress, string.Format(Strings.ProcessedItem, add)); } //Re-calculate combined extent for spatial context var env = conf.CalculateExtent(); if (env != null) conf.SpatialContexts[0].Extent = env; return result; }