예제 #1
0
파일: SiteController.cs 프로젝트: Godoy/CMS
        public virtual ActionResult ImportRepository(string siteName, ImportRepositoryModel model, string @return)
        {
            var data = new JsonResultData(ModelState);

            var site = new Site(siteName).AsActual();
            if (site != null && ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                    {
                        Kooboo.CMS.Content.Models.Repository repository = null;
                        if (Request.Files.Count > 0)
                        {
                            repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Repository, Request.Files[0].InputStream);
                        }
                        else
                        {
                            repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Repository, model.File);
                        }

                        var oldRepository = site.Repository;
                        if (repository != null)
                        {
                            site.Repository = repository.Name;
                            ServiceFactory.SiteManager.Update(site);
                        }
                        try
                        {
                            if (model.DeleteTheOldRepository)
                            {
                                repository = new Kooboo.CMS.Content.Models.Repository(oldRepository);
                                if (!Kooboo.CMS.Sites.Services.ServiceFactory.SiteManager.IfTheRepositoryUsedByOtherSites(site, oldRepository))
                                {
                                    Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Remove(repository);
                                };
                            }
                        }
                        catch (Exception e)
                        {
                            Kooboo.HealthMonitoring.Log.LogException(e);
                        }

                        resultData.RedirectUrl = @return;
                    });
            }

            return Json(data);
        }
예제 #2
0
        public virtual ActionResult ImportRepository(string siteName, ImportRepositoryModel model, bool uploadNew)
        {
            var entry = new JsonResultEntry();

            try
            {
                var site = new Site(siteName).AsActual();

                if (site != null && ModelState.IsValid)
                {
                    Kooboo.CMS.Content.Models.Repository repository = null;
                    if (uploadNew)
                    {
                        if (!Request.Files[0].FileName.EndsWith(".zip"))
                        {
                            throw new KoobooException("Please upload an zip file".Localize());
                        }

                        repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, Request.Files[0].InputStream);
                    }
                    else
                    {
                        repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, model.File);
                    }

                    if (repository != null)
                    {
                        site.Repository = repository.Name;
                        ServiceFactory.SiteManager.Update(site);
                    }
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }