Example #1
0
        private void CreateLogs(string actionCode, int[] ids, int?parentEntityId)
        {
            var backendLog = _serviceProvider.GetRequiredService <IBackendActionLogRepository>();

            BackendActionContext.SetCurrent(actionCode, ids.Select(n => n.ToString()), parentEntityId);

            var logs = BackendActionLog.CreateLogs(BackendActionContext.Current, backendLog);

            backendLog.Save(logs);
            BackendActionContext.ResetCurrent();
        }
Example #2
0
        private static void CreateLogs(string actionCode, int[] ids, int?parentEntityId)
        {
            var backendLog = DependencyResolver.Current.GetService <IBackendActionLogRepository>();

            BackendActionContext.SetCurrent(actionCode, ids.Select(n => n.ToString()), parentEntityId);

            var logs = BackendActionLog.CreateLogs(BackendActionContext.Current, backendLog);

            backendLog.Save(logs);
            BackendActionContext.ResetCurrent();
        }
Example #3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception == null)
            {
                if (BackendActionContext.Current.IsChanged)
                {
                    _logs = BackendActionLog.CreateLogs(BackendActionContext.Current, _repository);
                }

                _logs = _repository.Save(_logs);
            }

            base.OnActionExecuted(filterContext);
        }
Example #4
0
        public ActionResult UploadChunk(int?chunk, int?chunks, string name, string destinationUrl)
        {
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                var errorMsg = $"File to upload: \"{name}\" has invalid characters";
                Logger.Log.Warn(errorMsg);
                return(Json(new { message = errorMsg, isError = true }));
            }

            destinationUrl = HttpUtility.UrlDecode(destinationUrl);
            if (string.IsNullOrEmpty(destinationUrl))
            {
                throw new ArgumentException("Folder Path is empty");
            }

            if (!Directory.Exists(destinationUrl))
            {
                Directory.CreateDirectory(destinationUrl);
            }

            chunk  = chunk ?? 0;
            chunks = chunks ?? 1;
            PathSecurityResult securityResult;

            var fileUpload = Request.Files[0];
            var tempPath   = Path.Combine(QPConfiguration.TempDirectory, name);
            var destPath   = Path.Combine(destinationUrl, name);

            if (chunk == 0 && chunks == 1)
            {
                securityResult = PathInfo.CheckSecurity(destinationUrl);
                if (!securityResult.Result)
                {
                    var errorMsg = string.Format(PlUploadStrings.ServerError, name, destinationUrl, $"Access to the folder (ID = {securityResult.FolderId}) denied");
                    Logger.Log.Warn(errorMsg);
                    return(Json(new { message = errorMsg, isError = true }));
                }

                try
                {
                    using (var fs = new FileStream(destPath, FileMode.Create))
                    {
                        var buffer = new byte[fileUpload.InputStream.Length];
                        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }
                }
                catch (Exception ex)
                {
                    var errorMsg = string.Format(PlUploadStrings.ServerError, name, destinationUrl, ex.Message);
                    Logger.Log.Error(errorMsg, ex);
                    return(Json(new { message = errorMsg, isError = true }));
                }
            }
            else
            {
                try
                {
                    using (var fs = new FileStream(tempPath, chunk == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[fileUpload.InputStream.Length];
                        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }
                }
                catch (Exception ex)
                {
                    var errorMsg = string.Format(PlUploadStrings.ServerError, name, tempPath, ex.Message);
                    Logger.Log.Error(errorMsg, ex);
                    return(Json(new { message = errorMsg, isError = true }));
                }

                try
                {
                    var isTheLastChunk = chunk.Value == chunks.Value - 1;
                    if (isTheLastChunk)
                    {
                        securityResult = PathInfo.CheckSecurity(destinationUrl);
                        var actionCode = securityResult.IsSite ? ActionCode.UploadSiteFile : ActionCode.UploadContentFile;

                        if (!securityResult.Result)
                        {
                            var errorMsg = string.Format(PlUploadStrings.ServerError, name, destinationUrl, $"Access to the folder (ID = {securityResult.FolderId}) denied");
                            Logger.Log.Warn(errorMsg);
                            return(Json(new { message = errorMsg, isError = true }));
                        }

                        if (FileIO.Exists(destPath))
                        {
                            FileIO.SetAttributes(destPath, FileAttributes.Normal);
                            FileIO.Delete(destPath);
                        }

                        FileIO.Move(tempPath, destPath);
                        BackendActionContext.SetCurrent(actionCode, new[] { name }, securityResult.FolderId);

                        var logs = BackendActionLog.CreateLogs(BackendActionContext.Current, _logger);
                        _logger.Save(logs);

                        BackendActionContext.ResetCurrent();
                    }
                }
                catch (Exception ex)
                {
                    var errorMsg = string.Format(PlUploadStrings.ServerError, name, destinationUrl, ex.Message);
                    Logger.Log.Error(errorMsg, ex);
                    return(Json(new { message = errorMsg, isError = true }));
                }

                return(Json(new { message = $"chunk#{chunk.Value}, of file{name} uploaded", isError = false }));
            }

            return(Json(new { message = $"file{name} uploaded", isError = false }));
        }
Example #5
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     _repository = filterContext.HttpContext.RequestServices.GetRequiredService <IBackendActionLogRepository>();
     _logs       = BackendActionLog.CreateLogs(BackendActionContext.Current, _repository);
     base.OnActionExecuting(filterContext);
 }
Example #6
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     _logs = BackendActionLog.CreateLogs(BackendActionContext.Current, _repository);
     base.OnActionExecuting(filterContext);
 }