Exemplo n.º 1
0
        public List <Model.AttachmentModel> Get(int atcEntry)
        {
            List <Model.AttachmentModel> result = new List <Model.AttachmentModel>();

            Attachments2 attachment = (Attachments2)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oAttachments2);

            try
            {
                if (attachment.GetByKey(atcEntry))
                {
                    for (int line = 0; line < attachment.Lines.Count; line++)
                    {
                        attachment.Lines.SetCurrentLine(line);

                        result.Add(new Model.AttachmentModel()
                        {
                            AbsEntry = attachment.AbsoluteEntry,
                            Line     = line,
                            Path     = Path.ChangeExtension(Path.Combine(GetAttachmentFolder(), attachment.Lines.FileName), attachment.Lines.FileExtension)
                        });
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(attachment);
            }

            return(result);
        }
 private static Attachments2 MapToSapObject(Attachment entity, Attachments2 sapEntity)
 {
     sapEntity.Lines.FileName      = entity.FileName;
     sapEntity.Lines.FileExtension = entity.Ext;
     sapEntity.Lines.SourcePath    = entity.Path;
     sapEntity.Lines.Override      = BoYesNoEnum.tYES;
     return(sapEntity);
 }
Exemplo n.º 3
0
        public void Insert(Model.AttachmentModel attachmentModel)
        {
            Attachments2 attachment = (Attachments2)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oAttachments2);

            try
            {
                if (attachment.GetByKey(attachmentModel.AbsEntry))
                {
                    attachment.Lines.Add();

                    attachment.Lines.SetCurrentLine(attachment.Lines.Count - 1);

                    attachment.Lines.SourcePath    = Path.GetDirectoryName(attachmentModel.Path);
                    attachment.Lines.FileName      = Path.GetFileNameWithoutExtension(attachmentModel.Path);
                    attachment.Lines.FileExtension = Path.GetExtension(attachmentModel.Path).Replace(".", "");
                    attachment.Lines.Override      = BoYesNoEnum.tYES;

                    foreach (KeyValuePair <string, dynamic> userField in attachmentModel.UserFields)
                    {
                        attachment.Lines.UserFields.Fields.Item(userField.Key).Value = userField.Value;
                    }

                    attachment.Update();

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();
                }
                else
                {
                    attachment.Lines.SourcePath    = Path.GetDirectoryName(attachmentModel.Path);
                    attachment.Lines.FileName      = Path.GetFileNameWithoutExtension(attachmentModel.Path);
                    attachment.Lines.FileExtension = Path.GetExtension(attachmentModel.Path).Replace(".", "");
                    attachment.Lines.Override      = BoYesNoEnum.tYES;

                    foreach (KeyValuePair <string, dynamic> userField in attachmentModel.UserFields)
                    {
                        attachment.Lines.UserFields.Fields.Item(userField.Key).Value = userField.Value;
                    }

                    attachment.Add();

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();

                    attachmentModel.AbsEntry = Convert.ToInt32(Controller.ConnectionController.Instance.Company.GetNewObjectKey());
                }
            }
            finally
            {
                Marshal.ReleaseComObject(attachment);
            }
        }
Exemplo n.º 4
0
        public Model.AttachmentModel Get(int atcEntry, int line)
        {
            Model.AttachmentModel result = new Model.AttachmentModel();

            Attachments2 attachment = (Attachments2)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oAttachments2);

            try
            {
                if (attachment.GetByKey(atcEntry))
                {
                    attachment.Lines.SetCurrentLine(line - 1);

                    result.AbsEntry = attachment.AbsoluteEntry;
                    result.Line     = line;
                    result.Path     = Path.ChangeExtension(Path.Combine(GetAttachmentFolder(), attachment.Lines.FileName), attachment.Lines.FileExtension);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(attachment);
            }

            return(result);
        }
Exemplo n.º 5
0
        public void Delete(Model.AttachmentModel attachmentModel)
        {
            Attachments2 attachment = (Attachments2)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oAttachments2);

            try
            {
                if (attachment.GetByKey(attachmentModel.AbsEntry))
                {
                    attachment.Lines.SetCurrentLine(attachmentModel.Line - 1);

                    attachment.Lines.SourcePath    = string.Empty;
                    attachment.Lines.FileName      = string.Empty;
                    attachment.Lines.FileExtension = string.Empty;

                    attachment.Update();

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();
                }
            }
            finally
            {
                Marshal.ReleaseComObject(attachment);
            }
        }
Exemplo n.º 6
0
        public Cipher ToCipher(Cipher existingCipher)
        {
            switch (existingCipher.Type)
            {
            case CipherType.Login:
                var loginObj = JObject.FromObject(new CipherLoginData(this),
                                                  new JsonSerializer {
                    NullValueHandling = NullValueHandling.Ignore
                });
                loginObj[nameof(CipherLoginData.Uri)]?.Parent?.Remove();
                existingCipher.Data = loginObj.ToString(Formatting.None);
                break;

            case CipherType.Card:
                existingCipher.Data = JsonConvert.SerializeObject(new CipherCardData(this),
                                                                  new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                break;

            case CipherType.Identity:
                existingCipher.Data = JsonConvert.SerializeObject(new CipherIdentityData(this),
                                                                  new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                break;

            case CipherType.SecureNote:
                existingCipher.Data = JsonConvert.SerializeObject(new CipherSecureNoteData(this),
                                                                  new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                break;

            default:
                throw new ArgumentException("Unsupported type: " + nameof(Type) + ".");
            }

            var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
            var hasAttachments  = (Attachments?.Count ?? 0) > 0;

            if (!hasAttachments2 && !hasAttachments)
            {
                return(existingCipher);
            }

            var attachments = existingCipher.GetAttachments();

            if ((attachments?.Count ?? 0) == 0)
            {
                return(existingCipher);
            }

            if (hasAttachments2)
            {
                foreach (var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
                {
                    var attachment2 = Attachments2[attachment.Key];
                    attachment.Value.FileName = attachment2.FileName;
                    attachment.Value.Key      = attachment2.Key;
                }
            }
            else if (hasAttachments)
            {
                foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
                {
                    attachment.Value.FileName = Attachments[attachment.Key];
                    attachment.Value.Key      = null;
                }
            }

            existingCipher.SetAttachments(attachments);
            return(existingCipher);
        }
Exemplo n.º 7
0
        public Cipher ToCipher(Cipher existingCipher)
        {
            switch (existingCipher.Type)
            {
            case CipherType.Login:
                var loginObj = NSL.JObject.FromObject(ToCipherLoginData(),
                                                      new NS.JsonSerializer {
                    NullValueHandling = NS.NullValueHandling.Ignore
                });
                // TODO: Switch to JsonNode in .NET 6 https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter?pivots=dotnet-6-0
                loginObj[nameof(CipherLoginData.Uri)]?.Parent?.Remove();
                existingCipher.Data = loginObj.ToString(NS.Formatting.None);
                break;

            case CipherType.Card:
                existingCipher.Data = JsonSerializer.Serialize(ToCipherCardData(), JsonHelpers.IgnoreWritingNull);
                break;

            case CipherType.Identity:
                existingCipher.Data = JsonSerializer.Serialize(ToCipherIdentityData(), JsonHelpers.IgnoreWritingNull);
                break;

            case CipherType.SecureNote:
                existingCipher.Data = JsonSerializer.Serialize(ToCipherSecureNoteData(), JsonHelpers.IgnoreWritingNull);
                break;

            default:
                throw new ArgumentException("Unsupported type: " + nameof(Type) + ".");
            }

            existingCipher.Reprompt = Reprompt;

            var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
            var hasAttachments  = (Attachments?.Count ?? 0) > 0;

            if (!hasAttachments2 && !hasAttachments)
            {
                return(existingCipher);
            }

            var attachments = existingCipher.GetAttachments();

            if ((attachments?.Count ?? 0) == 0)
            {
                return(existingCipher);
            }

            if (hasAttachments2)
            {
                foreach (var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
                {
                    var attachment2 = Attachments2[attachment.Key];
                    attachment.Value.FileName = attachment2.FileName;
                    attachment.Value.Key      = attachment2.Key;
                }
            }
            else if (hasAttachments)
            {
                foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
                {
                    attachment.Value.FileName = Attachments[attachment.Key];
                    attachment.Value.Key      = null;
                }
            }

            existingCipher.SetAttachments(attachments);
            return(existingCipher);
        }