Beispiel #1
0
        public ObjectTypesResponse ObjectTypes()
        {
            Console.WriteLine("Getting object types...");
            ObjectTypesResponse result = JsonRpcCaller.Call <ObjectTypesResponse>("cmdb.object_types", new { apikey = Config.GetInstance().ApiKey });

            return(result);
        }
Beispiel #2
0
        public ConstantsResponse Constants()
        {
            Console.WriteLine("Getting constants...");
            ConstantsResponse response = JsonRpcCaller.Call <ConstantsResponse>("idoit.constants", new { apikey = Config.GetInstance().ApiKey });

            return(response);
        }
Beispiel #3
0
        public ObjectTypeCategoriesResponse ObjectTypeCategories(ObjectType ot)
        {
            Console.WriteLine("Getting object type categories...");
            ObjectTypeCategoriesResponse result = JsonRpcCaller.Call <ObjectTypeCategoriesResponse>("cmdb.object_type_categories", new
            {
                apikey = Config.GetInstance().ApiKey,
                type   = ot.constant
            });

            return(result);
        }
Beispiel #4
0
        public List <T> CategoryRead <T>(long id, int catg)
        {
            List <T> temp = JsonRpcCaller.Call <List <T> >("cmdb.category.read", new
            {
                apikey = Config.GetInstance().ApiKey,
                objID  = id,
                catgID = 43
            });

            return(temp);
        }
Beispiel #5
0
        public LogoutResponse Logout()
        {
            Console.WriteLine("Logging out...");
            LogoutResponse result = JsonRpcCaller.Call <LogoutResponse>("idoit.logout", new { apikey = Config.GetInstance().ApiKey });

            if (result.result == 1)
            {
                JsonRpcCaller.XRpcAuthSession = null;
            }
            return(result);
        }
Beispiel #6
0
        public CmdbObject GetCmdbObject(int cmdb_id)
        {
            Console.WriteLine("Fetching CMDB Object {0}...", cmdb_id);
            CmdbObject response = JsonRpcCaller.Call <CmdbObject>("cmdb.object.read", new
            {
                apikey = Config.GetInstance().ApiKey,
                id     = cmdb_id
            });

            return(response);
        }
Beispiel #7
0
        public Dictionary <string, DialogFieldInfo> CategoryInfo(CategoryInfo ci)
        {
            Console.WriteLine("Getting category info {0}...", ci.constant);
            Dictionary <string, DialogFieldInfo> result = JsonRpcCaller.Call <Dictionary <string, DialogFieldInfo> >("cmdb.category_info.read", new
            {
                apikey   = Config.GetInstance().ApiKey,
                category = ci.constant
            });

            return(result);
        }
Beispiel #8
0
        public bool DialogEditSpecific(Category c, string propertyName, string valueToAdd)
        {
            Console.WriteLine("Adding {0} to {1} {2}s...", valueToAdd, c.DisplayName, propertyName);

            DialogEditResponse response = JsonRpcCaller.Call <DialogEditResponse>("cmdb.dialog.create", new
            {
                apikey   = Config.GetInstance().ApiKey,
                catsID   = c.Constant,
                property = propertyName,
                value    = valueToAdd
            });

            return(response.success);
        }
Beispiel #9
0
        public bool DialogEdit(Category c, string propertyName, string valueToAdd)
        {
            Console.WriteLine("Adding {0} to {1} {2}s...", valueToAdd, c.DisplayName, propertyName);

            DialogEditResponse response = JsonRpcCaller.Call <DialogEditResponse>("cmdb.dialog.create", new
            {
                apikey   = Config.GetInstance().ApiKey,
                catgID   = c.Constant,      //nicht dokumentierter Aufruf... Quelle: http://forum.i-doit.org/index.php/topic,4570.msg13880.html#msg13880
                property = propertyName,
                value    = valueToAdd
            });

            return(response.success);
        }
Beispiel #10
0
        public CreateObjectResponse CreateCmdbObject(ObjectType objectType, string name)
        {
            Console.WriteLine("Creating a {0} named {1}...", objectType.title, name);
            CreateObjectResponse response = JsonRpcCaller.Call <CreateObjectResponse>("cmdb.object.create", new
            {
                apikey = Config.GetInstance().ApiKey,
                type   = objectType.constant,
                title  = name
            });

            Console.WriteLine("-> {0}", response.message);

            return(response);
        }
Beispiel #11
0
        public List <CmdbObject> FindObjects(ObjectType objectType)
        {
            Console.WriteLine("Looking up {1}s...", null, objectType.title);
            List <CmdbObject> o = JsonRpcCaller.Call <List <CmdbObject> >("cmdb.objects", new
            {
                apikey = Config.GetInstance().ApiKey,
                filter = new
                {
                    type = objectType.id
                }
            });

            return(o);
        }
Beispiel #12
0
        public IdoitEnumerator Dialog(string categoryConstant, string property)
        {
            Console.WriteLine("Getting Dialog {0} of {1}...", property, categoryConstant);
            IdoitEnumerator result = JsonRpcCaller.Call <IdoitEnumerator>("cmdb.dialog.read", new
            {
                apikey   = Config.GetInstance().ApiKey,
                category = categoryConstant,
                property = property
            });

            result.categoryConstant = categoryConstant;
            result.property         = property;

            return(result);
        }
Beispiel #13
0
        public LoginResponse Login(string username, string password)
        {
            Console.WriteLine("Logging in...");
            JsonRpcCaller.XRpcAuthUsername = username;
            JsonRpcCaller.XRpcAuthPassword = password;

            LoginResponse result = JsonRpcCaller.Call <LoginResponse>("idoit.login",
                                                                      new { apikey = Config.GetInstance().ApiKey });

            //Daten wieder vergessen, nachdem das einloggen erfolgreich war!
            JsonRpcCaller.XRpcAuthUsername = null;
            JsonRpcCaller.XRpcAuthPassword = null;

            JsonRpcCaller.XRpcAuthSession = result.session_id;
            return(result);
        }
Beispiel #14
0
        public List <T> CategoryRead <T>(long id, Category c)
        {
            if (c.Constant.Equals("C__CMDB__SUBCAT__STORAGE__DEVICE"))
            {
                return(CategoryRead <T>(id, 43)); //Workaround für einen Bug in der i-doit API.
            }

            List <T> temp = JsonRpcCaller.Call <List <T> >("cmdb.category.read", new
            {
                apikey   = Config.GetInstance().ApiKey,
                objID    = id,
                category = c.Constant
            });

            return(temp);
        }
Beispiel #15
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);
            }
        }
Beispiel #16
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);
            }
        }
Beispiel #17
0
        public void CategoryCreate <T>(CmdbObject obj, T theObject)
            where T : Category
        {
            Console.WriteLine("Adding a {0} to {1}", theObject.DisplayName, obj.title);

            CategoryCreateResponse response;

            if (theObject.Constant.Equals("C__CATG__GLOBAL"))
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catgID = 1,
                    objID  = obj.id,
                    data   = theObject,
                });
            }

            if (theObject.Constant.Contains("CATS__"))
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catsID = theObject.Constant,
                    objID  = obj.id,
                    data   = theObject,
                });
            }
            else
            {
                response = JsonRpcCaller.Call <CategoryCreateResponse>("cmdb.category.create", new
                {
                    apikey = Config.GetInstance().ApiKey,
                    catgID = theObject.Constant,
                    objID  = obj.id,
                    data   = theObject,
                });
            }

            if (response.success != 1)
            {
                throw new Exception(response.message);
            }
        }
Beispiel #18
0
        public Dictionary <string, DialogFieldInfo> CategoryInfo(string ci)
        {
            switch (ci) //Workaround für einen Bug in der i-doit API.
            {
            case "C__CMDB__SUBCAT__STORAGE__DEVICE":
                return(CategoryInfo(43));

            default:
                break;
            }
            Console.WriteLine("Getting category info {0}...", ci);
            Dictionary <string, DialogFieldInfo> result = JsonRpcCaller.Call <Dictionary <string, DialogFieldInfo> >("cmdb.category_info.read", new
            {
                apikey   = Config.GetInstance().ApiKey,
                category = ci
            });

            return(result);
        }
Beispiel #19
0
 public VersionResponse Version()
 {
     Console.WriteLine("Checking i-doit Version...");
     return(JsonRpcCaller.Call <VersionResponse>("idoit.version", new { apikey = Config.GetInstance().ApiKey }));
 }