Пример #1
0
        /// <summary>
        /// Remove the status paragraph from file
        /// </summary>
        /// <param name="adr">the <see cref="AdrEntry"/></param>
        private void ClearAdrStatus(AdrEntry adr)
        {
            if (adr is null)
            {
                throw new ArgumentNullException(nameof(adr));
            }

            var fileName = adr.File.FullName;
            var txtLines = File.ReadAllLines(fileName)
                           .ToList();

            int statusLineIndex  = txtLines.IndexOf("## Status");
            int contextLineIndex = txtLines.IndexOf("## Context");

            // something is wrong, cannot clear status paragraph
            if (statusLineIndex == -1 || contextLineIndex == -1 || contextLineIndex <= statusLineIndex)
            {
                return;
            }

            int elementsToRemove = contextLineIndex - statusLineIndex - 1;

            txtLines.RemoveRange(statusLineIndex + 1, elementsToRemove);

            File.WriteAllLines(fileName, txtLines);
        }
Пример #2
0
        /// <summary>
        /// Supercedes an existing record with a new one
        /// </summary>
        /// <param name="supercededRecord">the superceded record</param>
        /// <param name="newRecord">the new record</param>
        private void SupercedesAdr(AdrEntry supercededRecord, AdrEntry newRecord)
        {
            if (supercededRecord is null)
            {
                throw new ArgumentNullException(nameof(supercededRecord));
            }

            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            this.ClearAdrStatus(supercededRecord);

            FileUtils.InsertTextToFile(
                newRecord.File.FullName,
                "## Context",
                new[] {
                $"Supercedes: [{supercededRecord.Title}]({supercededRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );

            FileUtils.InsertTextToFile(
                supercededRecord.File.FullName,
                "## Context",
                new[] {
                string.Empty,
                $"Superceded by: [{newRecord.Title}]({newRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );
        }
Пример #3
0
        internal static Participant ParticipantFromAddressEntry(AdrEntry entry)
        {
            string displayName  = string.Empty;
            string emailAddress = string.Empty;
            string routingType  = string.Empty;

            foreach (PropValue propValue in entry.Values)
            {
                PropTag propTag = propValue.PropTag;
                if (propTag != PropTag.DisplayName)
                {
                    if (propTag != PropTag.AddrType)
                    {
                        if (propTag == PropTag.EmailAddress)
                        {
                            emailAddress = (string)propValue.Value;
                        }
                    }
                    else
                    {
                        routingType = (string)propValue.Value;
                    }
                }
                else
                {
                    displayName = (string)propValue.Value;
                }
            }
            return(new Participant(displayName, emailAddress, routingType));
        }
Пример #4
0
 private static AdrEntry[] GetAdrEntries(StoreSession session, ExTimeZone timeZone, IList <RuleAction.ForwardActionBase.ActionRecipient> recipients)
 {
     Util.ThrowOnNullArgument(recipients, "recipients");
     AdrEntry[] array = new AdrEntry[recipients.Count];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = RuleActionConverter.GetAdrEntry(session, timeZone, recipients[i]);
     }
     return(array);
 }
Пример #5
0
        /// <summary>
        /// Supercedes an existing record with a new one
        /// </summary>
        /// <param name="supercededRecordNumber">the number of the superceded record</param>
        /// <param name="newRecord">the new record</param>
        internal void SupercedesAdr(int supercededRecordNumber, AdrEntry newRecord)
        {
            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            AdrEntry supercededRecord = this.SearchAdr(supercededRecordNumber);

            this.SupercedesAdr(supercededRecord, newRecord);
        }
Пример #6
0
 private void ModifyRecipients()
 {
     if (this.recipientChangeTracker.ModifiedRecipients.Count > 0)
     {
         AdrEntry[] array = new AdrEntry[this.recipientChangeTracker.ModifiedRecipients.Count];
         for (int i = 0; i < this.recipientChangeTracker.ModifiedRecipients.Count; i++)
         {
             array[i] = this.GetAdrEntry(this.recipientChangeTracker.ModifiedRecipients[i]);
             this.recipientChangeTracker.ModifiedRecipients[i].SetUnchanged();
         }
         this.ModifyParticipants(ModifyRecipientsFlags.ModifyRecipients, array);
         this.recipientChangeTracker.ModifiedRecipients.Clear();
     }
 }
Пример #7
0
        /// <summary>
        /// Links an existing record with a new one
        /// </summary>
        /// <param name="linkedRecordNumber">the number of the linked record</param>
        /// <param name="newRecord">the new record</param>
        /// <param name="link">the link details</param>
        internal void LinksAdr(AdrEntry newRecord, AdrLink link)
        {
            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            if (link is null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            AdrEntry linkedRecord = this.SearchAdr(link.Number);

            this.LinksAdr(linkedRecord, newRecord, link);
        }
Пример #8
0
        /// <summary>
        /// Load entry from file
        /// </summary>
        /// <param name="file">the source <see cref="FileInfo"/></param>
        /// <returns>an <see cref="AdrEntry"/> or <code>null</code> if not found</returns>
        private AdrEntry LoadAdr(FileInfo file)
        {
            AdrEntry entry = null;

            if (File.Exists(file.FullName))
            {
                entry = new AdrEntry(TemplateType.New);

                entry.Title = File.ReadLines(file.FullName)
                              .FirstOrDefault()?
                              .Replace("# ", string.Empty) ?? string.Empty;
                entry.File = file;
            }

            return(entry);
        }
Пример #9
0
        /// <summary>
        /// Search a record by number
        /// </summary>
        /// <param name="adrNumber">the number of the record</param>
        /// <returns>an <see cref="AdrEntry"/> or <code>null</code> if not found</returns>
        internal AdrEntry SearchAdr(int adrNumber)
        {
            var needle = adrNumber.ToString().PadLeft(4, '0');

            var allFiles = this.GetRecords();

            var file = allFiles.FirstOrDefault(f => f.Name.StartsWith(needle));

            AdrEntry entry = null;

            if (file != null)
            {
                entry = this.LoadAdr(file);
            }

            return(entry);
        }
Пример #10
0
        private void AddRecipients()
        {
            int num = this.maxMapiTableRowCount;

            if (this.recipientChangeTracker.AddedRecipients.Count > 0)
            {
                AdrEntry[] array = new AdrEntry[this.recipientChangeTracker.AddedRecipients.Count];
                int        num2  = 0;
                foreach (CoreRecipient coreRecipient in this.recipientChangeTracker.AddedRecipients)
                {
                    coreRecipient.SetRowId(num++);
                    array[num2++] = this.GetAdrEntry(coreRecipient);
                    coreRecipient.SetUnchanged();
                }
                this.ModifyParticipants(ModifyRecipientsFlags.AddRecipients, array);
                this.recipientChangeTracker.ClearAddedRecipients();
            }
        }
Пример #11
0
        /// <summary>
        /// Links an existing record with a new one
        /// </summary>
        /// <param name="linkedRecord">the linked record</param>
        /// <param name="newRecord">the new record</param>
        /// <param name="link">the link details</param>
        private void LinksAdr(AdrEntry linkedRecord, AdrEntry newRecord, AdrLink link)
        {
            if (linkedRecord is null)
            {
                throw new ArgumentNullException(nameof(linkedRecord));
            }

            if (newRecord is null)
            {
                throw new ArgumentNullException(nameof(newRecord));
            }

            if (link is null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            FileUtils.InsertTextToFile(
                newRecord.File.FullName,
                "## Context",
                new[] {
                $"{link.LinkDescription}: [{linkedRecord.Title}]({linkedRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );

            FileUtils.InsertTextToFile(
                linkedRecord.File.FullName,
                "## Context",
                new[] {
                string.Empty,
                $"{link.ReverseLinkDescription}: [{newRecord.Title}]({newRecord.File.Name})",
                string.Empty
            },
                FileUtils.TextInsertionMode.Prepend
                );
        }
Пример #12
0
 private void RemoveRecipients()
 {
     if (this.recipientChangeTracker.RemovedRecipientIds.Count > 0)
     {
         if (this.GetMapiTableRowCount() == this.recipientChangeTracker.RemovedRecipientIds.Count)
         {
             this.ModifyParticipants((ModifyRecipientsFlags)0, RecipientTable.EmptyParticipantArray);
         }
         else
         {
             AdrEntry[] array = new AdrEntry[this.recipientChangeTracker.RemovedRecipientIds.Count];
             int        num   = 0;
             foreach (int num2 in this.recipientChangeTracker.RemovedRecipientIds)
             {
                 array[num++] = new AdrEntry(new PropValue[]
                 {
                     new PropValue(PropTag.RowId, num2)
                 });
             }
             this.ModifyParticipants(ModifyRecipientsFlags.RemoveRecipients, array);
         }
         this.recipientChangeTracker.ClearRemovedRecipients();
     }
 }
Пример #13
0
 private static RuleAction.ForwardActionBase.ActionRecipient GetRecipient(StoreSession session, ExTimeZone timeZone, AdrEntry adrEntry)
 {
     Util.ThrowOnNullArgument(adrEntry, "adrEntry");
     PropTag[] array = new PropTag[adrEntry.Values.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = adrEntry.Values[i].PropTag;
     }
     NativeStorePropertyDefinition[] array2 = PropertyTagCache.Cache.SafePropertyDefinitionsFromPropTags(session, array);
     object[] array3 = new object[adrEntry.Values.Length];
     for (int j = 0; j < array3.Length; j++)
     {
         array3[j] = MapiPropertyBag.GetValueFromPropValue(session, timeZone, array2[j], adrEntry.Values[j]);
     }
     return(new RuleAction.ForwardActionBase.ActionRecipient(array2, array3));
 }