コード例 #1
0
        private void SaveReportBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog.FileName, false))
                    {
                        foreach (KeyValuePair <string, ValidationIssue[]> p in m_issues)
                        {
                            if (p.Value.Length > 0)
                            {
                                sw.WriteLine(new string('*', 80)); //NOXLATE
                                sw.WriteLine(string.Format(Strings.ValidationProgressMessage, p.Key));
                                foreach (ValidationIssue i in p.Value)
                                {
                                    sw.WriteLine(string.Format(Strings.ValidationResultFormat, i.Status, i.StatusCode, i.Message));
                                }

                                sw.WriteLine();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.ValidationFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var items = this.SelectedItems;

            if (items.Length > 0)
            {
                if (MessageBox.Show(Strings.ConfirmDeleteResourceData, Strings.Confirm, MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                try
                {
                    using (new WaitCursor(this))
                    {
                        foreach (var item in items)
                        {
                            //_edSvc.RemoveResourceData(item.Name);
                            IResource res = _edSvc.GetEditedResource();
                            _edSvc.CurrentConnection.ResourceService.DeleteResourceData(res.ResourceID, item.Name);
                            _data.Remove(item);
                        }
                        BindResourceList();
                        OnDataListChanged();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(NestedExceptionMessageProcessor.GetFullMessage(ex), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #3
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (UseAlternateName.Checked && AlternateName.Text.Trim().Length == 0)
                {
                    MessageBox.Show(this, Strings.AlternateNameMissing, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AlternateName.Focus();
                    return;
                }

                if (UseHeader.Checked && !System.IO.File.Exists(HeaderPath.Text))
                {
                    MessageBox.Show(this, Strings.HeaderFileMissing, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    HeaderPath.Focus();
                    return;
                }

                if (!System.IO.File.Exists(ContentPath.Text))
                {
                    MessageBox.Show(this, Strings.ContentFileMissing, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ContentPath.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.FilenameValidationError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #4
0
        private void PackageEditor_Load(object sender, EventArgs e)
        {
            this.Show();

            try
            {
                m_resources = PackageProgress.ListPackageContents(this, _conn, m_filename);
                if (m_resources == null)
                {
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                    return;
                }

                RebuildTree();
            }
            catch (Exception ex)
            {
                if (ex is System.Reflection.TargetInvocationException && ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.PackageReadError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            OKBtn.Enabled = true;
        }
コード例 #5
0
        private void AutoGenerateWFSBounds_Click(object sender, EventArgs e)
        {
            try
            {
                m_isUpdating = true;
                System.Globalization.CultureInfo ic = System.Globalization.CultureInfo.InvariantCulture;
                IFeatureSource fs       = (IFeatureSource)m_connection.ResourceService.GetResource(m_resourceId);
                bool           failures = false;

                IEnvelope env  = null;
                var       desc = m_connection.FeatureService.DescribeFeatureSource(fs.ResourceID);
                foreach (ClassDefinition scm in desc.AllClasses)
                {
                    foreach (var col in scm.Properties)
                    {
                        if (col.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Geometry ||
                            col.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Raster)
                        {
                            try
                            {
                                IEnvelope re = m_connection.FeatureService.GetSpatialExtent(fs.ResourceID, scm.Name, col.Name, true);
                                if (env == null)
                                {
                                    env = re;
                                }
                                else
                                {
                                    env.ExpandToInclude(re);
                                }
                            }
                            catch
                            {
                                failures = true;
                            }
                        }
                    }
                }

                if (env == null)
                {
                    throw new Exception(failures ? Strings.ResProp_NoSpatialDataWithFailuresError : Strings.ResProp_NoSpatialDataError);
                }

                m_isUpdating   = false;
                WFSBounds.Text = "<Bounds west=\"" + env.MinX.ToString(ic) + "\" east=\"" + env.MaxX.ToString(ic) + "\" south=\"" + env.MinY.ToString(ic) + "\" north=\"" + env.MaxY.ToString(ic) + "\" />"; //NOXLATE
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.ResProp_WFSBoundsReadError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                m_isUpdating = false;
            }
        }
コード例 #6
0
        protected object BackgroundValidate(BackgroundWorker worker, DoWorkEventArgs e, params object[] args)
        {
            //Collect all documents to be validated. Some of these selected items
            //may be folders.
            var documents = new List <string>();
            var conn      = (IServerConnection)args[0];

            foreach (object a in args.Skip(1))
            {
                string rid = a.ToString();
                if (ResourceIdentifier.Validate(rid))
                {
                    var resId = new ResourceIdentifier(rid);
                    if (resId.IsFolder)
                    {
                        foreach (IRepositoryItem o in conn.ResourceService.GetRepositoryResources(rid).Children)
                        {
                            if (!o.IsFolder)
                            {
                                documents.Add(o.ResourceId);
                            }
                        }
                    }
                    else
                    {
                        documents.Add(rid);
                    }
                }
            }

            worker.ReportProgress(0);
            var context = new ResourceValidationContext(conn);

            var set = new ValidationResultSet();
            int i   = 0;

            foreach (string s in documents)
            {
                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
                IResource item = null;
                try
                {
                    item = conn.ResourceService.GetResource(s);
                    set.AddIssues(ResourceValidatorSet.Validate(context, item, true));
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    set.AddIssue(new ValidationIssue(item, ValidationStatus.Error, ValidationStatusCode.Error_General_ValidationError, string.Format("Failed to validate resource: {0}", msg)));
                }
                i++;
                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
            }

            return(set.GetAllIssues());
        }
コード例 #7
0
        private void btnBuild_Click(object sender, EventArgs e)
        {
            IServerConnection con = m_connection;

            try
            {
                TilingRunCollection bx = new TilingRunCollection(con);

                if (LimitTileset.Checked)
                {
                    if (MaxRowLimit.Value > 0)
                    {
                        bx.LimitRows((int)MaxRowLimit.Value);
                    }
                    if (MaxColLimit.Value > 0)
                    {
                        bx.LimitCols((int)MaxColLimit.Value);
                    }
                }

                bx.Config.MetersPerUnit = (double)MetersPerUnit.Value;

                bx.Config.ThreadCount           = (int)ThreadCount.Value;
                bx.Config.RandomizeTileSequence = RandomTileOrder.Checked;

                foreach (Config c in ReadTree())
                {
                    MapTilingConfiguration bm = new MapTilingConfiguration(bx, c.MapDefinition);
                    bm.SetGroups(c.Group);
                    bm.SetScalesAndExtend(c.ScaleIndexes, c.ExtentOverride);

                    bx.Maps.Add(bm);
                }

                if (bx.Maps.Count == 0)
                {
                    MessageBox.Show(Strings.NoMapsOrTileSetsSelected);
                    return;
                }

                Progress p = new Progress(bx);
                if (p.ShowDialog(this) != DialogResult.Cancel)
                {
                    var ts = p.TotalTime;
                    MessageBox.Show(string.Format(Strings.TileGenerationCompleted, ((ts.Days * 24) + ts.Hours), ts.Minutes, ts.Seconds));
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.InternalError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        private void SaveResourceData_Click(object sender, EventArgs e)
        {
            try
            {
                if (ResourceDataFileList.SelectedItems.Count != 1 || ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem == null)
                {
                    return;
                }

                SaveResourceDataFile.FileName = System.IO.Path.GetFileName((ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).Filename);

                if (SaveResourceDataFile.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                if ((ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).Filename == SaveResourceDataFile.FileName)
                {
                    return;
                }

                if ((ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).EntryType == EntryTypeEnum.Regular)
                {
                    using (ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(m_filename))
                    {
                        int index = FindZipEntry(zipfile, (ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).Filename);
                        if (index >= 0)
                        {
                            using (System.IO.FileStream fs = new System.IO.FileStream(SaveResourceDataFile.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                Utility.CopyStream(zipfile.GetInputStream(index), fs);
                        }
                    }
                }
                else if ((ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).EntryType == EntryTypeEnum.Added)
                {
                    System.IO.File.Copy((ResourceDataFileList.SelectedItems[0].Tag as ResourceDataItem).Filename, SaveResourceDataFile.FileName, true);
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.FileCopyError, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #9
0
        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);
                        }
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Validates the specified item using an existing validation context to skip over
        /// items already validated
        /// </summary>
        /// <param name="context"></param>
        /// <param name="item"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        public static ValidationIssue[] Validate(ResourceValidationContext context, IResource item, bool recurse)
        {
            Check.ArgumentNotNull(item, nameof(item));
            var issueSet = new ValidationResultSet();

            if (!HasValidator(item.ResourceType, item.ResourceVersion))
            {
                issueSet.AddIssue(new ValidationIssue(item, ValidationStatus.Warning, ValidationStatusCode.Warning_General_NoRegisteredValidatorForResource, string.Format(Strings.ERR_NO_REGISTERED_VALIDATOR, item.ResourceType, item.ResourceVersion)));
            }
            else
            {
                foreach (IResourceValidator v in m_validators)
                {
                    //Ensure the current connection is set before validating
                    v.Connection = context.Connection;

                    if (!v.SupportedResourceAndVersion.Equals(item.GetResourceTypeDescriptor()))
                    {
                        continue;
                    }

                    try
                    {
                        ValidationIssue[] tmp = v.Validate(context, item, recurse);
                        if (tmp != null)
                        {
                            issueSet.AddIssues(tmp);
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                        if (ex is NullReferenceException)
                        {
                            msg = ex.ToString();
                        }
                        issueSet.AddIssue(new ValidationIssue(item, ValidationStatus.Error, ValidationStatusCode.Error_General_ValidationError, string.Format(Strings.ErrorValidationGeneric, msg)));
                    }
                }
            }
            return(issueSet.GetAllIssues());
        }
コード例 #11
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (var open = DialogFactory.OpenFile())
     {
         open.Multiselect = true;
         if (open.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 foreach (var fileName in open.FileNames)
                 {
                     UploadFile(fileName);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(NestedExceptionMessageProcessor.GetFullMessage(ex), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
コード例 #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                try
                {
                    PreferedSite ps = null;

                    if (_selectedIndex == 0) //HTTP
                    {
                        var builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["Url"]                  = _http.Server;                                                                       //NOXLATE
                        builder["Username"]             = _http.Username;                                                                     //NOXLATE
                        builder["Password"]             = _http.Password;                                                                     //NOXLATE
                        builder["Locale"]               = _http.Language;                                                                     //NOXLATE
                        builder["AllowUntestedVersion"] = true;                                                                               //NOXLATE

                        string agent = "MapGuide Maestro v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //NOXLATE

                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", builder.ToString());                              //NOXLATE
                        _conn.SetCustomProperty("UserAgent", agent);                                                                          //NOXLATE

                        //Update preferred site entry if it exists
                        int index = 0;
                        foreach (PreferedSite s in _http.GetSites())
                        {
                            if (s.SiteURL == _http.Server)
                            {
                                ps = s;
                                break;
                            }
                            else
                            {
                                index++;
                            }
                        }

                        if (ps == null)
                        {
                            ps = new PreferedSite();
                        }

                        if (ps.ApprovedVersion == null)
                        {
                            ps.ApprovedVersion = new Version(0, 0, 0, 0);
                        }

                        if (_conn.SiteVersion > _conn.MaxTestedVersion && _conn.SiteVersion > ps.ApprovedVersion)
                        {
                            if (MessageBox.Show(this, Strings.UntestedServerVersion, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) != DialogResult.Yes)
                            {
                                return;
                            }
                        }

                        try
                        {
                            ps.SiteURL         = _http.Server;
                            ps.StartingPoint   = _http.StartingPoint;
                            ps.Username        = _http.Username;
                            ps.SavePassword    = chkSavePassword.Checked;
                            ps.ApprovedVersion = ps.ApprovedVersion > _conn.SiteVersion ? ps.ApprovedVersion : _conn.SiteVersion;
                            if (ps.SavePassword)
                            {
                                ps.UnscrambledPassword = _http.Password;
                            }
                            else
                            {
                                ps.ScrambledPassword = string.Empty;
                            }

                            if (index >= _siteList.Sites.Length)
                            {
                                _siteList.AddSite(ps);
                            }

                            //_siteList.AutoConnect = chkAutoConnect.Checked;
                            _siteList.PreferedSite = index;
                            var ci = _http.SelectedCulture;
                            if (ci != null)
                            {
                                _siteList.GUILanguage = ci.Name;
                            }
                            _siteList.Save();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else if (_selectedIndex == 1) //Native
                    {
                        System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["ConfigFile"] = LocalNativeLoginCtrl.LastIniPath;                                         //NOXLATE
                        builder["Username"]   = _localNative.Username;                                                    //NOXLATE
                        builder["Password"]   = _localNative.Password;                                                    //NOXLATE
                        builder["Locale"]     = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName; //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", builder.ToString());   //NOXLATE
                    }
                    else //Local
                    {
                        NameValueCollection param = new NameValueCollection();
                        param["ConfigFile"] = LocalLoginCtrl.LastIniPath;                            //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Local", param); //NOXLATE
                    }

                    _conn.AutoRestartSession = true;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (TargetInvocationException ex)
                {
                    //We don't care about the outer exception
                    string msg = ex.InnerException.Message;
                    if (msg.IndexOf("MgConnectionFailedException") >= 0)
                    {
                        new ConnectionErrorDialog().ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    if (msg.IndexOf("MgConnectionFailedException") >= 0)
                    {
                        new ConnectionErrorDialog().ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
コード例 #13
0
        public BoundsPicker(string bounds, string[] coordsys)
            : this()
        {
            m_bounds = bounds;

            if (coordsys == null)
            {
                SRSLabel.Visible     =
                    SRSCombo.Visible =
                        false;
                this.Height -= 30;
            }
            else
            {
                SRSCombo.Items.AddRange(coordsys);
            }

            if (!string.IsNullOrEmpty(bounds))
            {
                try
                {
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    if (bounds.Trim().StartsWith("&lt;")) //NOXLATE
                    {
                        bounds = System.Web.HttpUtility.HtmlDecode(bounds);
                    }
                    bounds = $"<root>{bounds}</root>";                              //NOXLATE
                    doc.LoadXml(bounds);
                    System.Xml.XmlNode root = doc["root"];                          //NOXLATE
                    if (root["Bounds"] != null)                                     //NOXLATE
                    {
                        if (root["Bounds"].Attributes["SRS"] != null)               //NOXLATE
                        {
                            SRSCombo.Text = root["Bounds"].Attributes["SRS"].Value; //NOXLATE
                        }
                        if (root["Bounds"].Attributes["west"] != null)              //NOXLATE
                        {
                            MinX.Text = root["Bounds"].Attributes["west"].Value;    //NOXLATE
                        }
                        if (root["Bounds"].Attributes["east"] != null)              //NOXLATE
                        {
                            MaxX.Text = root["Bounds"].Attributes["east"].Value;    //NOXLATE
                        }
                        if (root["Bounds"].Attributes["south"] != null)             //NOXLATE
                        {
                            MinY.Text = root["Bounds"].Attributes["south"].Value;   //NOXLATE
                        }
                        if (root["Bounds"].Attributes["north"] != null)             //NOXLATE
                        {
                            MaxY.Text = root["Bounds"].Attributes["north"].Value;   //NOXLATE
                        }
                    }
                    else
                    {
                        throw new Exception(Strings.BoundsPicker_MissingBoundsError);
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    MessageBox.Show(this, string.Format(Strings.BoundsPicker_BoundsDecodeError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #14
0
        private void LookupValues_Click(object sender, EventArgs e)
        {
            //Use UNIQUE() method first. This should work in most cases
            using (new WaitCursor(this))
            {
                string filter    = null;
                var    expr      = $"UNIQUE({ColumnName.Text})"; //NOXLATE
                bool   bFallback = false;
                ColumnValue.Items.Clear();
                ColumnValue.Tag = null;
                try
                {
                    using (var rdr = _featSvc.AggregateQueryFeatureSource(m_featureSource, _cls.QualifiedName, filter, new System.Collections.Specialized.NameValueCollection()
                    {
                        { UNIQ_VALS, expr }
                    }))
                    {
                        ColumnValue.Tag = rdr.GetPropertyType(UNIQ_VALS);
                        while (rdr.ReadNext())
                        {
                            if (!rdr.IsNull(UNIQ_VALS))
                            {
                                object value = rdr[UNIQ_VALS];
                                ColumnValue.Items.Add(value);
                            }
                        }
                        rdr.Close();
                    }
                }
                catch
                {
                    ColumnValue.Items.Clear();
                    bFallback = true;
                }
                if (!bFallback)
                {
                    ColumnValue.Enabled       = true;
                    ColumnValue.SelectedIndex = -1;
                    ColumnValue.DroppedDown   = true;
                    return;
                }

                try
                {
                    SortedList <string, PropertyDefinition> cols = (SortedList <string, PropertyDefinition>)ColumnName.Tag;
                    PropertyDefinition col = cols[ColumnName.Text];

                    bool      retry = true;
                    Exception rawEx = null;

                    SortedList <string, string> values = new SortedList <string, string>();
                    bool hasNull = false;

                    while (retry)
                    {
                        try
                        {
                            retry = false;
                            using (var rd = _featSvc.QueryFeatureSource(m_featureSource, _cls.QualifiedName, filter, new string[] { ColumnName.Text }))
                            {
                                while (rd.ReadNext())
                                {
                                    if (rd.IsNull(ColumnName.Text))
                                    {
                                        hasNull = true;
                                    }
                                    else
                                    {
                                        values[Convert.ToString(rd[ColumnName.Text], System.Globalization.CultureInfo.InvariantCulture)] = null;
                                    }
                                }
                                rd.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            if (filter == null && ex.Message.IndexOf("MgNullPropertyValueException") >= 0) //NOXLATE
                            {
                                hasNull = true;
                                rawEx   = ex;
                                retry   = true;
                                filter  = $"{ColumnName.Text} != NULL"; //NOXLATE
                            }
                            else if (rawEx != null)
                            {
                                throw rawEx;
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }

                    ColumnValue.Items.Clear();
                    if (hasNull)
                    {
                        ColumnValue.Items.Add("NULL"); //NOXLATE
                    }
                    foreach (string s in values.Keys)
                    {
                        ColumnValue.Items.Add(s);
                    }

                    ColumnValue.Tag = col.Type;

                    if (ColumnValue.Items.Count == 0)
                    {
                        MessageBox.Show(this, Strings.NoColumnValuesError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        ColumnValue.Enabled       = true;
                        ColumnValue.SelectedIndex = -1;
                        ColumnValue.DroppedDown   = true;
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    MessageBox.Show(this, string.Format(Strings.ColumnValueError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Performs base validation logic
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        protected static ValidationIssue[] ValidateBase(ResourceValidationContext context, IResource resource, bool recurse)
        {
            Check.ArgumentNotNull(context, nameof(context));

            if (context.IsAlreadyValidated(resource.ResourceID))
            {
                return(null);
            }

            if (resource.ResourceType != ResourceTypes.WebLayout.ToString())
            {
                return(null);
            }

            List <ValidationIssue> issues = new List <ValidationIssue>();

            IWebLayout layout = resource as IWebLayout;

            if (layout.Map == null || layout.Map.ResourceId == null)
            {
                issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_MissingMap, string.Format(Strings.WL_MissingMapError)));
            }
            else
            {
                //Check for duplicate command names
                var cmdSet = layout.CommandSet;
                Dictionary <string, ICommand> cmds = new Dictionary <string, ICommand>();
                foreach (ICommand cmd in cmdSet.Commands)
                {
                    if (cmds.ContainsKey(cmd.Name))
                    {
                        issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_DuplicateCommandName, string.Format(Strings.WL_DuplicateCommandName, cmd.Name)));
                    }
                    else
                    {
                        cmds[cmd.Name] = cmd;
                    }
                }

                //Check for duplicate property references in search commands
                foreach (ISearchCommand search in cmdSet.Commands.OfType <ISearchCommand>())
                {
                    Dictionary <string, string> resColProps = new Dictionary <string, string>();
                    foreach (IResultColumn resCol in search.ResultColumns.Column)
                    {
                        if (resColProps.ContainsKey(resCol.Property))
                        {
                            issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_DuplicateSearchCommandResultColumn, string.Format(Strings.WL_DuplicateSearchResultColumn, search.Name, resCol.Property)));
                        }
                        else
                        {
                            resColProps.Add(resCol.Property, resCol.Property);
                        }
                    }
                }

                //Check for command references to non-existent commands
                foreach (IUIItem item in layout.ContextMenu.Items)
                {
                    if (item.Function == UIItemFunctionType.Command)
                    {
                        ICommandItem cmdRef = (ICommandItem)item;
                        if (!cmds.ContainsKey(cmdRef.Command))
                        {
                            issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_NonExistentContextMenuCommandReference, string.Format(Strings.WL_NonExistentMenuCommandReference, cmdRef.Command)));
                        }
                    }
                }

                foreach (IUIItem item in layout.TaskPane.TaskBar.Items)
                {
                    if (item.Function == UIItemFunctionType.Command)
                    {
                        ICommandItem cmdRef = (ICommandItem)item;
                        if (!cmds.ContainsKey(cmdRef.Command))
                        {
                            issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_NonExistentTaskPaneCommandReference, string.Format(Strings.WL_NonExistentTaskPaneCommandReference, cmdRef.Command)));
                        }
                    }
                }

                foreach (IUIItem item in layout.ToolBar.Items)
                {
                    if (item.Function == UIItemFunctionType.Command)
                    {
                        ICommandItem cmdRef = (ICommandItem)item;
                        if (!cmds.ContainsKey(cmdRef.Command))
                        {
                            issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_NonExistentToolbarCommandReference, string.Format(Strings.WL_NonExistentToolbarCommandReference, cmdRef.Command)));
                        }
                    }
                }

                try
                {
                    IMapDefinition mdef = (IMapDefinition)context.GetResource(layout.Map.ResourceId);
                    if (layout.Map.InitialView != null)
                    {
                        var mapEnv = ObjectFactory.CreateEnvelope(mdef.Extents.MinX, mdef.Extents.MinY, mdef.Extents.MaxX, mdef.Extents.MaxY);
                        if (!mapEnv.Contains(layout.Map.InitialView.CenterX, layout.Map.InitialView.CenterY))
                        {
                            issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Warning_WebLayout_InitialViewOutsideMapExtents, string.Format(Strings.WL_StartViewOutsideExtentsWarning)));
                        }
                    }

                    if (recurse)
                    {
                        issues.AddRange(ResourceValidatorSet.Validate(context, mdef, true));
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(layout, ValidationStatus.Error, ValidationStatusCode.Error_WebLayout_Generic, string.Format(Strings.WL_MapValidationError, layout.Map.ResourceId, msg)));
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }
コード例 #16
0
        /// <summary>
        /// Performs base resource validation
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        protected ValidationIssue[] ValidateBase(ResourceValidationContext context, IResource resource, bool recurse)
        {
            Check.ArgumentNotNull(context, nameof(context));

            if (context.IsAlreadyValidated(resource.ResourceID))
            {
                return(null);
            }

            if (resource.ResourceType != ResourceTypes.MapDefinition.ToString())
            {
                return(null);
            }

            List <ValidationIssue> issues = new List <ValidationIssue>();

            IMapDefinition mdef = resource as IMapDefinition;

            if (string.IsNullOrEmpty(mdef.CoordinateSystem))
            {
                issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_MissingCoordinateSystem, Strings.MDF_NoCoordinateSystem));
            }

            foreach (IMapLayerGroup g in mdef.MapLayerGroup)
            {
                if (g.ShowInLegend && (g.LegendLabel == null || g.LegendLabel.Trim().Length == 0))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_GroupMissingLabelInformation, string.Format(Strings.MDF_GroupMissingLabelInformation, g.Name)));
                }
                else if (g.ShowInLegend && g.LegendLabel.Trim().ToLower() == "layer group") //NOXLATE
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_GroupHasDefaultLabel, string.Format(Strings.MDF_GroupHasDefaultLabelInformation, g.Name)));
                }

                if (!string.IsNullOrEmpty(g.Group))
                {
                    var grp = mdef.GetGroupByName(g.Group);
                    if (grp == null)
                    {
                        issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_GroupWithNonExistentGroup, string.Format(Strings.MDF_GroupWithNonExistentGroup, g.Name, g.Group)));
                    }
                }
            }

            List <IBaseMapLayer> layers = new List <IBaseMapLayer>();

            foreach (IBaseMapLayer l in mdef.MapLayer)
            {
                layers.Add(l);
            }

            if (mdef.BaseMap != null && mdef.BaseMap.HasGroups())
            {
                if (mdef.BaseMap.ScaleCount == 0)
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_NoFiniteDisplayScales, Strings.MDF_NoFiniteDisplayScalesSpecified));
                }

                foreach (IBaseMapGroup g in mdef.BaseMap.BaseMapLayerGroups)
                {
                    foreach (IBaseMapLayer l in g.BaseMapLayer)
                    {
                        layers.Add(l);
                    }
                }
            }
            Dictionary <string, IBaseMapLayer> nameCounter = new Dictionary <string, IBaseMapLayer>();

            foreach (IBaseMapLayer l in layers)
            {
                if (nameCounter.ContainsKey(l.Name))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Error_MapDefinition_DuplicateLayerName, string.Format(Strings.MDF_LayerNameDuplicateWarning, l.Name, l.ResourceId, nameCounter[l.Name].ResourceId)));
                }
                else
                {
                    nameCounter.Add(l.Name, l);
                }

                var ml = l as IMapLayer;
                if (ml != null && !string.IsNullOrEmpty(ml.Group))
                {
                    var grp = mdef.GetGroupByName(ml.Group);
                    if (grp == null)
                    {
                        issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_LayerWithNonExistentGroup, string.Format(Strings.MDF_LayerWithNonExistentGroup, ml.Name, ml.Group)));
                    }
                }

                if (l.ShowInLegend && (string.IsNullOrEmpty(l.LegendLabel) || l.LegendLabel.Trim().Length == 0))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Warning_MapDefinition_LayerMissingLegendLabel, string.Format(Strings.MDF_LayerMissingLabelInformation, l.Name)));
                }

                var mapEnv = ObjectFactory.CreateEnvelope(mdef.Extents.MinX, mdef.Extents.MinY, mdef.Extents.MaxX, mdef.Extents.MaxY);

                try
                {
                    ILayerDefinition layer = null;
                    IResource        res   = context.GetResource(l.ResourceId);
                    if (!ResourceValidatorSet.HasValidator(res.ResourceType, res.ResourceVersion))
                    {
                        //Need to trap the no registered validator message
                        issues.AddRange(ResourceValidatorSet.Validate(context, res, true));
                        continue;
                    }

                    layer = (ILayerDefinition)res;
                    if (recurse)
                    {
                        issues.AddRange(ResourceValidatorSet.Validate(context, layer, recurse));
                    }

                    IVectorLayerDefinition vl = null;
                    if (layer.SubLayer.LayerType == LayerType.Vector)
                    {
                        vl = (IVectorLayerDefinition)layer.SubLayer;
                    }

                    if (vl != null)
                    {
                        try
                        {
                            IFeatureSource fs = (IFeatureSource)context.GetResource(vl.ResourceId);
                            if (l.Selectable)
                            {
                                //Test selectability requirement
                                string[] idProps = fs.GetIdentityProperties(this.Connection, vl.FeatureName);
                                if (idProps == null || idProps.Length == 0)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_UnselectableLayer, string.Format(Strings.MDF_UnselectableLayer, l.Name, vl.FeatureName, fs.ResourceID)));
                                }
                            }

                            try
                            {
                                FdoSpatialContextList scList = context.GetSpatialContexts(fs.ResourceID);

                                if (scList.SpatialContext == null || scList.SpatialContext.Count == 0)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_MissingSpatialContext, string.Format(Strings.MDF_MissingSpatialContextWarning, fs.ResourceID)));
                                }
                                else
                                {
                                    if (scList.SpatialContext.Count > 1)
                                    {
                                        issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_MultipleSpatialContexts, string.Format(Strings.MDF_MultipleSpatialContextsInformation, fs.ResourceID)));
                                    }

                                    bool skipGeomCheck = false;

                                    //TODO: Switch to the correct version (2.1), once released
                                    if (scList.SpatialContext[0].CoordinateSystemWkt != mdef.CoordinateSystem)
                                    {
                                        if (layer.SubLayer.LayerType == LayerType.Raster && this.Connection.SiteVersion <= SiteVersions.GetVersion(OSGeo.MapGuide.MaestroAPI.KnownSiteVersions.MapGuideOS2_0_2))
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_RasterReprojection, string.Format(Strings.MDF_RasterReprojectionError, fs.ResourceID)));
                                        }
                                        else
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_LayerReprojection, string.Format(Strings.MDF_DataReprojectionWarning, fs.ResourceID)));
                                        }

                                        skipGeomCheck = true;
                                    }

                                    if (vl.Geometry != null && !skipGeomCheck)
                                    {
                                        var env = this.Connection.FeatureService.GetSpatialExtent(fs.ResourceID, vl.FeatureName, vl.Geometry);
                                        if (!env.Intersects(mapEnv))
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_DataOutsideMapBounds, string.Format(Strings.MDF_DataOutsideMapWarning, fs.ResourceID)));
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var nex = ex as NullExtentException;
                                if (nex != null)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_FeatureSourceWithNullExtent, string.Format(Strings.MDF_LayerWithNullExtent, fs.ResourceID)));
                                }
                                else
                                {
                                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_ResourceRead, string.Format(Strings.MDF_ResourceReadError, fs.ResourceID, msg)));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                            issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_FeatureSourceRead, string.Format(Strings.MDF_FeatureSourceReadError, l.ResourceId, msg)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_LayerRead, string.Format(Strings.MDF_LayerReadError, l.ResourceId, msg)));
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }
コード例 #17
0
        private void CreateThemeButton_Click(object sender, EventArgs e)
        {
            try
            {
                IVectorStyle owner = null;

                if (m_point != null)
                {
                    owner = m_point;
                }
                else if (m_line != null)
                {
                    owner = m_line;
                }
                else if (m_area != null)
                {
                    owner = m_area;
                }
                else if (m_comp != null)
                {
                    owner = m_comp;
                }

                if (owner is ICompositeTypeStyle)
                {
                    MessageBox.Show(Strings.CannotCreateThemeForCompositeStyleClassicEditor);
                    return;
                }

                ILayerDefinition       layer = (ILayerDefinition)m_owner.Editor.GetEditedResource();
                IVectorLayerDefinition vl    = (IVectorLayerDefinition)layer.SubLayer;
                if (string.IsNullOrEmpty(vl.FeatureName))
                {
                    MessageBox.Show(Strings.NoFeatureClassAssigned);
                    return;
                }
                var cls = m_owner.Editor.CurrentConnection.FeatureService.GetClassDefinition(vl.ResourceId, vl.FeatureName);
                if (cls == null)
                {
                    MessageBox.Show(string.Format(Strings.FeatureClassNotFound, vl.FeatureName));
                    return;
                }
                ThemeCreator dlg = new ThemeCreator(
                    m_owner.Editor,
                    layer,
                    m_owner.SelectedClass,
                    owner);
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    var area  = owner as IAreaVectorStyle;
                    var point = owner as IPointVectorStyle;
                    var line  = owner as ILineVectorStyle;
                    if (area != null)
                    {
                        SetItem(m_parent, area);
                    }
                    else if (point != null)
                    {
                        SetItem(m_parent, point);
                    }
                    else if (line != null)
                    {
                        SetItem(m_parent, line);
                    }

                    m_owner.HasChanged();
                    m_owner.UpdateDisplay();
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                m_owner.SetLastException(ex);
                MessageBox.Show(this, string.Format(Strings.GenericError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #18
0
        /// <summary>
        /// Validats the specified resources for common issues associated with this
        /// resource type
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        public ValidationIssue[] Validate(ResourceValidationContext context, IResource resource, bool recurse)
        {
            if (resource.ResourceType != ResourceTypes.ApplicationDefinition.ToString())
            {
                return(null);
            }

            //TODO: Other items to check for
            //
            // - References to non-existent widgets
            // - MapWidget checks
            //   - Ensure map id checks out
            //   - Ensure context menu id checks out
            // - Verify containers of template are all referenced within this flexible layout
            // - Check required parameters of widgets are satisfied

            List <ValidationIssue> issues = new List <ValidationIssue>();

            IApplicationDefinition fusionApp = resource as IApplicationDefinition;

            if (fusionApp.MapSet == null || fusionApp.MapSet.MapGroupCount == 0)
            {
                issues.Add(new ValidationIssue(fusionApp, ValidationStatus.Error, ValidationStatusCode.Error_Fusion_MissingMap, string.Format(Strings.ADF_MapMissingError)));
            }
            else
            {
                foreach (IMapGroup mapGroup in fusionApp.MapSet.MapGroups)
                {
                    bool checkCmsProjection = false;
                    List <IMapDefinition> mapDefsInGroup = new List <IMapDefinition>();
                    foreach (IMap map in mapGroup.Map)
                    {
                        if (IsCommercialOverlay(map))
                        {
                            checkCmsProjection = true;
                        }
                        if (map.Type.ToLower() == "virtualearth")
                        {
                            //As of July 1, 2017 we need an API key on Bing Maps
                            var bingMapsKey = fusionApp.GetValue("BingMapKey");
                            if (string.IsNullOrEmpty(bingMapsKey))
                            {
                                issues.Add(new ValidationIssue(fusionApp, ValidationStatus.Error, ValidationStatusCode.Error_Fusion_BingMapsMissingApiKey, Strings.ADF_BingMapsMissingApiKey));
                            }

                            //If this is still referencing the "Hybrid" base layer type, that no longer exists in the v8 API
                            if (map.CmsMapOptions.Type == "Hybrid")
                            {
                                issues.Add(new ValidationIssue(fusionApp, ValidationStatus.Error, ValidationStatusCode.Error_Fusion_BingMapsHybridBaseLayerNoLongerAvailable, Strings.ADF_BingMapsHybridLayerNoLongerAvailable));
                            }
                        }
                        try
                        {
                            if (map.Type.ToLower() == "mapguide") //NOXLATE
                            {
                                var mdfId = map.GetMapDefinition();
                                if (string.IsNullOrEmpty(mdfId) || !this.Connection.ResourceService.ResourceExists(mdfId))
                                {
                                    issues.Add(new ValidationIssue(fusionApp, ValidationStatus.Error, ValidationStatusCode.Error_Fusion_InvalidMap, string.Format(Strings.ADF_MapInvalidError, mapGroup.id)));
                                }
                                else
                                {
                                    IMapDefinition mdef = (IMapDefinition)context.GetResource(mdfId);
                                    mapDefsInGroup.Add(mdef);

                                    IEnvelope mapEnv = ObjectFactory.CreateEnvelope(mdef.Extents.MinX, mdef.Extents.MinY, mdef.Extents.MaxX, mdef.Extents.MaxY);

                                    if (mapGroup.InitialView != null)
                                    {
                                        if (!mapEnv.Contains(mapGroup.InitialView.CenterX, mapGroup.InitialView.CenterY))
                                        {
                                            issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Warning_Fusion_InitialViewOutsideMapExtents, string.Format(Strings.ADF_ViewOutsideMapExtents)));
                                        }
                                    }

                                    if (recurse)
                                    {
                                        issues.AddRange(ResourceValidatorSet.Validate(context, mdef, recurse));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                            issues.Add(new ValidationIssue(fusionApp, ValidationStatus.Error, ValidationStatusCode.Error_Fusion_MapValidationError, string.Format(Strings.ADF_MapValidationError, mapGroup.id, msg)));
                        }
                    }

                    if (checkCmsProjection)
                    {
                        foreach (var mdf in mapDefsInGroup)
                        {
                            var wkt    = mdf.CoordinateSystem;
                            var csCode = this.Connection.CoordinateSystemCatalog.ConvertWktToCoordinateSystemCode(wkt);
                            if (csCode.ToUpper() != "WGS84.PSEUDOMERCATOR") //NOXLATE
                            {
                                issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_Fusion_MapCoordSysIncompatibleWithCommericalLayers, string.Format(Strings.ADF_MapWithIncompatibleCommericalCs, mdf.ResourceID)));
                            }
                        }
                    }
                }
            }

            //Check labels of referenced widgets
            foreach (var wset in fusionApp.WidgetSets)
            {
                foreach (var cnt in wset.Containers)
                {
                    var menu = cnt as IMenu;
                    if (menu != null)
                    {
                        ValidateWidgetReferencesForMenu(fusionApp, menu, issues, context, resource);
                    }
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }
コード例 #19
0
        private void AutoGenerateWMSBounds_Click(object sender, EventArgs e)
        {
            try
            {
                m_isUpdating = true;
                string srs        = "EPSG:????"; //NOXLATE
                string bounds     = WMSBounds.Text;
                bool   warnedEPSG = false;

                try
                {
                    if (!string.IsNullOrEmpty(bounds))
                    {
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                        if (bounds.Trim().StartsWith("&lt;")) //NOXLATE
                        {
                            bounds = System.Web.HttpUtility.HtmlDecode(bounds);
                        }
                        bounds = "<root>" + bounds + "</root>";               //NOXLATE
                        doc.LoadXml(bounds);
                        System.Xml.XmlNode root = doc["root"];                //NOXLATE
                        if (root["Bounds"] != null)                           //NOXLATE
                        {
                            if (root["Bounds"].Attributes["SRS"] != null)     //NOXLATE
                            {
                                srs = root["Bounds"].Attributes["SRS"].Value; //NOXLATE
                            }
                        }
                        else
                        {
                            throw new Exception(Strings.ResProp_MissingBoundsError);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    warnedEPSG = true;
                    MessageBox.Show(this, string.Format(Strings.ResProp_BoundsDecodeError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                System.Globalization.CultureInfo ic = System.Globalization.CultureInfo.InvariantCulture;
                ILayerDefinition ldef = (ILayerDefinition)m_connection.ResourceService.GetResource(m_resourceId);
                string           csWkt;
                var env  = ldef.GetSpatialExtent(m_connection, true, out csWkt);
                var epsg = m_connection.CoordinateSystemCatalog.ConvertWktToEpsgCode(csWkt);
                if (!string.IsNullOrEmpty(epsg) && epsg != "0")
                {
                    if (epsg != "4326")
                    {
                        var targetWkt = m_connection.CoordinateSystemCatalog.ConvertEpsgCodeToWkt("4326"); //NOXLATE
                        env  = Utility.TransformEnvelope(env, csWkt, targetWkt);
                        epsg = "4326";
                    }

                    srs = $"EPSG:{epsg}";
                }

                //TODO: Convert to lon/lat

                bounds  = $"<Bounds west=\"{env.MinX.ToString(ic)}\" east=\"{env.MaxX.ToString(ic)}\" south=\"{env.MinY.ToString(ic)}\" north=\"{env.MaxY.ToString(ic)}\" "; //NOXLATE
                bounds += $" SRS=\"{srs}\"";                                                                                                                                 //NOXLATE
                bounds += " />";                                                                                                                                             //NOXLATE

                m_isUpdating   = false;
                WMSBounds.Text = bounds;

                if ((srs == string.Empty || srs == "EPSG:????") && !warnedEPSG) //NOXLATE
                {
                    MessageBox.Show(this, Strings.ResProp_EpsgMissingWarning, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    WMSBounds.SelectionStart  = WMSBounds.Text.IndexOf("SRS=\"") + "SRS=\"".Length; //NOXLATE
                    WMSBounds.SelectionLength = WMSBounds.Text.IndexOf("\"", WMSBounds.SelectionStart) - WMSBounds.SelectionStart;
                    WMSBounds.ScrollToCaret();
                    WMSBounds.Focus();
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.ResProp_WMSBoundsReadError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                m_isUpdating = false;
            }
        }
コード例 #20
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            m_openResource = null;

            try
            {
                //Update security info
                if (m_resourceId.IsFolder)
                {
                    m_folderHeader.Security.Inherited = UseInherited.Checked;
                    if (m_folderHeader.Security.Inherited)
                    {
                        m_folderHeader.Security.Groups = null;
                        m_folderHeader.Security.Users  = null;
                    }
                    else
                    {
                        m_folderHeader.Security.Groups = ObjectFactory.CreateSecurityGroup();
                        m_folderHeader.Security.Users  = ObjectFactory.CreateSecurityUser();
                        //m_folderHeader.Security.Groups.Group = new ResourceSecurityTypeGroupsGroupCollection();
                        //m_folderHeader.Security.Users.User = new ResourceSecurityTypeUsersUserCollection();
                        ReadSecurityData(m_folderHeader.Security.Groups.Group, m_folderHeader.Security.Users.User);
                    }
                }
                else
                {
                    m_resourceHeader.Security.Inherited = UseInherited.Checked;
                    if (m_resourceHeader.Security.Inherited)
                    {
                        m_resourceHeader.Security.Groups = null;
                        m_resourceHeader.Security.Users  = null;
                    }
                    else
                    {
                        m_resourceHeader.Security.Groups = ObjectFactory.CreateSecurityGroup();
                        m_resourceHeader.Security.Users  = ObjectFactory.CreateSecurityUser();
                        //m_resourceHeader.Security.Groups.Group = new ResourceSecurityTypeGroupsGroupCollection();
                        //m_resourceHeader.Security.Users.User = new ResourceSecurityTypeUsersUserCollection();
                        ReadSecurityData(m_resourceHeader.Security.Groups.Group, m_resourceHeader.Security.Users.User);
                    }
                }

                //Save header
                if (m_resourceId.IsFolder)
                {
                    m_connection.ResourceService.SetFolderHeader(m_resourceId, m_folderHeader);
                }
                else
                {
                    m_connection.ResourceService.SetResourceHeader(m_resourceId, m_resourceHeader);
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.ResProp_SaveError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #21
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            SavePackageDialog.FileName = m_filename;
            if (SavePackageDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            //Preparation: Update all resources with the correct path, and build a list with them
            List <ResourceItem> items = new List <ResourceItem>();

            try
            {
                ResourceTree.PathSeparator = "/";
                ResourceTree.Nodes[0].Text = "Library:/";

                Queue <TreeNode> nl = new Queue <TreeNode>();
                foreach (TreeNode n in ResourceTree.Nodes[0].Nodes)
                {
                    nl.Enqueue(n);
                }

                while (nl.Count > 0)
                {
                    TreeNode n = nl.Dequeue();
                    foreach (TreeNode tn in n.Nodes)
                    {
                        nl.Enqueue(tn);
                    }

                    if (n.Tag as ResourceItem != null && (n.Tag as ResourceItem).EntryType != EntryTypeEnum.Deleted)
                    {
                        ResourceItem ri = new ResourceItem(n.Tag as ResourceItem);
                        ri.ResourcePath = n.FullPath + (ri.IsFolder ? "/" : "");
                        if (string.IsNullOrEmpty(ri.OriginalResourcePath))
                        {
                            ri.OriginalResourcePath = ri.ResourcePath;
                        }

                        items.Add(ri);
                    }
                }
            }
            finally
            {
                ResourceTree.Nodes[0].Text = "Library://";
            }

            try
            {
                if (PackageProgress.RebuildPackage(this, _conn, m_filename, items, SavePackageDialog.FileName, InsertDeleteCommands.Checked) != DialogResult.OK)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                if (ex is System.Reflection.TargetInvocationException && ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.PackageBuildError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #22
0
        /// <summary>
        /// Validats the specified resources for common issues associated with this
        /// resource type
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        public ValidationIssue[] Validate(ResourceValidationContext context, IResource resource, bool recurse)
        {
            Check.ArgumentNotNull(context, nameof(context));

            if (context.IsAlreadyValidated(resource.ResourceID))
            {
                return(null);
            }

            if (resource.ResourceType != ResourceTypes.FeatureSource.ToString())
            {
                return(null);
            }

            List <ValidationIssue> issues = new List <ValidationIssue>();

            IFeatureSource  feature = (IFeatureSource)resource;
            IFeatureService featSvc = this.Connection.FeatureService;

            //Feature Join Optimization check
            foreach (var ext in feature.Extension)
            {
                foreach (var rel in ext.AttributeRelate)
                {
                    if (string.IsNullOrEmpty(rel.Name))
                    {
                        issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_EmptyJoinPrefix, string.Format(Strings.FS_EmptyJoinPrefix, ext.Name)));
                    }

                    if (rel.RelatePropertyCount > 0)
                    {
                        if (rel.RelatePropertyCount == 1)
                        {
                            var srcFs = feature;
                            var dstFs = (IFeatureSource)context.GetResource(rel.ResourceId);

                            var leftProvider  = srcFs.Provider.ToUpper();
                            var rightProvider = dstFs.Provider.ToUpper();

                            //FDO Join optimization check
                            if (leftProvider.Contains("OSGEO.SQLITE") && rightProvider.Contains("OSGEO.SQLITE") && srcFs.ResourceID == rel.ResourceId) //NOXLATE
                            {
                                continue;
                            }

                            //FDO Join optimization check
                            if (leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") && rightProvider.Contains("OSGEO.SQLSERVERSPATIAL") && srcFs.ResourceID == rel.ResourceId) //NOXLATE
                            {
                                continue;
                            }

                            //TODO: Fix the capabilities response. Because it's not telling us enough information!
                            //Anyways, these are the providers known to provide sorted query results.
                            bool bLeftSortable = leftProvider.Contains("OSGEO.SDF") ||               //NOXLATE
                                                 leftProvider.Contains("OSGEO.SHP") ||               //NOXLATE
                                                 leftProvider.Contains("OSGEO.SQLITE") ||            //NOXLATE
                                                 leftProvider.Contains("OSGEO.ODBC") ||              //NOXLATE
                                                 leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") ||  //NOXLATE
                                                 leftProvider.Contains("OSGEO.MYSQL") ||             //NOXLATE
                                                 leftProvider.Contains("OSGEO.POSTGRESQL");          //NOXLATE

                            bool bRightSortable = leftProvider.Contains("OSGEO.SDF") ||              //NOXLATE
                                                  leftProvider.Contains("OSGEO.SHP") ||              //NOXLATE
                                                  leftProvider.Contains("OSGEO.SQLITE") ||           //NOXLATE
                                                  leftProvider.Contains("OSGEO.ODBC") ||             //NOXLATE
                                                  leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") || //NOXLATE
                                                  leftProvider.Contains("OSGEO.MYSQL") ||            //NOXLATE
                                                  leftProvider.Contains("OSGEO.POSTGRESQL");         //NOXLATE

                            if (!bLeftSortable || !bRightSortable)
                            {
                                issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Potential_Bad_Join_Performance, string.Format(Strings.FS_PotentialBadJoinPerformance, ext.Name, bLeftSortable, bRightSortable)));
                            }
                        }
                        else
                        {
                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Potential_Bad_Join_Performance, string.Format(Strings.FS_PotentialBadJoinPerformance2, ext.Name)));
                        }
                    }
                }
            }

            //Plaintext credential check
            string providerNameUpper = feature.Provider.ToUpper();
            string fsXml             = feature.Serialize().ToUpper();

            //You'll get warnings either way
            if (providerNameUpper == "OSGEO.SQLSERVERSPATIAL" || //NOXLATE
                providerNameUpper == "OSGEO.MYSQL" ||            //NOXLATE
                providerNameUpper == "OSGEO.POSTGRESQL" ||       //NOXLATE
                providerNameUpper == "OSGEO.ODBC" ||             //NOXLATE
                providerNameUpper == "OSGEO.ARCSDE" ||           //NOXLATE
                providerNameUpper == "OSGEO.WFS" ||              //NOXLATE
                providerNameUpper == "OSGEO.WMS" ||              //NOXLATE
                providerNameUpper == "KING.ORACLE" ||            //NOXLATE
                providerNameUpper == "AUTODESK.ORACLE")          //NOXLATE
            {
                //Fortunately, all the above providers are universal in the naming choice of credential connection parameters
                if ((fsXml.Contains("<NAME>USERNAME</NAME>") && !fsXml.Contains(StringConstants.MgUsernamePlaceholder)) || (fsXml.Contains("<NAME>PASSWORD</NAME>") && !fsXml.Contains(StringConstants.MgPasswordPlaceholder))) //NOXLATE
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Plaintext_Credentials, Strings.FS_PlaintextCredentials));
                }
                else
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Cannot_Package_Secured_Credentials, Strings.FS_CannotPackageSecuredCredentials));
                }

                //Has the placeholder token(s)
                if (fsXml.Contains(StringConstants.MgUsernamePlaceholder) || fsXml.Contains(StringConstants.MgPasswordPlaceholder))
                {
                    //Find the MG_USER_CREDENTIALS resource data item
                    bool bFound  = false;
                    var  resData = this.Connection.ResourceService.EnumerateResourceData(feature.ResourceID);
                    foreach (var data in resData.ResourceData)
                    {
                        if (data.Name == StringConstants.MgUserCredentialsResourceData)
                        {
                            bFound = true;
                        }
                    }

                    if (!bFound)
                    {
                        issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SecuredCredentialTokensWithoutSecuredCredentialData, Strings.FS_SecuredCredentialTokensWithoutSecuredCredentialData));
                    }
                }
            }

            //Note: Must be saved!
            string s = featSvc.TestConnection(feature.ResourceID);

            if (s.Trim().ToUpper() != true.ToString().ToUpper())
            {
                issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_ConnectionTestFailed, string.Format(Strings.FS_ConnectionTestFailed, s)));
                return(issues.ToArray());
            }

            try
            {
                System.Globalization.CultureInfo ci  = System.Globalization.CultureInfo.InvariantCulture;
                FdoSpatialContextList            lst = context.GetSpatialContexts(feature.ResourceID);
                if (lst == null || lst.SpatialContext == null || lst.SpatialContext.Count == 0)
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_NoSpatialContext, Strings.FS_NoSpatialContextWarning));
                }
                else
                {
                    foreach (FdoSpatialContextListSpatialContext c in lst.SpatialContext)
                    {
                        if (c.Extent == null || c.Extent.LowerLeftCoordinate == null || c.Extent.UpperRightCoordinate == null)
                        {
                            issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_EmptySpatialContext, Strings.FS_EmptySpatialContextWarning));
                        }
                        else if (double.Parse(c.Extent.LowerLeftCoordinate.X, ci) <= -1000000 && double.Parse(c.Extent.LowerLeftCoordinate.Y, ci) <= -1000000 && double.Parse(c.Extent.UpperRightCoordinate.X, ci) >= 1000000 && double.Parse(c.Extent.UpperRightCoordinate.Y, ci) >= 1000000)
                        {
                            issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_DefaultSpatialContext, Strings.FS_DefaultSpatialContextWarning));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SpatialContextReadError, string.Format(Strings.FS_SpatialContextReadError, msg)));
            }

            List <string> classes = new List <string>();

            try
            {
                var schemaNames = featSvc.GetSchemas(feature.ResourceID);
                if (schemaNames.Length == 0)
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_NoSchemasFound, Strings.FS_SchemasMissingWarning));
                }
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex != null) //Most likely timeout due to really large schema
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Validation_Timeout, string.Format(Strings.FS_ValidationTimeout, msg)));
                }
                else
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SchemaReadError, string.Format(Strings.FS_SchemaReadError, msg)));
                }
            }

            string configDocXml = feature.GetConfigurationContent(Connection);

            if (!string.IsNullOrEmpty(configDocXml))
            {
                var doc     = ConfigurationDocument.LoadXml(configDocXml);
                var odbcDoc = doc as OdbcConfigurationDocument;
                if (odbcDoc != null)
                {
                    issues.AddRange(ValidateOdbcDoc(feature, odbcDoc));
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }