예제 #1
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);
        }
예제 #2
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgPropertyCollection propColl = new MgPropertyCollection();

            propColl.Add(new MgInt32Property("intProp", 10));
            MgUpdateFeatures uf = new MgUpdateFeatures("ClassName", propColl, "filter");

            Assert.AreEqual("ClassName", uf.FeatureClassName);
            Assert.AreEqual("ClassName", uf.FeatureClassName);
        }
예제 #3
0
        internal void UpdateRedlineText(string text, int[] ids)
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            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
            List <string> filters = new List <string>();

            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string updateFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands     = new MgFeatureCommandCollection();
            MgPropertyCollection       updateValues = new MgPropertyCollection();
            MgStringProperty           updateProp   = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            updateValues.Add(updateProp);

            MgUpdateFeatures update = new MgUpdateFeatures(redlineLayer.FeatureClassName, updateValues, updateFilter);

            commands.Add(update);

            MgPropertyCollection result       = redlineLayer.UpdateFeatures(commands);
            MgInt32Property      updateResult = result.GetItem(0) as MgInt32Property;
            MgStringProperty     errorResult  = result.GetItem(0) as MgStringProperty;

            if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
            _viewer.RefreshMap();
        }
예제 #4
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);
        }
예제 #5
0
        internal void UpdateRedlineText(string text, int[] ids)
        {
            MgMapBase map = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();
            MgLayerBase redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            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
            List<string> filters = new List<string>();
            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string updateFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgPropertyCollection updateValues = new MgPropertyCollection();
            MgStringProperty updateProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);
            updateValues.Add(updateProp);
            
            MgUpdateFeatures update = new MgUpdateFeatures(redlineLayer.FeatureClassName, updateValues, updateFilter);
            commands.Add(update);

            MgPropertyCollection result = redlineLayer.UpdateFeatures(commands);
            MgInt32Property updateResult = result.GetItem(0) as MgInt32Property;
            MgStringProperty errorResult = result.GetItem(0) as MgStringProperty;
            if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
            _viewer.RefreshMap();
        }
예제 #6
0
        internal int UpdateFeatures(MgResourceIdentifier fsId, string className, MgPropertyCollection props, string filter)
        {
            try
            {
                MgFeatureCommandCollection cmds = new MgFeatureCommandCollection();
                MgUpdateFeatures update = new MgUpdateFeatures(className, props, filter);
                cmds.Add(update);

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

                var ip = result.GetItem(0) as MgInt32Property;
                if (ip != null)
                    return ip.GetValue();
                return -1;
            }
            catch (MgException ex)
            {
                var exMgd = new FeatureServiceException(ex.Message);
                exMgd.MgErrorDetails = ex.GetDetails();
                exMgd.MgStackTrace = ex.GetStackTrace();
                ex.Dispose();
                throw exMgd;
            }
        }
예제 #7
0
        /* OldUpdateFeature
        public void oldUpdateFeature(string filter)
        {
            string featureclassname = string.empty;

            mgresourceidentifier featureresid = new mgresourceidentifier(mlayer.getfeaturesourceid());

            mgbytereader reader1 = msiteutilities.resourceservice.getresourceheader(featureresid);
            string s = reader1.tostring();
            //join update
            mgstringcollection r = msiteutilities.featureservice.getclasses(featureresid, mlayer.featureclassname.split(':')[0]);
            if (r.getcount() > 1)
            {
                mgclassdefinition classdefinition = msiteutilities.featureservice.getclassdefinition(featureresid, mlayer.featureclassname.split(':')[0], mlayer.featureclassname.split(':')[1]);
                dictionary<string, list<mgpropertydefinition>> propcollection = new dictionary<string, list<mgpropertydefinition>>();
                foreach(var item in classdefinition.getproperties())
                {
                    string[] strs = item.qualifiedname.split('.');
                    if(!propcollection.containskey(strs[0]))
                    {
                        propcollection.add(strs[0], new list<mgpropertydefinition>());
                    }
                    propcollection[strs[0]].add(item);
                }
                string joinedschema = r.getitem(1);
                string[] arr = joinedschema.split(']');
                string schemaname = arr[2];
                string prefix = arr[1].remove(0, 1);
                string joinname = arr[0].remove(0, 1);
                featureclassname = r.getitem(0);
                dictionary<string, featproperty> parentproperties = new dictionary<string, featproperty>();
                dictionary<string, featproperty> childproperties = new dictionary<string, featproperty>();
                foreach (var item in propertiescollection)
                {
                    if (item.key.indexof(prefix) >= 0)
                    {
                        item.value.name = item.value.name.substring(prefix.length);
                        childproperties.add(item.value.name, item.value);
                    }
                    else
                    {
                        parentproperties.add(item.key, item.value);
                    }
                }

                updatingfeature(featureresid, featureclassname, filter, parentproperties);

                if (propertiescollection.containskey("uid"))
                {
                    mgresourceidentifier childresid = new mgresourceidentifier(featureresid.tostring());
                    string childfeatureclassname = schemaname.split(':')[1];
                    string childupdatingfilter = string.format("uid={0}", propertiescollection["uid"].value);
                    childresid.setname(childfeatureclassname);
                    updatingfeature(childresid, schemaname, childupdatingfilter, childproperties);
                }
                return;
            }
            else
            {
                updatingfeature(featureresid, featureclassname, filter, propertiescollection);
            }
        }
        */
        private void UpdatingFeature(MgResourceIdentifier featureResId, string FeatureClassName, string Filter, Dictionary<string, FeatProperty> propCollection)
        {
            string _filter = "FeatId LIKE '%%'";

            MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
            queryOptions.SetFilter(_filter);

            MgFeatureReader featureReader = mSiteUtilities.FeatureService.SelectFeatures(featureResId, FeatureClassName.Split(':')[1], null);

            featureReader = mSiteUtilities.FeatureService.SelectFeatures(featureResId, FeatureClassName.Split(':')[1], queryOptions);

            featureReader.ReadNext();
            //---------------------------------
            //-----lets start update
            //---------------------------------
            MgFeatureCommandCollection updCommands = new MgFeatureCommandCollection();

            MgPropertyCollection properties = new MgPropertyCollection();
            foreach (var item in propCollection)
            {
                try
                {
                    MgProperty prop = item.Value.GenerateProperty();
                    if (prop != null)
                    {
                        prop.Name = item.Key;
                        properties.Add(prop);
                    }
                }
                catch (InvalidOperationException)
                { }
            }

            if (FeatureClassName == string.Empty)
                FeatureClassName = mLayer.FeatureClassName;
            if (properties.Count > 0)
            {
                MgUpdateFeatures updateCommand = new MgUpdateFeatures(FeatureClassName, properties, Filter);
                updCommands.Add(updateCommand);

                MgPropertyCollection res = mSiteUtilities.FeatureService.UpdateFeatures(featureResId, updCommands, false);

                mSiteUtilities.Map.Save(mSiteUtilities.ResourceService);
                //---------------------------------
                //-----end of update
                //---------------------------------
                //====================================================================
            }
            featureReader.Close();
        }
예제 #8
0
 public void UpdateFeatures()
 {
     MgPropertyCollection propColl = new MgPropertyCollection();
     propColl.Add(new MgInt32Property("intProp", 10));
     MgUpdateFeatures uf = new MgUpdateFeatures("ClassName", propColl, "filter");
     Assert.AreEqual("ClassName", uf.FeatureClassName);
     Assert.AreEqual("ClassName", uf.FeatureClassName);
 }
예제 #9
0
파일: Feature.cs 프로젝트: ranyaof/Meuhedet
 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);
     }
 }