Exemplo n.º 1
0
        async private void btnScript_Click(object sender, EventArgs e)
        {
            if (_fcs.Count == 0)
            {
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Title  = "Explort Script...";
            dlg.Filter = "BATCH File(*.bat)|*.bat";

            string destConnStr = String.Empty;
            Guid   destGUID    = new Guid();

            if (cmbDestFormat.Visible == true && cmbDestFormat.SelectedItem is FileDatabaseItem)
            {
                destConnStr = _directory;
                destGUID    = PlugInManager.PlugInID(((FileDatabaseItem)cmbDestFormat.SelectedItem).FileFeatureDatabase);
            }
            else if (_destDataset != null)
            {
                if (_destDataset is IDataset2)
                {
                    IDataset2 ds2 = await((IDataset2)_destDataset).EmptyCopy();
                    if (ds2 != null)
                    {
                        destConnStr = ds2.ConnectionString;
                        ds2.Dispose();
                    }
                }
                else
                {
                    destConnStr = _destDataset.ConnectionString;
                }
                destGUID = PlugInManager.PlugInID(_destDataset);
            }
            else
            {
                return;
            }

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("echo off\r\n");

                //foreach (IFeatureClass fc in _fcs)
                foreach (FeatureClassListViewItem item in FeatureClassItems)
                {
                    if (!item.Checked || item.FeatureClass == null)
                    {
                        continue;
                    }
                    IDataset ds      = item.FeatureClass.Dataset;
                    string   connStr = ds.ConnectionString;
                    if (item.FeatureClass.Dataset is IDataset2)
                    {
                        IDataset2 ds2 = await((IDataset2)item.FeatureClass.Dataset).EmptyCopy();
                        await ds2.AppendElement(item.FeatureClass.Name);

                        connStr = ds2.ConnectionString;
                        ds2.Dispose();
                    }
                    if (ds == null)
                    {
                        sb.Append("rem FeatureClass " + item.FeatureClass.Name + " has no dataset...\r\n");
                        continue;
                    }

                    FieldTranslation ftrans = item.ImportFieldTranslation;
                    StringBuilder    sb1    = new StringBuilder();
                    StringBuilder    sb2    = new StringBuilder();
                    foreach (IField field in ftrans.SourceFields.ToEnumerable())
                    {
                        if (field.type == FieldType.ID || field.type == FieldType.Shape)
                        {
                            continue;
                        }

                        if (sb1.Length != 0)
                        {
                            sb1.Append(";");
                        }
                        sb1.Append(field.name);
                    }
                    foreach (IField field in ftrans.DestinationFields.ToEnumerable())
                    {
                        if (field.type == FieldType.ID || field.type == FieldType.Shape)
                        {
                            continue;
                        }

                        if (sb2.Length != 0)
                        {
                            sb2.Append(";");
                        }
                        sb2.Append(field.name);
                    }
                    sb.Append("\"%GVIEW4_HOME%\\gView.Cmd.CopyFeatureclass\" -source_connstr \"" + connStr + "\" -source_guid \"" + PlugInManager.PlugInID(ds) + "\" -source_fc \"" + item.FeatureClass.Name + "\" ");
                    sb.Append("-dest_connstr \"" + destConnStr + "\" -dest_guid \"" + destGUID + "\" -dest_fc \"" + item.FeatureClass.Name + "\" ");
                    sb.Append("-sourcefields \"" + sb1.ToString() + "\" -destfields \"" + sb2.ToString() + "\"");
                    sb.Append("\r\n");
                }

                StreamWriter sw = new StreamWriter(dlg.FileName, false);
                if (!String2DOS(sw.BaseStream, sb.ToString()))
                {
                    MessageBox.Show("Warning: Can't find encoding codepage (ibm850)...");
                    sw.WriteLine(sb.ToString());
                }
                sw.Close();
            }
        }
Exemplo n.º 2
0
        async public Task <List <IDataset> > Datasets()
        {
            List <IDataset>        datasets    = new List <IDataset>();
            List <IExplorerObject> usedObjects = new List <IExplorerObject>();

            foreach (IExplorerObject exObject in ExplorerObjects)
            {
                if (exObject == null)
                {
                    continue;
                }
                if (usedObjects.Contains(exObject))
                {
                    continue;
                }

                var instance = await exObject.GetInstanceAsync();

                if (instance is IDataset)
                {
                    datasets.Add((IDataset)instance);
                    usedObjects.Add(exObject);
                }
                else if (instance is IFeatureClass && ((IFeatureClass)instance).Dataset is IDataset2)
                {
                    IDataset2 dataset      = (IDataset2)((IFeatureClass)instance).Dataset;
                    IDataset2 datasetClone = await dataset.EmptyCopy();

                    if (datasetClone == null)
                    {
                        continue;
                    }

                    foreach (IExplorerObject exObject2 in ExplorerObjects)
                    {
                        if (exObject2 == null)
                        {
                            continue;
                        }

                        var instance2 = await exObject2.GetInstanceAsync();

                        if (instance2 is IFeatureClass && ((IFeatureClass)instance2).Dataset == dataset)
                        {
                            await datasetClone.AppendElement(((IFeatureClass)instance2).Name);

                            usedObjects.Add(exObject2);
                        }
                    }

                    datasets.Add(datasetClone);
                }
                else if (instance is IRasterClass && ((IRasterClass)instance).Dataset is IDataset2)
                {
                    IDataset2 dataset      = (IDataset2)((IRasterClass)instance).Dataset;
                    IDataset2 datasetClone = await dataset.EmptyCopy();

                    if (datasetClone == null)
                    {
                        continue;
                    }

                    foreach (IExplorerObject exObject2 in ExplorerObjects)
                    {
                        if (exObject2 == null)
                        {
                            continue;
                        }

                        var instance2 = await exObject2.GetInstanceAsync();

                        if (instance2 is IRasterClass && ((IRasterClass)instance2).Dataset == dataset)
                        {
                            await datasetClone.AppendElement(((IRasterClass)instance2).Name);

                            usedObjects.Add(exObject2);
                        }
                    }

                    datasets.Add(datasetClone);
                }
                else if (instance is IFeatureClass && ((IFeatureClass)instance).Dataset is IDataset)
                {
                    datasets.Add(((IFeatureClass)instance).Dataset);
                }
                else if (instance is IWebServiceClass && ((IWebServiceClass)instance).Dataset is IDataset)
                {
                    datasets.Add(((IWebServiceClass)instance).Dataset);
                }
                else if (instance is IRasterClass && ((IRasterClass)instance).Dataset is IDataset)
                {
                    datasets.Add(((IRasterClass)instance).Dataset);
                }
            }

            return(datasets);
        }