Ejemplo n.º 1
0
        public static MsSqlServerDataRepositoryItem GetMsSqlServerDataRepositoryItem(MsSql2008FeatureLayerInfo configureInfo)
        {
            MsSqlServerDataRepositoryItem serverItem = new MsSqlServerDataRepositoryItem();

            SyncToServerItem(configureInfo, serverItem);
            return(serverItem);
        }
Ejemplo n.º 2
0
        public DatabaseTreeViewModel(MsSql2008FeatureLayerInfo model)
        {
            children = new ObservableCollection <DataRepositoryItem>();
            MsSqlServerDataRepositoryItem serverItem = MsSqlServerDataRepositoryPlugin.GetMsSqlServerDataRepositoryItem(model);

            Children.Add(serverItem);
            if (Children.Count > 0)
            {
                Children[0].IsSelected = true;
            }
        }
Ejemplo n.º 3
0
        private void AddServer()
        {
            MsSqlServerConfigureWindow configureWindow = new MsSqlServerConfigureWindow();

            configureWindow.Owner = Application.Current.MainWindow;
            configureWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            MsSql2008FeatureLayerInfo model = new MsSql2008FeatureLayerInfo();

            configureWindow.SetSource(model);
            if (configureWindow.ShowDialog().GetValueOrDefault())
            {
                MsSqlServerDataRepositoryItem serverItem = GetMsSqlServerDataRepositoryItem(model);
                serverItem.Parent = rootItem;
                rootItem.Children.Add(serverItem);
                GisEditor.InfrastructureManager.SaveSettings(this);
            }
        }
Ejemplo n.º 4
0
        private Collection <MsSqlFeatureLayer> GetMsSql2008FeatureLayers()
        {
            if (LayerInfo != null)
            {
                MsSqlServerDataRepositoryItem serverItem = Parent.Parent.Parent.Parent.Parent as MsSqlServerDataRepositoryItem;
                if (serverItem != null)
                {
                    LayerInfo.TableName    = TableName;
                    LayerInfo.DatabaseName = DatabaseName;
                    LayerInfo.SchemaName   = SchemaName;
                    Collection <string>   newColumnNames        = LayerInfo.CollectColumnsFromTable();
                    FeatureIdColumnWindow featureIdColumnWindow = new FeatureIdColumnWindow(newColumnNames);
                    featureIdColumnWindow.Owner = Application.Current.MainWindow;
                    featureIdColumnWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    if (featureIdColumnWindow.ShowDialog().GetValueOrDefault())
                    {
                        GetLayersParameters layerParameters = new GetLayersParameters();
                        layerParameters.CustomData["TableName"]    = TableName;
                        layerParameters.CustomData["SchemaName"]   = SchemaName;
                        layerParameters.CustomData["DatabaseName"] = DatabaseName;
                        layerParameters.CustomData["IdColumn"]     = featureIdColumnWindow.FeatureIdColumn;
                        layerParameters.CustomData["ServerName"]   = serverItem.Name;
                        layerParameters.CustomData["UserName"]     = serverItem.UserName;
                        layerParameters.CustomData["Password"]     = serverItem.Password;

                        Collection <MsSqlFeatureLayer> newLayers = new Collection <MsSqlFeatureLayer>();
                        try
                        {
                            newLayers = GisEditor.LayerManager.GetLayers <MsSqlFeatureLayer>(layerParameters);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Unable to Load Layer(s)", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        if (newLayers != null && newLayers.Count > 0)
                        {
                            return(newLayers);
                        }
                    }
                }
            }
            return(new Collection <MsSqlFeatureLayer>());
        }
Ejemplo n.º 5
0
        protected override void ApplySettingsCore(StorableSettings settings)
        {
            base.ApplySettingsCore(settings);
            if (settings.GlobalSettings.ContainsKey("MsSqlServers"))
            {
                try
                {
                    if (rootItem != null)
                    {
                        rootItem.Children.Clear();
                        XElement serversElement = XElement.Parse(settings.GlobalSettings["MsSqlServers"]);
                        serversElement.Elements("Server").ForEach(item =>
                        {
                            string serverString = item.Value;
                            serverString        = StringProtector.Instance.Decrypt(serverString);
                            string[] server     = serverString.Split('|');

                            MsSqlServerDataRepositoryItem serverItem = new MsSqlServerDataRepositoryItem();
                            serverItem.Name     = server[0];
                            serverItem.Server   = server[0];
                            serverItem.UserName = server[1];
                            serverItem.Password = server[2];
                            rootItem.Children.Add(serverItem);

                            MsSql2008FeatureLayerInfo configureInfo = new MsSql2008FeatureLayerInfo();
                            configureInfo.ServerName = serverItem.Server;
                            configureInfo.UserName   = serverItem.UserName;
                            configureInfo.Password   = serverItem.Password;
                            if (!string.IsNullOrEmpty(configureInfo.UserName) && !string.IsNullOrEmpty(configureInfo.Password))
                            {
                                configureInfo.UseTrustAuthority = false;
                            }
                            SyncToServerItem(configureInfo, serverItem);
                        });
                    }
                }
                catch (Exception)
                { }
            }
        }
Ejemplo n.º 6
0
        private string GetToServerConnectionString(MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem)
        {
            DataRepositoryItem item = msSqlTableDataRepositoryItem.Parent;

            while (!(item is MsSqlServerDataRepositoryItem))
            {
                item = item.Parent;
            }

            MsSqlServerDataRepositoryItem serverItem = (MsSqlServerDataRepositoryItem)item;
            StringBuilder connectionBuilder          = new StringBuilder();

            connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "Data Source={0};Persist Security Info=True;", serverItem.Server);
            if (string.IsNullOrEmpty(serverItem.UserName) && string.IsNullOrEmpty(serverItem.Password))
            {
                connectionBuilder.Append("Trusted_Connection=Yes;");
            }
            else
            {
                connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "User ID={0};Password={1};", serverItem.UserName, serverItem.Password);
            }

            return(connectionBuilder.ToString());
        }
Ejemplo n.º 7
0
        private static void SyncToServerItem(MsSql2008FeatureLayerInfo configureInfo, MsSqlServerDataRepositoryItem serverItem)
        {
            serverItem.Name     = configureInfo.ServerName;
            serverItem.Server   = configureInfo.ServerName;
            serverItem.UserName = configureInfo.UserName;
            serverItem.Password = configureInfo.Password;

            Task <Collection <DatabaseModel> > task = new Task <Collection <DatabaseModel> >(GetDatabaseItems, configureInfo);

            task.Start();
            task.ContinueWith(t =>
            {
                Application.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (t.Result.Count > 0)
                    {
                        serverItem.Children.Clear();
                        foreach (var databaseItem in t.Result)
                        {
                            if (databaseItem.TableModels.Count > 0)
                            {
                                DatabaseDataRepositoryItem dbItem = new DatabaseDataRepositoryItem();
                                dbItem.Name = databaseItem.Name;

                                var groupItems = databaseItem.TableModels.GroupBy(g => g.SchemaName);

                                DataRepositoryItem schemaItem = new DataRepositoryItem();
                                schemaItem.Name = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", "Schemas", groupItems.Count());
                                schemaItem.Icon = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/schemas.png", UriKind.RelativeOrAbsolute));
                                dbItem.Children.Add(schemaItem);

                                foreach (var group in groupItems)
                                {
                                    IEnumerable <string> tableGroup = group.Where(v => !v.IsView).Select(g => g.Name);
                                    IEnumerable <string> viewGroup  = group.Where(v => v.IsView).Select(g => g.Name);

                                    AddSchemaChildrens(schemaItem, tableGroup, viewGroup, "/GisEditorPluginCore;component/Images/tablefolder.png", group.Key, configureInfo, databaseItem.Name);
                                }

                                serverItem.Children.Add(dbItem);
                                DataRepositoryContentViewModel.RestoreChildrenExpandStatus(new ObservableCollection <DataRepositoryItem> {
                                    serverItem
                                }, GisEditor.DataRepositoryManager.ExpandedFolders);
                            }
                        }
                    }
                });
            });
        }