Exemple #1
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) + ".");
            }

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

            var attachments = existingCipher.GetAttachments();

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

            foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
            {
                attachment.Value.FileName = Attachments[attachment.Key];
            }

            existingCipher.SetAttachments(attachments);
            return(existingCipher);
        }
        public Cipher ToCipher(Cipher existingCipher)
        {
            switch (existingCipher.Type)
            {
            case CipherType.Login:
                existingCipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this),
                                                                  new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                break;

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

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

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

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

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

            var attachments = existingCipher.GetAttachments();

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

            foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
            {
                attachment.Value.FileName = Attachments[attachment.Key];
            }

            existingCipher.SetAttachments(attachments);
            return(existingCipher);
        }
Exemple #3
0
 public void AddAttachmentsIfAbsent(Dictionary <string, string> attachments)
 {
     if (attachments == null)
     {
         return;
     }
     foreach (var entry in attachments)
     {
         if (!Attachments.ContainsKey(entry.Key))
         {
             Attachments.Add(entry.Key, entry.Value);
         }
     }
 }
        public BitmapSource GetActiveDirectoryImageValue(string alias, StoreItem itemToNotify, [CallerMemberName] string publicPropName = null)
        {
            if (!Attachments.ContainsKey(publicPropName))
            {
                if (!BackgroundProcessByProperty.Contains(publicPropName))
                {
                    BackgroundProcessByProperty.Add(publicPropName);
                    BackgroundGetActiveDirectoryImageValue(alias, itemToNotify, publicPropName);
                }

                return(null);
            }
            else
            {
                return(Attachments[publicPropName].BitmapSource);
            }
        }
        public void AttachFiles(int workItemId, IEnumerable <string> fileList)
        {
            foreach (var filename in fileList.Where(filename => !File.Exists(filename)))
            {
                Logger.ErrorFormat("Couldn't find attachment file {0}", filename);
            }

            if (ThrowOnAttachFiles != null)
            {
                throw ThrowOnAttachFiles;
            }

            if (!Attachments.ContainsKey(workItemId))
            {
                Attachments[workItemId] = new List <string>();
            }

            Attachments[workItemId].AddRange(fileList);
        }
Exemple #6
0
        public void AttachFiles(int workItemId, IReadOnlyCollection <MessageAttachmentInfo> fileList)
        {
            foreach (var filename in fileList.Where(filename => !File.Exists(filename.FilePath)))
            {
                Logger.ErrorFormat("Couldn't find attachment file {0}", filename);
            }

            if (ThrowOnAttachFiles != null)
            {
                throw ThrowOnAttachFiles;
            }

            if (!Attachments.ContainsKey(workItemId))
            {
                Attachments[workItemId] = new List <string>();
            }

            Attachments[workItemId].AddRange(fileList.Select(f => f.FilePath));
        }
Exemple #7
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the value of the given property as a document represented by a stream.
        /// </summary>
        //------------------------------------------------------------------------------------
        public MemoryStream GetDocumentValue(string propName)
        {
            if (!Attachments.ContainsKey(propName))
            {
                MemoryStream mStream = Item.Store.GetRichTextFileAttachmentStream(Item, propName);

                if (mStream != null)
                {
                    Attachments.Add(propName, new DocumentAttachment {
                        AttachmentStream = mStream
                    });
                }
                else
                {
                    return(null);
                }
            }

            return(Attachments[propName].AttachmentStream);
        }
        void IWorkItemManager.AttachAndInlineFiles(int workItemId, IEnumerable <Tuple <string, IIncomingEmailAttachment> > fileList)
        {
            foreach (var filename in fileList.Where(filename => !File.Exists(filename.Item1)))
            {
                Logger.ErrorFormat("Couldn't find attachment file {0}", filename.Item1);
            }

            if (ThrowOnAttachFiles != null)
            {
                throw ThrowOnAttachFiles;
            }

            if (!Attachments.ContainsKey(workItemId))
            {
                Attachments[workItemId] = new List <string>();
            }

            foreach (var filename in fileList.Where(filename => File.Exists(filename.Item1)))
            {
                Attachments[workItemId].Add(filename.Item1);
            }
        }
Exemple #9
0
 public bool IsDocumentLoaded(string propName)
 {
     return(Attachments.ContainsKey(propName));
 }
Exemple #10
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);
        }