Example #1
0
 internal ITool Tool(Guid guid)
 {
     foreach (ITool tool in _tools)
     {
         if (PlugInManager.PlugInID(tool) == guid)
         {
             return(tool);
         }
     }
     return(null);
 }
Example #2
0
 internal void AddTool(ITool tool)
 {
     if (tool == null)
     {
         return;
     }
     if (this.Tool(PlugInManager.PlugInID(tool)) != null)
     {
         return;                                                  // Schon vorhanden
     }
     _tools.Add(tool);
 }
Example #3
0
        static public void AppendMenuItems(ContextMenuStrip strip, IExplorerObject ExplorerObject)
        {
            if (ExplorerObject == null)
            {
                return;
            }

            Guid          ExplorerObjectGUID = PlugInManager.PlugInID(ExplorerObject);
            PlugInManager compManager        = new PlugInManager();

            var commands = compManager.GetPlugins(Plugins.Type.IExplorerCommand);

            if (commands == null)
            {
                return;
            }

            foreach (var commandType in commands)
            {
                try
                {
                    IExplorerCommand command = compManager.CreateInstance <IExplorerCommand>(commandType);
                    if (command == null ||
                        (command.ExplorerObjectGUID != ExplorerObjectGUID && command.ExplorerObjectGUID != KnownExplorerObjectIDs.Any))
                    {
                        continue;
                    }

                    foreach (XmlNode node in command.CommandDefs)
                    {
                        if (node.Attributes["name"] == null)
                        {
                            continue;
                        }

                        ToolStripItem item = new CommandToolStripItem(ExplorerObject, node);
                        item.Click += new EventHandler(CommandItem_Click);

                        if (strip.Items.Count == 0)
                        {
                            strip.Items.Add(new ToolStripSeparator());
                        }

                        strip.Items.Add(item);
                    }
                }
                catch
                {
                }
            }
        }
Example #4
0
        public IMetadataProvider MetadataProvider(Guid guid)
        {
            if (_providers == null)
            {
                return(null);
            }

            foreach (IMetadataProvider provider in _providers)
            {
                if (PlugInManager.PlugInID(provider).Equals(guid))
                {
                    return(provider);
                }
            }
            return(null);
        }
Example #5
0
        async virtual public Task WriteMetadata(IPersistStream stream)
        {
            PlugInManager plugins = new PlugInManager();

            if (_providers != null)
            {
                foreach (IMetadataProvider provider in _providers)
                {
                    if (provider == null)
                    {
                        continue;
                    }

                    // mit ApplyTo noch einmal das this Objekt auf den Provider
                    // setzen, damit beim speichern immer das aktuelle Object gesetzt wird...
                    await provider.ApplyTo(this);

                    stream.Save("IMetadataProvider", provider);
                }
            }
            else
            {
                _providers = new ConcurrentBag <IMetadataProvider>();
            }

            foreach (Type providerType in plugins.GetPlugins(typeof(IMetadataProvider)))
            {
                IMetadataProvider provider = plugins.CreateInstance(providerType) as IMetadataProvider;
                if (provider == null)
                {
                    continue;
                }

                // nach bereits vorhanden suchen...
                IMetadataProvider provider2 = this.MetadataProvider(PlugInManager.PlugInID(provider));
                if (provider2 != null)
                {
                    continue;
                }

                if (await provider.ApplyTo(this))
                {
                    stream.Save("IMetadataProvider", provider);
                    _providers.Add(provider);
                }
            }
        }
Example #6
0
        public Serialized GetSerialize()
        {
            return(new Serialized()
            {
                ConnectionString = _dataset.ConnectionString,
                DatasetGuid = PlugInManager.PlugInID(_dataset).ToString(),
                DatasetName = _dataset.DatasetName,
                NetworkCreatorAssembly = new FileInfo(this._networkCreatorType.Assembly.Location).Name,
                NetworkCreatorType = this._networkCreatorType.ToString(),

                FeatureClasses = _selecteFeturesclasses.Serialize,
                NetworkTolerance = _tolerance.Serialize,
                ComplexEdges = _complexEdges.Serialize,
                Nodes = _switches.Serialize,
                EdgeWeights = _edgeWeights.Serialize
            });
        }
Example #7
0
        public virtual Task <bool> Match(IExplorerObject exObject)
        {
            if (exObject == null)
            {
                return(Task.FromResult(false));
            }

            bool found = false;

            foreach (Guid guid in ExplorerObjectGUIDs)
            {
                if (PlugInManager.PlugInID(exObject) == guid)
                {
                    found = true;
                    break;
                }
            }
            return(Task.FromResult(found));
        }
Example #8
0
        public ExtensionSerializer(object extension)
        {
            if (PlugInManager.IsPlugin(extension) &&
                extension is IPersistable)
            {
                XmlStream stream = new XmlStream("");

                ((IPersistable)extension).Save(stream);

                MemoryStream ms = new MemoryStream();
                stream.WriteStream(ms);
                ms.Position = 0;
                byte[] b = new byte[ms.Length];
                ms.Read(b, 0, (int)ms.Length);

                _string = System.Text.Encoding.Unicode.GetString(b).Trim();
                _guid   = PlugInManager.PlugInID(extension);
            }
        }
Example #9
0
        public IToolbar Toolbar(Guid guid)
        {
            if (_appWindow == null)
            {
                return(null);
            }

            foreach (ToolbarStrip strip in _appWindow.ToolbarStrips)
            {
                if (strip == null)
                {
                    continue;
                }
                if (PlugInManager.PlugInID(strip) == guid)
                {
                    return(strip);
                }
            }
            return(null);
        }
Example #10
0
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            if (_selectedSymbol == null)
            {
                return;
            }
            if (PlugInManager.IsPlugin(_selectedSymbol))
            {
                PlugInManager comMan    = new PlugInManager();
                ISymbol       newSymbol = (ISymbol)comMan.CreateInstance(PlugInManager.PlugInID(_selectedSymbol));

                if (newSymbol != null)
                {
                    AddSymbol(newSymbol);
                }
                if (SelectedSymbolChanged != null)
                {
                    SelectedSymbolChanged(_selectedSymbol);
                }
            }
        }
Example #11
0
        virtual public void WriteMetadata(IPersistStream stream)
        {
            PlugInManager plugins = new PlugInManager();

            if (_providers != null)
            {
                foreach (IMetadataProvider provider in _providers)
                {
                    if (provider == null) continue;

                    // mit ApplyTo noch einmal das this Objekt auf den Provider 
                    // setzen, damit beim speichern immer das aktuelle Object gesetzt wird...
                    provider.ApplyTo(this);
                    stream.Save("IMetadataProvider", provider);
                }
            }
            else
            {
                _providers = new List<IMetadataProvider>();
            }

            foreach (XmlNode providerNode in plugins.GetPluginNodes(Plugins.Type.IMetadataProvider))
            {
                IMetadataProvider provider = plugins.CreateInstance(providerNode) as IMetadataProvider;
                if (provider == null) continue;

                // nach bereits vorhanden suchen...
                IMetadataProvider provider2 = this.MetadataProvider(PlugInManager.PlugInID(provider));
                if (provider2 != null)
                    continue;

                if (provider.ApplyTo(this))
                {
                    stream.Save("IMetadataProvider", provider);
                    _providers.Add(provider);
                }
            }
        }
Example #12
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();
            }
        }
Example #13
0
        public string ServiceRequest2(string OnlineResource, string service, string request, string InterpreterGUID, string usr, string pwd)
        {
            //string clientAddress = CallContext.GetData("ClientAddress").ToString();
            try
            {
#if (DEBUG)
                Logger.LogDebug("Start SendRequest");
#endif
                Identity id = Identity.FromFormattedString(usr);
                id.HashedPassword = pwd;

                if (IMS.acl != null && !IMS.acl.HasAccess(id, pwd, service))
                {
                    throw new UnauthorizedAccessException();   //return "ERROR: Not Authorized!";
                }
                if (service == "catalog" && IMS.acl != null)
                {
                    IMS.acl.ReloadXmlDocument();
                }

                if (service == "catalog" && request == "get_used_servers")
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<servers>");
                    foreach (DataRow server in MapServer.GDIServers.Rows)
                    {
                        sb.Append("<server uri='" + (string)server["Server"] + "' port='" + (int)server["Port"] + "' />");
                    }
                    sb.Append("</servers>");
                    return(sb.ToString());
                }
                if (service == "catalog" && request == "get_instance_info")
                {
                    StringBuilder sb        = new StringBuilder();
                    MapServer     mapServer = IMS.mapServer;
                    sb.Append("<instance_info>");
                    if (mapServer != null)
                    {
                        sb.Append("<output url='" + mapServer.OutputUrl + "' />");
                    }
                    sb.Append("</instance_info>");
                    return(sb.ToString());
                }

                Guid guid = new Guid(InterpreterGUID);
                IServiceRequestInterpreter interperter = null;
                foreach (IServiceRequestInterpreter i in IMS._interpreters)
                {
                    if (PlugInManager.PlugInID(i) == guid)
                    {
                        interperter = i;
                        break;
                    }
                }
                if (interperter == null)
                {
                    return("FATAL ERROR: Unknown request interpreger...");
                }
                // User berechtigungen überprüfen


                ServiceRequest serviceRequest = new ServiceRequest(service, request);
                serviceRequest.OnlineResource = OnlineResource;
                //serviceRequest.UserName = usr;
                serviceRequest.Identity = id;

                IServiceRequestContext context = new ServiceRequestContext(
                    IMS.mapServer,
                    interperter,
                    serviceRequest);

                //ManualResetEvent resetEvent = new ManualResetEvent(false);
                //IMS.threadQueue.AddQueuedThread(interperter.Request, context, resetEvent);
                //resetEvent.WaitOne();
                IMS.threadQueue.AddQueuedThreadSync(interperter.Request, context);

                return(serviceRequest.Response);

#if (DEBUG)
                Logger.LogDebug("SendRequest Finished");
#endif
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Process.GetCurrentProcess().Kill();
                return("FATAL ERROR: " + ex.Message);
            }
        }
        private void gridFcs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || lstWeights.SelectedItems.Count != 1)
            {
                return;
            }

            IGraphWeight weight = ((WeightListViewItem)lstWeights.SelectedItems[0]).GraphWeight;
            int          fcId   = Convert.ToInt32(gridFcs.Rows[e.RowIndex].Cells[0].Value);

            string fieldName = (string)((DataGridViewComboBoxCell)gridFcs.Rows[e.RowIndex].Cells[2]).Value;
            IGraphWeightFeatureClass gwfc = weight.FeatureClasses[fcId];

            if (gwfc == null)
            {
                gwfc = new GraphWeightFeatureClass(fcId, fieldName);
                weight.FeatureClasses[fcId] = gwfc;
            }
            if (e.ColumnIndex == 2)
            {
                if (fieldName == null || fieldName == "<none>")
                {
                    ((GraphWeightFeatureClass)gwfc).FieldName = String.Empty;
                }
                else
                {
                    ((GraphWeightFeatureClass)gwfc).FieldName = fieldName;
                }
            }
            if (e.ColumnIndex == 3)
            {
                if (gwfc.SimpleNumberCalculation != null &&
                    gwfc.SimpleNumberCalculation.Name == gridFcs.Rows[e.RowIndex].Cells[3].Value.ToString())
                {
                }
                else
                {
                    if (gridFcs.Rows[e.RowIndex].Cells[3].Value.ToString() == "<none>")
                    {
                        ((GraphWeightFeatureClass)gwfc).SimpleNumberCalculation = null;
                    }
                    foreach (ISimpleNumberCalculation calc in _calculators)
                    {
                        if (calc.Name == gridFcs.Rows[e.RowIndex].Cells[3].Value.ToString())
                        {
                            PlugInManager pMan = new PlugInManager();
                            ((GraphWeightFeatureClass)gwfc).SimpleNumberCalculation = pMan.CreateInstance(PlugInManager.PlugInID(calc)) as ISimpleNumberCalculation;
                        }
                    }
                }
            }
        }
Example #15
0
        private bool InsertImage(IFeatureUpdater fdb, IFeatureClass rasterFC, FileInfo fi, Dictionary <string, Guid> providers)
        {
            if (!_cancelTracker.Continue)
            {
                _errMsg = "Canceled by user...";
                return(false);
            }

            if (ReportAction != null)
            {
                ReportAction(this, "Insert Image: " + fi.FullName);
            }
            if (ReportProgress != null)
            {
                ReportProgress(this, 1);
            }

            System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
            switch (fi.Extension.ToLower())
            {
            case ".png":
                format = System.Drawing.Imaging.ImageFormat.Png;
                break;

            case ".tif":
            case ".tiff":
                format = System.Drawing.Imaging.ImageFormat.Tiff;
                break;
            }

            #region RasterFileDataset bestimmen
            List <IRasterFileDataset> rFileDatasets = new List <IRasterFileDataset>();
            IRasterFileDataset        rFileDataset  = null;
            IRasterLayer  rasterLayer = null;
            PlugInManager compMan     = new PlugInManager();
            foreach (XmlNode ds in compMan.GetPluginNodes(Plugins.Type.IDataset))
            {
                IRasterFileDataset rds = compMan.CreateInstance(ds) as IRasterFileDataset;
                if (rds == null)
                {
                    continue;
                }

                if (rds.SupportsFormat(fi.Extension) < 0)
                {
                    continue;
                }
                if (providers != null && providers.ContainsKey(fi.Extension.ToLower()))
                {
                    if (!providers[fi.Extension.ToLower()].Equals(PlugInManager.PlugInID(rds)))
                    {
                        continue;
                    }
                }
                rFileDatasets.Add(rds);
            }
            if (rFileDatasets.Count == 0)
            {
                _errMsg = "No Rasterfile Provider for " + fi.Extension;
                return(false);
            }

            // RasterFileDataset nach priorität sortieren
            rFileDatasets.Sort(new RasterFileDatasetComparer(fi.Extension));

            // RasterFileDataset suchen, mit dem sich Bild öffnen läßt
            foreach (IRasterFileDataset rfd in rFileDatasets)
            {
                rfd.AddRasterFile(fi.FullName);

                if (rfd.Elements.Count == 0)
                {
                    //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster File...");
                    continue;
                }
                IDatasetElement element = rfd.Elements[0];
                if (!(element is IRasterLayer))
                {
                    //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer...");
                    rFileDataset.Dispose();
                    continue;
                }

                // gefunden...
                rasterLayer  = (IRasterLayer)element;
                rFileDataset = rfd;
                break;
            }
            if (rasterLayer == null || rFileDataset == null)
            {
                Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer...");
                return(false);
            }
            #endregion

            FileInfo fiWorld = null;
            double   cellX   = 1;
            double   cellY   = 1;

            IRasterFile rasterFile = null;
            if (rasterLayer is IRasterFile)
            {
                rasterFile = (IRasterFile)rasterLayer;
            }
            if (rasterLayer.RasterClass != null)
            {
                if (rasterLayer.RasterClass is IRasterFile &&
                    ((IRasterFile)rasterLayer.RasterClass).WorldFile != null)
                {
                    rasterFile = (IRasterFile)rasterLayer.RasterClass;
                }
                else
                {
                    IRasterClass c = (IRasterClass)rasterLayer.RasterClass;
                    cellX = Math.Sqrt(c.dx1 * c.dx1 + c.dx2 * c.dx2);
                    cellY = Math.Sqrt(c.dy1 * c.dy1 + c.dy2 * c.dy2);
                }
            }
            if (rasterFile != null)
            {
                try
                {
                    IRasterWorldFile world = rasterFile.WorldFile;
                    if (world != null)
                    {
                        if (!world.isGeoReferenced)
                        {
                            if (handleNonGeorefAsError)
                            {
                                _errMsg = "Can't add non georeferenced images: " + fi.FullName;
                                return(false);
                            }
                            else
                            {
                                return(true);
                            }
                        }

                        cellX = Math.Sqrt(world.dx_X * world.dx_X + world.dx_Y * world.dx_Y);
                        cellY = Math.Sqrt(world.dy_X * world.dy_X + world.dy_Y * world.dy_Y);

                        fiWorld = new FileInfo(rasterFile.WorldFile.Filename);
                        if (!fiWorld.Exists)
                        {
                            fiWorld = null;
                        }
                    }
                }
                catch
                {
                    fiWorld = null;
                }
            }

            #region Check if already Exits
            //
            // Suchen, ob Image mit gleichen Pfad schon vorhanden ist, wenn ja
            // nur weitermachen, wenn sich das änderungsdatum unterscheidet...
            //

            QueryFilter filter = new QueryFilter();
            filter.AddField("FDB_OID");
            filter.AddField("PATH");
            filter.AddField("LAST_MODIFIED");
            filter.AddField("PATH2");
            filter.AddField("LAST_MODIFIED2");

            string fullName = fi.FullName.Replace(@"\", @"\\");
            if (_fdb is AccessFDB)
            {
                filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fullName + "'";
            }
            else
            {
                filter.WhereClause = "PATH='" + fullName + "'";
            }
            int deleteOID = -1;
            using (IFeatureCursor cursor = rasterFC.GetFeatures(filter))
            {
                IFeature existingFeature = cursor.NextFeature;
                if (existingFeature != null)
                {
                    DateTime dt1 = (DateTime)existingFeature["LAST_MODIFIED"];
                    if (Math.Abs(((TimeSpan)(dt1 - fi.LastWriteTimeUtc)).TotalSeconds) > 1.0)
                    {
                        deleteOID = existingFeature.OID;
                    }
                    else if (fiWorld != null &&
                             existingFeature["PATH2"] != System.DBNull.Value &&
                             existingFeature["PATH2"].ToString() != String.Empty)
                    {
                        DateTime dt2 = (DateTime)existingFeature["LAST_MODIFIED2"];
                        if (existingFeature["PATH2"].ToString().ToLower() != fiWorld.FullName.ToLower() ||
                            Math.Abs(((TimeSpan)(dt2 - fiWorld.LastWriteTimeUtc)).TotalSeconds) > 1.0)
                        {
                            deleteOID = existingFeature.OID;
                        }
                    }

                    if (deleteOID == -1)
                    {
                        Console.Write(".");
                        //Console.WriteLine(fi.FullName + " already exists...");
                        return(true);
                    }
                }
            }
            if (deleteOID != -1)
            {
                if (!fdb.Delete(rasterFC, deleteOID))
                {
                    Console.WriteLine(_errMsg = "Can't delete old record " + fi.FullName + "\n" + fdb.lastErrorMsg);
                    return(false);
                }
            }
            //
            ///////////////////////////////////////////////////////////////////
            //
            #endregion

            Feature feature = new Feature();
            feature.Shape = rasterLayer.RasterClass.Polygon;
            feature.Fields.Add(new FieldValue("PATH", fi.FullName));
            feature.Fields.Add(new FieldValue("LAST_MODIFIED", fi.LastWriteTimeUtc));
            if (fiWorld != null)
            {
                feature.Fields.Add(new FieldValue("PATH2", fiWorld.FullName));
                feature.Fields.Add(new FieldValue("LAST_MODIFIED2", fiWorld.LastWriteTimeUtc));
            }
            else
            {
                feature.Fields.Add(new FieldValue("PATH2", ""));
            }
            feature.Fields.Add(new FieldValue("RF_PROVIDER", PlugInManager.PlugInID(rFileDataset).ToString()));
            feature.Fields.Add(new FieldValue("MANAGED", _managed && (rasterLayer is IBitmap)));
            feature.Fields.Add(new FieldValue("FORMAT", fi.Extension.Replace(".", "")));
            feature.Fields.Add(new FieldValue("CELLX", cellX));
            feature.Fields.Add(new FieldValue("CELLY", cellY));
            feature.Fields.Add(new FieldValue("LEVELS", (_managed) ? Math.Max(_levels, 1) : 0));

            if (!fdb.Insert(rasterFC, feature))
            {
                Console.WriteLine("\nERROR@" + fi.FullName + ": " + fdb.lastErrorMsg);
            }
            else
            {
                if (_managed && (rasterLayer is IBitmap) && (fdb is SqlFDB))
                {
                    QueryFilter qfilter = new QueryFilter();
                    qfilter.SubFields = "FDB_OID";
                    if (_fdb is AccessFDB)
                    {
                        filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fi.FullName + "'";
                    }
                    else
                    {
                        qfilter.WhereClause = "PATH='" + fi.FullName + "'";
                    }
                    IFeatureCursor cursor = ((SqlFDB)fdb).Query(rasterFC, qfilter);
                    if (cursor != null)
                    {
                        IFeature feat = cursor.NextFeature;
                        if (feat != null)
                        {
                            InsertImageDatasetBitmap(feat.OID, rasterLayer, _levels, format);
                        }
                        cursor.Dispose();
                    }
                }

                Console.WriteLine(">" + fi.FullName + " added...");
            }

            rFileDataset.Dispose();
            return(true);
        }
Example #16
0
        public Stream TileWmts(string name, string cacheType, string origin, string epsg, string style, string level, string row, string col)
        {
            try
            {
                if (_serverConfig == null || _serverConfig.Instances.Length == 0)
                {
                    return(WriteException("ServiceType not initialized!"));
                }

                if (IfMatch())
                {
                    OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                    context.StatusCode = HttpStatusCode.NotModified;
                    return(null);
                }

                string user, pwd;
                var    request = Request(out user, out pwd);

                int instanceNr = GetRandom(_serverConfig.Instances.Length /*  MapServerConfig.ServerCount*/);
                MapServerConfig.ServerConfig.InstanceConfig config = _serverConfig.Instances[instanceNr];
                InstanceConnection conn = new InstanceConnection("localhost:" + config.Port);

                IServiceRequestInterpreter requestInterpreter = GetInterpreter("wmts");

                string ret = conn.Send(String.Empty, name, cacheType + "/" + origin + "/" + epsg + "/" + style + "/~" + level + "/" + row + "/" + col, PlugInManager.PlugInID(requestInterpreter).ToString(), user, pwd);

                if (ret.StartsWith("image:"))
                {
                    OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                    context.ContentType = "image/png";

                    ret = ret.Substring(6, ret.Length - 6);
                    return(WriteFile(ret));
                }
                if (ret.StartsWith("{"))
                {
                    try
                    {
                        var mapServerResponse = gView.Framework.system.MapServerResponse.FromString(ret);

                        OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                        context.ContentType = mapServerResponse.ContentType;

                        if (mapServerResponse.Expires != null)
                        {
                            AppendEtag((DateTime)mapServerResponse.Expires);
                        }

                        return(WriteBytes(mapServerResponse.Data));
                    }
                    catch { }
                }

                return(WriteValue(ret));
            }
            catch (UnauthorizedAccessException)
            {
                return(WriteUnauthorized());
            }
        }
Example #17
0
        public Stream MapRequestPost(string interpreter, string name, Stream data)
        {
            try
            {
                if (_serverConfig == null || _serverConfig.Instances.Length == 0)
                {
                    return(WriteException("ServiceType not initialized!"));
                }

                if (IfMatch())
                {
                    OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                    context.StatusCode = HttpStatusCode.NotModified;
                    return(null);
                }

                //DateTime td = DateTime.Now;
                //Console.WriteLine("Start Map Request " + td.ToLongTimeString() + "." + td.Millisecond + " (" + name + ")");
                //System.Threading.Thread.Sleep(10000);

                string user, pwd;
                var    request = Request(out user, out pwd);
                NameValueCollection queryString = KeysToLower(request.UriTemplateMatch.QueryParameters);
                string input = (data != null ? new StreamReader(data).ReadToEnd() : String.Empty);

                if (String.IsNullOrEmpty(input))
                {
                    StringBuilder parameters = new StringBuilder();
                    foreach (string key in queryString.Keys)
                    {
                        if (parameters.Length > 0)
                        {
                            parameters.Append("&");
                        }
                        parameters.Append(key.ToUpper() + "=" + queryString[key]);
                    }
                    input = parameters.ToString();
                }

                int instanceNr = GetRandom(_serverConfig.Instances.Length /*  MapServerConfig.ServerCount*/);
                MapServerConfig.ServerConfig.InstanceConfig config = _serverConfig.Instances[instanceNr];
                InstanceConnection conn = new InstanceConnection("localhost:" + config.Port);

                string onlineResource = _serverConfig.OnlineResource + "/MapRequest/" + interpreter + "/" + name;

                IServiceRequestInterpreter requestInterpreter = GetInterpreter(interpreter);

                string ret = conn.Send(onlineResource, name, input, PlugInManager.PlugInID(requestInterpreter).ToString(), user, pwd,
                                       input.Contains("tile:render") ? 3600 : 0);

                //Console.WriteLine("Finished map Request: " + (DateTime.Now - td).TotalMilliseconds + "ms (" + name + ")");
                if (ret.StartsWith("image:"))
                {
                    OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                    context.ContentType = "image/png";

                    ret = ret.Substring(6, ret.Length - 6);
                    return(WriteFile(ret));
                }
                if (ret.StartsWith("{"))
                {
                    try
                    {
                        var mapServerResponse = gView.Framework.system.MapServerResponse.FromString(ret);

                        OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
                        context.ContentType = mapServerResponse.ContentType;

                        if (mapServerResponse.Expires != null)
                        {
                            AppendEtag((DateTime)mapServerResponse.Expires);
                        }

                        return(WriteBytes(mapServerResponse.Data));
                    }
                    catch { }
                }

                return(WriteValue(ret));
            }
            catch (UnauthorizedAccessException)
            {
                return(WriteUnauthorized());
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            #region Parse Parameters
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-add":
                    if (job != jobs.unknown)
                    {
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.add;
                    break;

                case "-clean":
                    if (job != jobs.unknown)
                    {
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.removeUnexisting;
                    break;

                case "-truncate":
                    if (job != jobs.unknown)
                    {
                        Usage();
                        Console.WriteLine("Can't do more than one job. Run programm twice...");
                        return;
                    }
                    job = jobs.truncate;
                    break;

                case "-s":
                    connectinString = args[++i];
                    break;

                case "-db":
                    dbType = args[++i].ToLower();
                    break;

                case "-provider":
                    provider = args[++i].ToLower();
                    break;

                case "-fn":
                    if (rootPath != String.Empty)
                    {
                        Usage();
                        Console.WriteLine("Filename OR Rootdirectory...");
                        return;
                    }
                    fileName = args[++i];
                    break;

                case "-rd":
                    if (fileName != String.Empty)
                    {
                        Usage();
                        Console.WriteLine("Filename OR Rootdirectory...");
                        return;
                    }
                    rootPath = args[++i];
                    break;

                case "-f":
                    Filters = args[++i];
                    break;
                }
            }
            #endregion

            #region Check Parameters
            if (connectinString == String.Empty)
            {
                Usage();
                Console.WriteLine("No connection string...");
                return;
            }
            switch (job)
            {
            case jobs.removeUnexisting:
            case jobs.truncate:
                break;

            case jobs.add:
                if (fileName == String.Empty &&
                    (rootPath == String.Empty || Filters == String.Empty))
                {
                    Usage();
                    Console.WriteLine("No file or rootdirectory and filter defined...");
                    return;
                }
                break;

            case jobs.unknown:
                Usage();
                Console.WriteLine("No job defined...");
                return;
            }
            #endregion

            DateTime dt = DateTime.Now;

            string mdb     = ConfigTextStream.ExtractValue(connectinString, "mdb");
            string dsname  = ConfigTextStream.ExtractValue(connectinString, "dsname");
            string connStr = ConfigTextStream.RemoveValue(connectinString, "dsname");

            IFeatureDataset ds = null;
            if (mdb != String.Empty)
            {
                AccessFDB fdb = new AccessFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "sql")
            {
                SqlFDB fdb = new SqlFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "postgres")
            {
                pgFDB fdb = new pgFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }
            else if (dbType == "sqlite")
            {
                SQLiteFDB fdb = new SQLiteFDB();
                fdb.Open(connStr);
                IFeatureDataset dataset = fdb[dsname];
                if (dataset == null)
                {
                    Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg);
                    return;
                }
                //dataset.ConnectionString = connectinString;
                if (!dataset.Open())
                {
                    Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg);
                    return;
                }
                ds = dataset;
            }

            IRasterFileDataset rds = null;
            if (provider == "gdal")
            {
                rds = PlugInManager.Create(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IRasterFileDataset;
            }
            else if (provider == "raster")
            {
                rds = PlugInManager.Create(new Guid("D4812641-3F53-48eb-A66C-FC0203980C79")) as IRasterFileDataset;
            }

            Dictionary <string, Guid> providers = new Dictionary <string, Guid>();
            if (rds != null)
            {
                foreach (string format in rds.SupportedFileFilter.Split('|'))
                {
                    string extension = format;

                    int pos = format.LastIndexOf(".");
                    if (pos > 0)
                    {
                        extension = format.Substring(pos, format.Length - pos);
                    }

                    providers.Add(extension, PlugInManager.PlugInID(rds));
                    Console.WriteLine("Provider " + extension + ": " + rds.ToString() + " {" + PlugInManager.PlugInID(rds).ToString() + "}");
                }
            }
            if (providers.Count == 0)
            {
                providers = null;
            }

            switch (job)
            {
            case jobs.truncate:
                Truncate(ds, dsname + "_IMAGE_POLYGONS");
                break;

            case jobs.removeUnexisting:
                RemoveUnexisting(ds);
                CalculateExtent(ds);
                break;

            case jobs.add:
                if (fileName != String.Empty)
                {
                    if (!ImportFiles(ds, fileName.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return;
                        }
                    }
                }
                else if (rootPath != String.Empty && Filters != String.Empty)
                {
                    if (!ImportDirectory(ds, new DirectoryInfo(rootPath), Filters.Split(';'), providers))
                    {
                        if (!continueOnError)
                        {
                            return;
                        }
                    }
                }
                CalculateExtent(ds);
                break;
            }
            Console.WriteLine("\n" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "s");
            Console.WriteLine("done...");
        }
Example #19
0
        private void btnScript_Click(object sender, EventArgs e)
        {
            if (_childFc == null || _childFc.Dataset == null ||
                _parentFc == null || _parentFc.Dataset == null)
            {
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

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

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

                sb.Append("\"%GVIEW4_HOME%\\checkin\" -source_connstr \"" + _childFc.Dataset.ConnectionString + "\" -source_guid \"" + PlugInManager.PlugInID(_childFc.Dataset) + "\" -source_fc \"" + _childFc.Name + "\" ");
                sb.Append("-dest_connstr \"" + _parentFc.Dataset.ConnectionString + "\" -dest_guid \"" + PlugInManager.PlugInID(_parentFc.Dataset) + "\" -dest_fc \"" + _parentFc.Name + "\"");
                if (radioReconcile.Checked == true)
                {
                    sb.Append(" -reconcile");
                }
                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();
            }
        }
Example #20
0
        private void btnScript_Click(object sender, EventArgs e)
        {
            if (_dataset == null || _sourceFC == null || _sourceFC.Dataset == null)
            {
                return;
            }

            Replication.VersionRights rights = Replication.VersionRights.NONE;

            if (chkINSERT.Checked)
            {
                rights |= Replication.VersionRights.INSERT;
            }
            if (chkUPDATE.Checked)
            {
                rights |= Replication.VersionRights.UPDATE;
            }
            if (chkDELETE.Checked)
            {
                rights |= Replication.VersionRights.DELETE;
            }

            SaveFileDialog dlg = new SaveFileDialog();

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

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

                sb.Append("\"%GVIEW4_HOME%\\gView.Cmd.CopyFeatureclass\" -source_connstr \"" + _sourceFC.Dataset.ConnectionString + "\" -source_guid \"" + PlugInManager.PlugInID(_sourceFC.Dataset) + "\" -source_fc \"" + _sourceFC.Name + "\" ");
                sb.Append("-dest_connstr \"" + _dataset.ConnectionString + "\" -dest_guid \"" + PlugInManager.PlugInID(_dataset) + "\" -dest_fc \"" + txtTargetClass.Text + "\" ");
                sb.Append("-checkout \"" + txtCheckoutDescription.Text + "\" ");
                sb.Append("-pr iud -cr ");
                if (rights == Replication.VersionRights.NONE)
                {
                    sb.Append("x");
                }
                else
                {
                    if (Bit.Has(rights, Replication.VersionRights.INSERT))
                    {
                        sb.Append("i");
                    }
                    if (Bit.Has(rights, Replication.VersionRights.UPDATE))
                    {
                        sb.Append("u");
                    }
                    if (Bit.Has(rights, Replication.VersionRights.DELETE))
                    {
                        sb.Append("d");
                    }
                }
                sb.Append(" -ch ");
                if (radioNoConflict.Checked)
                {
                    sb.Append("none");
                }
                else if (radioNormalConflict.Checked)
                {
                    sb.Append("normal");
                }
                else if (radioParentWins.Checked)
                {
                    sb.Append("parent_wins");
                }
                else if (radioChildWins.Checked)
                {
                    sb.Append("child_wins");
                }
                else if (radioNewerWins.Checked)
                {
                    sb.Append("newer_wins");
                }

                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();
            }
        }
Example #21
0
        private void Save(string key, object val, bool encrypt)
        {
            XmlNode node = this.CreateNode(key);

            _parent.Node.AppendChild(node);
            if (PlugInManager.IsPlugin(val))
            {
                node.Attributes.Append(
                    this.CreateAttribute("GUID", PlugInManager.PlugInID(val).ToString()));
                node.Attributes.Append(
                    this.CreateAttribute("type", val.ToString()));
            }
            if (val is IPersistable)
            {
                _parent.Node = node;
                ((IPersistable)val).Save(this);
                _parent.Node = node.ParentNode;
                return;
            }
            if (val is IPersistableLoadAsync)
            {
                _parent.Node = node;
                ((IPersistableLoadAsync)val).Save(this);
                _parent.Node = node.ParentNode;
                return;
            }
            if (val is XmlStreamObject)
            {
                if (((XmlStreamObject)val).Value == null)
                {
                    return;
                }

                CreateXmlStreamObjectAttributes(node, (XmlStreamObject)val);

                if (val is XmlStreamOption &&
                    ((XmlStreamOption)val).Options != null)
                {
                    XmlStreamOption streamObject = (XmlStreamOption)val;

                    node.Attributes.Append(
                        this.CreateAttribute("type", typeof(XmlStreamOption).ToString()));

                    _parent.Node = node;
                    Save("Value", streamObject.Value);
                    foreach (object option in streamObject.Options)
                    {
                        Save("Option", option);
                    }
                    _parent.Node = node.ParentNode;
                }
                else if (val is XmlStreamStringArray &&
                         ((XmlStreamStringArray)val).Value is Array)
                {
                    XmlStreamStringArray streamObject = (XmlStreamStringArray)val;

                    node.Attributes.Append(
                        this.CreateAttribute("type", typeof(XmlStreamStringArray).ToString()));
                    _parent.Node = node;
                    foreach (object Value in (Array)streamObject.Value)
                    {
                        Save("Value", Value.ToString());
                    }
                    _parent.Node = node.ParentNode;
                }
                else
                {
                    XmlStreamObject streamObject = (XmlStreamObject)val;

                    node.Attributes.Append(
                        this.CreateAttribute("type", typeof(XmlStreamObject).ToString()));

                    _parent.Node = node;
                    Save("Value", streamObject.Value);
                    _parent.Node = node.ParentNode;
                }
                return;
            }

            if (val != null)
            {
                if (node.Attributes["type"] == null)
                {
                    node.Attributes.Append(
                        this.CreateAttribute("type", val.GetType().ToString()));
                }
                if (val.GetType() == typeof(double))
                {
                    node.Attributes.Append(
                        this.CreateAttribute("value", ((double)val).ToString(_parent.NumberFormat)));
                }
                else if (val.GetType() == typeof(float))
                {
                    node.Attributes.Append(
                        this.CreateAttribute("value", ((float)val).ToString(_parent.NumberFormat)));
                }
                else if (val.GetType() == typeof(decimal))
                {
                    node.Attributes.Append(
                        this.CreateAttribute("value", ((decimal)val).ToString(_parent.NumberFormat)));
                }
                else
                {
                    string v = val.ToString();
                    if (encrypt == true)
                    {
                        v = Crypto.Encrypt(v, "3f9932916f9746e1a3df048cc70dd30a");
                        node.Attributes.Append(this.CreateAttribute("encryption_type", "1"));
                    }
                    node.Attributes.Append(
                        this.CreateAttribute("value", v));
                }
            }
            //object f=Activator.CreateInstance(System.Type.GetType("System.String",false,true));
            //f=null;
        }
        private void FillFormatList()
        {
            PlugInManager compMan = new PlugInManager();

            foreach (var dsType in compMan.GetPlugins(Plugins.Type.IDataset))
            {
                IRasterFileDataset rds = compMan.CreateInstance <IDataset>(dsType) as IRasterFileDataset;
                if (rds == null)
                {
                    continue;
                }

                foreach (string format in rds.SupportedFileFilter.Split('|'))
                {
                    if (format == String.Empty)
                    {
                        continue;
                    }

                    int priority = rds.SupportsFormat(format.Replace("*", ""));
                    //FormatListItem item = FindFormatItem(format);
                    //if (item != null)
                    //{
                    //    if (item.Priority < priority)
                    //    {
                    //        item.Provider = rds.ToString();
                    //        item.Priority = priority;
                    //    }
                    //}
                    //else
                    //{
                    //    lstFormats.Items.Add(new FormatListItem(format, rds.ToString(), priority));
                    //}
                    lstFormats.Items.Add(new FormatListItem(format, rds.ToString(), priority, PlugInManager.PlugInID(rds)));
                }
            }
        }