private static void add(ref AppointmentItem ai, MetadataId key, OlUserPropertyType keyType, object keyValue)
        {
            String addkeyName = metadataIdKeyName(key);

            UserProperties ups = null;

            try {
                if (!Exists(ai, key))
                {
                    int newSet;
                    int?keySet = getKeySet(ai, out newSet);
                    keySet = keySet ?? newSet + 1;
                    if (keySet.HasValue && keySet.Value != 0)
                    {
                        addkeyName += "-" + keySet.Value.ToString("D2");
                    }

                    try {
                        ups = ai.UserProperties;
                        ups.Add(addkeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addkeyName, keyType, false);
                    } finally {
                        ups = (UserProperties)Calendar.ReleaseObject(ups);
                    }
                }
                ups = ai.UserProperties;
                ups[addkeyName].Value = keyValue;
                log.Fine("Set userproperty " + addkeyName + "=" + keyValue.ToString());
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
Example #2
0
 /// <summary>
 /// Gets the property value for a <see cref="_MailItem">_MailItem</see> user property.
 /// </summary>
 /// <typeparam name="T">Type of property</typeparam>
 /// <param name="mailItem">The contact item.</param>
 /// <param name="name">The name of the user property.</param>
 /// <param name="type">The type of the user property.</param>
 /// <param name="create">if set to <c>false</c> the property will not be created if it doesn't exist.</param>
 /// <param name="converter">The converter to use to convert the object to.</param>
 /// <param name="defaultValue">The default value to use if user property not found.</param>
 /// <returns>User property value or default</returns>
 public static T GetPropertyValue <T>(this _MailItem mailItem, string name, OlUserPropertyType type, bool create, Func <object, T> converter, T defaultValue)
 {
     using (var userProperties = mailItem.UserProperties.WithComCleanup())
     {
         return(GetPropertyValue(userProperties.Resource, name, type, create, converter, defaultValue));
     }
 }
Example #3
0
        private void SetProperty(string propertyName, Object value, OlUserPropertyType type)
        {
            if (item.UserProperties.Find(propertyName) == null)
            {
                item.UserProperties.Add(propertyName, type, false);
            }

            item.UserProperties[propertyName].Value = value;
        }
Example #4
0
 public UserProperty Add(string Name, OlUserPropertyType Type, [Optional] object AddToFolderFields,
                         [Optional] object DisplayFormat)
 {
     if (!_wsUserProperties.ContainsKey(Name))
     {
         var property = new WsUserProperty(_userProperties.Add(Name, Type, AddToFolderFields, DisplayFormat));
         _wsUserProperties.Add(Name, property);
     }
     return _wsUserProperties[Name];
 }
Example #5
0
		public UserProperty Add(string Name, OlUserPropertyType Type, object AddToFolderFields, object DisplayFormat)
		{
			var property = new MockUserProperty();

			if (_properties.ContainsKey(Name) == false)
			{
				property.Name = Name;
				property.Type = Type;
				property.Value = string.Empty;
				_properties.Add(Name, property);
			}
			return property;
		}
Example #6
0
        private static void add(ref AppointmentItem ai, MetadataId key, OlUserPropertyType keyType, object keyValue)
        {
            String addkeyName = metadataIdKeyName(key);

            UserProperties ups = null;

            try {
                int    maxSet;
                int?   keySet         = null;
                String currentKeyName = null;
                if (!Exists(ai, key, out currentKeyName))
                {
                    keySet = getKeySet(ai, out maxSet);
                    if (key == MetadataId.gCalendarId && (keySet ?? 0) == 0)  //Couldn't find key set for calendar
                    {
                        keySet = maxSet + 1;                                  //So start a new one
                    }
                    else if (key != MetadataId.gCalendarId && keySet == null) //Couldn't find non-calendar key in the current set
                    {
                        keySet = 0;                                           //Add them in to the default key set
                    }
                    if (keySet.HasValue && keySet.Value != 0)
                    {
                        addkeyName += "-" + keySet.Value.ToString("D2");
                    }

                    try {
                        ups = ai.UserProperties;
                        ups.Add(addkeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addkeyName, keyType, false);
                    } finally {
                        ups = (UserProperties)Calendar.ReleaseObject(ups);
                    }
                }
                else
                {
                    addkeyName = currentKeyName; //Might be suffixed with "-01"
                }
                ups = ai.UserProperties;
                ups[addkeyName].Value = keyValue;
                OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.KeySet, keySet));
                OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.MaxSet, keySet));
                log.Fine("Set userproperty " + addkeyName + "=" + keyValue.ToString());
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
Example #7
0
        public static Outlook.UserProperty GetOrCreateUserProperty(Outlook.MailItem mailItem, string propName,OlUserPropertyType propertyType)
        {
            try
            {
                var prop = mailItem.UserProperties[propName];
                if (prop != null)
                {
                    return prop;
                }
                else
                {
                    prop = mailItem.UserProperties.Add(propName, propertyType);

                }

                return prop;
            }
            catch (Exception ex)
            {

                Logger.Log.Error(ex.Message,ex);
                throw ex;
            }
        }
        private void addOutlookCustomProperty(ref AppointmentItem copiedAi, String addKeyName, OlUserPropertyType keyType, object keyValue)
        {
            UserProperties ups = null;

            try {
                ups = copiedAi.UserProperties;
                if (ups[addKeyName] == null)
                {
                    try {
                        ups.Add(addKeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addKeyName, keyType, false);
                    }
                }
                ups[addKeyName].Value = keyValue;
            } catch (System.Exception) {
                log.Warn("Failed to add " + addKeyName);
                throw;
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
Example #9
0
        private void SetProperty(string propertyName, Object value, OlUserPropertyType type)
        {
            if (item.UserProperties.Find(propertyName) == null)
            {
                item.UserProperties.Add(propertyName, type, false);
            }

            item.UserProperties[propertyName].Value = value;
        }
        /// <summary>
        /// Gets the user property value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="userProperties">The user properties.</param>
        /// <param name="name">The name of the user property.</param>
        /// <param name="type">The type of the user property.</param>
        /// <param name="create">if set to <c>false</c> the property will not be created if it doesn't exist.</param>
        /// <param name="converter">The converter to use to convert the object to.</param>
        /// <param name="defaultValue">The default value to use if user property not found.</param>
        /// <returns>User property vlaue or default</returns>
        public static T GetPropertyValue <T>(this UserProperties userProperties, string name, OlUserPropertyType type, bool create, Func <object, T> converter, T defaultValue)
        {
            using (var property = userProperties.Find(name, true).WithComCleanup())
            {
                var format = type == OlUserPropertyType.olInteger ? OlFormatNumber.olFormatNumberAllDigits : Type.Missing;

                if (property.Resource == null && create)
                {
                    userProperties.Add(name, type, false, format).ReleaseComObject();
                }

                if (property.Resource == null)
                {
                    return(defaultValue);
                }

                var value = property.Resource.Value;
                return(converter(value));
            }
        }
        /// <summary>
        /// Sets the user property value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="userProperties">The user properties collection to set user property for.</param>
        /// <param name="name">The name of the user property to set.</param>
        /// <param name="type">The type of the user property.</param>
        /// <param name="value">The value to set.</param>
        /// <param name="addToFolder">if set to <c>true</c> add to containing folder. Enables search/display column for user property.</param>
        public static void SetPropertyValue <T>(this UserProperties userProperties, string name, OlUserPropertyType type, T value, bool addToFolder)
        {
            using (var property = userProperties.Find(name, true).WithComCleanup())
            {
                var format = type == OlUserPropertyType.olInteger ? OlFormatNumber.olFormatNumberAllDigits : Type.Missing;

                if (property.Resource == null)
                {
                    using (var newProperty = userProperties.Add(name, type, addToFolder, format).WithComCleanup())
                    {
                        newProperty.Resource.Value = value;
                    }
                }
                else
                {
                    property.Resource.Value = value;
                }
            }
        }
 /// <summary>
 /// Sets the user property value.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="contactItem">The appointment item.</param>
 /// <param name="name">The name of the user property to set.</param>
 /// <param name="type">The type of the user property.</param>
 /// <param name="value">The value to set.</param>
 /// <param name="addToFolder">if set to <c>true</c> add to containing folder. Enables search/display column for user property.</param>
 public static void SetPropertyValue <T>(this _AppointmentItem contactItem, string name, OlUserPropertyType type, T value, bool addToFolder)
 {
     using (var userProperties = contactItem.UserProperties.WithComCleanup())
         SetPropertyValue(userProperties.Resource, name, type, value, addToFolder);
 }
Example #13
0
        /// <summary>
        /// Creates or gets a user property field
        /// </summary>
        /// <param name="folder">The target folder</param>
        /// <param name="name">The name</param>
        /// <param name="type">The property value type</param>
        /// <returns>The user property field</returns>
        public static UserDefinedProperty CreateOrGetProperty(MAPIFolder folder, string name, OlUserPropertyType type)
        {
            try
            {
                foreach (var prop in folder.UserDefinedProperties)
                {
                    if (((UserDefinedProperty)prop).Name == name)
                    {
                        return((UserDefinedProperty)prop);
                    }
                }

                return(folder.UserDefinedProperties.Add(name, type, true));
            }
            catch (COMException interoptComException)
            {
                Log.Error(string.Format("Das Feld '{0}' konnte nicht hinzugefĆ¼gt werden.", name), interoptComException);
                return(null);
            }
        }
Example #14
0
 /// <summary>
 /// Creates or gets a user property field
 /// </summary>
 /// <param name="item">The target item</param>
 /// <param name="name">The name</param>
 /// <param name="type">The property value type</param>
 /// <returns>The user property field</returns>
 public static UserProperty CreateOrGetProperty(AppointmentItem item, string name, OlUserPropertyType type)
 {
     foreach (var prop in item.UserProperties)
     {
         if (((UserProperty)prop).Name == name)
         {
             return((UserProperty)prop);
         }
     }
     return(item.UserProperties.Add(name, type, true));
 }
Example #15
0
 /// <summary>
 /// Sets the user property value.
 /// </summary>
 /// <typeparam name="T">Type of property</typeparam>
 /// <param name="mailItem">The mail item.</param>
 /// <param name="name">The name of the user property to set.</param>
 /// <param name="type">The type of the user property.</param>
 /// <param name="value">The value to set.</param>
 /// <param name="addToFolder">if set to <c>true</c> add to containing folder. Enables search/display column for user property.</param>
 public static void SetPropertyValue <T>(this _MailItem mailItem, string name, OlUserPropertyType type, T value, bool addToFolder)
 {
     using (var userProperties = mailItem.UserProperties.WithComCleanup())
     {
         SetPropertyValue(userProperties.Resource, name, type, value, addToFolder);
     }
 }