private void BuildDefaultDocument() { _doc = new OdbcConfigurationDocument(); var xmlDoc = new XmlDocument(); XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable); mgr.AddNamespace("xs", XmlNamespaces.XS); //NOXLATE mgr.AddNamespace("xsi", XmlNamespaces.XSI); //NOXLATE mgr.AddNamespace("fdo", XmlNamespaces.FDO); //NOXLATE mgr.AddNamespace("gml", XmlNamespaces.GML); //NOXLATE mgr.AddNamespace("xlink", XmlNamespaces.XLINK); //NOXLATE mgr.AddNamespace("fds", XmlNamespaces.FDS); //NOXLATE //This may have changed, so reapply var props = Use64BitDriver ? this.ChildEditor.Get64BitConnectionProperties() : this.ChildEditor.ConnectionProperties; _fs.ApplyConnectionProperties(props); _service.SyncSessionCopy(); try { var schemaName = _service.CurrentConnection.FeatureService.GetSchemas(_fs.ResourceID)[0]; var classNames = _service.CurrentConnection.FeatureService.GetClassNames(_fs.ResourceID, schemaName); var diag = new FilteredLogicalSchemaDialog(classNames); if (diag.ShowDialog() == DialogResult.Cancel) { throw new ApplicationException(Strings.TextNoItemSelected); } var names = diag.ClassNames; BusyWaitDelegate worker = () => { classNames = names.Select(x => x.Contains(":") ? x.Split(':')[1] : x).ToArray(); //NOXLATE var schema = _service.CurrentConnection.FeatureService.DescribeFeatureSourcePartial(_fs.ResourceID, schemaName, classNames); _doc.AddSchema(schema); //Only one schema is supported by ODBC so this is ok var scList = _service.CurrentConnection.FeatureService.GetSpatialContextInfo(_fs.ResourceID, false); foreach (var sc in scList.SpatialContext) { _doc.AddSpatialContext(sc); } return(null); }; BusyWaitDialog.Run(Strings.TextPreparingConfigurationDocument, worker, (obj, ex) => { if (ex != null) { throw ex; } //Done }); } catch (Exception ex) { _doc = null; MessageBox.Show(ex.Message); } }
internal BusyWaitDialog(BusyWaitDelegate action, CultureInfo culture) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); _action = action; _culture = culture; }
/// <summary> /// Previews the specified resource /// </summary> /// <param name="res">The resource to be previewed</param> /// <param name="edSvc">The editor service</param> /// <param name="locale">The locale to use if launching a viewer-based preview</param> public void Preview(IResource res, IEditorService edSvc, string locale) { //TODO: Prompt for symbol parameters if there are any, as these can affect the rendered output //and it is a nice way to test symbol parameters wrt to rendering IServerConnection conn = edSvc.CurrentConnection; BusyWaitDelegate worker = () => { //Save the current resource to another session copy string resId = "Session:" + edSvc.SessionID + "//" + res.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + res.ResourceType.ToString(); //NOXLATE var resSvc = edSvc.CurrentConnection.ResourceService; resSvc.SaveResourceAs(res, resId); resSvc.CopyResource(res.ResourceID, resId, true); var previewCopy = resSvc.GetResource(resId); if (previewCopy.ResourceType == ResourceTypes.SymbolDefinition.ToString() && conn.SiteVersion >= new Version(2, 0)) { return(GenerateSymbolDefinitionPreview(conn, previewCopy, 100, 100)); } else { //Now feed it to the preview engine var url = new ResourcePreviewEngine(edSvc).GeneratePreviewUrl(previewCopy, locale); return(new UrlPreviewResult() { Url = url }); } }; Action <object, Exception> onComplete = (result, ex) => { if (ex != null) { ErrorDialog.Show(ex); } else { var urlResult = result as UrlPreviewResult; var imgResult = result as ImagePreviewResult; if (urlResult != null) { var url = urlResult.Url; _launcher.OpenUrl(url); } else if (imgResult != null) { new SymbolPreviewDialog(imgResult.ImagePreview).Show(null); } } }; BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete); }
/// <summary> /// Uploads the file. /// </summary> /// <param name="fileName">Name of the file.</param> public void UploadFile(string fileName) { //TODO: Obviously support progress BusyWaitDelegate method = () => { DoFileUpload(fileName); return(null); }; BusyWaitDialog.Run(Strings.TextUploading, method, (obj, ex) => { LoadResourceData(); OnDataListChanged(); this.ResourceDataUploaded?.Invoke(Path.GetFileName(fileName), fileName); }); }
/// <summary> /// Performs any pre-save validation logic. The base implementation performs /// a <see cref="ResourceValidatorSet"/> validation (non-casccading) on the /// edited resource before attempting a save into the session repository /// (triggering any errors relating to invalid XML content). Override this /// method if the base implementation just described does not cover your /// validation needs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void OnBeforeSave(object sender, CancelEventArgs e) { //We've been editing an in-memory model of the session copy //so we need to save this model back to the session copy before Save() //commits the changes back to the original resource _svc.UpdateResourceContent(GetXmlContent()); try { var validate = PropertyService.Get(ConfigProperties.ValidateOnSave, true); if (this.IsDirty && validate) { BusyWaitDelegate del = () => { var errors = new List <ValidationIssue>(ValidateEditedResource()).ToArray(); return(errors); }; BusyWaitDialog.Run(Strings.PrgPreSaveValidation, del, (result, ex) => { if (ex != null) { throw ex; } ValidationIssue[] errors = result as ValidationIssue[]; if (errors.Length > 0) { MessageService.ShowError(Strings.FixErrorsBeforeSaving); ValidationResultsDialog diag = new ValidationResultsDialog(this.Resource.ResourceID, errors, OpenAffectedResource); diag.ShowDialog(Workbench.Instance); e.Cancel = true; } else { e.Cancel = false; } }); } else { LoggingService.Info("Skipping validation on save"); //NOXLATE e.Cancel = false; } } catch (Exception ex) { ErrorDialog.Show(ex); e.Cancel = true; } }
private void lnkViewer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { TreeNode root = MapTree.SelectedNode; while (root.Parent != null) { root = root.Parent; } IMapDefinition mdf = root.Tag as IMapDefinition; if (mdf != null) { BusyWaitDelegate worker = () => { IMappingService mapSvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping); var rtMap = mapSvc.CreateMap(mdf); return(rtMap); }; Action <object, Exception> onComplete = (obj, ex) => { if (ex != null) { throw ex; } if (obj != null) { var rtMap = (RuntimeMap)obj; using (var diag = new MapExtentsDialog(rtMap)) { if (diag.ShowDialog() == DialogResult.OK) { var env = diag.GetEnvelope(); txtLowerX.Text = env.MinX.ToString(CultureInfo.InvariantCulture); txtLowerY.Text = env.MinY.ToString(CultureInfo.InvariantCulture); txtUpperX.Text = env.MaxX.ToString(CultureInfo.InvariantCulture); txtUpperY.Text = env.MaxY.ToString(CultureInfo.InvariantCulture); } } } }; BusyWaitDialog.Run(Strings.PreparingMap, worker, onComplete); } }
/// <summary> /// Opens a modal dialog to execute the given delegate in a background worker /// </summary> /// <param name="message"></param> /// <param name="action"></param> /// <param name="onComplete"></param> /// <param name="bPreserveThreadCulture"></param> public static void Run(string message, BusyWaitDelegate action, Action <object, Exception> onComplete, bool bPreserveThreadCulture) { if (action == null) { throw new ArgumentNullException(nameof(action)); //NOXLATE } if (onComplete == null) { throw new ArgumentNullException(nameof(onComplete)); //NOXLATE } var frm = new BusyWaitDialog(action, bPreserveThreadCulture ? Thread.CurrentThread.CurrentCulture : null); frm.lblBusy.Text = message; if (frm.ShowDialog() == DialogResult.OK) { onComplete.Invoke(frm.ReturnValue, frm.Error); } }
private void btnDownload_Click(object sender, EventArgs e) { var item = this.SelectedItem; if (item != null) { using (var save = DialogFactory.SaveFile()) { save.FileName = item.Name; if (save.ShowDialog() == DialogResult.OK) { var fn = save.FileName; try { //TODO: Obviously support progress BusyWaitDelegate method = () => { IResource res = _edSvc.GetEditedResource(); var stream = _edSvc.CurrentConnection.ResourceService.GetResourceData(res.ResourceID, item.Name); using (var fs = File.OpenWrite(fn)) { Utility.CopyStream(stream, fs); } return(null); }; BusyWaitDialog.Run(Strings.TextDownloading, method, (obj, ex) => { if (ex != null) { throw ex; } MessageBox.Show(string.Format(Strings.FileDownloaded, fn)); }); } catch (Exception ex) { MessageBox.Show(NestedExceptionMessageProcessor.GetFullMessage(ex), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
/// <summary> /// Opens a modal dialog to execute the given delegate in a background worker /// </summary> /// <param name="message"></param> /// <param name="action"></param> /// <param name="onComplete"></param> public static void Run(string message, BusyWaitDelegate action, Action <object, Exception> onComplete) { Run(message, action, onComplete, true); }
/// <summary> /// Previews the given resource /// </summary> /// <param name="res"></param> /// <param name="edSvc"></param> /// <param name="locale"></param> public void Preview(IResource res, IEditorService edSvc, string locale) { IServerConnection conn = edSvc.CurrentConnection; if (this.UseLocal && IsLocalPreviewableType(res) && SupportsMappingService(conn)) { BusyWaitDelegate worker = () => { IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); IMapDefinition previewMdf = null; switch (res.ResourceType) { case "LayerDefinition": { ILayerDefinition ldf = (ILayerDefinition)res; string layerName = string.Empty; if (edSvc.IsNew) { layerName = ResourceIdentifier.GetName(ldf.SubLayer.ResourceId); } else { layerName = ResourceIdentifier.GetName(edSvc.ResourceID); } previewMdf = ResourcePreviewEngine.CreateLayerPreviewMapDefinition(ldf, edSvc.SessionID, layerName, conn); } break; case "WatermarkDefinition": { previewMdf = Utility.CreateWatermarkPreviewMapDefinition((IWatermarkDefinition)res); } break; case "MapDefinition": { previewMdf = (IMapDefinition)res; } break; } if (string.IsNullOrEmpty(previewMdf.ResourceID)) { var sessionId = edSvc.SessionID; var mdfId = "Session:" + sessionId + "//" + Guid.NewGuid() + ".MapDefinition"; //NOXLATE conn.ResourceService.SaveResourceAs(previewMdf, mdfId); previewMdf.ResourceID = mdfId; } if (previewMdf != null) { return(mapSvc.CreateMap(previewMdf, false)); } else { return(null); } }; Action <object, Exception> onComplete = (obj, ex) => { if (ex != null) { throw ex; } if (obj != null) { var rtMap = (RuntimeMap)obj; if (_viewManager != null) { _viewManager.OpenContent(ViewRegion.Document, () => new MapPreviewViewContent(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID)); } else { var diag = new MapPreviewDialog(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID); diag.Show(null); } } else //Fallback, shouldn't happen { _inner.Preview(res, edSvc, locale); } }; BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete); } else { _inner.Preview(res, edSvc, locale); } }
/// <summary> /// Opens a modal dialog to execute the given delegate in a background worker /// </summary> /// <param name="message"></param> /// <param name="action"></param> /// <param name="onComplete"></param> public static void Run(string message, BusyWaitDelegate action, Action<object, Exception> onComplete) { Run(message, action, onComplete, true); }
/// <summary> /// Opens a modal dialog to execute the given delegate in a background worker /// </summary> /// <param name="message"></param> /// <param name="action"></param> /// <param name="onComplete"></param> /// <param name="bPreserveThreadCulture"></param> public static void Run(string message, BusyWaitDelegate action, Action<object, Exception> onComplete, bool bPreserveThreadCulture) { if (action == null) throw new ArgumentNullException("action"); //NOXLATE if (onComplete == null) throw new ArgumentNullException("onComplete"); //NOXLATE var frm = new BusyWaitDialog(action, bPreserveThreadCulture ? Thread.CurrentThread.CurrentCulture : null); frm.lblBusy.Text = message; if (frm.ShowDialog() == DialogResult.OK) { onComplete.Invoke(frm.ReturnValue, frm.Error); } }