//To find the array response when queried as the issues URL
 //The function is seperated as the functionality can be further used by the project over time
 //Owing to the fact we need one of the function to just return the array response and the other to return
 //The simple json response
 public static JArray GetReponseAsyncArray(string url, ref StatusStructure statusStructure)
 {
     try
     {
         HttpWebResponse response       = Response(url, ref statusStructure);
         var             responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
         JArray          responseArray  = JArray.Parse(responseString);
         statusStructure.m_statusCode    = 200;
         statusStructure.m_statusMessage = "OK";
         return(responseArray);
     }
     catch (Exception ex)
     {
         statusStructure.m_statusCode    = 400;
         statusStructure.m_statusMessage = ex.Message;
         return(new JArray());
     }
 }
 /* Returns the HttpResponse
  *  This is needed for getting the response headers so as to make out
  *  whether pagination is needed or not
  */
 public static HttpWebResponse Response(string url, ref StatusStructure statusStructure)
 {
     try
     {
         if (url.EndsWith("/"))
         {
             url = url.TrimEnd('/');
         }
         var request = (HttpWebRequest)WebRequest.Create(url);
         request.UserAgent = "request";
         return((HttpWebResponse)request.GetResponse());
     }
     catch (WebException ex)
     {
         var exception = ex.Response as HttpWebResponse;
         statusStructure.m_statusCode    = (int)exception.StatusCode;
         statusStructure.m_statusMessage = ex.Message;
         return(exception);
     }
 }
Exemple #3
0
        public ActionResult Index(string url)
        {
            StatusStructure statusStructure      = new StatusStructure();
            string          fixedGithubUrl       = "https://github.com/";
            int             fixedGithubUrlLength = fixedGithubUrl.Length;

            if (!url.Contains(fixedGithubUrl))
            {
                statusStructure.m_statusCode    = 201;
                statusStructure.m_statusMessage = "Please enter a valid github repo";
                return(View("Index", new ResponseStructure(statusStructure)));
            }

            string retrieveApiUrl = url.Substring(fixedGithubUrlLength);

            if (!retrieveApiUrl.EndsWith("/"))
            {
                retrieveApiUrl += "/";
            }
            return(View("Index", new ResponseStructure(retrieveApiUrl, statusStructure)));
        }
Exemple #4
0
        //parse command line arguments http://www.ndesk.org/Options
        static void Main(string[] args)
        {
            System.DateTime?firstDate        = null;
            System.DateTime?secondDate       = null;
            String          templateFilePath = "";
            String          outputPath       = "";

            StatusStructure messageHandlingStatus = new StatusStructure {
                show_help = false, templateExpected = false, resultUnspecified = false
            };

            OptionSet p = new OptionSet()
                          .Add("d1|date1=", "First {DATE1} of span to generate calendar", delegate(string v) {
                if (v != null)
                {
                    firstDate = System.DateTime.Parse(v);
                }
            })
                          .Add("d2|date2=", "Second {DATE2} of span to generate calendar", delegate(string v) {
                if (v != null)
                {
                    secondDate = System.DateTime.Parse(v);
                }
            })
                          .Add("h|?|help", "Show help message", delegate(string v) { messageHandlingStatus.show_help = (v != null); })
                          .Add("t|template=", "{TEMPLATE} xml file containing list of important dates", delegate(string v) {
                if (v != null)
                {
                    templateFilePath = v;
                }
                else
                {
                    messageHandlingStatus.templateExpected = true;
                }
            })
                          .Add("o|output=", "{RESULT} file with calendar: docx", delegate(string v) {
                if (v != null)
                {
                    outputPath = v;
                }
                else
                {
                    messageHandlingStatus.resultUnspecified = true;
                    outputPath = String.Format("{0: yyyyMMdd_mmHHss}.docx", System.DateTime.Now);
                }
            });

            try {
                List <string> extra = p.Parse(args);
            }
            catch (OptionException e) {
                Console.WriteLine(e.Message);
                p.WriteOptionDescriptions(Console.Out);
            }

            if (messageHandlingStatus.show_help)   //user requested for help
            {
                DisplayHelpMessage(p);
                return;
            }
            else
            {
                if ((firstDate == null) || (secondDate == null))
                {
                    System.Console.WriteLine("Explicitly specify both dates");
                    p.WriteOptionDescriptions(Console.Out);
                    return;
                }
                else
                if (messageHandlingStatus.templateExpected == true)
                {
                    System.Console.WriteLine("Explicitly specify path to template");
                    p.WriteOptionDescriptions(Console.Out);
                    return;
                }
            }
            if (messageHandlingStatus.resultUnspecified)
            {
                System.Console.WriteLine("You have not specified path to result...");
            }
            System.Console.WriteLine("Writing to file {0}", outputPath);
            //==============Program. Main part.======================
            CodeHandling myHandl = new CodeHandling();
            GenericDocumentParameters genericDocumentParameters = new GenericDocumentParameters();

            myHandl.constructDocument(firstDate.GetValueOrDefault(), secondDate.GetValueOrDefault());
            myHandl.fromvariableCreateDocument(genericDocumentParameters, templateFilePath);
        }