Example #1
0
        internal void AddRedlineLayer(RedlineLayer layer, string fdoProvider)
        {
            var fsId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands   = new MgFeatureCommandCollection();
            MgPropertyCollection       insertVals = new MgPropertyCollection();

            MgStringProperty regId     = new MgStringProperty("ResourceId", layer.FeatureSource);
            MgStringProperty ldfId     = new MgStringProperty("LayerDefinition", layer.LayerDefinition);
            MgStringProperty name      = new MgStringProperty("Name", layer.Name);
            MgStringProperty provider  = new MgStringProperty("FdoProvider", fdoProvider);
            MgInt32Property  geomTypes = new MgInt32Property("GeometryTypes", layer.GeometryTypes);
            MgInt32Property  styleType = new MgInt32Property("StyleType", (int)layer.StyleType);

            insertVals.Add(regId);
            insertVals.Add(ldfId);
            insertVals.Add(name);
            insertVals.Add(provider);
            insertVals.Add(geomTypes);
            insertVals.Add(styleType);

            MgInsertFeatures insert = new MgInsertFeatures("Default:MarkupRegistry", insertVals);

            commands.Add(insert);

            MgPropertyCollection result       = _featSvc.UpdateFeatures(fsId, commands, false);
            MgFeatureProperty    insertResult = result.GetItem(0) as MgFeatureProperty;

            if (insertResult != null)
            {
                MgFeatureReader fr = insertResult.GetValue();
                fr.Close();
            }
        }
Example #2
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgPropertyCollection propVals = new MgPropertyCollection();
            MgInt32Property      prop     = new MgInt32Property("prop", 1);

            propVals.Add(prop);
            MgUpdateFeatures update = new MgUpdateFeatures("class2", propVals, "where cat < dog");
            MgInsertFeatures insert = new MgInsertFeatures("class3", propVals);
            MgDeleteFeatures del    = new MgDeleteFeatures("class1", "where cat > dog");

            MgFeatureCommandCollection coll = new MgFeatureCommandCollection();

            coll.Add(update);
            coll.Add(insert);
            coll.Add(del);

            Assert.AreEqual(3, coll.Count);
            Assert.AreEqual(MgFeatureCommandType.DeleteFeatures, coll[2].GetCommandType());
            coll[0] = coll[1];

            string txt = "";

            foreach (MgFeatureCommand cmd in coll)
            {
                txt += "[" + cmd.GetCommandType() + "]";
            }
            Assert.AreEqual("[0][0][2]", txt);
        }
Example #3
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgPropertyCollection propColl = new MgPropertyCollection();

            propColl.Add(new MgInt32Property("intProp", 10));
            MgInsertFeatures inf = new MgInsertFeatures("ClassName", propColl);

            Assert.AreEqual("ClassName", inf.FeatureClassName);
        }
Example #4
0
 public static void AddPointFeature(string FeatureName, MgPropertyCollection featureProps, MgPoint geom, MgFeatureService featureSrvc, MgResourceIdentifier dataSourceId)
 {
     MgByteReader geomReader = new MgAgfReaderWriter().Write(geom);
     MgGeometryProperty geometryProp = new MgGeometryProperty("GEOM", geomReader);
     featureProps.Add(geometryProp);
     MgInsertFeatures cmd = new MgInsertFeatures(FeatureName, featureProps);
     MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
     commands.Add(cmd);
     ReleaseReader(featureSrvc.UpdateFeatures(dataSourceId, commands, false));
 }
Example #5
0
        private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded)
        {
            MgPropertyCollection feature  = new MgPropertyCollection();
            MgByteReader         agf      = _agfRW.Write(geom);
            MgGeometryProperty   geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf);

            feature.Add(geomProp);
            MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            feature.Add(strProp);

            MgMapBase         map                  = _viewer.GetMap();
            MgLayerCollection layers               = map.GetLayers();
            MgLayerBase       redlineLayer         = layers.GetItem(_layer.SystemName);
            MgClassDefinition cls                  = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

            MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature);

            commands.Add(insert);

            MgPropertyCollection result = redlineLayer.UpdateFeatures(commands);
            //Insert result is a MgFeatureProperty containing an MgFeatureReader
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            MgStringProperty  errorResult  = result.GetItem(0) as MgStringProperty;

            if (insertResult != null)
            {
                var reader   = insertResult.GetValue();
                int inserted = 0;
                int?id       = null;
                try
                {
                    if (reader.ReadNext())
                    {
                        inserted++;
                        id = reader.GetInt32(idProp.Name);
                    }
                }
                catch (MgException ex)
                {
                    ex.Dispose();
                }
                finally
                {
                    reader.Close();
                }
                if (inserted > 0)
                {
                    _viewer.RefreshMap();
                    onRedlineAdded(id, text);
                }
            }
            else if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
        }
Example #6
0
 private void SetOrder()
 {
     int index = 1;
     MgFeatureCommandCollection cmdCollection = new MgFeatureCommandCollection();
     MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection {
     CreateOrderEntry("FeatureSource", 0),
     CreateOrderEntry("UID", 0),
     CreateOrderEntry("InfrastructureType", index++),
     CreateOrderEntry("OperationType", index++),
     CreateOrderEntry("OperationDescription", index++),
     CreateOrderEntry("Status", index++),
     CreateOrderEntry("Contractor", index++),
     CreateOrderEntry("Inspector", index++),
     CreateOrderEntry("OrderNum", index++),
     CreateOrderEntry("dtStart", index++),
     CreateOrderEntry("dtDue", index++),
     CreateOrderEntry("dtEnd", index++),
     CreateOrderEntry("dtUpdate", index++),
     CreateOrderEntry("WorkCost", index++),
     CreateOrderEntry("Note", index)
     };
     MgInsertFeatures insert = new MgInsertFeatures("Maintenance:FIELDS_ORDER", batchPropertyCollection);
     cmdCollection.Add(insert);
     this._helper.FeatureService.UpdateFeatures(this._sdfResId, cmdCollection, false);
 }
Example #7
0
 public void CreateNew(int uid, string infrastructureType)
 {
     if (!string.IsNullOrEmpty(infrastructureType) && (infrastructureType != "בחר מרשימה"))
     {
         SetInfrastructureType(this._parentLayer.FeatureSourceId, infrastructureType);
         MgGeometryProperty geometry = null;
         MgResourceIdentifier resId = new MgResourceIdentifier(this._parentLayer.FeatureSourceId);
         MgFeatureQueryOptions opt = new MgFeatureQueryOptions();
         opt.SetFilter(string.Format("{0}={1}", this._uidKey, uid));
         MgFeatureReader reader = this._helper.FeatureService.SelectFeatures(resId, this._parentLayer.FeatureClassName, opt);
         MgClassDefinition classDefinition = this._helper.FeatureService.GetClassDefinition(resId, this._parentLayer.FeatureClassName.Split(new char[] { ':' })[0], this._parentLayer.FeatureClassName.Split(new char[] { ':' })[1]);
         if (classDefinition != null)
         {
             string geomName = classDefinition.DefaultGeometryPropertyName;
             if (reader.ReadNext())
             {
                 MgByteReader value = reader.GetGeometry(geomName);
                 if (value != null)
                 {
                     geometry = new MgGeometryProperty(geomName, value);
                 }
             }
         }
         reader.Close();
         reader.Dispose();
         if (geometry != null)
         {
             MgDateTime today = new MgDateTime();
             MgPropertyCollection properties = new MgPropertyCollection {
             geometry,
             new MgInt32Property("UID", uid),
             new MgStringProperty("InfrastructureType", infrastructureType),
             new MgStringProperty("OperationType", "לא מוגדר"),
             new MgStringProperty("Status", "פתוח"),
             new MgStringProperty("FeatureSource", this._parentLayer.FeatureSourceId),
             new MgDateTimeProperty("dtStart", today),
             new MgDateTimeProperty("dtDue", today),
             new MgDateTimeProperty("dtUpdate", today)
         };
             MgInsertFeatures insert = new MgInsertFeatures("Maintenance", properties);
             MgFeatureCommandCollection commands = new MgFeatureCommandCollection {
             insert
         };
             this._helper.FeatureService.UpdateFeatures(this._sdfResId, commands, false);
         }
     }
 }
Example #8
0
        public void FeatureCommandCollection()
        {
            MgPropertyCollection propVals = new MgPropertyCollection();
            MgInt32Property prop = new MgInt32Property("prop", 1);
            propVals.Add(prop);
            MgUpdateFeatures update = new MgUpdateFeatures("class2", propVals, "where cat < dog");
            MgInsertFeatures insert = new MgInsertFeatures("class3", propVals);
            MgDeleteFeatures del = new MgDeleteFeatures("class1", "where cat > dog");

            MgFeatureCommandCollection coll = new MgFeatureCommandCollection();
            coll.Add(update);
            coll.Add(insert);
            coll.Add(del);

            Assert.AreEqual(3, coll.Count);
            Assert.AreEqual(MgFeatureCommandType.DeleteFeatures, coll[2].GetCommandType());
            coll[0] = coll[1];

            string txt = "";
            foreach (MgFeatureCommand cmd in coll)
            {
                txt += "[" + cmd.GetCommandType() + "]";
            }
            Assert.AreEqual("[0][0][2]", txt);
        }
Example #9
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ������ʱ��
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public bool CreatePointsLayer(String rootPath, String sessionId)
    {
        // ��ȡҪ�ط������Դ����
        MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        //  �򿪵�ͼ
        MgMap map = new MgMap();
        map.Open(resourceService, "Sheboygan");
        // ---Ҫ�����Ҫ�ز������û��������������滹Ҫ���ܣ�--��ʼ
        // ���������ݵ�Ҫ��Դ
        CreateFeatureSource(sessionId);
        String featureSourceName = "Session:" + sessionId + "//Points.FeatureSource";
        MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);

        MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
        MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        MgGeometryFactory geometryFactory = new MgGeometryFactory();

        // �������¼
        MgPropertyCollection propertyCollection = MakePoint("Point A", -87.727, 43.748);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point B", -87.728, 43.730);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point C", -87.726, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point D", -87.728, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        // ��������Ҫ��������ӵ�Ҫ��Դ
        MgInsertFeatures Insertcmd = new MgInsertFeatures("Points", batchPropertyCollection);
        MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
        featureCommandCollection.Add(Insertcmd);
        featureService.UpdateFeatures(resourceIdentifier, featureCommandCollection, false);
        MgResourceIdentifier resourceID = null;
        //--------------Ҫ�����Ҫ�ز��� ����

        // �����㣬ͨ���㹤��LayerDefinitionFactory
        LayerDefinitionFactory factory = new LayerDefinitionFactory();
        factory.RootDirectoryPath = rootPath;

        //-------------------��������ʽ------------------------//
        // ������Ƿ���l
        string resourceSymbel = "Library://MgTutorial/Symbols/BasicSymbols.SymbolLibrary";
        string symbolName = "PushPin";
        string width = "24";  // unit = points
        string height = "24"; // unit = points
        string color = "FFFF0000";
        string markSymbol = factory.CreateMarkSymbol(resourceSymbel, symbolName, width, height, color);

        // �����ı�
        string text = "ID";
        string fontHeight = "12";
        string foregroundColor = "FF000000";
        string textSymbol = factory.CreateTextSymbol(text, fontHeight, foregroundColor);

        // ���������
        string legendLabel = "trees";
        string filter = "";
        string pointRule = factory.CreatePointRule(legendLabel, filter, textSymbol, markSymbol);

        // ��������ʽ
        string pointTypeStyle = factory.CreatePointTypeStyle(pointRule);

        // �������ŷ�Χ
        string minScale = "0";
        string maxScale = "1000000000000";
        string pointScaleRange = factory.CreateScaleRange(minScale, maxScale, pointTypeStyle);

        // �����㶨��
        string featureName = "PointSchema:Points";
        string geometry = "GEOM";
        string layerDefinition = factory.CreateLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange);

        MgByteSource byteSource = new MgByteSource(Encoding.UTF8.GetBytes(layerDefinition), layerDefinition.Length);
        MgByteReader byteReader = byteSource.GetReader();

        resourceID = new MgResourceIdentifier("Session:" + sessionId + "//Points.LayerDefinition");
        resourceService.SetResource(resourceID, byteReader, null);
        //��������IJ㶨�����ݣ������ã�
        MgByteSink byteSink = new MgByteSink(resourceService.GetResourceContent(resourceID));
        string filePath = "C:\\Temp\\LayerDefinition.xml";
        byteSink.ToFile(filePath);

        // �����㲢��ӵ�����͵�ͼ��
        MgLayer newLayer = CreateLayerResource(resourceID, resourceService, "Points", "��ʱ��", map);

        AddLayerToGroup(newLayer, "Analysis", "����", map);

        MgLayerCollection layerCollection = map.GetLayers();
        if (layerCollection.Contains("Points"))
        {
            MgLayer pointsLayer = layerCollection.GetItem("Points");
            pointsLayer.SetVisible(true);
        }
        // �����ͼ
        map.Save(resourceService);

        return true;
    }
Example #10
0
        private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded)
        {
            MgPropertyCollection feature = new MgPropertyCollection();
            MgByteReader agf = _agfRW.Write(geom);
            MgGeometryProperty geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf);
            feature.Add(geomProp);
            MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);
            feature.Add(strProp);

            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerBase redlineLayer = layers.GetItem(_layer.SystemName);
            MgClassDefinition cls = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition idProp = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            
            MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature);
            commands.Add(insert);

            MgPropertyCollection result = redlineLayer.UpdateFeatures(commands);
            //Insert result is a MgFeatureProperty containing an MgFeatureReader
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            MgStringProperty errorResult = result.GetItem(0) as MgStringProperty;
            if (insertResult != null)
            {
                var reader = insertResult.GetValue();
                int inserted = 0;
                int? id = null;
                try
                {
                    if (reader.ReadNext())
                    {
                        inserted++;
                        id = reader.GetInt32(idProp.Name);
                    }
                }
                catch (MgException ex)
                {
                    ex.Dispose();
                }
                finally
                {
                    reader.Close();
                }
                if (inserted > 0)
                {
                    _viewer.RefreshMap();
                    onRedlineAdded(id, text);
                }
            }
            else if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
        }
Example #11
0
        internal void InsertFeatures(MgResourceIdentifier fsId, string className, MgPropertyCollection props)
        {
            try
            {
                MgFeatureCommandCollection cmds = new MgFeatureCommandCollection();
                MgInsertFeatures insert = new MgInsertFeatures(className, props);
                cmds.Add(insert);

                MgFeatureService fs = (MgFeatureService)this.Connection.CreateService(MgServiceType.FeatureService);
                MgPropertyCollection result = fs.UpdateFeatures(fsId, cmds, false);

                ((MgFeatureProperty)result.GetItem(0)).GetValue().Close();
            }
            catch (MgException ex)
            {
                var exMgd = new FeatureServiceException(ex.Message);
                exMgd.MgErrorDetails = ex.GetDetails();
                exMgd.MgStackTrace = ex.GetStackTrace();
                ex.Dispose();
                throw exMgd;
            }
        }
Example #12
0
        internal void AddRedlineLayer(RedlineLayer layer, string fdoProvider)
        {
            var fsId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgPropertyCollection insertVals = new MgPropertyCollection();

            MgStringProperty regId = new MgStringProperty("ResourceId", layer.FeatureSource);
            MgStringProperty ldfId = new MgStringProperty("LayerDefinition", layer.LayerDefinition);
            MgStringProperty name = new MgStringProperty("Name", layer.Name);
            MgStringProperty provider = new MgStringProperty("FdoProvider", fdoProvider);
            MgInt32Property geomTypes = new MgInt32Property("GeometryTypes", layer.GeometryTypes);
            MgInt32Property styleType = new MgInt32Property("StyleType", (int)layer.StyleType);

            insertVals.Add(regId);
            insertVals.Add(ldfId);
            insertVals.Add(name);
            insertVals.Add(provider);
            insertVals.Add(geomTypes);
            insertVals.Add(styleType);

            MgInsertFeatures insert = new MgInsertFeatures("Default:MarkupRegistry", insertVals);
            commands.Add(insert);

            MgPropertyCollection result = _featSvc.UpdateFeatures(fsId, commands, false);
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            if (insertResult != null)
            {
                MgFeatureReader fr = insertResult.GetValue();
                fr.Close();
            }
        }
Example #13
0
 public void InsertFeatures()
 {
     MgPropertyCollection propColl = new MgPropertyCollection();
     propColl.Add(new MgInt32Property("intProp", 10));
     MgInsertFeatures inf = new MgInsertFeatures("ClassName", propColl);
     Assert.AreEqual("ClassName", inf.FeatureClassName);
 }
Example #14
0
 private void UpdatingFeature(MgResourceIdentifier featureResId, string featureClassName, string filter, Dictionary<string, FeatureProperty> propCollection)
 {
     MgFeatureCommandCollection updCommands = new MgFeatureCommandCollection();
     MgPropertyCollection properties = new MgPropertyCollection();
     MgPropertyCollection properties2Log = new MgPropertyCollection();
     if (this.InsertToLog)
     {
         properties2Log.Add(new MgInt32Property("ItemId", this.FeatId));
     }
     foreach (KeyValuePair<string, FeatureProperty> item in propCollection)
     {
         try
         {
             MgProperty prop = item.Value.GenerateProperty();
             MgProperty prop4Log = item.Value.GenerateProperty(false);
             if (prop4Log != null)
             {
                 prop4Log.Name = item.Key;
                 if (this.InsertToLog)
                 {
                     properties2Log.Add(prop4Log);
                 }
             }
             if (prop != null)
             {
                 prop.Name = item.Key;
                 properties.Add(prop);
             }
         }
         catch (InvalidOperationException)
         {
         }
     }
     if (featureClassName == string.Empty)
     {
         featureClassName = this.Layer.FeatureClassName;
     }
     if (properties.Count > 0)
     {
         MgUpdateFeatures updateCommand = new MgUpdateFeatures(featureClassName, properties, filter);
         updCommands.Add(updateCommand);
         if (this.InsertToLog)
         {
             MgInsertFeatures insert = new MgInsertFeatures(featureClassName + "Log", properties2Log);
             updCommands.Add(insert);
         }
         this._helper.FeatureService.UpdateFeatures(featureResId, updCommands, false);
         this._helper.Map.Save(this._helper.ResourceService);
     }
 }