示例#1
0
        public void CategoryUpdate <T>(CmdbObject obj, T theObject)
            where T : Category
        {
            if (theObject.Constant.Equals("C__CMDB__SUBCAT__STORAGE__DEVICE"))
            {
                CategoryUpdate(obj, theObject, 43);     //Workaround für einen Bug in der i-doit API
                return;
            }
            Dictionary <string, object> updateData = new Dictionary <string, object>();

            updateData.Add("category_id", theObject.id);
            foreach (var fi in theObject.GetType().GetFields())
            {
                //Falls ein Feld mit JsonIgnore gekennzeichnet ist, es ausschließen.
                object[] attribs  = fi.GetCustomAttributes(true);
                bool     ignoreMe = false;
                foreach (object o in attribs)
                {
                    if (o is JsonIgnoreAttribute)
                    {
                        ignoreMe = true;
                        break;
                    }
                }
                if (ignoreMe)
                {
                    continue;
                }

                //Feld in die Update Warteschlage einreihen:
                updateData.Add(fi.Name, fi.GetValue(theObject));
            }

            Console.WriteLine("Updating {0} #{1} in {2}", theObject.DisplayName, theObject.id, obj.title);
            CategoryDeleteResponse r = JsonRpcCaller.Call <CategoryDeleteResponse>("cmdb.category.update", new
            {
                apikey   = Config.GetInstance().ApiKey,
                category = theObject.Constant,
                objID    = obj.id,
                data     = updateData
            });

            if (r.success != 1)
            {
                throw new Exception(r.message);
            }
        }
示例#2
0
        public void CategoryDelete <T>(CmdbObject obj, string catConstant, int categoryNumber)
            where T : Category
        {
            Console.WriteLine("Deleting {1} #{2} from {0}", obj.title, catConstant, categoryNumber);
            CategoryDeleteResponse cdr = JsonRpcCaller.Call <CategoryDeleteResponse>("cmdb.category.delete", new
            {
                catgID = catConstant,
                cateID = categoryNumber,
                objID  = obj.id,
                apikey = Config.GetInstance().ApiKey
            });

            if (cdr.success != 1)
            {
                throw new Exception(cdr.message);
            }
        }