Example #1
0
        private static object FindInDataset(GxCatalog _catalog, string path, out int numberFound)
        {
            numberFound = 0;
            int lastBackslashIndex        = path.LastIndexOf('\\');
            int lastBackslashIndexPlusOne = lastBackslashIndex + 1;

            if (lastBackslashIndex == -1 || lastBackslashIndexPlusOne == path.Length)
            {
                return(null);
            }
            string dbName = path.Substring(0, lastBackslashIndex);
            string fcName = path.Substring(lastBackslashIndexPlusOne, path.Length - lastBackslashIndexPlusOne);
            object obj    = _catalog.GetObjectFromFullName(dbName, out numberFound);

            if (numberFound == 0)
            {
                return(null);
            }
            IGxObject geoObject;

            if (numberFound == 1)
            {
                geoObject = obj as IGxObject;
            }
            else
            {
                geoObject = ((IEnumGxObject)obj).Next(); //get the first and ignore the rest.
            }
            numberFound = 0;
            if (geoObject == null)
            {
                return(null);
            }
            IGxDatabase db = geoObject as IGxDatabase;

            if (db == null || db.Workspace == null)
            {
                return(null);
            }
            foreach (string dsName in GetFeatureDataSetNames(db.Workspace))
            {
                string newPath = dbName + "\\" + dsName + "\\" + fcName;
                obj = _catalog.GetObjectFromFullName(newPath, out numberFound);
                if (numberFound != 0)
                {
                    return(obj);
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Sets all the necessary references from the main view.
        /// </summary>
        /// <remarks>We don't use contructor injection here since most of other services use this one as a parameter.
        /// Perhaps property injection can be used.</remarks>
        internal void Init(
            IMainView mainView,
            IProjectService project,
            IConfigService configService,
            MapLegendPresenter mapLegendPresenter,
            OverviewPresenter overviewPresenter
            )
        {
            Logger.Current.Trace("Start AppContext.Init()");
            if (mainView == null)
            {
                throw new ArgumentNullException("mainView");
            }
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (mapLegendPresenter == null)
            {
                throw new ArgumentNullException("legendPresenter");
            }
            //初始化图例控件
            _mapLegendPresenter = mapLegendPresenter;
            var legend = _mapLegendPresenter.LegendControl;

            legend.LegendControl.SetBuddyControl(mainView.MapControl);


            // it's expected here that we are on the UI thread
            SynchronizationContext = SynchronizationContext.Current;

            PluginManager = Container.GetSingleton <IPluginManager>();
            Broadcaster   = Container.GetSingleton <IBroadcasterService>();
            Container.RegisterInstance <IMapControl2>(mainView.MapControl);

            MainView       = mainView;
            View           = new AppView(mainView, _styleService);
            _project       = project;
            _configService = configService;
            MainView.AddFrameworkControl(legend.LegendControl.Object);

            _overviewPresenter = overviewPresenter;
            _overviewPresenter.SetBuddyControl(mainView.MapControl);
            MainView.AddFrameworkControl(_overviewPresenter.OverviewControl);

            //  _map = mainView.Map;
            //
            //   Repository = repository;

            //  Legend.Lock();

            DockPanels = new DockPanelCollection(mainView.DockingManager, mainView as Form, Broadcaster, _styleService);

            //Menu到最后丢弃不用,Menu部分全部采用Ribbon
            RibbonMenu = RibbonFactory.InitMenus((RibbonControl)mainView.RibbonManager,
                                                 mainView.RibbonStatusBar as RibbonStatusBar);

            // Menu = MenuFactory.CreateMainMenu(mainView.RibbonManager,true);
            // Toolbars = MenuFactory.CreateMainToolbars(mainView.MenuManager);
            // StatusBar = MenuFactory.CreateStatusBar(mainView.RibbonStatusBar, PluginIdentity.Default);

            // _projectionDatabase.ReadFromExecutablePath(Application.ExecutablePath);

            // Repository.Initialize(this);

            // comment this line to prevent locator loading
            // may be useful for ocx debugging to not create additional
            // instance of map
            // _locator = new LocatorPresenter(_map);

            this.InitDocking();

            //YTHookHelper设置

            OperationStack  = new OperationStackClass();
            m_pStyleGallery = null;

            //Catalog配置
            GxCatalog = new GxCatalog();
            //GxSelection=new GxSelection();
            //if (this._gxSelection is IGxSelectionEvents)
            //{
            //    (this._gxSelection as IGxSelectionEvents).OnSelectionChanged += new OnSelectionChangedEventHandler(this.GxSelection_Changed);
            //}

            Initialized = true;
            Logger.Current.Trace("End AppContext.Init()");

            //为了减少修改,给ApplicationRef赋值
            ApplicationRef.AppContext = this;
        }
Example #3
0
        private static void LoadWithCatalog(string path)
        {
            Trace.TraceInformation("{0}:   Begin get ESRI Metadata With Catalog for {1}", DateTime.Now, path); Stopwatch time = new Stopwatch(); time.Start();

            if (_catalog == null)
            {
                _catalog = new GxCatalogClass(); // Fairly quick to return. May throw an exception.
            }
            if (_catalog == null)
            {
                throw new Exception("Unable to communicate with ArcCatalog");
            }

            int numberFound;

            //This takes a long time on the first call (loads up the ESRI libraries)
            //Not to worry, this is _always_ called inside an awaited Task.Run().
            Trace.TraceInformation("{0}:     Begin _catalog.GetObjectFromFullName({1}), elapsed ms = {2}", DateTime.Now, path, time.Elapsed.TotalMilliseconds); time.Reset(); time.Start();
            object obj = _catalog.GetObjectFromFullName(path, out numberFound);

            Trace.TraceInformation("{0}:     End   _catalog.GetObjectFromFullName({1}), elapsed ms = {2}", DateTime.Now, path, time.Elapsed.TotalMilliseconds); time.Reset(); time.Start();

            if (numberFound == 0)
            {
                // If the user does not have a folder connection to some point above this dataset,
                // then ArcGIS will not find the dataset.  Therefore:
                // try adding the root of path as a new folder connection, and trying again.
                _catalog.ConnectFolder(Path.GetPathRoot(path));
                obj = _catalog.GetObjectFromFullName(path, out numberFound);
                if (numberFound == 0)
                {
                    // TM2.2 stored the data path without the dataset, so
                    // database/dataset/featureclass was saved as just database/featureclass
                    // Therefore if we didn't find database/featureclass, try looking for database/*/featureclass
                    obj = FindInDataset(_catalog, path, out numberFound);
                }
                if (numberFound == 0)
                {
                    throw new ArgumentException("Path (" + path + ") not found");
                }
            }

            IGxObject geoObject;

            if (numberFound == 1)
            {
                geoObject = obj as IGxObject;
            }
            else
            {
                geoObject = ((IEnumGxObject)obj).Next(); //get the first and ignore the rest.
            }
            IPropertySet propertySet;

            if (geoObject is IMetadata)
            {
                propertySet = ((IMetadata)geoObject).Metadata;
            }
            else
            {
                throw new ArgumentException("Path (" + path + ") has no metadata");
            }

            if (!(propertySet is IXmlPropertySet2))
            {
                throw new ArgumentException("Path (" + path + ") metadata not available as XML");
            }
            string text = ((IXmlPropertySet2)propertySet).GetXml("");

            Trace.TraceInformation("{0}:   End   get ESRI Metadata With Catalog for {1}, elapsed ms = {2}", DateTime.Now, path, time.Elapsed.TotalMilliseconds);
            _cache[path] = text;
            return;
        }