Exemple #1
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != Constants.TakeSnapshotTaskName)
            {
                return;
            }

            try {
                //the default export service impl makes an assumption that there is an associated user, so we need to set the owner here
                var siteOwner = _membershipService.GetUser(_orchardServices.WorkContext.CurrentSite.As <SiteSettingsPart>().SuperUser);
                _authenticationService.SetAuthenticatedUserForRequest(siteOwner);

                _snapshotService.TakeSnaphot();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Failed to generate a scheduled Content Sync Snapshot. An exception was thrown by the task handler.");
            }

            //now reschedule the task
            _scheduledTaskManager.DeleteTasks(null, a => a.TaskType == Constants.TakeSnapshotTaskName);

            var snapshotFrequency = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>().SnapshotFrequencyMinutes;

            if (snapshotFrequency == 0)
            {
                return;
            }

            _scheduledTaskManager.CreateTask(Constants.TakeSnapshotTaskName, _clock.UtcNow.AddMinutes(snapshotFrequency), null);
        }
        public ActionResult Take()
        {
            _snapshotService.TakeSnaphot();
            _notifier.Information(T("A snapshot of this site's current configuration has been taken and added to the collection."));

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public ActionResult Take()
        {
            if (!_authorizer.Authorize(ContentSyncPermissions.SnapshotManager, T("You need the {0} permission to do this.", ContentSyncPermissions.SnapshotManager.Name)))
            {
                return(new HttpUnauthorizedResult());
            }

            _snapshotService.TakeSnaphot();
            _notifier.Information(T("A snapshot of this site's current configuration has been taken and added to the collection."));

            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public ActionResult Index(string username, string password, bool takeFreshSnapshot = false)
        {
            var user = _membershipService.ValidateUser(username, password);

            if (user == null)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                Response.End();
                return(new HttpUnauthorizedResult());
            }

            _authenticationService.SignIn(user, false);

            if (!_authorizer.Authorize(ContentSyncPermissions.ContentExportApi))
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                Response.End();
                return(new HttpUnauthorizedResult());
            }


            if (takeFreshSnapshot)
            {
                _snapshotService.TakeSnaphot();
            }

            var snapshot = _snapshotService.GetLatestSnaphot();

            if (snapshot == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                Response.End();
                return(new HttpNotFoundResult("No snapshots were available to download. Either manually create a snapshot on the remote site, or add 'takeFreashSnapshot=true' to the querystring of this request."));
            }

            var fileName = string.Format("Snapshot-{0}-taken-{1:yyyyMMddHHmmss}-from-{2}.xml", snapshot.Id, snapshot.TimeTaken, _shellSettings.Name);

            return(File(Encoding.UTF8.GetBytes(snapshot.Data), "text/xml", fileName));
        }