Beispiel #1
0
        public virtual TransferResponse ByPage(ApiCall call)
        {
            string fulldomain = call.GetValue("FullDomain");

            if (string.IsNullOrEmpty(fulldomain))
            {
                string RootDomain = call.GetValue("RootDomain");
                string SubDomain  = call.GetValue("SubDomain");
                fulldomain = SubDomain + "." + RootDomain;
            }
            string sitename = call.GetValue("SiteName");

            if (string.IsNullOrEmpty(sitename) || string.IsNullOrEmpty(fulldomain))
            {
                return(null);
            }

            string        urlstring = call.GetValue("Urls");
            List <string> urls      = Lib.Helper.JsonHelper.Deserialize <List <string> >(urlstring);

            if (urls != null && urls.Count() > 0)
            {
                var first = urls.First();

                if (Kooboo.Sites.SiteTransfer.TransferManager.IsUrlBanned(first))
                {
                    string error = Data.Language.Hardcoded.GetValue("Target Url is Protected", call.Context);

                    throw new Exception(error);
                }

                WebSite newsite = Kooboo.Sites.Service.WebSiteService.AddNewSite(call.Context.User.CurrentOrgId, sitename, fulldomain, call.Context.User.Id);

                var transferTask = TransferManager.AddTask(newsite.SiteDb(), urls, call.Context.User.Id);

                TransferManager.ExecuteTask(newsite.SiteDb(), transferTask);

                return(new TransferResponse
                {
                    SiteId = newsite.Id,
                    TaskId = transferTask.Id,
                    Success = true
                });
            }
            return(null);
        }
Beispiel #2
0
        public SingleResponse Single(string pageUrl, string name, ApiCall call)
        {
            SingleResponse response = new SingleResponse();
            var            sitedb   = call.WebSite.SiteDb();

            if (Kooboo.Sites.SiteTransfer.TransferManager.IsUrlBanned(pageUrl))
            {
                string error = Data.Language.Hardcoded.GetValue("Target Url is Protected", call.Context);

                throw new Exception(error);
            }

            if (!pageUrl.ToLower().StartsWith("http"))
            {
                pageUrl = "http://" + pageUrl;
            }

            if (!Lib.Helper.UrlHelper.IsValidUrl(pageUrl, true))
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Invalid Url", call.Context));
            }

            if (string.IsNullOrEmpty(name))
            {
                name = UrlHelper.GetPageName(pageUrl);
            }

            if (!sitedb.Routes.Validate(name, default(Guid)))
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Url occupied", call.Context));
            }

            if (!string.IsNullOrEmpty(pageUrl))
            {
                var task = TransferManager.AddTask(sitedb, pageUrl, name, call.Context.User.Id);

                TransferManager.ExecuteTask(sitedb, task).Wait();

                response.TaskId = task.Id;
                response.Finish = true;

                var transferpages = sitedb.TransferPages.Query.Where(o => o.taskid == task.Id).SelectAll();
                if (transferpages == null || transferpages.Count() == 0)
                {
                    response.Success = false;
                    response.Messages.Add("no page downloaded");
                }
                else
                {
                    var transferpage = transferpages.Find(o => o.done == true);
                    if (transferpage != null && transferpage.PageId != default(Guid))
                    {
                        response.Success = true;
                        var sitepage = sitedb.Pages.Get(transferpage.PageId);
                        if (sitepage != null)
                        {
                            response.Model = PageApi.ToPageViewModel(sitedb, sitepage);
                        }
                    }
                }
            }
            else
            {
                response.Finish  = true;
                response.Success = false;
                response.Messages.Add("page url not found");
            }
            return(response);
        }
Beispiel #3
0
        public virtual TransferResponse ByLevel(ApiCall call)
        {
            string RootDomain = call.GetValue("RootDomain");
            string SubDomain  = call.GetValue("SubDomain");
            string fulldomain = SubDomain + "." + RootDomain;

            string sitename = call.GetValue("SiteName");

            if (string.IsNullOrEmpty(sitename) || string.IsNullOrEmpty(fulldomain))
            {
                return(null);
            }
            // model.Url, model.TotalPages, model.Depth
            string url = call.GetValue("url");

            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            if (Kooboo.Sites.SiteTransfer.TransferManager.IsUrlBanned(url))
            {
                string error = Data.Language.Hardcoded.GetValue("Target Url is Protected", call.Context);

                throw new Exception(error);
            }


            url = url.Trim();
            if (!url.ToLower().StartsWith("http"))
            {
                url = "http://" + url;
            }

            if (!Lib.Helper.UrlHelper.IsValidUrl(url, true))
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Invalid Url", call.Context));
            }

            string strTotalPages = call.GetValue("TotalPages");
            string strDepth      = call.GetValue("Depth");

            int totalpages = 0;
            int depth      = 0;

            if (string.IsNullOrEmpty(strTotalPages) || !int.TryParse(strTotalPages, out totalpages))
            {
                totalpages = 10;
            }

            if (string.IsNullOrEmpty(strDepth) || !int.TryParse(strDepth, out depth))
            {
                depth = 2;
            }

            //if (Data.AppSettings.IsOnlineServer)
            //{
            //    if (totalpages > 3)
            //    {
            //        totalpages = 3;
            //    }
            //}

            WebSite newsite = Kooboo.Sites.Service.WebSiteService.AddNewSite(call.Context.User.CurrentOrgId, sitename, fulldomain, call.Context.User.Id);

            var transferTask = TransferManager.AddTask(newsite.SiteDb(), url, totalpages, depth, call.Context.User.Id);

            TransferManager.ExecuteTask(newsite.SiteDb(), transferTask);

            return(new TransferResponse
            {
                SiteId = newsite.Id,
                TaskId = transferTask.Id,
                Success = true
            });
        }