public bool FilterAttachments(AttachmentInformation attachment, string destinationInstanceId)
        {
            if (attachment.Key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase) ||                         // don't replicate system attachments
                attachment.Key.StartsWith("transactions/recoveryInformation", StringComparison.InvariantCultureIgnoreCase)) // don't replicate transaction recovery information
            {
                return(false);
            }

            // explicitly marked to skip
            if (attachment.Metadata.ContainsKey(Constants.NotForReplication) && attachment.Metadata.Value <bool>(Constants.NotForReplication))
            {
                return(false);
            }

            if (attachment.Metadata.ContainsKey(Constants.RavenReplicationConflict))            // don't replicate conflicted documents, that just propagate the conflict
            {
                return(false);
            }

            // we don't replicate stuff that was created there
            if (attachment.Metadata.Value <string>(Constants.RavenReplicationSource) == destinationInstanceId)
            {
                return(false);
            }

            switch (ReplicationOptionsBehavior)
            {
            case TransitiveReplicationOptions.None:
                return(attachment.Metadata.Value <string>(Constants.RavenReplicationSource) == null ||
                       (attachment.Metadata.Value <string>(Constants.RavenReplicationSource) == CurrentDatabaseId));
            }
            return(true);
        }
        public async Task <IActionResult> SaveVehicleWithImage(GDViewModel model)
        {
            try
            {
                var user = await _userManager.FindByNameAsync(model.userName);

                string        gdNumber      = RandomString(6);
                GDInformation gDInformation = new GDInformation
                {
                    ApplicationUserId = user.Id,
                    gdFor             = "Own",
                    gdDate            = DateTime.Now,
                    gdNumber          = gdNumber,
                    gDTypeId          = model.gdTypeId,
                    productTypeId     = 1,
                    //documentTypeId = model.documentTypeId == 0 ? null : model.documentTypeId,
                    //documentDescription = model.documentDescription,
                    statusId = 1
                };

                int gdId = await lostAndFoundService.SaveGDInformation(gDInformation);

                VehicleInformation vehicleInformation = new VehicleInformation
                {
                    gDInformationId = gdId,
                    vehicleTypeId   = model.vehicleTypeId,
                    vehicleBrandId  = model.vehicleBrandId,
                    vehicleRegNo    = model.regNoFirstPart + " " + model.regNoSecondPart + " " + model.regNoThiredPart,
                    regNoFirstPart  = model.regNoFirstPart,
                    regNoSecondPart = model.regNoSecondPart,
                    regNoThiredPart = model.regNoThiredPart,
                    //madeBy = model.madeBy,
                    //madeIn = model.madeIn,
                    //modelNo = model.modelNo,
                    //mfcDate = model.mfcDate,
                    engineNo = model.engineNo,
                    //chasisNo = model.chasisNo,
                    //ccNo = model.ccNo,
                    vehicleModelNo = model.modelNo
                };

                int vchid = await lostAndFoundService.SaveVehicleInformation(vehicleInformation);

                AttachmentInformation attachment = new AttachmentInformation
                {
                    gDInformationId = gdId,
                    encodedImage    = model.encodedImage,
                    fileSubject     = model.vehicleDescription
                };

                int imageId = await lostAndFoundService.SaveAttachmentInformation(attachment);

                return(Ok(gdId));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <byte[]> GetAttachmentData(AttachmentInformation attachmentInformation)
        {
            var attachment = await Store.AsyncDatabaseCommands.GetAttachmentAsync(attachmentInformation.Key).ConfigureAwait(false);

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

            return(attachment.Data().ReadData());
        }
Exemple #4
0
        private void ExecuteAttachmentReadTriggers(AttachmentInformation information)
        {
            if (information == null)
            {
                return;
            }

            foreach (var attachmentReadTrigger in Database.AttachmentReadTriggers)
            {
                attachmentReadTrigger.Value.OnRead(information);
            }
        }
Exemple #5
0
        private AttachmentInformation ProcessAttachmentReadVetoes(AttachmentInformation attachment)
        {
            if (attachment == null)
            {
                return(null);
            }

            var foundResult = false;

            foreach (var attachmentReadTriggerLazy in Database.AttachmentReadTriggers)
            {
                if (foundResult)
                {
                    break;
                }
                var attachmentReadTrigger = attachmentReadTriggerLazy.Value;
                var readVetoResult        = attachmentReadTrigger.AllowRead(attachment.Key, null, attachment.Metadata,
                                                                            ReadOperation.Load);
                switch (readVetoResult.Veto)
                {
                case ReadVetoResult.ReadAllow.Allow:
                    break;

                case ReadVetoResult.ReadAllow.Deny:
                    attachment.Size     = 0;
                    attachment.Metadata = new RavenJObject
                    {
                        {
                            "Raven-Read-Veto",
                            new RavenJObject
                            {
                                { "Reason", readVetoResult.Reason },
                                { "Trigger", attachmentReadTrigger.ToString() }
                            }
                        }
                    };
                    foundResult = true;
                    break;

                case ReadVetoResult.ReadAllow.Ignore:
                    attachment  = null;
                    foundResult = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString());
                }
            }
            return(attachment);
        }
    public void MyAction(FileAttachment pdf)
    {
        var attachInfo = new AttachmentInformation
        {
            AttachmentId   = Guid.NewGuid(),
            AttachmentNote = "New Version",
            FileName       = pdf.FileName,
            ImageByte      = pdf.FileBytes
        };

        try
        {
            /// do something here
        }
        catch (Exception ex)
        {
            ///log error
        }
    }
Exemple #7
0
        public async Task <int> SaveAttachmentInformation(AttachmentInformation attachment)
        {
            if (attachment.Id != 0)
            {
                _context.AttachmentInformation.Update(attachment);

                await _context.SaveChangesAsync();

                return(attachment.Id);
            }
            else
            {
                await _context.AttachmentInformation.AddAsync(attachment);

                await _context.SaveChangesAsync();

                return(attachment.Id);
            }
        }
Exemple #8
0
        private AttachmentInformation AttachmentInfoByKey(string key)
        {
            var attachment = GetAttachment(key);

            if (attachment == null)             //precaution
            {
                throw new InvalidDataException(
                          "Tried to read attachment with key='{0}' but failed. Data mismatch between attachment indice and attachment data? (key by etag indice)");
            }

            var attachmentInfo = new AttachmentInformation
            {
                Etag     = attachment.Etag,
                Key      = attachment.Key,
                Metadata = attachment.Metadata,
                Size     = attachment.Size
            };

            return(attachmentInfo);
        }
        public Task <byte[]> GetAttachmentData(AttachmentInformation attachmentInformation)
        {
            var attachment = database.Attachments.GetStatic(attachmentInformation.Key);

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

            var data = attachment.Data;

            attachment.Data = () =>
            {
                var memoryStream = new MemoryStream();
                database.TransactionalStorage.Batch(accessor => data().CopyTo(memoryStream));
                memoryStream.Position = 0;
                return(memoryStream);
            };

            return(new CompletedTask <byte[]>(attachment.Data().ReadData()));
        }
Exemple #10
0
 public virtual void OnRead(AttachmentInformation information)
 {
 }
Exemple #11
0
        private Tuple <RavenJArray, Guid> GetAttachments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
        {
            RavenJArray attachments        = null;
            Guid        lastAttachmentEtag = Guid.Empty;

            try
            {
                var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

                docDb.TransactionalStorage.Batch(actions =>
                {
                    int attachmentSinceLastEtag = 0;
                    List <AttachmentInformation> attachmentsToReplicate;
                    List <AttachmentInformation> filteredAttachmentsToReplicate;
                    lastAttachmentEtag = destinationsReplicationInformationForSource.LastAttachmentEtag;
                    while (true)
                    {
                        attachmentsToReplicate = GetAttachmentsToReplicate(actions, lastAttachmentEtag);

                        filteredAttachmentsToReplicate = attachmentsToReplicate.Where(attachment => destination.FilterAttachments(attachment, destinationId)).ToList();

                        attachmentSinceLastEtag += attachmentsToReplicate.Count;

                        if (attachmentsToReplicate.Count == 0 ||
                            filteredAttachmentsToReplicate.Count != 0)
                        {
                            break;
                        }

                        AttachmentInformation jsonDocument = attachmentsToReplicate.Last();
                        Guid attachmentEtag = jsonDocument.Etag;
                        log.Debug("All the attachments were filtered, trying another batch from etag [>{0}]", attachmentEtag);
                        lastAttachmentEtag = attachmentEtag;
                    }

                    log.Debug(() =>
                    {
                        if (attachmentSinceLastEtag == 0)
                        {
                            return(string.Format("No attachments to replicate to {0} - last replicated etag: {1}", destination,
                                                 destinationsReplicationInformationForSource.LastDocumentEtag));
                        }

                        if (attachmentSinceLastEtag == filteredAttachmentsToReplicate.Count)
                        {
                            return(string.Format("Replicating {0} attachments [>{1}] to {2}.",
                                                 attachmentSinceLastEtag,
                                                 destinationsReplicationInformationForSource.LastDocumentEtag,
                                                 destination));
                        }

                        var diff = attachmentsToReplicate.Except(filteredAttachmentsToReplicate).Select(x => x.Key);
                        return(string.Format("Replicating {1} attachments (out of {0}) [>{4}] to {2}. [Not replicated: {3}]",
                                             attachmentSinceLastEtag,
                                             filteredAttachmentsToReplicate.Count,
                                             destination,
                                             string.Join(", ", diff),
                                             destinationsReplicationInformationForSource.LastDocumentEtag));
                    });

                    attachments = new RavenJArray(filteredAttachmentsToReplicate
                                                  .Select(x =>
                    {
                        var data = new byte[0];
                        if (x.Size > 0)
                        {
                            data = actions.Attachments.GetAttachment(x.Key).Data().ReadData();
                        }
                        return(new RavenJObject
                        {
                            { "@metadata", x.Metadata },
                            { "@id", x.Key },
                            { "@etag", x.Etag.ToByteArray() },
                            { "data", data }
                        });
                    }));
                });
            }
            catch (Exception e)
            {
                log.WarnException("Could not get attachments to replicate after: " + destinationsReplicationInformationForSource.LastAttachmentEtag, e);
            }
            return(Tuple.Create(attachments, lastAttachmentEtag));
        }
Exemple #12
0
 public virtual void OnRead(AttachmentInformation information)
 {
 }