Exemple #1
0
 public PackageManager(IPackageValidator packageValidator, IExceptionHandler exceptionHandler, IPackageRepository packageRepository, IAddressValidator addressValidator)
 {
     _packageValidator  = packageValidator;
     _addressValidator  = addressValidator;
     _exceptionHandler  = exceptionHandler;
     _packageRepository = packageRepository;
 }
        private bool IsValidPackage(PackageServiceModel package)
        {
            IPackageValidator validator = PackageValidatorFactory.GetValidator(
                package.PackageType,
                package.ConfigType);

            // Bypass validation for custom _config type
            return(validator == null || validator.Validate());
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="RepositoryManager" /> class.
 /// </summary>
 /// <param name="repositoryDataAccess">The repository data access.</param>
 /// <param name="packageValidator">A validation engine to validate the package.</param>
 /// <param name="handler">A handler that creates the arelda metadata XML</param>
 /// <param name="parameterHelper">Class to read settings parameters</param>
 public RepositoryManager(IRepositoryDataAccess repositoryDataAccess, IPackageValidator packageValidator, IPackageHandler handler,
                          IParameterHelper parameterHelper, IBus bus)
 {
     this.repositoryDataAccess = repositoryDataAccess;
     this.packageValidator     = packageValidator;
     this.handler         = handler;
     this.bus             = bus;
     syncSettings         = parameterHelper.GetSetting <RepositorySyncSettings>();
     ignoredFilenameRegex = syncSettings.IgnorierteDateinamenRegex.Split('\n').Select(s => s.Trim()).ToList();
 }
Exemple #4
0
 public PackageUploader(IStorageUploader storageUploader,
                        IPackageValidator packageValidator,
                        IHashGenerator hashGenerator,
                        IOptions <AccessOptions> accessOptions,
                        IOptions <PackageOptions> packageOptions)
 {
     _storageUploader  = storageUploader;
     _packageValidator = packageValidator;
     _hashGenerator    = hashGenerator;
     _accessOptions    = accessOptions;
     _packageOptions   = packageOptions;
 }
Exemple #5
0
        /// <summary>
        /// Respond to request for data received by web service method call.
        /// (TODO wtf translate the above comment to english please :) )
        /// </summary>
        /// <param name="data">The data received via web service method call.</param>
        /// <returns>Response to web service client.</returns>
        public object DataRequested(object data)
        {
            GetDataParameters methodParams = (GetDataParameters)data;

            if (methodParams == null)
            {
                return(null);
            }

            DatabaseConnector.DatabaseConnectorManager dbm = GetDatabaseConnector();
            dbm.StartModule();

            //ICommunicationPackageMapper mapper = NullMapperFactory.Instance.CreateMapper<ICommunicationPackageMapper>(dbm);
            List <ICommunicationPackage> packagesQueue = null;

            try
            {
                using (IUnitOfWork uow = new UnitOfWork(dbm))
                {
                    uow.MapperFactory = IoC.Get <IMapperFactory>();
                    CommunicationPackageRepository repo = new CommunicationPackageRepository(uow);
                    if (methodParams.LastReceivedXmlId != null)
                    {
                        repo.MarkAsSend(methodParams.LastReceivedXmlId.Value);
                    }

                    packagesQueue = repo.FindUndeliveredPackages(1, methodParams.LastReceivedXmlId, methodParams.DatabaseId);
                    if (packagesQueue.Count == 0)
                    {
                        return(null);
                    }

                    ICommunicationPackage pkg = packagesQueue.Single(cPkg => cPkg.OrderNumber == packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber));

                    //IEnumerable<ICommunicationPackage> tmp = packagesQueue.Where(cPkg => cPkg.BranchId == methodParams.DatabaseId);
                    //ICommunicationPackage pkg = tmp.Single(cPkg => cPkg.OrderNumber == tmp.Min(communicationPackage => communicationPackage.OrderNumber));
                    //from pkg2 in packagesQueue where pkg2.OrderNumber == packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber) select pkg2;
                    //packagesQueue[packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber) - 1];
                    if (pkg.CheckSyntax() == false)
                    {
                        Log.Error("Invalid xml in outgoing queue.- syntax error. Xml Id=" + pkg.XmlData.Id);
                        return(null);
                    }

                    if (isValidationEnabled)
                    {
                        if (validator == null)
                        {
                            object context = IoC.Get <IContextProvider>().CreateContext(IoC.Container(), "IDatabaseConnectionManager", uow.ConnectionManager);
                            //throws XmlSchemaValidationException
                            this.validator = IoC.Get <IPackageValidator>(context);
                        }
                        this.validator.ConnectionManager = uow.ConnectionManager;
                        this.validator.Validate(pkg);
                    }

                    pkg.Compress();
                    GetDataResponse response = new GetDataResponse();
                    response.XmlData        = pkg.XmlData;
                    response.DatabaseId     = pkg.DatabaseId;
                    response.AdditionalData = GetUndeliveredPackagesQuantity(response.AdditionalData, repo, methodParams);
                    return(response);
                }
            }
            finally
            {
                dbm.StopModule();
            }
        }
Exemple #6
0
 /// <summary>
 /// Removes the validator from the collection of used validators.
 /// </summary>
 /// <param name="validator">The validator.</param>
 public void RemoveValidator(IPackageValidator validator)
 {
     this.validators.Remove(validator);
 }
Exemple #7
0
 /// <summary>
 /// Adds the validator to collection of used validators.
 /// </summary>
 /// <param name="validator">The validator.</param>
 public void AddValidator(IPackageValidator validator)
 {
     this.validators.Add(validator);
 }