Exemple #1
0
        /// <summary>
        /// Uploads the UI5 Project int <see cref="ProjectDir"/> to the SAP system specified by <see cref="Credentials"/>. If <see cref="Credentials.Username"/> is <c>null</c>, a single sign on authentification is performed.
        /// </summary>
        public void Upload()
        {
            if (string.IsNullOrWhiteSpace(ProjectDir)) throw new InvalidOperationException("ProjectDir not set.");
             if (!Directory.Exists(ProjectDir)) throw new InvalidOperationException("ProjectDir not set to a folder.");
             if (Credentials == null) throw new InvalidOperationException("Credentials not set.");
             if (string.IsNullOrWhiteSpace(Credentials.System)) throw new InvalidOperationException("Credentials.System not set.");
             if (string.IsNullOrWhiteSpace(AppName)) throw new InvalidOperationException("AppName not set.");

             if (TestMode) Log.Instance.Write("Test mode on!");

             try
             {
            var uri = new Uri(this.Credentials.System);
            uri = uri.AddQuery("sap-client", Credentials.Mandant.ToString());
            uri = uri.AddQuery("sapui5applicationname", AppName);
            uri = uri.AddQuery("sapui5applicationdescription", AppDescription);
            uri = uri.AddQuery("sapui5applicationpackage", Package);
            uri = uri.AddQuery("workbenchrequest", TransportRequest);
            uri = uri.AddQuery("externalcodepage", ExternalCodepage);
            uri = uri.AddQuery("deltamode", DeltaMode ? "true" : "false");
            uri = uri.AddQuery("testmode", TestMode ? "true" : "false");

            if (IgnoreCertificateErrors)
            {
               System.Net.ServicePointManager.ServerCertificateValidationCallback += ServerCertificateValidationIgnoreAll;
            }

            var cookieContainer = new System.Net.CookieContainer();
            //Try to Authenticate with a HEAD request and retrieve an authentification token cookie before uploading the whole application.
            var headRequest = System.Net.HttpWebRequest.Create(uri);
            headRequest.PreAuthenticate = false;
            headRequest.Timeout = 10000;
            headRequest.Method = System.Net.WebRequestMethods.Http.Head;
            ((System.Net.HttpWebRequest)headRequest).CookieContainer = cookieContainer;

            if (Credentials.Username != null)
            {
               headRequest.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password);
            }
            else //SSO
            {
               headRequest.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
               headRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            headRequest.GetResponse().Close();

            //The actual POST request with the ziped project.
            var request = System.Net.HttpWebRequest.Create(uri);
            request.Timeout = Timeout * 1000;
            request.PreAuthenticate = true;
            request.UseDefaultCredentials = false;
            ((System.Net.HttpWebRequest)request).CookieContainer = cookieContainer; //Contains the authentification token if acquired
            if (Credentials.Username != null)                                       //if not: credentials to reauthenficiate.
            {
               request.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password);
            }
            else //SSO
            {
               request.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
               request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            Log.Instance.Write("Uploading project...");
            request.Method = System.Net.WebRequestMethods.Http.Post;
            request.ContentType = "application/zip";
            using (var stream = request.GetRequestStream())
            {
               using (var zipHelper = new ZipHelper(stream))
               {
                  zipHelper.Zip(".Ui5RepositoryUploadParameters", Encoding.UTF8.GetBytes(cleanedConfigFileContent));
                  zipHelper.Zip(ProjectDir, new[] { ".Ui5Repository*", "WebContent" }, IgnoreMasks.ToArray());
               }
               stream.Close();
            }
            Log.Instance.Write("Installing App...");
            var response = (System.Net.HttpWebResponse)request.GetResponse();
            HandleResponse(response);
             }
             catch (System.Net.WebException ex)
             {
            if (ex.Response != null)
            {
               HandleResponse((System.Net.HttpWebResponse)ex.Response);
            }
            else
            {
               Log.Instance.Write(ex.ToString());
               Log.Instance.Write("Upload failed!");
               throw new UploadFailedException();
            }
             }
        }
 /// <summary>
 ///     Gets teachers in teacher section associations within the sections.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="sectionId"></param>
 /// <param name="limit">Max number of sections to return(optional)</param>
 /// <param name="offset">Starting position of result set(optional)</param>
 /// <returns></returns>
 public async Task<JArray> GetSectionTeacherAssociationTeacherListAsync(string accessToken, string sectionId, int? limit, int? offset)
 {
     Uri apiEndPoint = new Uri(String.Format(ApiHelper.BaseUrl + "/sections/{0}/teacherSectionAssociations/teachers", sectionId));
     if (limit != null) { apiEndPoint = apiEndPoint.AddQuery("limit", limit.ToString()); }
     if (offset != null) { apiEndPoint = apiEndPoint.AddQuery("offset", offset.ToString()); }
     return (await ApiHelper.CallApiForGetAsync(apiEndPoint.ToString(), accessToken));
 }
 /// <summary>
 ///      Gets students details in student section associations within the sections.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="sectionId"></param>
 /// <param name="limit">Max number of sections to return(optional)</param>
 /// <param name="offset">Starting position of result set(optional)</param>
 /// <param name="views">View name (optional)</param>
 /// <returns></returns>
 public JArray GetSectionStudentAssociationStudentList(string accessToken, string sectionId, int? limit, int? offset, string views)
 {
     Uri apiEndPoint = new Uri(String.Format(ApiHelper.BaseUrl + "/sections/{0}/studentSectionAssociations/students", sectionId));
     if (limit != null) { apiEndPoint = apiEndPoint.AddQuery("limit", limit.ToString()); }
     if (offset != null) { apiEndPoint = apiEndPoint.AddQuery("offset", offset.ToString()); }
     if (!string.IsNullOrEmpty(views)) { apiEndPoint = apiEndPoint.AddQuery("views", views); }
     return ApiHelper.CallApiForGet(apiEndPoint.ToString(), accessToken);
 }
        public override ScrapedPage ScrapeVideos(SearchParameters sparam = null)
        {
            var rootUrl = RootUrl;
            if (sparam != null )
            {
                if (!String.IsNullOrEmpty(sparam.Url))
                    rootUrl = sparam.Url;
                var ub = new Uri(rootUrl);
                if (!String.IsNullOrEmpty(sparam.Query))
                {
                    ub = ub.AddQuery("k", sparam.Query);
                    ub = ub.AddQuery("sort", sparam.SortBy == VideoSortby.Relevance ? "relevance"
                        : (sparam.SortBy == VideoSortby.Rating ? "rating" : "uploaddate"));
                    ub = ub.AddQuery("durf", sparam.Duration == VideoDuration.All ? "allduration" : (sparam.Duration == VideoDuration.Long ? "10min_more" :
                        (sparam.Duration == VideoDuration.Short ? "1-3min" : "3-10min")));
                    ub = ub.AddQuery("datef", sparam.Period == VideoPeriod.Anytime ? "all" : (sparam.Period == VideoPeriod.Today ? "today" :
                        ((sparam.Period == VideoPeriod.ThisWeek ? "week" : "month"))));
                    rootUrl = ub.AbsoluteUri;
                }
            }

            var page = new ScrapedPage();
            var elem = GotoUrl(rootUrl);
            page.Videos =  ScrapThumbnailVideos(elem);
            //get next page
            var pages = SelectItems(elem, ".pagination.small.top a").ToList();
            foreach (var p in pages)
            {
                bool selected = p.Attributes["class"] != null && p.Attributes["class"].Value == "sel";
                page.Links.Add(new PagingLink
                {
                    Url = selected? rootUrl : new Uri(new Uri(RootUrl), p.Attributes["href"].Value).AbsoluteUri,
                    IsSelected = selected,
                    Text = p.InnerText
                });
            }

               var showMore = SelectItem(elem, ".showMore a");
               if (showMore != null)
               {
                page.Links.Add(new PagingLink
                {
                    Url = String.Format("{0}{1}", RootUrl, showMore.Attributes["href"].Value),
                    Text = showMore.InnerText,
                });
               }

            return page;
        }
 /// <summary>
 ///     Gets students details.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public JArray GetStudents(string accessToken, int? limit, int? offset)
 {
     Uri apiEndPoint = new Uri(ApiHelper.BaseUrl + "/students");
     if (limit != null) { apiEndPoint = apiEndPoint.AddQuery("limit", limit.ToString()); }
     if (offset != null) { apiEndPoint = apiEndPoint.AddQuery("offset", offset.ToString()); }
     return ApiHelper.CallApiForGet(apiEndPoint.ToString(), accessToken);
 }
 /// <summary>
 ///     Gets attendances within the students.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="studentId"></param>
 /// <returns></returns>
 public async Task<JArray> GetStudentAttendancesAsync(string accessToken, string studentId, int? limit)
 {
     Uri apiEndPoint = new Uri(String.Format(ApiHelper.BaseUrl + "/students/{0}/attendances", studentId));
     if (limit != null) { apiEndPoint = apiEndPoint.AddQuery("limit", limit.ToString()); }
     return await ApiHelper.CallApiForGetAsync(apiEndPoint, accessToken);
 }
 /// <summary>
 ///     Gets student section associations within the students.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="studentId"></param>
 /// <param name="studentId"></param>
 /// <returns></returns>
 public JArray GetStudentStudentSectionAssociations(string accessToken, string studentId, string views)
 {
     Uri apiEndPoint = new Uri(String.Format(ApiHelper.BaseUrl + "/students/{0}/studentSectionAssociations", studentId));
     if (!string.IsNullOrEmpty(views)) { apiEndPoint = apiEndPoint.AddQuery("views", views); }
     return ApiHelper.CallApiForGet(apiEndPoint.ToString(), accessToken);
 }
 /// <summary>
 ///     Gets teachers details.
 /// </summary>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public async Task<JArray> GetTeachersAsync(string accessToken, int? limit, int? offset)
 {
     Uri apiEndPoint = new Uri(String.Format(ApiHelper.BaseUrl + "/teachers"));
     if (limit != null) { apiEndPoint = apiEndPoint.AddQuery("limit", limit.ToString()); }
     if (offset != null) { apiEndPoint = apiEndPoint.AddQuery("offset", offset.ToString()); }
     return await ApiHelper.CallApiForGetAsync(apiEndPoint, accessToken);
 }