Exemplo n.º 1
0
        public ActionResult <IReturnModel <FmDirectoryDTO> > AddDirectory([FromBody] FmDirectoryAddModel filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            #region Declares

            IReturnModel <FmDirectoryDTO> rtn = new ReturnModel <FmDirectoryDTO>(_logger);

            #endregion Declares

            #region Hash Control

            if (!filter.HashControl(_configuration["AppSettings:HashSecureKeys:UserCloudManager:Fm:AddDirectory"]))
            {
                _logger.LogError("InvalidHash: " + filter.Hash);
                return(BadRequest(rtn.SendError(GlobalErrors.HashCodeInValid)));
            }

            #endregion Hash Control

            #region Action Body

            try
            {
                int userId  = Tools.GetTokenNameClaim(HttpContext);
                int tokenId = Tools.GetTokenIdClaim(HttpContext);
                ServiceParamsWithIdentifier <FmDirectoryAddModel> serviceFilterModel = new ServiceParamsWithIdentifier <FmDirectoryAddModel>(filter, userId, tokenId);
                serviceFilterModel.Param.UserId = userId;
                IReturnModel <FmDirectoryDTO> serviceAction = _service.AddDirectory(serviceFilterModel);
                if (serviceAction.Error.Status)
                {
                    rtn.Error = serviceAction.Error;
                }
                else
                {
                    rtn.Result = serviceAction.Result;
                }
            }
            catch (Exception ex)
            {
                rtn = rtn.SendError(GlobalErrors.TechnicalError, ex);
            }

            #endregion Action Body

            return(Ok(rtn));
        }
Exemplo n.º 2
0
        public IReturnModel <SendModuleDataModel> InComingClientData(InComingClientDataModel data)
        {
            IReturnModel <SendModuleDataModel> rtn = new ReturnModel <SendModuleDataModel>(_logger);

            try
            {
                var userId       = Tools.GetTokenNameClaim(Context);
                var tokenId      = Tools.GetTokenIdClaim(Context);
                var serviceParam = new ServiceParamsWithIdentifier <InComingClientDataModel>(data, userId, tokenId);
                var exec         = _eventService.GetEvent("Main", "InComingHubClientData").EventHandler <SendModuleDataModel, ServiceParamsWithIdentifier <InComingClientDataModel> >(serviceParam);
                if (exec.Error.Status)
                {
                    rtn.Error = exec.Error;
                }
                else
                {
                    rtn.Result = exec.Result;
                }
            }
            catch (Exception ex)
            {
                rtn = rtn.SendError(GlobalErrors.TechnicalError, ex);
            }

            return(rtn);
        }
Exemplo n.º 3
0
        public IReturnModel <bool> OnSync <T>(HubSyncDataModel <T> data, string group = "")
        {
            IReturnModel <bool> rtn = new ReturnModel <bool>(_logger);

            try
            {
                var globalHub = _serviceProvider.GetService <IHubContext <GlobalHub> >();

                if (!string.IsNullOrWhiteSpace(group))
                {
                    globalHub.Clients.Group(group).SendAsync("HubSyncData", data).ConfigureAwait(false);
                }
                else
                {
                    globalHub.Clients.All.SendAsync("HubSyncData", data).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                rtn = rtn.SendError(GlobalErrors.TechnicalError, ex);
            }

            return(rtn);
        }
Exemplo n.º 4
0
        public IReturnModel <string> Upload(IFormFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            IReturnModel <string> rtn = new ReturnModel <string>(_logger);
            bool   cnt         = true;
            string newFilePath = "";

            try
            {
                if (!Directory.Exists(_path))
                {
                    rtn = rtn.SendError(FileUploaderErrorsEnum.Upload_UploadPathNotFound);
                    cnt = false;
                }

                if (cnt && _minSize > 0 && file.Length < _minSize)
                {
                    rtn = rtn.SendError(FileUploaderErrorsEnum.Upload_MinSize);
                    cnt = false;
                }

                if (cnt && _minSize > 0 && file.Length > _maxSize)
                {
                    rtn = rtn.SendError(FileUploaderErrorsEnum.Upload_MaxSize);
                    cnt = false;
                }

                if (cnt && !_allowTypes.Any(i => i == file.ContentType))
                {
                    rtn = rtn.SendError(FileUploaderErrorsEnum.Upload_ContentType);
                    cnt = false;
                }

                if (cnt)
                {
                    var setting_guidDontUse  = _configuration["AppSettings:FileUploader:fileName:guidDontUse"] != null ? _configuration["AppSettings:FileUploader:fileName:guidDontUse"].ToBool2() : false;
                    var setting_prepend      = _configuration["AppSettings:FileUploader:fileName:prepend"] != null ? _configuration["AppSettings:FileUploader:fileName:prepend"] : "";
                    var setting_append       = _configuration["AppSettings:FileUploader:fileName:append"] != null ? _configuration["AppSettings:FileUploader:fileName:append"] : "";
                    var setting_importantExt = _configuration["AppSettings:FileUploader:fileName:importantExt"] != null ? _configuration["AppSettings:FileUploader:fileName:importantExt"] : "";

                    newFilePath = setting_prepend + (setting_guidDontUse ? file.FileName : Guid.NewGuid().ToString()) + setting_append + (!setting_guidDontUse ? Path.GetExtension(file.FileName) : "") + (!string.IsNullOrWhiteSpace(setting_importantExt) ? setting_importantExt : "");
                }

                if (cnt)
                {
                    using var stream = new FileStream(Path.Combine(_path, newFilePath), FileMode.Create);
                    file.CopyTo(stream);
                }

                if (cnt)
                {
                    rtn.Result = newFilePath;
                }
            }
            catch (Exception ex)
            {
                rtn        = rtn.SendError(GlobalErrors.TechnicalError, ex);
                rtn.Result = "";
            }

            return(rtn);
        }
Exemplo n.º 5
0
        public IReturnModel <TResult> RunAction <TResult, TServiceParamsWithIdentifier> (
            ServiceParamsWithIdentifier <TServiceParamsWithIdentifier> args,
            string actionName,
            string serviceName,
            string moduleName,
            Func <ServiceParamsWithIdentifier <TServiceParamsWithIdentifier>, IReturnModel <TResult>, IReturnModel <TResult> > invoker
            )
            where TServiceParamsWithIdentifier : class
        {
            IReturnModel <TResult> rtn = new ReturnModel <TResult>(_logger);

            try
            {
                var modelValidation = args.Param.ModelValidation();

                if (modelValidation.Any())
                {
                    rtn = rtn.SendError(GlobalErrors.ModelValidationFail);
                    return(rtn);
                }

                #region Before Event Handler

                var beforeEventHandler = _eventService.GetEvent(moduleName, $"{serviceName}.{actionName}.Before").EventHandler <bool, ServiceParamsWithIdentifier <TServiceParamsWithIdentifier> >(args);
                if (beforeEventHandler != null)
                {
                    if (beforeEventHandler.Error.Status)
                    {
                        rtn.Error = beforeEventHandler.Error;
                        return(rtn);
                    }
                }

                #endregion Before Event Handler

                #region Action Body

                if (invoker != null)
                {
                    rtn = invoker(args, rtn);
                }

                #endregion

                #region After Event Handler

                var afterEventParameterModel = new AfterEventParameterModel <IReturnModel <TResult>, ServiceParamsWithIdentifier <TServiceParamsWithIdentifier> >
                {
                    DataToBeSent    = rtn,
                    ActionParameter = args,
                    ModuleName      = moduleName,
                    ServiceName     = serviceName,
                    ActionName      = actionName
                };
                var afterEventHandler = _eventService.GetEvent(moduleName, $"{serviceName}.{actionName}.After")
                                        .EventHandler <TResult, IAfterEventParameterModel <IReturnModel <TResult>, ServiceParamsWithIdentifier <TServiceParamsWithIdentifier> > >(afterEventParameterModel);
                if (afterEventHandler != null)
                {
                    if (afterEventHandler.Error.Status)
                    {
                        rtn.Error = afterEventHandler.Error;
                        return(rtn);
                    }
                    else
                    {
                        rtn.Result = afterEventHandler.Result;
                    }
                }

                #endregion After Event Handler
            }
            catch (Exception ex)
            {
                rtn = rtn.SendError(GlobalErrors.TechnicalError, ex);
            }

            return(rtn);
        }