Exemple #1
0
        static void Main(string[] args)
        {
            bool repeat = true;
            while (repeat)
            {

                var mainNameSpace = string.Empty;
                var folder = string.Empty;
                var userName = string.Empty;
                var passWord = string.Empty;
                string howManyEntities = string.Empty;
                int count = 0;
                string countEntities = "N";
                string[] yn = { "Y", "N", "y", "n" };
                bool limitEntities = false;

                ReadInputFromUser(ref userName, "Please enter your Clarizen Username");
                ReadInputFromUserSecretly(ref passWord, "Please enter your Clarizen Password");
                ReadInputFromUser(ref mainNameSpace, "Please enter a Main Namespace ");
                ReadInputFromUser(ref countEntities, "Parse all Clarizen Entities? Y/N ", yn);

                if (countEntities == "N" || countEntities == "n") limitEntities = true;
                if (limitEntities == true)
                {
                    ReadInputFromUser(ref howManyEntities, "How many Entities to parse?");
                    try
                    {
                        count = Convert.ToInt32(howManyEntities);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Input string is not a sequence of digits.");
                    }
                    catch (OverflowException e)
                    {
                        Console.WriteLine("The number cannot fit in an Int32.");
                    }
                }

                //TODO add logic to test this is a correct drive/folder.
                ReadInputFromUser(ref folder, "Please enter the folder location to save your code files ");

                ///need to change your password.
                RestClient client = new RestClient(userName, passWord);

                Console.WriteLine("Fetching data from Clarizen...");
                if (client.ListEntities != null)
                {
                    int counting = 0;
                    foreach (string s in client.ListEntities)
                    {
                        counting++;
                        client.GetAllMetadataDescribeEntitiesAndGetAllFields(s);
                        Console.Write(".");
                        if (counting > count && limitEntities == true) break;
                    }
                    Console.WriteLine();
                }

                if (client.ConvertedMetadata != null)
                {

                    Console.WriteLine("Creating Classes...");
                    foreach (KeyValuePair<string, JToken> pair in client.ConvertedMetadataWithoutCustomFields)
                    {

                        Console.Write(".");
                        var gen = Prepare(pair.Value, pair.Key, folder, mainNameSpace);
                        if (gen == null) return;

                        try
                        {
                            gen.GenerateClasses();

                        }
                        catch (Exception ex)
                        {
                            Console.Write("Error writing class " + ex + pair.Key + " " + pair.Value);
                        }

                    }
                }

                Console.WriteLine();
                Console.Write("Finished! - code should be ready in folder " + folder + " ");
                Console.WriteLine();
                string go = string.Empty;
                ReadInputFromUser(ref go, "Continue? ");
                if (go == "Y" || go == "y")
                {
                    repeat = true;
                }
                else
                {
                    repeat = false;
                }

            }
        }