Ejemplo n.º 1
0
        public IActionResult Post([FromBody] ArchiveMessage archiveMessage)
        {
            _logger.LogInformation($"{nameof(Post)}: Received ArchiveMessage with JobId: {archiveMessage.JobId}");

            if (_settings.Value.EnableTestValidation && Validate(archiveMessage) is { } prob)
            {
                _logger.LogWarning(prob.Detail);
                return(BadRequest(prob));
            }

            Directory.CreateDirectory(_settings.Value.ArchiveFolder);
            var archiveId = Guid.NewGuid();

            if (archiveMessage.MainDocument?.DocumentData != null)
            {
                System.IO.File.WriteAllBytes(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.pdf"),
                                             archiveMessage.MainDocument.DocumentData);
                // Don't save document data in JSON or XML
                archiveMessage.MainDocument.DocumentData = null;
            }
            if (archiveMessage.Addendums != null)
            {
                foreach (var addendum in archiveMessage.Addendums)
                {
                    addendum.DocumentData = null;
                }
            }

            System.IO.File.WriteAllText(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.json"), JsonSerializer.Serialize(archiveMessage));
            using (var fs = new FileStream(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.xml"), FileMode.Create))
                new XmlSerializer(typeof(ArchiveMessage)).Serialize(fs, archiveMessage);
            return(Ok($"Archive ID: {archiveId}"));
        }
 /// <getArchiveMessagebyId>
 /// Get ArchieveMessage by UserId and ArchieveId.
 /// </summary>
 /// <param name="userid">UserId of the ArchieveMessage(Guid)</param>
 /// <param name="archiveId">ArchieveId of the ArchieveMessage(Guid)</param>
 /// <returns>Return Unique object of Ads</returns>
 public ArchiveMessage getArchiveMessagebyId(Guid userid, Guid archiveid)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action, to get archive mesaages by user id and archive id.
                 NHibernate.IQuery query = session.CreateQuery("from ArchiveMessage where UserId = :userid and Id=:archivename");
                 query.SetParameter("userid", userid);
                 query.SetParameter("archivename", archiveid);
                 ArchiveMessage grou = query.UniqueResult <ArchiveMessage>();
                 return(grou);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(null);
             }
         } // End using transaction
     }     //End Using session
 }
Ejemplo n.º 3
0
        private ProblemDetails Validate(ArchiveMessage archiveMessage)
        {
            // Example validation
            if (archiveMessage.Receiver?.Length != 10)
            {
                return(new ProblemDetails
                {
                    Type = "https://onetoox.dk/validation-error",
                    Detail = $"The format of the receiver '{archiveMessage.Receiver}' is not valid",
                    Title = "Invalid receiver format"
                });
            }

            if ("1234560000" != archiveMessage.Receiver && "1122334455" != archiveMessage.ArchiveCategory)
            {
                return(new ProblemDetails
                {
                    Type = "https://onetoox.dk/unknown-receiver",
                    Detail = $"The receiver '{archiveMessage.Receiver}' is unknown",
                    Title = "Unknown receiver"
                });
            }

            if (!archiveMessage.ArchiveCategory?.StartsWith("Category") ?? true)
            {
                return(new ProblemDetails
                {
                    Type = "https://onetoox.dk/invalid-archive-category",
                    Detail = $"The category '{archiveMessage.ArchiveCategory}' is not valid",
                    Title = "Invalid category"
                });
            }
            return(null);
        }
 /// <DeleteArchiveMessage>
 /// Delete a ArchieveMessage From Database by UserId and Message.
 /// </summary>
 /// <param name="archive">the object of the ArchieveMessage class(Domain.ArchieveMEssage)</param>
 /// <returns>Return 1 for True and 0 for False</returns>
 public int DeleteArchiveMessage(ArchiveMessage archive)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 // Proceed action to Detele specific data.
                 // return the integer value when it is success or not (0 or 1).
                 NHibernate.IQuery query = session.CreateQuery("delete from ArchiveMessage where UserId = :userid and Message = :message")
                                           .SetParameter("message", archive.Message)
                                           .SetParameter("userid", archive.UserId);
                 int isUpdated = query.ExecuteUpdate();
                 transaction.Commit();
                 return(isUpdated);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(0);
             }
         } // End using trasaction
     }     // End using session
 }
 /// <UpdateArchiveMessage>
 /// update ArchieveMessage by UserId.
 /// </summary>
 /// <param name="archive">the object of the ArchieveMessage class(Domain.ArchieveMEssage).</param>
 public void UpdateArchiveMessage(ArchiveMessage archive)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action, to update Message by Id
                 session.CreateQuery("Update ArchiveMessage set Message =:message where UserId = :userid")
                 .SetParameter("message", archive.Message)
                 .SetParameter("userid", archive.UserId)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End using transaction
     }     // End using session
 }
Ejemplo n.º 6
0
        public IActionResult Post([FromBody] ArchiveMessage archiveMessage)
        {
            _logger.LogInformation($"{nameof(Post)}: Received ArchiveMessage with JobId: {archiveMessage.JobId}");

            // Example validation
            if (archiveMessage.Receiver?.Length != 10)
            {
                return(BadRequest(new ProblemDetails
                {
                    Type = "https://onetoox.dk/validation-error",
                    Detail = $"The format of the receiver '{archiveMessage.Receiver}' is not valid",
                    Title = "Invalid receiver format"
                }));
            }
            if ("1234560000" != archiveMessage.Receiver && "1122334455" != archiveMessage.ArchiveCategory)
            {
                return(BadRequest(new ProblemDetails
                {
                    Type = "https://onetoox.dk/unknown-receiver",
                    Detail = $"The receiver '{archiveMessage.Receiver}' is unknown",
                    Title = "Unknown receiver"
                }));
            }
            if (!archiveMessage.ArchiveCategory?.StartsWith("Category") ?? true)
            {
                return(BadRequest(new ProblemDetails
                {
                    Type = "https://onetoox.dk/invalid-archive-category",
                    Detail = $"The category '{archiveMessage.ArchiveCategory}' is not valid",
                    Title = "Invalid category"
                }));
            }

            Directory.CreateDirectory(_settings.Value.ArchiveFolder);
            var archiveId = Guid.NewGuid();

            if (archiveMessage.MainDocument?.DocumentData != null)
            {
                System.IO.File.WriteAllBytes(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.pdf"),
                                             archiveMessage.MainDocument.DocumentData);
                // Don't save document data in JSON or XML
                archiveMessage.MainDocument.DocumentData = null;
            }
            if (archiveMessage.Addendums != null)
            {
                foreach (var addendum in archiveMessage.Addendums)
                {
                    addendum.DocumentData = null;
                }
            }

            System.IO.File.WriteAllText(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.json"), JsonSerializer.Serialize(archiveMessage));
            using (var fs = new FileStream(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.xml"), FileMode.Create))
                new XmlSerializer(typeof(ArchiveMessage)).Serialize(fs, archiveMessage);
            return(Ok($"Archive ID: {archiveId}"));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Archives the entity.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TId">The type of the t identifier.</typeparam>
        /// <param name="oldEntity">The old entity.</param>
        /// <param name="newEntity">The new entity.</param>
        /// <returns>ArchiveMessage.</returns>
        public static ArchiveMessage ArchiveEntity <T, TId>(this T oldEntity, T newEntity) where T : Entity <TId>
        {
            ArchiveMessage archiveMessage = new ArchiveMessage
            {
                ObjectFullName = $"{oldEntity}{typeof(T).FullName}",
                ObjectId       = oldEntity.Id.ToString()
            };

            archiveMessage.AddOldObject(oldEntity);
            archiveMessage.AddNewObject(newEntity);
            return(archiveMessage);
        }
 /// <AddArchiveMessage>
 /// Add a new  ArchieveMEssage in a database.
 /// </summary>
 /// <param name="archive">et Values in a ArchieveMEssage Class Property and Pass the Object of ArchieveMEssage Class.(Domain.ArchieveMEssage)</param>
 public void AddArchiveMessage(ArchiveMessage archive)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action, to save data.
             session.Save(archive);
             transaction.Commit();
         } // End Using Trasaction
     }     // End using session
 }
Ejemplo n.º 9
0
        public async Task <HttpResponseMessage> ArchiveBatch(List <string> messageIds)
        {
            if (messageIds.Any(string.IsNullOrEmpty))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            foreach (var id in messageIds)
            {
                var request = new ArchiveMessage {
                    FailedMessageId = id
                };

                await messageSession.SendLocal(request).ConfigureAwait(false);
            }

            return(Request.CreateResponse(HttpStatusCode.Accepted));
        }
Ejemplo n.º 10
0
        public ArchiveMessages()
        {
            Post["/errors/archive"] = Patch["/errors/archive"] = _ =>
            {
                var ids = this.Bind <List <string> >();

                if (ids.Any(string.IsNullOrEmpty))
                {
                    return(HttpStatusCode.BadRequest);
                }

                foreach (var id in ids)
                {
                    var request = new ArchiveMessage {
                        FailedMessageId = id
                    };

                    Bus.SendLocal(request);
                }

                return(HttpStatusCode.Accepted);
            };

            Post["/errors/{messageid}/archive"] = Patch["/errors/{messageid}/archive"] = parameters =>
            {
                var failedMessageId = parameters.MessageId;

                if (string.IsNullOrEmpty(failedMessageId))
                {
                    return(HttpStatusCode.BadRequest);
                }

                Bus.SendLocal <ArchiveMessage>(m =>
                {
                    m.FailedMessageId = failedMessageId;
                });

                return(HttpStatusCode.Accepted);
            };
        }
Ejemplo n.º 11
0
        public ArchiveMessages()
        {
            Patch["/errors/archive"] = _ =>
            {
                var ids = this.Bind<List<string>>();

                if (ids.Any(string.IsNullOrEmpty))
                {
                    return HttpStatusCode.BadRequest;
                }

                foreach (var id in ids)
                {
                    var request = new ArchiveMessage { FailedMessageId = id };

                    Bus.SendLocal(request); 
                }

                return HttpStatusCode.Accepted;
            };

            Patch["/errors/{messageid}/archive"] = parameters =>
            {
                var failedMessageId = parameters.MessageId;

                if (string.IsNullOrEmpty(failedMessageId))
                {
                    return HttpStatusCode.BadRequest;
                }

                Bus.SendLocal<ArchiveMessage>(m =>
                {
                    m.FailedMessageId = failedMessageId;
                });

                return HttpStatusCode.Accepted;
            };
        }
Ejemplo n.º 12
0
        public ArchiveMessages()
        {
            Post["/errors/archive", true] = Patch["/errors/archive", true] = async(_, ctx) =>
            {
                var ids = this.Bind <List <string> >();

                if (ids.Any(string.IsNullOrEmpty))
                {
                    return(HttpStatusCode.BadRequest);
                }

                foreach (var id in ids)
                {
                    var request = new ArchiveMessage {
                        FailedMessageId = id
                    };

                    await Bus.SendLocal(request).ConfigureAwait(false);
                }

                return(HttpStatusCode.Accepted);
            };

            Post["/errors/{messageid}/archive", true] = Patch["/errors/{messageid}/archive", true] = async(parameters, ctx) =>
            {
                var failedMessageId = parameters.MessageId;

                if (string.IsNullOrEmpty(failedMessageId))
                {
                    return(HttpStatusCode.BadRequest);
                }

                await Bus.SendLocal <ArchiveMessage>(m => { m.FailedMessageId = failedMessageId; }).ConfigureAwait(false);

                return(HttpStatusCode.Accepted);
            };
        }
Ejemplo n.º 13
0
 public void Archive(ArchiveMessage archiveMessage)
 {
 }
 public void Archive(ArchiveMessage archiveMessage)
 {
 }