Ejemplo n.º 1
0
                    if (week_total_hours < required_hours && time_needed > 0 /**/ && i!=0 && i !=6) { //hard code ignore of sunday and saturaday for now

                        Console.WriteLine(day_name + " FAILED inspection. Tai says, 'add some time m**********r!'");

                        while (time_needed > 0) {

                            //muaha! now create the new time items using the api
                            //remember we are looking into the payload manipulation via c#

                            foreach(string priority in priority_strings) { //since days only get iterated over once, this will save a max of 6 hours in single day. either iterate over the days while week_time_needed > 0 OR add more priorty strings. the prior is superior because if tere is at least 1 priority, then it will get filled out to the max instead of each priority only getting filled out then closing

                                var post_date = week_begin_date.AddDays(i);

                                string existing_object_id = priority_chart[priority].getTimeValueObjectIdForThisDate(post_date);
                                int existing_hours = priority_chart[priority].getTimeValueHoursForThisDate(post_date);

                                JObject postJson = new JObject();
                                postJson["Verb"] =  existing_object_id != string.Empty ? "update" : "insert";
                                postJson["ObjectID"] = existing_object_id;
                                postJson["DateVal"] = post_date.ToString("yyyy-MM-ddTHH:mm:ssZ");
                                postJson["Hours"] = (existing_hours+1);
                                postJson["TimeEntryItem"] = priority_chart[priority].timeEntryObjectId;

                                Console.WriteLine(postJson);
                                Console.WriteLine("..........");

                                db.PostNewTimeEntryValue(postJson);
                                //if post was a success then add time to mem
                                day_hours[i] += (existing_hours+1);

                                time_needed -= (int)postJson["Hours"];
                                if(time_needed <= 0){
                                    break;}

                            }
                        }

                    }else{
                        Console.WriteLine(day_name + " PASSED inspection");
                    }
                }

            }else {
                Console.WriteLine("Autofilling is not needed since you have already filled out the minimum necessary time");
            }
        }

        private static StringBuilder GenerateCLIReport(List<JToken> fullTeam, List<JToken> iterations, List<JToken> storys, List<JToken> tasks)
        {
            var report = new StringBuilder();

            foreach (JToken iteration in iterations){
                report.AppendLine((string)iteration["Name"]);}
            report.AppendLine("==========================\n\n");

            report.AppendLine("Team Members");
            foreach (JToken person in fullTeam){
                report.AppendLine((string)person["DisplayName"]);}
            report.AppendLine("==========================\n\n");

            foreach (JToken story in storys) {

                var hero = (string)story["HeroOfTime"];
                var name = (string)story["Name"];
                var risk = (string)story["BlockedReason"];
                var status = (string)story["ScheduleState"];
                var date = ((string)story["AcceptedDate"]).GetPrettyDate();

                var line = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", hero, name, date, status, risk);

                report.AppendLine(line);
                report.AppendLine("-----------------------\n");
            }

            return report;
        }

        private static StringBuilder GenerateGenerictHtmlTabularReport(List<JToken> storys, RallyBotConfig config)
        {
            var emailBody   = new StringBuilder();

            var headerRow = string.Format("<tr><td><p>{0}</p></td> <td><p>{1}</p></td> <td><p>{2}</p></td> <td><p>{3}</p></td> <td><p>{4}</p></td></tr>",
                "Person",
                "Story",
                "Finished On",
                "Status",
                "Risks"
                );

            emailBody.Append(string.Format("<p>{0},</p><br>Here is the latest status report.<br><br>", config.emailGreeting));
            emailBody.Append("<table>");
            emailBody.Append(headerRow);

            foreach (JToken story in storys) {

                var hero = (string)story["HeroOfTime"];
                var name = (string)story["Name"];
                var risk = (string)story["BlockedReason"];
                var status = (string)story["ScheduleState"];
                var date = ((string)story["AcceptedDate"]).GetPrettyDate();

                var dataRow = string.Format("<tr><td><p>{0}</p></td> <td><p>{1}</p></td> <td><p>{2}</p></td> <td><p>{3}</p></td> <td><p>{4}</p></td></tr>",
                    hero,
                    name,
                    date,
                    status,
                    risk
                    );

                emailBody.Append(dataRow);
            }
            emailBody.Append("</table>");

            var signature = string.Format("<br><br><p>{0},</p><br><p>-{1}</p>", GetFarewell(), config.emailSignature);

            emailBody.Append(signature);

            return emailBody;
        }

        private static StringBuilder GenerateMicrosoftHtmlTabularReport(List<JToken> storys, RallyBotConfig config)
        {
            var emailBody   = new StringBuilder();

            var headerRow = string.Format("<tr><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{0}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;border-left:none;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{1}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;border-left:none;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{2}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;border-left:none;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{3}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;border-left:none;padding:0in 5.4pt 0in 5.4pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{4}<o:p></o:p></p></td></tr>",
                "Person",
                "Story",
                "Finished On",
                "Status",
                "Risks"
                );

            emailBody.Append(string.Format("<p>{0},</p><br>Here is the latest status report.<br><br>", config.emailGreeting));
            emailBody.Append("<table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 align=left style='border-collapse:collapse;border:none;margin-left:6.75pt;margin-right:6.75pt'>");
            emailBody.Append(headerRow);

            foreach (JToken story in storys) {

                var hero = (string)story["HeroOfTime"];
                var name = (string)story["Name"];
                var risk = (string)story["BlockedReason"];
                var status = (string)story["ScheduleState"];
                var date = ((string)story["AcceptedDate"]).GetPrettyDate();

                var dataRow = string.Format("<tr style='height:14.35pt'><td width=125 valign=top style='width:93.5pt;border:solid windowtext 1.0pt;border-top:none;padding:0in 5.4pt 0in 5.4pt;height:14.35pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{0}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:14.35pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{1}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:14.35pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{2}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:14.35pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{3}<o:p></o:p></p></td><td width=125 valign=top style='width:93.5pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:14.35pt'><p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:margin;mso-element-top:-.65pt;mso-height-rule:exactly'>{4}<o:p></o:p></p></td></tr>",
                    hero,
                    name,
                    date,
                    status,
                    risk
                    );

                emailBody.Append(dataRow);
            }
            emailBody.Append("</table>");

            var signature = string.Format("<br><br><p>{0},</p><br><p>-{1}</p>", GetFarewell(), config.emailSignature);

            emailBody.Append(signature);

            return emailBody;
        }

        private static StringBuilder GetErrorReport(string[] badInput)
        {
            var err_report = new StringBuilder();

            foreach(string misunderstood_word in badInput) {
                err_report.AppendLine("No switch available for: " + misunderstood_word);}

            return err_report;
        }

        private static string GetFarewell()
        {
            var farewell = new string[]{
            "thinking of you",
            "your majesty",
            "with smugness",
            "smugly yours",
            "sincerely",
            "with great jubilation",
            "fearfully yours",
            "lurking behind you",
            "good day",
            "with regrets",
            "My Best",
            "My best to you",
            "Best",
            "All Best",
            "All the best",
            "Best Wishes",
            "Bests",
            "Best Regards",
            "Regards",
            "Warm Regards",
            "Warmest Regards",
            "Warmest",
            "Warmly",
            "Take care",
            "Many thanks",
            "Thanks for your consideration",
            "Hope this helps",
            "Looking forward",
            "Rushing",
            "In haste",
            "Be well",
            "Peace",
            "Yours Truly",
            "Yours",
            "Very Truly Yours",
            "Sincerely",
            "Sincerely Yours",
            "Cheers!"
            };

            return farewell[new Random().Next(0, farewell.Length)];
        }

        private static string GetIterationNumberFromTerminal(string someQuestion)
        {
            //todo: input validation
            Console.WriteLine("\n"+someQuestion+"\n");
            return Console.ReadLine();
        }

        private static string GetPasswordFromTerminal()
        {
            //TODO: actually hide password
            Console.Write("enter rally password\n\nyour hidden password: "******"Your Rally ProjectId is associated with your specific team;
            such as dream team, seal team 6, or team impact.
            In order to get your ProjectId:

            1. goto https://rally1.rallydev.com/
            2. login using your credentials
            3. In the top left corner, be sure that your team name is selected
            4. Once you have selected your team name, the ProjectId will be located in the url after the hashtag(#) symbol
            5. be sure to exclude the last letter 'd'

            What is your ProjectId?
            ");

            return Console.ReadLine();
        }

        private static string[] GetTeamMemberFirstNamesFromTerminal()
        {
            Console.Write("enter first name(s) of your dev team members seperated by a single space \nex: ross derrick antonio \n\nfirst names: ");
            return Console.ReadLine().Split(' ');
        }

        private static string GetThisFolder()
        {
            var path_bits = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\');

            string simple_path_i_have_to_build_because_you_suck_microsoft = "";

            for(int i=0; i<(path_bits.Length-1); ++i) {
                simple_path_i_have_to_build_because_you_suck_microsoft += path_bits[i]+'\\';}

            return simple_path_i_have_to_build_because_you_suck_microsoft;
        }

        private static string GetUsernameFromTerminal()
        {
            //todo: validate email format regex ? /w.*\@/w.*\.com
            Console.Write("enter rally username\nex: [email protected]\n\nyour username: "******"rallybot.conf")
        {
            //todo: check if the file exists, if it does not, then create one
            //todo: encode the password or some other method. ask ross (if there is a plaintext password then erase it and write the back the encoded version as a different serialized property name)

            RallyBotConfig conf = new RallyBotConfig(@fileLocation);

            if(!conf.isValidConfiguration) {

                conf.username = GetUsernameFromTerminal();
                conf.password = GetPasswordFromTerminal();
                conf.emailGreeting = "Hey Boss";
                conf.emailSignature = "dev team";
                conf.includeNames = GetTeamMemberFirstNamesFromTerminal();
                conf.projectId = GetProjectIdFromTerminal();
                SaveNewConfig(@fileLocation, conf);
            }

            return conf;
        }

        private static string OffensiveGesture()
        {
            return @"┌∩┐(>_<)┌∩┐";
        }

        private static bool SaveNewConfig(string newFileLocation, RallyBotConfig config)
        {
            //delete any potential existing file at location
            //create the new file and save the serialized version into it config.ToString() override
            // if there is a failure, just tell the user. dont try to solve any issues yet

            return false;
        }

        /**M: Sets a story's buildID and Unit Test Config flag (to true by default)**/
        private static void SetBuildId(RallyBotConfig config, string buildId)
        {
            var buildid = buildId.Length > 0 ? buildId : GetIterationNumberFromTerminal("What BuildId number do want to use ?");
            var userStoryId = GetIterationNumberFromTerminal("Please Enter the User story ID (ex: US12345) : ");   //sry using your GetIterationNumberFromTerminal() for general console input :P

            //should prolly do input validation..
            Console.WriteLine("User story ID: " + userStoryId);
            Console.WriteLine("Build ID: " + buildid);

            var db = new RallyDatabase(config);
            string UserStoryURL= db.GetUserStoryRef(userStoryId);

            JObject postJson = new JObject();
            postJson["c_BuildID"] = buildid;

            db.PostNewBuildId(postJson, UserStoryURL);
            Console.WriteLine("..........");
        }