Пример #1
0
        public static String Get(AppointmentItem ai, MetadataId key)
        {
            String retVal = null;
            String searchKey;

            if (Exists(ai, key, out searchKey))
            {
                UserProperties ups  = null;
                UserProperty   prop = null;
                try {
                    ups  = ai.UserProperties;
                    prop = ups.Find(searchKey);
                    if (prop != null)
                    {
                        if (prop.Type != OlUserPropertyType.olText)
                        {
                            log.Warn("Non-string property " + searchKey + " being retrieved as String.");
                        }
                        retVal = prop.Value.ToString();
                    }
                } finally {
                    prop = (UserProperty)OutlookOgcs.Calendar.ReleaseObject(prop);
                    ups  = (UserProperties)OutlookOgcs.Calendar.ReleaseObject(ups);
                }
            }
            return(retVal);
        }
Пример #2
0
        public static Boolean Exists(AppointmentItem ai, MetadataId searchId, out String searchKey)
        {
            searchKey = metadataIdKeyName(searchId);

            int maxSet;
            int?keySet = getKeySet(ai, out maxSet);

            if (keySet.HasValue && keySet.Value != 0)
            {
                searchKey += "-" + keySet.Value.ToString("D2");
            }

            UserProperties ups  = null;
            UserProperty   prop = null;

            try {
                ups  = ai.UserProperties;
                prop = ups.Find(searchKey);
                if (searchId == MetadataId.gCalendarId)
                {
                    return(prop != null && prop.Value.ToString() == Settings.Instance.UseGoogleCalendar.Id);
                }
                else
                {
                    return(prop != null && Get(ai, MetadataId.gCalendarId) == Settings.Instance.UseGoogleCalendar.Id);
                }
            } catch {
                return(false);
            } finally {
                prop = (UserProperty)OutlookOgcs.Calendar.ReleaseObject(prop);
                ups  = (UserProperties)OutlookOgcs.Calendar.ReleaseObject(ups);
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the property.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if Changed.</returns>
        public static bool SetProperty(this UserProperties properties, string key, string value)
        {
            var property = properties.Find(key, true);

            if (property == null)
            {
                properties.Add(key, OlUserPropertyType.olText, false, System.Type.Missing);
                properties.Find(key, true).Value = value;
                return(true);
            }

            if (property.Value != value)
            {
                property.Value = value;
                return(true);
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Gets the property.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <param name="key">The key.</param>
        /// <returns>The Property value.</returns>
        public static string GetProperty(this UserProperties properties, string key)
        {
            var property = properties.Find(key, true);

            if (property != null)
            {
                return(property.Value);
            }

            return(null);
        }
        public string FetchIndexProperty(object obj)
        {
            UserProperties props = FetchUserProperties(obj);

            if (props != null)
            {
                UserProperty prop = props.Find(index, false);
                if (prop != null)
                {
                    return(Normalise((string)prop.Value));
                }
            }
            return(null);
        }
        public string FetchNameProperty(object obj)
        {
            UserProperties props = FetchUserProperties(obj);

            if (props != null)
            {
                UserProperty prop = props.Find(NameProperty(type), false);
                if (prop != null)
                {
                    return((string)prop.Value);
                }
            }
            return(null);
        }
        /// <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;
                }
            }
        }
Пример #8
0
        public static void Remove(ref AppointmentItem ai, MetadataId key)
        {
            String searchKey;

            if (Exists(ai, key, out searchKey))
            {
                UserProperties ups  = null;
                UserProperty   prop = null;
                try {
                    ups  = ai.UserProperties;
                    prop = ups.Find(searchKey);
                    prop.Delete();
                    log.Debug("Removed " + searchKey + " property.");
                } finally {
                    prop = (UserProperty)Calendar.ReleaseObject(prop);
                    ups  = (UserProperties)Calendar.ReleaseObject(ups);
                }
            }
        }
        /// <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));
            }
        }
        private String deleteOutlookCustomProperty(ref AppointmentItem copiedAi, String propertyName)
        {
            UserProperties ups           = null;
            UserProperty   prop          = null;
            String         propertyValue = null;

            try {
                ups  = copiedAi.UserProperties;
                prop = ups.Find(propertyName);
                if (prop != null)
                {
                    propertyValue = prop.Value.ToString();
                    prop.Delete();
                    log.Debug("Removed " + propertyName + " property.");
                }
            } finally {
                prop = (UserProperty)Calendar.ReleaseObject(prop);
                ups  = (UserProperties)Calendar.ReleaseObject(ups);
            }
            return(propertyValue);
        }
        private void untagAsCopied(String entryID)
        {
            //Allow time for pasted item to complete
            System.Threading.Thread.Sleep(2000);
            log.Debug("Untagging copied Outlook item");

            AppointmentItem copiedAi = null;

            try {
                OutlookOgcs.Calendar.Instance.IOutlook.GetAppointmentByID(entryID, out copiedAi);
                if (copiedAi == null)
                {
                    throw new System.Exception("Could not find Outlook item with entryID " + entryID + " for post-processing.");
                }
                log.Debug(OutlookOgcs.Calendar.GetEventSummary(copiedAi));
                UserProperties ups  = null;
                UserProperty   prop = null;
                try {
                    String propertyName = OutlookOgcs.CustomProperty.MetadataId.locallyCopied.ToString();
                    ups  = copiedAi.UserProperties;
                    prop = ups.Find(propertyName);
                    if (prop != null)
                    {
                        prop.Delete();
                        log.Debug("Removed " + propertyName + " property.");
                    }
                } finally {
                    prop = (UserProperty)Calendar.ReleaseObject(prop);
                    ups  = (UserProperties)Calendar.ReleaseObject(ups);
                }
                copiedAi.Save();
            } catch (System.Exception ex) {
                log.Warn("Failed to remove OGCS 'copied' property on copied item.");
                OGCSexception.Analyse(ex);
            } finally {
                copiedAi = (AppointmentItem)OutlookOgcs.Calendar.ReleaseObject(copiedAi);
            }
        }
Пример #12
0
        private static DateTime get_datetime(AppointmentItem ai, MetadataId key)
        {
            DateTime retVal = new DateTime();
            String   searchKey;

            if (Exists(ai, key, out searchKey))
            {
                UserProperties ups  = null;
                UserProperty   prop = null;
                try {
                    ups  = ai.UserProperties;
                    prop = ups.Find(searchKey);
                    if (prop != null)
                    {
                        try {
                            if (prop.Type != OlUserPropertyType.olDateTime)
                            {
                                log.Warn("Non-datetime property " + searchKey + " being retrieved as DateTime.");
                                retVal = DateTime.Parse(prop.Value.ToString());
                            }
                            else
                            {
                                retVal = (DateTime)prop.Value;
                            }
                        } catch (System.Exception ex) {
                            log.Error("Failed to retrieve DateTime value for property " + searchKey);
                            OGCSexception.Analyse(ex);
                        }
                    }
                } finally {
                    prop = (UserProperty)Calendar.ReleaseObject(prop);
                    ups  = (UserProperties)Calendar.ReleaseObject(ups);
                }
            }
            return(retVal);
        }
Пример #13
0
		private void DoCompare(IList redundant, IList duplicateList, IDictionary cache, ItemPropertyHandler props, object obj)
		{
			if (props.IsCorrectType(obj))
			{
				string value = props.FetchIndexProperty(obj);
				if ((value!=null)&&(value.Length>0))
				{
					IList list;
					if (cache.Contains(value))
					{
						list = (IList)cache[value];
						bool exact=false;
						UserProperties testprops = props.FetchUserProperties(obj);
						foreach (object known in list)
						{
							exact=true;
							UserProperties knownprops = props.FetchUserProperties(known);
							foreach (string prop in propertyList)
							{
								string knownprop = null;
								try
								{
									UserProperty check = knownprops.Find(prop,false);
									if (check!=null)
									{
										knownprop = (string)check.Value;
									}
								}
								catch {}
								string testprop = null;
								try
								{
									UserProperty check = testprops.Find(prop,false);
									if (check!=null)
									{
										testprop = (string)check.Value;
									}
								}
								catch {}
								if ((testprop==null)&&(knownprop==null))
								{
									continue;
								}
								if ((testprop!=null)&&(knownprop!=null))
								{
									testprop=testprop.Trim().ToLower();
									knownprop=knownprop.Trim().ToLower();
									if ((testprop==knownprop))
									{
										continue;
									}
								}
								if (badprop.Contains(prop))
								{
									badprop[prop]=((int)badprop[prop])+1;
								}
								else
								{
									badprop[prop]=1;
								}
								exact=false;
								break;
							}
							if (exact)
							{
								break;
							}
						}
						if (!exact)
						{
							list.Add(obj);
						}
						else
						{
							redundant.Add(obj);
						}
						if (list.Count==2)
						{
							duplicateList.Add(value);
						}
					}
					else
					{
						list = new ArrayList();
						list.Add(obj);
						cache.Add(value,list);
					}
				}
			}
		}