Exemple #1
0
        private static void AnalyzeCategories(Dictionary <string, string> gCats, Idoit idoit, List <string> ignoredList)
        {
            /*Dictionary<string, KeyValuePair<string, DialogFieldInfo>> enumKeyValuePairs =
             *  new Dictionary<string, KeyValuePair<string, DialogFieldInfo>>();*/

            foreach (var catDictionaryEntry in gCats)
            {
                if (catDictionaryEntry.Key.Equals("C__CMDB__SUBCAT__STORAGE__DEVICE"))
                {
                }
                try
                {
                    var fields = idoit.CategoryInfo(catDictionaryEntry.Key);
                    if (fields != null)
                    {
                        CSharpSourceWriter writer = new CSharpSourceWriter(catDictionaryEntry.Key,
                                                                           catDictionaryEntry.Value);
                        foreach (var fieldEntry in fields)
                        {
                            if ((fieldEntry.Value.ui.type == "dialog" || (fieldEntry.Value.ui.type == "popup")) && (fieldEntry.Value.data.type == "int" || (fieldEntry.Value.data.type == "text")))
                            {
                                try
                                {
                                    var enumData = idoit.Dialog(catDictionaryEntry.Key, fieldEntry.Key);
                                    writer.AddEnum(fieldEntry.Value.ui.id, enumData);
                                }
                                catch (JsonReaderException)
                                {
                                }
                            }
                            writer.AddField(fieldEntry.Key, fieldEntry.Value);
                        }
                        writer.Finalize();
                        writer.SaveTo(writer.RecommendedFileName);
                        writer.Dispose();
                    }
                }
                catch (JsonRpcException rpcException)
                {
                    Console.WriteLine("-> Ignored class cause it could not be parsed.");
                    ignoredList.Add(catDictionaryEntry.Key);
                }
                catch (WebException webException)
                {
                    HttpWebResponse hwr = (HttpWebResponse)webException.Response;
                    if (hwr.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        Console.WriteLine("-> Ignored class because it does not contain any data.");
                        ignoredList.Add(catDictionaryEntry.Key);
                    }
                }
            }
        }
Exemple #2
0
        private static void Interactive(string apiKey, string url, string username, string password)
        {
            Idoit  idoit  = Idoit.Login(apiKey, url, username, password);
            string cat    = null;
            bool   active = true;

            Console.WriteLine("OK");
            while (active)
            {
                string[] args = Console.ReadLine().Split(' ');
                switch (args[0])
                {
                case "setcat":
                    cat = args[1];
                    break;

                case "enum":
                    if (string.IsNullOrEmpty(cat))
                    {
                        Console.WriteLine("no category specified. Use setcat first.");
                    }
                    CSharpSourceWriter csw = new CSharpSourceWriter("", "");
                    var dialog             = idoit.Dialog(cat, args[1]);
                    csw.GenEnum(args[1], dialog, Console.Out);
                    csw.Dispose();
                    break;

                case "exit":
                    active = false;
                    break;

                default:
                    Console.WriteLine("What?");
                    break;
                }
            }
            idoit.Logout();
        }