Beispiel #1
0
 /// <summary>
 /// Serves as the default hash function.
 /// </summary>
 /// <returns>
 /// A hash code for the current object.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         return((SessionGuid.GetHashCode() * 397) ^ (Command != null ? Command.GetHashCode() : 0));
     }
 }
        public async Task IntegrationTestOrderAttack()
        {
            // Arrange
            CommandQueue repository       = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid         targetRegionGuid = new Guid("8449A25B-363D-4F01-B3D9-7EF8C5D42047");

            // Act
            Guid operationGuid;

            using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable))
            {
                operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U);
            }

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(5U, queuedCommand.NumberOfTroops);
        }
        public async Task IntegrationTestOrderAttack_MergeWithExisting()
        {
            // Arrange
            CommandQueue           repository         = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid                   targetRegionGuid   = new Guid("7E3BCD95-EB8B-4401-A987-F613A3428676");
            Guid                   initialOperationId = Guid.NewGuid();
            CommandQueueTableEntry newCommand         = CommandQueueTableEntry.CreateAttackMessage(initialOperationId, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U);

            CommandTable.Execute(TableOperation.Insert(newCommand));

            // Act
            Guid operationGuid;

            using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable))
            {
                operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 4U);
            }

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreNotEqual(operationGuid, initialOperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(9U, queuedCommand.NumberOfTroops);
        }
        public async Task <Session> InputSessionId(User user, int sessionId)
        {
            var config      = this.Configuration.GetSection("Key")["containerName"];
            var session     = new SessionGuid();
            var sessionInfo = new Session();

            try
            {
                var data = _cache.Get("tempSession" + DateTime.Now.ToShortDateString().ToString() + sessionId);
                if (data == null)
                {
                    throw new Exception("Invalid Code");
                }

                session.SessionId = Guid.NewGuid();
                var fileName = user.Id + "/" + user.Id + "-" + session.SessionId + "/" + DateTime.Now.ToFileTime().ToString() + ".json";
                await blobService.UploadFileBlob(fileName, user, config);

                sessionInfo = (Session)(_cache.Get("spdInfo" + DateTime.Now.ToShortDateString().ToString() + sessionId));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(sessionInfo);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SessionGuid sessionGuid = db.SessionGuids.Find(id);

            db.SessionGuids.Remove(sessionGuid);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #6
0
 private Dictionary <string, string> GetPropertiesDictionary()
 {
     return(new Dictionary <string, string>
     {
         { "UserGuid", UserGuid.ToString() },
         { "SessionGuid", SessionGuid.ToString() },
     });
 }
 public ActionResult Edit([Bind(Include = "Id,UserName,Guid")] SessionGuid sessionGuid)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sessionGuid).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sessionGuid));
 }
        public ActionResult Create([Bind(Include = "Id,UserName,Guid")] SessionGuid sessionGuid)
        {
            if (ModelState.IsValid)
            {
                db.SessionGuids.Add(sessionGuid);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sessionGuid));
        }
        // GET: Admin/SessionGuids/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SessionGuid sessionGuid = db.SessionGuids.Find(id);

            if (sessionGuid == null)
            {
                return(HttpNotFound());
            }
            return(View(sessionGuid));
        }
Beispiel #10
0
        private async void StartNewRoundAsync(Pool sender)
        {
            if (string.IsNullOrEmpty(VerificationKey))
            {
                return;
            }
            Packet p = new Packet();

            p.Session     = ByteString.CopyFrom(SessionGuid.ToString(), Encoding.ASCII);
            p.Number      = GuestNumber;
            p.Message     = new Message();
            p.Message.Str = "New round";
            await _communicator.SendPacketAsync(p);
        }
Beispiel #11
0
        private async void ProcessPacketAsync(Communicator sender, Packet packet)
        {
            try
            {
                if (string.IsNullOrEmpty(VerificationKey))
                {
                    VerificationKey = packet.FromKey.Key;
                    Amount          = packet.Registration.Amount;
                    OnVerified(VerificationKey, this);

                    Packet p = new Packet();
                    p.Session = ByteString.CopyFrom(SessionGuid.ToString(), Encoding.ASCII);
                    p.Number  = GuestNumber;
                    await _communicator.SendPacketAsync(p);

                    return;
                }

                if (!IsPacketValid(packet))
                {
                    await SendBlameAsync(Reason.Invalidformat);

                    Disconnect();
                    return;
                }

                if (packet.Phase == Phase.Blame && packet.Message?.Blame?.Reason == Reason.Liar)
                {
                    string verificationKey = packet.Message?.Blame?.Accused?.Key;
                    if (!string.IsNullOrEmpty(verificationKey))
                    {
                        OnBanRequest(verificationKey, this);
                    }
                }

                OnForward(packet.ToKey?.Key, this, packet);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #12
0
        public string SessionGuidManager(string userName)
        {
            Guid guid        = Guid.NewGuid();
            var  sessionGuid = _ctx.SessionGuids.Where(s => s.UserName == userName).FirstOrDefault();

            if (sessionGuid == null)
            {
                sessionGuid = new SessionGuid {
                    UserName = userName, Guid = guid.ToString()
                };
                _ctx.SessionGuids.Add(sessionGuid);
                _ctx.SaveChanges();
            }
            else
            {
                sessionGuid.Guid = guid.ToString();
                _ctx.Entry(sessionGuid).State = EntityState.Modified;
                _ctx.SaveChanges();
            }

            return(sessionGuid.Guid);
        }
        public async Task IntegrationTestCreateReinforceMessage()
        {
            // Arrange
            CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString);

            // Act
            Guid operationGuid = await repository.DeployReinforcements(SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", 10U);

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + operationGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Reinforce, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual("DummyEtag", queuedCommand.TargetRegionEtag);
            Assert.AreEqual(10U, queuedCommand.NumberOfTroops);
        }
        public async Task IntegrationTestRedeploy()
        {
            // Arrange
            CommandQueue repository       = new CommandQueue(DevelopmentStorageAccountConnectionString);
            Guid         targetRegionGuid = new Guid("8449A25B-363D-4F01-B3D9-7EF8C5D42047");

            // Act
            Guid operationGuid = await repository.Redeploy(SessionGuid, SessionPhaseGuid, String.Empty, RegionGuid, targetRegionGuid, 5U);

            // Assert
            var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + operationGuid.ToString());
            var result    = await CommandTable.ExecuteAsync(operation);

            CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry;

            Assert.IsNotNull(queuedCommand);
            Assert.AreEqual(operationGuid, queuedCommand.OperationId);
            Assert.AreEqual(SessionGuid, queuedCommand.SessionId);
            Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId);
            Assert.AreEqual(CommandQueueMessageType.Redeploy, queuedCommand.MessageType);
            Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion);
            Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion);
            Assert.AreEqual(5U, queuedCommand.NumberOfTroops);
        }
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = "Start validate .metadata files.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            var  anyMessages = new List <String>();
            bool isSucces    = false;
            var  validation  = new List <MetadataValidationItem>();

            try
            {
                base.Execute();

                if (this.IsToPX)
                {
                    string   sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());
                    string[] metadatas     = Directory.GetFiles(sessionFolder, "*.metadata", SearchOption.AllDirectories);

                    eventModel.Summary.Processed = metadatas.Count();

                    foreach (string file in metadatas)
                    {
                        Logger.LogInformation("Metadata validatie : {0}", file);

                        string requestUri    = GetProcessingUrl(ApplicationSettings.XslWebServerName, ApplicationSettings.XslWebServerPort, file);
                        var    errorMessages = new List <String>();

                        using (HttpClient client = new HttpClient())
                        {
                            var httpResponse = client.GetAsync(requestUri).Result;

                            if (!httpResponse.IsSuccessStatusCode)
                            {
                                throw new Exception("Failed to request data! Status code not equals 200.");
                            }

                            var rootError = JsonConvert.DeserializeObject <Root>(httpResponse.Content.ReadAsStringAsync().Result);
                            if (rootError == null)
                            {
                                throw new ApplicationException("Metadata validation request failed!");
                            }

                            try
                            {
                                //schema+ validation
                                if (rootError.SchematronValidationReport != null && rootError.SchematronValidationReport.errors != null &&
                                    rootError.SchematronValidationReport.errors.Count > 0)
                                {
                                    var messages = rootError.SchematronValidationReport.errors.Select(item => item.message).ToArray();
                                    errorMessages.AddRange(messages);
                                }
                                //default schema validation
                                if (rootError.SchemaValidationReport != null && rootError.SchemaValidationReport.errors != null &&
                                    rootError.SchemaValidationReport.errors.Count > 0)
                                {
                                    var messages = rootError.SchemaValidationReport.errors.Select(item => String.Concat(item.message, ", ", String.Format("Line: {0}, col: {1}", item.line, item.col))).ToArray();
                                    errorMessages.AddRange(messages);
                                }

                                if (errorMessages.Count > 0)
                                {
                                    //error
                                    validation.Add(new MetadataValidationItem
                                    {
                                        IsValidated      = true,
                                        IsConfirmSchema  = false,
                                        ErrorMessages    = errorMessages.ToArray(),
                                        MetadataFilename = file,
                                        RequestUri       = requestUri
                                    });
                                }
                                else
                                {
                                    //no error
                                    validation.Add(new MetadataValidationItem
                                    {
                                        IsValidated      = true,
                                        IsConfirmSchema  = true,
                                        ErrorMessages    = new string[0],
                                        MetadataFilename = file,
                                        RequestUri       = requestUri
                                    });
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.LogError(e, String.Format("Exception occured in metadata validation with request '{0}' for metadata file '{1}'!", requestUri, file));
                                errorMessages.Clear();
                                errorMessages.Add(String.Format("Exception occured in metadata validation with request '{0}' for metadata file '{1}'!", requestUri, file));
                                errorMessages.Add(e.Message);
                                errorMessages.Add(e.StackTrace);

                                //error
                                validation.Add(new MetadataValidationItem
                                {
                                    IsValidated      = true,
                                    IsConfirmSchema  = false,
                                    ErrorMessages    = errorMessages.ToArray(),
                                    MetadataFilename = file,
                                    RequestUri       = requestUri
                                });
                            }
                        }

                        OnTrigger(new PreingestEventArgs {
                            Description = String.Format("Processing file '{0}'", file), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                        });
                    }

                    eventModel.Summary.Accepted = validation.Where(item => item.IsValidated && item.IsConfirmSchema).Count();
                    eventModel.Summary.Rejected = validation.Where(item => !item.IsValidated || !item.IsConfirmSchema).Count();

                    eventModel.ActionData = validation.ToArray();
                }

                if (this.IsMDTO)
                {
                    //TODO
                    throw new ApplicationException("Not supported in this current version yet!");
                }

                if (eventModel.Summary.Rejected > 0)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Error;
                }
                else
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                }

                isSucces = true;
            }
            catch (Exception e)
            {
                isSucces = false;
                Logger.LogError(e, "An exception occured in metadata validation!");
                anyMessages.Clear();
                anyMessages.Add("An exception occured in metadata validation!");
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                //eventModel.Summary.Processed = 0;
                eventModel.Summary.Accepted = 0;
                eventModel.Summary.Rejected = eventModel.Summary.Processed;

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured in metadata validation!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSucces)
                {
                    OnTrigger(new PreingestEventArgs {
                        Description = "Validation is done!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }
Beispiel #16
0
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = String.Format("Start building Opex for container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            var  anyMessages = new List <String>();
            bool isSuccess   = false;

            try
            {
                base.Execute();

                string       sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());
                BodySettings settings      = new SettingsReader(this.ApplicationSettings.DataFolderName, SessionGuid).GetSettings();

                if (settings == null)
                {
                    throw new ApplicationException("Settings are not saved!");
                }

                if (!String.IsNullOrEmpty(settings.MergeRecordAndFile))
                {
                    bool doMerge = settings.MergeRecordAndFile.Equals("Ja", StringComparison.InvariantCultureIgnoreCase);

                    if (doMerge && InheritanceSetting.MethodResult == InheritanceMethod.None)
                    {
                        //true && true
                        this.InheritanceSetting.MethodResult = InheritanceMethod.Combine;
                    }
                }

                string addNameSpaces   = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.ADD_NAMESPACE);
                string stripNameSpaces = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.STRIP_NAMESPACE);
                string opexFolders     = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.OPEX_FOLDERS);
                string opexFolderFiles = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.OPEX_FOLDER_FILES);
                string opexFiles       = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.OPEX_FILES);
                string opexFinalize    = Path.Combine(ApplicationSettings.PreWashFolder, OpexItem.OPEX_FINALIZE);

                if (!File.Exists(addNameSpaces))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", addNameSpaces));
                }
                if (!File.Exists(stripNameSpaces))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", stripNameSpaces));
                }
                if (!File.Exists(opexFolders))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", opexFolders));
                }
                if (!File.Exists(opexFolderFiles))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", opexFolderFiles));
                }
                if (!File.Exists(opexFiles))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", opexFiles));
                }
                if (!File.Exists(opexFinalize))
                {
                    throw new FileNotFoundException(String.Format("Stylesheet file not found '{0}'!", opexFinalize));
                }

                List <StylesheetItem> stylesheetList = new List <StylesheetItem>();

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Load settings for building Opex.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                var stylesheets = Directory.GetFiles(ApplicationSettings.PreWashFolder, "*-opex-*.xsl").Select(item => new StylesheetItem {
                    KeyLocation = item, XmlContent = XDocument.Load(item).ToString()
                }).ToArray();
                stylesheetList.AddRange(stylesheets);

                List <OpexItem> potentionalOpexList = new List <OpexItem>();

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Reading collection to build Opex for container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                //trigger event read collections
                if (this.IsToPX)
                {
                    var listOfMetadata = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.metadata", SearchOption.AllDirectories).Select(item
                                                                                                                                                                                                => new OpexItem(this.TargetFolder, item.FullName,
                                                                                                                                                                                                                XDocument.Load(item.FullName).ToString(),
                                                                                                                                                                                                                item.Directory.GetFiles("*.metadata", SearchOption.TopDirectoryOnly).Count())).ToArray();
                    potentionalOpexList.AddRange(listOfMetadata);
                    OnTrigger(new PreingestEventArgs {
                        Description = String.Format("Found '{0}' metadata ({1}) files.", potentionalOpexList.Count, this.IsToPX ? "ToPX" : "MDTO"), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                    });
                }

                if (this.IsMDTO)
                {
                    var listOfMetadata = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.xml", SearchOption.AllDirectories).Where(item => item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).Select(item
                                                                                                                                                                                                                                                                                       => new OpexItem(this.TargetFolder, item.FullName,
                                                                                                                                                                                                                                                                                                       XDocument.Load(item.FullName).ToString(),
                                                                                                                                                                                                                                                                                                       item.Directory.GetFiles("*.xml", SearchOption.TopDirectoryOnly).Where(item
                                                                                                                                                                                                                                                                                                                                                                             => item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).Count())).ToArray();
                    potentionalOpexList.AddRange(listOfMetadata);
                    OnTrigger(new PreingestEventArgs {
                        Description = String.Format("Found '{0}' metadata ({1}) files.", potentionalOpexList.Count, this.IsToPX ? "ToPX" : "MDTO"), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                    });
                }

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Creating Opex files."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });
                //trigger event process opex
                potentionalOpexList.ForEach(item =>
                {
                    item.InitializeOpex(stylesheetList);
                });

                var jsonData = new List <String>();

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Removing original metadata files."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                //remove the old metadata files topx or mdto
                potentionalOpexList.ForEach(item =>
                {
                    try
                    {
                        File.Delete(item.KeyLocation);
                    }
                    catch (Exception delete)
                    {
                        anyMessages.Add(String.Format("Deleting file '{0}' failed! {1} {2}", item.KeyLocation, delete.Message, delete.StackTrace));
                    }
                });

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Saving Opex files (only file level)."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                var sortedPotentionalOpexList = new List <OpexItem>();

                if (InheritanceSetting.MethodResult == InheritanceMethod.Combine)
                {
                    var sorted = potentionalOpexList.Where(item => !item.IsFile).GroupBy(item => item.Level, (key, opex) => new { Level = key, Item = opex }).OrderByDescending(item
                                                                                                                                                                                => item.Level).FirstOrDefault();
                    sortedPotentionalOpexList.AddRange(sorted.Item.OfType <OpexItem>());
                }

                //save bestand level first
                potentionalOpexList.Where(item => item.IsFile).ToList().ForEach(item =>
                {
                    try
                    {
                        var metadataList = new List <System.Xml.XmlElement>();

                        if (InheritanceSetting.MethodResult == InheritanceMethod.Combine)
                        {
                            var parts           = item.KeyLocation.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToArray();
                            var startsWith      = parts.Skip(0).Take(parts.Count() - 1).ToArray();
                            var currentItemPath = "/" + Path.Combine(startsWith);

                            var profile = sortedPotentionalOpexList.FirstOrDefault(sorted => sorted.KeyLocation.StartsWith(currentItemPath));

                            if (profile == null)
                            {
                                throw new ApplicationException(String.Format("Adding profile to DescriptiveMetadata failed! Cannot find profile record in '{0}'", currentItemPath));
                            }

                            var xmlProfileDoc = new System.Xml.XmlDocument();
                            xmlProfileDoc.LoadXml(profile.OriginalMetadata);
                            metadataList.Add(xmlProfileDoc.DocumentElement);
                        }

                        if (InheritanceSetting.MethodResult == InheritanceMethod.None)
                        {
                            metadataList.Clear();
                        }

                        item.UpdateOpexFileLevel(ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, metadataList, true);
                        var xml = XDocument.Parse(item.FinalUpdatedOpexMetadata);
                        xml.Save(item.KeyOpexLocation);
                    }
                    catch (Exception save)
                    {
                        anyMessages.Add(String.Format("Saving Opex file '{0}' failed! {1} {2}", item.KeyOpexLocation, save.Message, save.StackTrace));
                    }
                });

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Saving Opex files (folder levels)."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                //update mappen levels
                //save the rest of the folder levels
                potentionalOpexList.Where(item => !item.IsFile).ToList().ForEach(item =>
                {
                    try
                    {
                        item.UpdateOpexFolderLevel();
                        var xml = XDocument.Parse(item.FinalUpdatedOpexMetadata);
                        xml.Save(item.KeyOpexLocation);
                    }
                    catch (Exception save)
                    {
                        anyMessages.Add(String.Format("Saving Opex file '{0}' failed! {1} {2}", item.KeyOpexLocation, save.Message, save.StackTrace));
                    }
                });

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Rounding up Opex."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                //create container opex file,
                //move the result to a folder named 'opex';
                //this folder will be used by the bucket container for upload to S3
                var currentCollectionDI         = new DirectoryInfo(TargetFolder);
                var currentCollectionFoldername = currentCollectionDI.GetDirectories().OrderBy(item => item.CreationTime).FirstOrDefault();
                if (currentCollectionFoldername == null)
                {
                    throw new DirectoryNotFoundException("Expanded collection folder not found!");
                }

                var opexContainerFilename = CreateContainerOpexMetadata(currentCollectionDI, currentCollectionFoldername.Name);
                var opexUploadFolder      = Directory.CreateDirectory(Path.Combine(TargetFolder, "opex"));

                opexContainerFilename.MoveTo(Path.Combine(opexUploadFolder.FullName, opexContainerFilename.Name), true);
                currentCollectionFoldername.MoveTo(Path.Combine(opexUploadFolder.FullName, currentCollectionFoldername.Name));

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Reading Opex files for XSD schema validation."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                var newOpexFiles = opexUploadFolder.GetFiles("*.opex").ToList();
                var schemaList   = SchemaHandler.GetSchemaList();

                var strXsd         = schemaList["Noord.Hollands.Archief.Preingest.WebApi.Schema.OPEX-Metadata.xsd"];
                var xsdTmpFilename = Path.GetTempFileName();
                var xsd            = XDocument.Parse(strXsd);
                xsd.Save(xsdTmpFilename);

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Validate Opex files with XSD schema."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                newOpexFiles.ForEach(opex =>
                {
                    try
                    {
                        if (String.IsNullOrEmpty(opex.FullName) || !File.Exists(opex.FullName))
                        {
                            throw new FileNotFoundException(String.Format("Opex file with location '{0}' is empty or not found!", opex.FullName));
                        }

                        XDocument xml = XDocument.Load(opex.FullName);

                        SchemaValidationHandler.Validate(xml.ToString(), xsdTmpFilename);
                    }
                    catch (Exception validate)
                    {
                        anyMessages.Add(String.Format("Schema validation error for Opex file '{0}'! {1} {2}", opex.FullName, validate.Message, validate.StackTrace));
                    }
                });

                try { File.Delete(xsdTmpFilename); } catch { }

                var result = potentionalOpexList.Select(item => String.Format("{0} >> {1}", item.KeyLocation, item.KeyOpexLocation)).ToArray();
                jsonData.AddRange(result);
                opexContainerFilename.Refresh();
                jsonData.Add("All moved to folder 'opex'.");
                jsonData.Add(opexContainerFilename.FullName);

                eventModel.ActionData          = jsonData.ToArray();
                eventModel.Summary.Processed   = potentionalOpexList.Count;
                eventModel.Summary.Accepted    = potentionalOpexList.Count;
                eventModel.Summary.Rejected    = anyMessages.Count();
                eventModel.Properties.Messages = anyMessages.ToArray();

                if (eventModel.Summary.Rejected > 0)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Error;
                }
                else
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                isSuccess = false;
                anyMessages.Clear();
                anyMessages.Add(String.Format("Build Opex with collection: '{0}' failed!", TargetCollection));
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                Logger.LogError(e, "Build Opex with collection: '{0}' failed!", TargetCollection);

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();
                eventModel.Summary.Processed        = 1;
                eventModel.Summary.Accepted         = 0;
                eventModel.Summary.Rejected         = 1;

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured while building opex!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSuccess)
                {
                    OnTrigger(new PreingestEventArgs {
                        Description = "Build Opex with a collection is done.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }
Beispiel #17
0
        public virtual void Execute()
        {
            if (!File.Exists(TargetCollection))
            {
                throw new FileNotFoundException("Collection not found!", TargetCollection);
            }

            DirectoryInfo directoryInfoSessionFolder = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString()));
            int           countToPXFiles             = directoryInfoSessionFolder.GetFiles("*.metadata", SearchOption.AllDirectories).Count();
            int           countMDTOFiles             = directoryInfoSessionFolder.GetFiles("*.xml", SearchOption.AllDirectories).Where(item => item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).Count();

            if (countToPXFiles > 0 && countMDTOFiles > 0)
            {
                throw new ApplicationException(String.Format("Found ToPX ({0}) and/or MDTO ({1}) files in collection with GUID {2}. Cannot handle both types in one collection.", countToPXFiles, countMDTOFiles, SessionGuid));
            }

            if (countMDTOFiles == 0 && countToPXFiles == 0)
            {
                throw new ApplicationException("Metadata files not found!");
            }

            this._isToPX = (countToPXFiles > 0);
            this._isMDTO = (countMDTOFiles > 0);
        }
Beispiel #18
0
 private bool IsPacketValid(Packet packet)
 {
     return(packet.Session != ByteString.CopyFrom(SessionGuid.ToString(), Encoding.ASCII) &&
            packet.FromKey.Key != VerificationKey &&
            packet.ToKey != null);
 }
Beispiel #19
0
 protected bool Equals(CommandEventArgs other)
 {
     return(SessionGuid.Equals(other.SessionGuid) && Equals(Command, other.Command));
 }
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = String.Format("Start expanding container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            string output = string.Empty;
            string error  = string.Empty;

            var  anyMessages = new List <String>();
            bool isSuccess   = false;

            try
            {
                if (!File.Exists(TargetCollection))
                {
                    throw new FileNotFoundException("Collection not found!", TargetCollection);
                }

                string sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());

                using (var tarProcess = new Process()
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = "tar",
                        Arguments = String.Format("-C \"{0}\" -oxvf \"{1}\"", sessionFolder, TargetCollection),
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                    }
                })
                {
                    tarProcess.Start();
                    OnTrigger(new PreingestEventArgs {
                        Description = "Container is expanding content.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                    });

                    this.Logger.LogDebug("Unpacking container '{0}'", TargetCollection);

                    output = tarProcess.StandardOutput.ReadToEnd();
                    error  = tarProcess.StandardError.ReadToEnd();

                    tarProcess.WaitForExit();
                }

                if (!String.IsNullOrEmpty(output))
                {
                    this.Logger.LogDebug(output);
                }

                if (!String.IsNullOrEmpty(error))
                {
                    this.Logger.LogDebug(error);
                }

                var fileInformation = new FileInfo(TargetCollection);
                anyMessages.Add(String.Concat("Name : ", fileInformation.Name));
                anyMessages.Add(String.Concat("Extension : ", fileInformation.Extension));
                anyMessages.Add(String.Concat("Size : ", fileInformation.Length));
                anyMessages.Add(String.Concat("CreationTime : ", fileInformation.CreationTimeUtc));
                anyMessages.Add(String.Concat("LastAccessTime : ", fileInformation.LastAccessTimeUtc));
                anyMessages.Add(String.Concat("LastWriteTime : ", fileInformation.LastWriteTimeUtc));

                eventModel.Properties.Messages = anyMessages.ToArray();

                bool isWindows = RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
                if (!isWindows)
                {
                    var unixDirInfo = new UnixDirectoryInfo(sessionFolder);
                    //trigger event executing
                    var passEventArgs = new PreingestEventArgs {
                        Description = String.Format("Execute chmod 777 for container '{0}'", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                    };
                    OnTrigger(passEventArgs);
                    ScanPath(unixDirInfo, passEventArgs);
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                isSuccess = false;
                anyMessages.Clear();
                anyMessages.Add(String.Format("Unpack container file: '{0}' failed!", TargetCollection));
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                Logger.LogError(e, "Unpack container file: '{0}' failed!", TargetCollection);

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();
                eventModel.Summary.Processed        = 1;
                eventModel.Summary.Accepted         = 0;
                eventModel.Summary.Rejected         = 1;

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured while unpacking a container!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSuccess)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                    eventModel.Summary.Processed        = 1;
                    eventModel.Summary.Accepted         = 1;
                    eventModel.Summary.Rejected         = 0;
                    eventModel.ActionData = output.Split(Environment.NewLine);

                    OnTrigger(new PreingestEventArgs {
                        Description = "Unpacking the container is done.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = String.Format("Start polishing Opex for container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            var  anyMessages = new List <String>();
            bool isSuccess   = false;

            try
            {
                string       sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());
                BodySettings settings      = new SettingsReader(this.ApplicationSettings.DataFolderName, SessionGuid).GetSettings();

                if (settings == null)
                {
                    throw new ApplicationException("Settings are not saved!");
                }

                if (String.IsNullOrEmpty(settings.Polish))
                {
                    throw new ApplicationException("Polish setting is empty!");
                }

                DirectoryInfo   directoryInfoSessionFolder = new DirectoryInfo(sessionFolder);
                List <FileInfo> opexFiles = directoryInfoSessionFolder.GetFiles("*.opex", SearchOption.AllDirectories).ToList();

                if (opexFiles.Count == 0)
                {
                    throw new ApplicationException("Zero OPEX files found!");
                }

                string xsltTranformationServiceUrl = String.Format("http://{0}:{1}/hooks/xslt-transformation", ApplicationSettings.TransformationServerName, ApplicationSettings.TransformationServerPort);
                string stylesheetFileLocation      = Path.Combine(ApplicationSettings.PreWashFolder, settings.Polish);

                var jsonData = new List <string>();

                int countTotal = opexFiles.Count;

                OnTrigger(new PreingestEventArgs
                {
                    Description     = String.Format("Transforming: {0} files", countTotal),
                    Initiate        = DateTimeOffset.Now,
                    ActionType      = PreingestActionStates.Executing,
                    PreingestAction = eventModel
                });

                if (!String.IsNullOrEmpty(settings.UseSaxon))
                {
                    bool useSaxon = settings.UseSaxon.Equals("Ja", StringComparison.InvariantCultureIgnoreCase);
                    if (TransformationSetting.UseSaxon != useSaxon)
                    {
                        TransformationSetting.UseSaxon = useSaxon;
                    }
                }

                opexFiles.ForEach(file =>
                {
                    string result = string.Empty;

                    try
                    {
                        if (TransformationSetting.UseSaxon)
                        {
                            using (HttpClient client = new HttpClient())
                            {
                                client.Timeout = Timeout.InfiniteTimeSpan;
                                HttpResponseMessage response = client.GetAsync(String.Format("{0}?xsl={1}&xml={2}", xsltTranformationServiceUrl, stylesheetFileLocation, file.FullName)).Result;
                                response.EnsureSuccessStatusCode();

                                result = response.Content.ReadAsStringAsync().Result;
                            }
                        }
                        else
                        {
                            var opex = XDocument.Load(file.FullName).ToString();
                            var xsl  = XDocument.Load(stylesheetFileLocation).ToString();

                            result = Transform(xsl, opex);
                        }
                    }
                    catch (Exception e)
                    {
                        anyMessages.Add(String.Format("Transformation with Opex file '{0}' failed! {1} {2}", file.FullName, e.Message, e.StackTrace));
                    }
                    finally
                    {
                        if (!String.IsNullOrEmpty(result))
                        {
                            try
                            {
                                XDocument doc = XDocument.Parse(result);
                                doc.Save(file.FullName);
                            }
                            catch (Exception ie)
                            {
                                anyMessages.Add(String.Format("Saving Opex file '{0}' failed! {1} {2}", file.FullName, ie.Message, ie.StackTrace));
                            }
                            finally
                            {
                                jsonData.Add(String.Format("Transformation processed: {0}", file.FullName));
                            }
                        }
                    }
                });

                //update opex
                var profiles = opexFiles.Select(item => new { Xml = XDocument.Load(item.FullName).ToString(), FullName = item.FullName }).Where(item => item.Xml.Contains("<Files>")).ToList();
                countTotal = profiles.Count;

                OnTrigger(new PreingestEventArgs
                {
                    Description     = String.Format("Updating profile (Opex files): Total {0} files.", countTotal),
                    Initiate        = DateTimeOffset.Now,
                    ActionType      = PreingestActionStates.Executing,
                    PreingestAction = eventModel
                });

                profiles.ForEach(item =>
                {
                    FileInfo opex             = new FileInfo(item.FullName);
                    FileInfo[] currentContent = opex.Directory.GetFiles().Where(content => content.FullName != item.FullName).ToArray();

                    var currentOpexMetadataFile = Preingest.WebApi.Utilities.DeserializerHelper.DeSerializeObjectFromXmlFile <Noord.Hollands.Archief.Entities.Opex.opexMetadata>(item.Xml);
                    //overwrite
                    if (currentContent.Count() > 0)
                    {
                        currentOpexMetadataFile.Transfer.Manifest       = new Noord.Hollands.Archief.Entities.Opex.manifest();
                        currentOpexMetadataFile.Transfer.Manifest.Files = currentContent.Select(item => new Noord.Hollands.Archief.Entities.Opex.file
                        {
                            size          = item.Length,
                            typeSpecified = true,
                            type          = item.Extension.Equals(".opex", StringComparison.InvariantCultureIgnoreCase) ? Noord.Hollands.Archief.Entities.Opex.fileType.metadata : Noord.Hollands.Archief.Entities.Opex.fileType.content,
                            sizeSpecified = true,
                            Value         = item.Name
                        }).ToArray();

                        string output = Preingest.WebApi.Utilities.SerializerHelper.SerializeObjectToString(currentOpexMetadataFile);
                        var newDoc    = XDocument.Parse(output);
                        newDoc.Save(item.FullName);
                    }
                });

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Reading Opex files for XSD schema validation."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                var newOpexFiles = directoryInfoSessionFolder.GetFiles("*.opex").ToList();
                var schemaList   = SchemaHandler.GetSchemaList();

                var strXsd         = schemaList["Noord.Hollands.Archief.Preingest.WebApi.Schema.OPEX-Metadata.xsd"];
                var xsdTmpFilename = Path.GetTempFileName();
                var xsd            = XDocument.Parse(strXsd);
                xsd.Save(xsdTmpFilename);

                OnTrigger(new PreingestEventArgs {
                    Description = String.Format("Validate Opex files with XSD schema."), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Executing, PreingestAction = eventModel
                });

                newOpexFiles.ForEach(opex =>
                {
                    try
                    {
                        if (String.IsNullOrEmpty(opex.FullName) || !File.Exists(opex.FullName))
                        {
                            throw new FileNotFoundException(String.Format("Opex file with location '{0}' is empty or not found!", opex.FullName));
                        }

                        XDocument xml = XDocument.Load(opex.FullName);

                        SchemaValidationHandler.Validate(xml.ToString(), xsdTmpFilename);
                    }
                    catch (Exception validate)
                    {
                        anyMessages.Add(String.Format("Schema validation error for Opex file '{0}'! {1} {2}", opex.FullName, validate.Message, validate.StackTrace));
                    }
                });

                try { File.Delete(xsdTmpFilename); } catch { }

                eventModel.Properties.Messages = anyMessages.ToArray();
                eventModel.ActionData          = jsonData.ToArray();

                eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                eventModel.Summary.Processed        = opexFiles.Count;
                eventModel.Summary.Accepted         = (opexFiles.Count - anyMessages.Count);
                eventModel.Summary.Rejected         = anyMessages.Count;

                if (eventModel.Summary.Rejected > 0)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Error;
                }
                else
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                isSuccess = false;
                anyMessages.Clear();
                anyMessages.Add(String.Format("Run polish with collection: '{0}' failed!", TargetCollection));
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                Logger.LogError(e, "Run polish with collection: '{0}' failed!", TargetCollection);

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();
                eventModel.Summary.Processed        = 1;
                eventModel.Summary.Accepted         = 0;
                eventModel.Summary.Rejected         = 1;

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured while running checksum!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSuccess)
                {
                    OnTrigger(new PreingestEventArgs {
                        Description = "Polish run with a collection is done.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = String.Format("Start running checksum for container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            var  anyMessages = new List <String>();
            bool isSuccess   = false;

            try
            {
                base.Execute();

                if (HashType == null)
                {
                    throw new ApplicationException("Algorithm is not set!");
                }

                string sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());

                //list of output result json files
                var outputJson = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.*", SearchOption.TopDirectoryOnly).ToList();
                //list all files from guid folder
                var allFiles = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.*", SearchOption.AllDirectories).ToList();
                //list of only files without json
                var targetFiles = allFiles.Where(item => !outputJson.Exists((x) => { return(x.FullName == item.FullName); })).ToList();

                var jsonData = new List <String[]>();

                if (HashType.ProcessingMode == ExecutionMode.CalculateAndCompare)
                {
                    var metadataFiles = this.IsToPX ? targetFiles.Where(item => item.Name.EndsWith(".metadata", StringComparison.InvariantCultureIgnoreCase)).ToList() : targetFiles.Where(item => item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).ToList();
                    eventModel.Summary.Processed = metadataFiles.Count();
                    //compare modus: compare checksum algorithm/value in metadata with self check algorithm/value
                    if (IsToPX)
                    {
                        var listOfFiles = metadataFiles.Select(item => new
                        {
                            Fullname = item.FullName,
                            ToPX     = DeserializerHelper.DeSerializeObjectFromXmlFile <Entities.ToPX.v2_3_2.topxType>(item)
                        }).Where(item => item.ToPX.Item is Entities.ToPX.v2_3_2.bestandType).Select(item => new
                        {
                            Fullname = item.Fullname,
                            Bestand  = item.ToPX.Item as Entities.ToPX.v2_3_2.bestandType
                        }).ToList();

                        eventModel.Summary.Processed = listOfFiles.Count();

                        listOfFiles.ForEach(topx =>
                        {
                            var fixityList = topx.Bestand.formaat.Select(fixity => fixity.fysiekeIntegriteit != null ?
                                                                         new
                            {
                                FixitiyAlgorithm = fixity.fysiekeIntegriteit.algoritme != null ? fixity.fysiekeIntegriteit.algoritme.Value : String.Empty,
                                FixitiyValue     = fixity.fysiekeIntegriteit.waarde != null ? fixity.fysiekeIntegriteit.waarde.Value : String.Empty
                            } :
                                                                         new
                            {
                                FixitiyAlgorithm = string.Empty,
                                FixitiyValue     = string.Empty
                            }).ToList();

                            fixityList.ForEach(fixity =>
                            {
                                bool isEmptyAlgorithm = String.IsNullOrEmpty(fixity.FixitiyAlgorithm);
                                bool isEmptyValue     = String.IsNullOrEmpty(fixity.FixitiyValue);

                                if (isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm + value found in '{0}'", topx.Fullname));
                                }

                                if (isEmptyAlgorithm && !isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm, but value found in '{0}'", topx.Fullname));
                                }

                                if (!isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("Algorithm found, but no value found in '{0}'", topx.Fullname));
                                }

                                if (!isEmptyAlgorithm && !isEmptyValue)
                                {
                                    //todo, set algorithm first
                                    AlgorithmTypes foundAlgorithm = Translate(fixity.FixitiyAlgorithm);
                                    var fixityCheckResult         = RunFixityCheck(new FileInfo(topx.Fullname.Replace(".metadata", String.Empty, StringComparison.InvariantCultureIgnoreCase)), foundAlgorithm, fixity.FixitiyValue);

                                    anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                                    jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                                }
                            });
                        });
                    }

                    if (IsMDTO)
                    {
                        var listOfFiles = metadataFiles.Select(item
                                                               => new
                        {
                            Fullname = item.FullName,
                            MDTO     = DeserializerHelper.DeSerializeObjectFromXmlFile <Entities.MDTO.v1_0.mdtoType>(item)
                        }).Where(item => item.MDTO.Item is Entities.MDTO.v1_0.bestandType).Select(item => new
                        {
                            Fullname = item.Fullname,
                            Bestand  = item.MDTO.Item as Entities.MDTO.v1_0.bestandType
                        }).ToList();

                        eventModel.Summary.Processed = listOfFiles.Count();

                        listOfFiles.ForEach(mdto =>
                        {
                            var fixityList = mdto.Bestand.checksum.Select(fixity => new
                            {
                                FixitiyAlgorithm = fixity.checksumAlgoritme != null ? fixity.checksumAlgoritme.begripLabel : String.Empty,
                                FixitiyValue     = fixity.checksumWaarde
                            }).ToList();

                            fixityList.ForEach(fixity =>
                            {
                                bool isEmptyAlgorithm = String.IsNullOrEmpty(fixity.FixitiyAlgorithm);
                                bool isEmptyValue     = String.IsNullOrEmpty(fixity.FixitiyValue);

                                if (isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm + value found in '{0}'", mdto.Fullname));
                                }

                                if (isEmptyAlgorithm && !isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm, but value found in '{0}'", mdto.Fullname));
                                }

                                if (!isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("Algorithm found, but no value found in '{0}'", mdto.Fullname));
                                }

                                if (!isEmptyAlgorithm && !isEmptyValue)
                                {
                                    //todo, set algorithm first
                                    AlgorithmTypes foundAlgorithm = Translate(fixity.FixitiyAlgorithm);
                                    var fixityCheckResult         = RunFixityCheck(new FileInfo(mdto.Fullname.Replace(".mdto.xml", String.Empty, StringComparison.InvariantCultureIgnoreCase)), foundAlgorithm, fixity.FixitiyValue);

                                    anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                                    jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                                }
                            });
                        });
                    }
                    eventModel.Properties.Messages = anyMessages.ToArray();
                }

                if (HashType.ProcessingMode == ExecutionMode.OnlyCalculate)
                {
                    var binaryFiles = this.IsToPX ? targetFiles.Where(item => !item.Name.EndsWith(".metadata", StringComparison.InvariantCultureIgnoreCase)).ToList() : targetFiles.Where(item => !item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).ToList();
                    eventModel.Summary.Processed = binaryFiles.Count();

                    foreach (FileInfo file in binaryFiles)
                    {
                        var fixityCheckResult = RunFixityCheck(file, HashType.ChecksumType);
                        anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                        jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                    }
                    eventModel.Properties.Messages = new string[] { HashType.ChecksumType.ToString() };
                }

                eventModel.ActionData       = jsonData.ToArray();
                eventModel.Summary.Accepted = jsonData.Count();
                eventModel.Summary.Rejected = anyMessages.Count();

                if (eventModel.Summary.Rejected > 0)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Error;
                }
                else
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                isSuccess = false;
                anyMessages.Clear();
                anyMessages.Add(String.Format("Running checksum with collection: '{0}' failed!", TargetCollection));
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                Logger.LogError(e, "Running checksum with collection: '{0}' failed!", TargetCollection);

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();
                eventModel.Summary.Processed        = 1;
                eventModel.Summary.Accepted         = 0;
                eventModel.Summary.Rejected         = 1;

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured while running checksum!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSuccess)
                {
                    OnTrigger(new PreingestEventArgs {
                        Description = "Checksum run with a collection is done.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }