Ejemplo n.º 1
0
        public ActionResult MaintenanceExecuteSql(MaintenanceModel model)
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            if (model.SqlQuery.HasValue())
            {
                var dbContext = EngineContext.Current.Resolve<IDbContext>();
                try
                {
					dbContext.ExecuteSqlThroughSmo(model.SqlQuery);

                    NotifySuccess("The sql command was executed successfully.");
                }
                catch (Exception ex)
                {
					NotifyError("Error executing sql command: {0}".FormatCurrentUI(ex.Message));
                }
            }

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult MaintenanceDeleteFiles(MaintenanceModel model)
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            DateTime? startDateValue = (model.DeleteExportedFiles.StartDate == null) ? null
							: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteExportedFiles.StartDate.Value, _dateTimeHelper.Value.CurrentTimeZone);

            DateTime? endDateValue = (model.DeleteExportedFiles.EndDate == null) ? null
							: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteExportedFiles.EndDate.Value, _dateTimeHelper.Value.CurrentTimeZone).AddDays(1);


            model.DeleteExportedFiles.NumberOfDeletedFiles = 0;
            string path = string.Format("{0}Content\\files\\exportimport\\", this.Request.PhysicalApplicationPath);
            foreach (var fullPath in System.IO.Directory.GetFiles(path))
            {
                try
                {
                    var fileName = Path.GetFileName(fullPath);
                    if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase))
                        continue;

					if (fileName.Equals("placeholder", StringComparison.InvariantCultureIgnoreCase))
						continue;

                    var info = new FileInfo(fullPath);
                    if ((!startDateValue.HasValue || startDateValue.Value < info.CreationTimeUtc)&&
                        (!endDateValue.HasValue || info.CreationTimeUtc < endDateValue.Value))
                    {
                        System.IO.File.Delete(fullPath);
                        model.DeleteExportedFiles.NumberOfDeletedFiles++;
                    }
                }
                catch (Exception exc)
                {
                    NotifyError(exc, false);
                }
            }

            return View(model);
        }
Ejemplo n.º 3
0
        public ActionResult MaintenanceDeleteGuests(MaintenanceModel model)
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            DateTime? startDateValue = (model.DeleteGuests.StartDate == null) ? null
							: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteGuests.StartDate.Value, _dateTimeHelper.Value.CurrentTimeZone);

            DateTime? endDateValue = (model.DeleteGuests.EndDate == null) ? null
							: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteGuests.EndDate.Value, _dateTimeHelper.Value.CurrentTimeZone).AddDays(1);

            model.DeleteGuests.NumberOfDeletedCustomers = _customerService.DeleteGuestCustomers(startDateValue, endDateValue, model.DeleteGuests.OnlyWithoutShoppingCart);

            return View(model);
        }
Ejemplo n.º 4
0
        public ActionResult Maintenance()
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            var model = new MaintenanceModel();
            model.DeleteGuests.EndDate = DateTime.UtcNow.AddDays(-7);
            model.DeleteGuests.OnlyWithoutShoppingCart = true;

            // image cache stats
            long imageCacheFileCount = 0;
            long imageCacheTotalSize = 0;
			_imageCache.Value.CacheStatistics(out imageCacheFileCount, out imageCacheTotalSize);
            model.DeleteImageCache.FileCount = imageCacheFileCount;
            model.DeleteImageCache.TotalSize = Prettifier.BytesToString(imageCacheTotalSize);

            return View(model);
        }
        public ActionResult MaintenanceExecuteSql(MaintenanceModel model)
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            if (model.SqlQuery.HasValue())
            {
                var dbContext = EngineContext.Current.Resolve<IDbContext>();
                try
                {
					dbContext.ExecuteSqlThroughSmo(model.SqlQuery);

                    NotifySuccess(T("Admin.System.Maintenance.SqlQuery.Succeeded"));
                }
                catch (Exception exception)
                {
					NotifyError(exception);
                }
            }

            return View(model);
        }
        public ActionResult MaintenanceDeleteFiles(MaintenanceModel model)
        {
			if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageMaintenance))
                return AccessDeniedView();

            DateTime? startDateValue = (model.DeleteExportedFiles.StartDate == null) ? null
				: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteExportedFiles.StartDate.Value, _dateTimeHelper.Value.CurrentTimeZone);

            DateTime? endDateValue = (model.DeleteExportedFiles.EndDate == null) ? null
				: (DateTime?)_dateTimeHelper.Value.ConvertToUtcTime(model.DeleteExportedFiles.EndDate.Value, _dateTimeHelper.Value.CurrentTimeZone).AddDays(1);


            model.DeleteExportedFiles.NumberOfDeletedFiles = 0;
			model.DeleteExportedFiles.NumberOfDeletedFolders = 0;

			var appPath = this.Request.PhysicalApplicationPath;

			string[] paths = new string[]
			{
				appPath + @"Content\files\exportimport\",
				appPath + @"Exchange\",
				appPath + @"App_Data\ExportProfiles\"
			};

			foreach (var path in paths)
			{
				foreach (var fullPath in System.IO.Directory.GetFiles(path))
				{
					try
					{
						var fileName = Path.GetFileName(fullPath);
						if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase))
							continue;

						if (fileName.Equals("placeholder", StringComparison.InvariantCultureIgnoreCase))
							continue;

						var info = new FileInfo(fullPath);

						if ((!startDateValue.HasValue || startDateValue.Value < info.CreationTimeUtc) &&
							(!endDateValue.HasValue || info.CreationTimeUtc < endDateValue.Value))
						{
							if (FileSystemHelper.Delete(fullPath))
								++model.DeleteExportedFiles.NumberOfDeletedFiles;
						}
					}
					catch (Exception exc)
					{
						NotifyError(exc, false);
					}
				}

				var dir = new DirectoryInfo(path);

				foreach (var dirInfo in dir.GetDirectories())
				{
					if ((!startDateValue.HasValue || startDateValue.Value < dirInfo.LastWriteTimeUtc) &&
						(!endDateValue.HasValue || dirInfo.LastWriteTimeUtc < endDateValue.Value))
					{
						FileSystemHelper.ClearDirectory(dirInfo.FullName, true);
						++model.DeleteExportedFiles.NumberOfDeletedFolders;
					}
				}
			}

			// clear unreferenced profile folders
			var importProfileFolders = _importProfileService.Value.GetImportProfiles()
				.Select(x => x.FolderName)
				.ToList();

			var infoImportProfiles = new DirectoryInfo(CommonHelper.MapPath("~/App_Data/ImportProfiles"));

			foreach (var infoSubFolder in infoImportProfiles.GetDirectories())
			{
				if (!importProfileFolders.Contains(infoSubFolder.Name))
				{
					FileSystemHelper.ClearDirectory(infoSubFolder.FullName, true);
					++model.DeleteExportedFiles.NumberOfDeletedFolders;
				}
			}

			return View(model);
        }