コード例 #1
0
        public async Task UpdateLibrary(LibraryDto input)
        {
            List <string> errorList = new List <string>();

            var data = await GetLibraryById(input.Id);

            data.Name       = input.Name;
            data.DistrictId = input.DistrictId;
            data.ProvinceId = input.ProvinceId;

            LibraryValidator validator        = new LibraryValidator();
            ValidationResult validationResult = validator.Validate(data);

            if (!validationResult.IsValid)
            {
                foreach (var failure in validationResult.Errors)
                {
                    errorList.Add(string.Format("{0}", failure.ErrorMessage));
                }
                string errorString = string.Join(" ", errorList.ToArray());
                throw new UserFriendlyException(errorString);
            }

            await _libraryRepository.UpdateAsync(data);
        }
コード例 #2
0
        public async Task AddLibrary(LibraryDto input)
        {
            List <string> errorList = new List <string>();

            var library = new Library
            {
                Name       = input.Name,
                DistrictId = input.DistrictId,
                ProvinceId = input.ProvinceId
            };

            LibraryValidator validator        = new LibraryValidator();
            ValidationResult validationResult = validator.Validate(library);

            if (!validationResult.IsValid)
            {
                foreach (var failure in validationResult.Errors)
                {
                    errorList.Add(string.Format("{0}", failure.ErrorMessage));
                }
                string errorString = string.Join(" ", errorList.ToArray());
                throw new UserFriendlyException(errorString);
            }
            await _libraryRepository.InsertAsync(library);
        }
コード例 #3
0
 public LibraryService(
     ILibraryReadRepository libraryReadRepository,
     ILibraryWriteRepository libraryWriteRepository,
     LibraryValidator libraryValidator
     ) : base(libraryReadRepository, libraryWriteRepository, libraryValidator)
 {
 }
コード例 #4
0
        public void TearDown()
        {
            libraryStreamParser = null;
            libraryValidator    = null;
            libraryExecutor     = null;

            MockDBContext = null;
        }
コード例 #5
0
        public void SetUp()
        {
            libraryStreamParser = new LibraryStreamParser();
            libraryValidator    = new LibraryValidator();
            libraryExecutor     = new LibraryExecutor();

            MockDBContext = new Mock <IDBContext>();
        }
コード例 #6
0
        private LibraryBooksOperationResult validate(InfoRequest infoReq)
        {
            var result = new LibraryBooksOperationResult();
            var book   = this._bookRepository.FindBy(x => x.Code == infoReq.BookCode).Result.FirstOrDefault();

            result.Success = !LibraryValidator.isBookAlreadyRegistered(book, ref result);

            return(result);
        }
コード例 #7
0
        private LibraryBooksOperationResult validate(InfoRequest infoReq, Book book)
        {
            var result = new LibraryBooksOperationResult();

            result.Success = !LibraryValidator.isBookNull(book, ref result) &&
                             LibraryValidator.isBookLoaned(book, ref result) &&
                             LibraryValidator.isBookLoanExceeds30Days(book, ref result, infoReq);

            return(result);
        }
コード例 #8
0
ファイル: App.xaml.cs プロジェクト: gitter-badger/Osmo
        private static bool ValidateLibraries()
        {
            List <Library> libraries = new List <Library>()
            {
                new Library(AppDomain.CurrentDomain.BaseDirectory, "ControlzEx.dll"),
                new Library(AppDomain.CurrentDomain.BaseDirectory, "MahApps.Metro.dll"),
                new Library(AppDomain.CurrentDomain.BaseDirectory, "MaterialDesignColors.dll"),
                new Library(AppDomain.CurrentDomain.BaseDirectory, "MaterialDesignThemes.MahApps.dll"),
                new Library(AppDomain.CurrentDomain.BaseDirectory, "MaterialDesignThemes.Wpf.dll"),
                new Library(AppDomain.CurrentDomain.BaseDirectory, "System.Windows.Interactivity.dll"),
            };

            LibraryValidator.ValidateLibraries(libraries);
            return(LibraryValidator.LibrariesMissing);
        }
コード例 #9
0
ファイル: LoanBook.cs プロジェクト: brokep/code-challenge-3
        private LibraryBooksOperationResult validate(InfoRequest infoReq)
        {
            var result = new LibraryBooksOperationResult();

            var user         = this._usersRepository.GetUserByUsername(infoReq.Username).Result;
            var book         = this._bookRepository.FindBy(x => x.Code == infoReq.BookCode).Result.FirstOrDefault();
            var userBookList = this._bookRepository.GetBookListByUsername(infoReq.Username).Result;

            result.Success = !LibraryValidator.isBookNull(book, ref result) &&
                             !LibraryValidator.isBookLoaned(book, ref result) &&
                             !LibraryValidator.isMaxLoanReached(userBookList, ref result) &&
                             !LibraryValidator.isUserFined(user, ref result);

            return(result);
        }
コード例 #10
0
        public async Task <IHttpActionResult> DynamicAction(string dapiNamespace, string dapiAction, DapiJson dapiJson)
        {
            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Start Function for route {dapiNamespace}/{dapiAction}");

            if (HttpContext.Current.Request.Headers["X-CSRF-Header"] == null)
            {
                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - X-CSRF-Header is missing");
                return(BadRequest("Please add X-CSRF-Header with an empty value."));
            }

            if (!dapiJson.IsJsonValid())
            {
                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - JSON is invalid.  Please make sure YamlFileName and Parameters exist, and that WorkspaceId is passed within Parameters.");
                return(BadRequest("JSON is invalid.  Please make sure YamlFileName and Parameters exist.  Also WorkspaceId is required within Parameters."));
            }

            IServicesMgr serviceManager = ConnectionHelper.Helper().GetServicesManager();

            using (Library library = new Library())
            {
                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Connected to RSAPI Client");

                List <Tuple <int, DateTime?> > yamlArtifactIdList        = new List <Tuple <int, DateTime?> >();
                List <Tuple <int, DateTime?> > removedYamlArtifactIdList = new List <Tuple <int, DateTime?> >();

                var userId = ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.ArtifactID;
                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - UserId: {userId}");

                bool doesUserHavePermissions = await DoesUserHavePermission(serviceManager, userId, false, nameof(DynamicAction));

                if (doesUserHavePermissions)
                {
                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Querying for YAML File ({dapiJson.YamlFileName}) in Resource Files");
                    yamlArtifactIdList = await QueryYamlFileArtifactIDsByNameAsync(serviceManager, dapiJson.YamlFileName);

                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Found ({yamlArtifactIdList.Count}) YAML File(s)");

                    removedYamlArtifactIdList = library.GetListOfRemovedYamlFiles(yamlArtifactIdList);
                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Found ({removedYamlArtifactIdList.Count}) removed YAML File(s)");

                    if (removedYamlArtifactIdList.Count > 0)
                    {
                        library.RemoveListOfYamlFiles(removedYamlArtifactIdList);
                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Cleared routes for removed YAML File(s)");
                    }

                    yamlArtifactIdList = library.GetListOfNewOrUpdatedYamlFiles(yamlArtifactIdList);
                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Found ({yamlArtifactIdList.Count}) new or updated YAML File(s)");

                    if (yamlArtifactIdList.Count > 0)
                    {
                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Requesting Auth Token");

                        var auth = await RequestAuthTokenAsync(serviceManager);

                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Received Auth Token");

                        foreach (var artifact in yamlArtifactIdList)
                        {
                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Getting YAML file string data for Artifact ID: {artifact} - {dapiJson.YamlFileName}");
                            var yamlData = await DownloadYamlData(serviceManager, artifact.Item1, auth);

                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Got YAML file string data for Artifact ID: {artifact} - {dapiJson.YamlFileName}");

                            LibraryStreamParser libraryStreamParser = new LibraryStreamParser();
                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Attempting to parse YAML for Artifact ID: {artifact} - {dapiJson.YamlFileName}");

                            ParseResult result = libraryStreamParser.Parse(yamlData);

                            LibraryValidator libraryValidator = new LibraryValidator();
                            libraryValidator.IsValid(result);

                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Parsed YAML for Artifact ID: {artifact} - {dapiJson.YamlFileName}");

                            if (result.Success)
                            {
                                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Attempting to Add or Update YAML actions within Artifact ID: {artifact} - {dapiJson.YamlFileName}");
                                library.AddNewOrUpdatedAction(result.Library.Actions, artifact);
                                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Added/Updated YAML actions within Artifact ID: {artifact} - {dapiJson.YamlFileName}");
                            }
                            else
                            {
                                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Errors during YAML Parsing on {artifact} - {dapiJson.YamlFileName}");
                                StringBuilder errors = new StringBuilder(500);
                                foreach (ParseError error in result.Errors)
                                {
                                    errors.AppendLine($"Error Name: {error.Name}");
                                    errors.AppendLine($"Error Description: {error.Description}");
                                }
                                foreach (ValidateError error in result.ValidateErrors)
                                {
                                    errors.AppendLine($"Error Name: {error.Name}");
                                    errors.AppendLine($"Error Description: {error.Description}");
                                }
                                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Error Info: {errors.ToString()}");
                                return(BadRequest(errors.ToString()));
                            }
                        }         // end foreach on yamlfiles
                    }
                }                 // end if user exists in group
                else
                {
                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - User is not authorized to use DynamicApi");
                    return(BadRequest("User is not authorized to use DynamicApi"));
                }

                // Now attempt to execute the SQL
                if (library.DoesNamespaceExist(dapiNamespace))
                {
                    if (library.DoesActionNameExist(dapiAction))
                    {
                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Found route {dapiNamespace}/{dapiAction}");
                        Action action = library.GetAction(dapiNamespace, dapiAction);

                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Attempting to get WorkspaceId from JSON Parameters");
                        int workspaceId = dapiJson.GetWorkspaceId();
                        _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Got WorkspaceId ({workspaceId}) from JSON Parameters");

                        IDBContext dbContext;
                        try
                        {
                            dbContext = ConnectionHelper.Helper().GetDBContext(workspaceId);
                        }
                        catch (Exception ex)
                        {
                            _logHelper.LogError(ex, $"DAPI - {nameof(DynamicAction)} - Failed to connect to Workspace ({workspaceId})");
                            return(BadRequest($"Failed to connect to Workspace ({workspaceId})"));
                        }

                        LibraryExecutor libraryExecutor = new LibraryExecutor();
                        object          result;
                        try
                        {
                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Attempting to Execute SQL: {action.SQL}");
                            result = libraryExecutor.ExecuteSql(dbContext, action, dapiJson);
                            _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Executed SQL");
                            return(Json(result));
                        }
                        catch (Exception ex)
                        {
                            _logHelper.LogError(ex, $"DAPI - {nameof(DynamicAction)} - Failed to Execute SQL: {((ex.InnerException != null) ? ex.InnerException.Message : string.Empty)}");
                            result = $"Error in executing SQL.  Please verify the SQL works. {((ex.InnerException != null) ? ex.InnerException.Message : string.Empty)}";
                            return(Json(result));
                        }
                    }

                    _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Bad Request for route {dapiNamespace}/{dapiAction}");
                    return(BadRequest($"Namespace ({dapiNamespace}) exists, but Action ({dapiAction}) does not"));
                }                 // end if on checking route (namespace/name)

                _logHelper.LogInformation($"DAPI - {nameof(DynamicAction)} - Bad Request for route {dapiNamespace}/{dapiAction}");
                return(BadRequest($"Namespace ({dapiNamespace}) does not exist!"));
            }             // end USING library
        }
コード例 #11
0
ファイル: App.xaml.cs プロジェクト: gitter-badger/Osmo
        //[DebuggerNonUserCode()]
        public static void Main()
        {
            bool canRun = true;

            if (ValidateLibraries())
            {
                canRun = !LibraryValidator.RequiredLibrariesMissing;

                if (canRun)
                {
                    canRun = MessageBox.Show(string.Format("I've detected something is missing!\n{0}\n\nOsmo can be started, but only limited support is given!", LibraryValidator.GetFailedLibraries())
                                             , "", MessageBoxButton.OKCancel) == MessageBoxResult.OK;
                }
                else
                {
                    MessageBox.Show(string.Format("I've detected something is missing!\n{0}\n\nOsmo can not be started!!", LibraryValidator.GetFailedLibraries())
                                    , "", MessageBoxButton.OK);
                }
            }

            if (canRun)
            {
                Un4seen.Bass.BassNet.Registration("*****@*****.**", "2X373361752918");
                App app = new App()
                {
                    ShutdownMode = ShutdownMode.OnMainWindowClose
                };
                app.InitializeComponent();
                app.Run();
            }
        }
コード例 #12
0
 public void TearDown()
 {
     libraryStreamParser = null;
     libraryValidator    = null;
 }
コード例 #13
0
 public void SetUp()
 {
     libraryStreamParser = new LibraryStreamParser();
     libraryValidator    = new LibraryValidator();
 }