//
        // GET: /PSCourse/
        // Default parse courses from the web
        public ActionResult Index(string courseUrl, DateTime? startDate)
        {
            if (HttpContext.Session[GlobalVariables.OAuthCodeKey] == null)
            {
                var model = new PSCoursesModel();
                return View(model);
            }
            else
            {
                _startDate = startDate;

                var startTime = System.DateTime.Now;
                PSCoursesModel currentCoursesModel;

                if (_startDate.HasValue && _startDate.Value < defaultStartTime)
                {
                    _startDate = defaultStartTime;
                }

                //Parsing
                var readCourseService = new ReadCourseFromWeb(courseUrl);
                var parser = new PSCourseParser(readCourseService, _startDate);
                currentCoursesModel = parser.ParseCourses();

                //Write Output
                WriteToGoogleDrive(parser, currentCoursesModel);

                var endTime = System.DateTime.Now;
                ViewData["StartTime"] = startTime;
                ViewData["EndTime"] = endTime;
                ViewData["ProcessTime"] = endTime - startTime;

                return View(currentCoursesModel);
            }
        }
        public ActionResult ParseFile(string fileName)
        {
            if (HttpContext.Session[GlobalVariables.OAuthCodeKey] == null)
            {
                var model = new PSCoursesModel();
                return View(model);
            }
            else
            {
                var code = HttpContext.Session[GlobalVariables.OAuthCodeKey].ToString();

                var parameters = OAuthHelper.GetOAuthParameter();
                parameters.AccessCode = code;
                OAuthUtil.GetAccessToken(parameters);

                GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, GlobalVariables.GoogleSpreadSheetAppName, parameters);
                SpreadsheetsService service = new SpreadsheetsService(GlobalVariables.GoogleSpreadSheetAppName);
                service.RequestFactory = requestFactory;

                //Parsing
                var startTime = System.DateTime.Now;
                var readCourseService = new ReadCourseFromFile(fileName);
                var parser = new PSCourseParser(readCourseService, defaultStartTime);
                var currentCoursesModel = parser.ParseCourses();

                var googleHelper = new GoogleDriveHelper(defaultStartTime);
                googleHelper.Service = service;
                var oldCourses = googleHelper.FetchOldCourseSheet();
                parser.UpdateCourseStatus(currentCoursesModel, oldCourses);

                var success = googleHelper.AddDriveSpreadsheet(currentCoursesModel);

                var endTime = System.DateTime.Now;
                var processingTime = endTime - startTime;

                ViewData["StartTime"] = startTime;
                ViewData["EndTime"] = endTime;
                ViewData["ProcessTime"] = processingTime;

                return View(currentCoursesModel);
            }
        }
        private bool WriteToGoogleDrive(PSCourseParser parser, PSCoursesModel currentCoursesModel)
        {
            var code = HttpContext.Session[GlobalVariables.OAuthCodeKey].ToString();

            var parameters = OAuthHelper.GetOAuthParameter();
            parameters.AccessCode = code;
            OAuthUtil.GetAccessToken(parameters);

            GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, GlobalVariables.GoogleSpreadSheetAppName, parameters);
            SpreadsheetsService service = new SpreadsheetsService(GlobalVariables.GoogleSpreadSheetAppName);
            service.RequestFactory = requestFactory;

            var googleHelper = new GoogleDriveHelper(_startDate);
            googleHelper.Service = service;
            var oldCourses = googleHelper.FetchOldCourseSheet();
            parser.UpdateCourseStatus(currentCoursesModel, oldCourses);

            return googleHelper.AddDriveSpreadsheet(currentCoursesModel);
        }