internal static RoutingEntity GetRoutingEntity(IUniversalRoutingEntity ure)
		{
			if (null == ure)
				throw new ArgumentNullException("ure");

			RoutingEntity routingEntity = new RoutingEntity();

			routingEntity.PolicyType = ure.PolicyType.ToString();
			routingEntity.RoutingType = ure.RoutingType;

			if (ure.Items != null && ure.Items.Count > 0)
			{
				routingEntity.Items = new Workshare.PolicyContent.RoutingItem[ure.Items.Count];
				int index = 0;
				foreach (IRoutingItem item in ure.Items)
				{
					Workshare.PolicyContent.RoutingItem routingItem = new Workshare.PolicyContent.RoutingItem();
					routingItem.Content = item.Content;

					if (item.Properties != null && item.Properties.Count > 0)
					{
						routingItem.Properties = new CustomProperty[item.Properties.Count];
						int propIndex = 0;
						foreach( string key in item.Properties.Keys)
						{
							routingItem.Properties[propIndex++] = new CustomProperty(key, item.Properties[key]);
						}
					}

					routingEntity.Items[index++] = routingItem;
				}
			}

			return routingEntity;
		}
        public UniversalRequestObject()
        {
            m_Properties = new Dictionary<string, string>();
            m_Attachments = new RequestAttachmentCollection();

            m_source = new UniversalRoutingEntity();
            m_source.RoutingType = RoutingTypes.Source;
            m_destination = new UniversalRoutingEntity();
            m_destination.RoutingType = RoutingTypes.Destination;
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves a RoutingItem of a given type from the RoutingEntity object.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        List<RoutingItem> GetRoutingItemOfType(IUniversalRoutingEntity entity, string type)
        {
            List<RoutingItem> items = new List<RoutingItem>();

            foreach (RoutingItem ri in entity.Items)
            {
                if (ri.Properties.ContainsKey("AddressType"))
                    if (ri.Properties["AddressType"].Equals(type, StringComparison.InvariantCultureIgnoreCase))
                        items.Add(ri);
            }

            return items;
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether a matching device type can be found in a pair of universal routing entities
        /// </summary>
        /// <param name="sourceEntity">Contains the device type routing item to search for</param>
        /// <param name="targetEntity">Contains a collection of routing items in which to search for the source routing item</param>
        /// <returns>True if a match is found</returns>
        public bool IsMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
        {
            if ((null == sourceEntity) || (null == targetEntity))
                return false;

            // Routing types must be the same.
            if (0 != string.Compare(sourceEntity.RoutingType, targetEntity.RoutingType, true, CultureInfo.InvariantCulture))
                return false;

            // The request types have to be the same before any processing
            if (sourceEntity.PolicyType != targetEntity.PolicyType)
                return false;

            //must have RequestChannel property on source
            if (!sourceEntity.Properties.ContainsKey(SMTPPropertyKeys.RequestChannel))
                return false;

            return (0 == string.Compare(sourceEntity.Properties[SMTPPropertyKeys.RequestChannel], RequestChannels.Blackberry, true, CultureInfo.InvariantCulture));
        }
        public bool IsMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
        {
            if ((null == sourceEntity) || (null == targetEntity))
                return false;

            // Routing types must be the same.
            if (0 != string.Compare(sourceEntity.RoutingType, targetEntity.RoutingType, true, CultureInfo.InvariantCulture))
                return false;

            // The request types have to be the same before any processing
            if (sourceEntity.PolicyType != targetEntity.PolicyType)
                return false;

            //must have RequestChannel property on source
            if (!sourceEntity.Properties.ContainsKey(SMTPPropertyKeys.RequestChannel))
            {
                return false;
            }

            // FOR OUTLOOK we now have the Internal property set on incoming - so no longer
            // need to resolve int/ext using mapi - we use the property!
            if ((string.Compare(sourceEntity.Properties[SMTPPropertyKeys.RequestChannel], RequestChannels.Outlook, true, CultureInfo.InvariantCulture) == 0) ||
                (string.Compare(sourceEntity.Properties[SMTPPropertyKeys.RequestChannel], RequestChannels.LotusNotes, true, CultureInfo.InvariantCulture) == 0))
            {
                return PropertyMatch(sourceEntity, targetEntity);
            }
            

            m_resolver.SetRequestChannel(sourceEntity.Properties[SMTPPropertyKeys.RequestChannel]);

            //compare routing item content
            string[] sourceRoutingItemContents = GetRoutingItemContents(sourceEntity);
            string[] targetRoutingItemContents = GetRoutingItemContents(targetEntity);

            return m_resolver.IsMemberOfGroup(sourceRoutingItemContents, targetRoutingItemContents);
        }
        private bool PropertyMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
        {
            bool bInternal = false;
            bool bExternal = false;
            bool bInternalMatch = false;
            bool bExternalMatch = false;

            foreach (IRoutingItem item in sourceEntity.Items)
            {
                string intern;
                if (item.Properties.TryGetValue(SMTPItemPropertyKeys.Internal, out intern))
                {
                    if (intern == true.ToString())
                        bInternal = true;

                    if (intern == false.ToString())
                        bExternal = true;
                }            
            }

            foreach (IRoutingItem item in targetEntity.Items)
            {
                if (item.Content == "Recipients:Internal")
                    bInternalMatch = true;

                if (item.Content == "Recipients:Everyone")
                    bExternalMatch = true;
            }

            if (bInternalMatch && bInternal && !bExternal)
                return true;

            if (bExternalMatch && !bInternal && bExternal)
                return true;

            if (bInternalMatch && bExternalMatch && bInternal && bExternal)
                return true;

            return false;
        }
 /// <summary>
 /// Extracts the content property of all routing items in an IUniversalRoutingEntity
 /// </summary>
 /// <param name="routingEntity">The routing entity to evaluate</param>
 /// <returns>The extracted routing item contents</returns>
 private string[] GetRoutingItemContents(IUniversalRoutingEntity routingEntity)
 {
     string[] routingItemContents = new string[routingEntity.Items.Count];
     for (int i = 0; i < routingEntity.Items.Count; i++)
     {
         routingItemContents[i] = routingEntity.Items[i].Content;
     }
     return routingItemContents;
 }
 public bool IsNotMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
 {
     return !IsMatch(sourceEntity, targetEntity);
 }
Beispiel #9
0
        public bool IsMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
        {
            if ((null == sourceEntity) || (null == targetEntity))
            {
                return false;
            }

            // Routing types must be the same.
            if (0 != string.Compare(sourceEntity.RoutingType, targetEntity.RoutingType, true, CultureInfo.InvariantCulture))
            {
                return false;
            }

            // The request types have to be the same before any processing
            if (sourceEntity.PolicyType != targetEntity.PolicyType)
            {
                return false;
            }

            //we must have some routing items for there to be a match
            if (0 == sourceEntity.Items.Count || (0 == targetEntity.Items.Count))
            {
                return false;
            }

            //check that the content property of the source routing item matches the content property of one 
            //of the target routing items
            string[] sourceRoutingItemContents = new string[sourceEntity.Items.Count];
            for (int i = 0; i < sourceEntity.Items.Count; i++)
            {
				sourceRoutingItemContents[i] = sourceEntity.Items[i].Content;

				//	LDAP routing can be used in removeable device policies. In these cases, the current user
				//	is added as a property in the source entity routing item.
				if (string.IsNullOrEmpty(sourceRoutingItemContents[i]))
				{
					string displayName;
					if ((sourceEntity.Items[i].Properties.TryGetValue(SMTPItemPropertyKeys.DisplayName, out displayName)) &&
						(m_directoryAnalyzer != null) &&
						(m_directoryAnalyzer.Engine != null))
					{
						//	Display name doesn't correspond to LDAP displayname, but to SAM/UID
						IAddress[] addresses = m_directoryAnalyzer.Engine.RetrieveMembersByField(FieldType.SAM, displayName, "");
						if (addresses.Length == 1)
						{
							sourceRoutingItemContents[i] = addresses[0].Email;
						}
					}
				}
            }
            string[] targetRoutingItemContents = new string[targetEntity.Items.Count];
            for (int i = 0; i < targetEntity.Items.Count; i++)
            {
                targetRoutingItemContents[i] = targetEntity.Items[i].Content;
            }

            return m_directoryAnalyzer.IsMemberOfGroup(sourceRoutingItemContents, targetRoutingItemContents);
        }
Beispiel #10
0
        /// <summary>
        /// Determines whether a matching device type can be found in a pair of universal routing entities
        /// </summary>
        /// <param name="sourceEntity">Contains the device type routing item to search for</param>
        /// <param name="targetEntity">Contains a collection of routing items in which to search for the source routing item</param>
        /// <returns>True if a match is found</returns>
        public bool IsMatch(IUniversalRoutingEntity sourceEntity, IUniversalRoutingEntity targetEntity)
        {
            if ((null == sourceEntity) || (null == targetEntity))
            {
                return false;
            }

            // Routing must be the same.
            if (0 != string.Compare(sourceEntity.RoutingType, targetEntity.RoutingType, true, CultureInfo.InvariantCulture))
            {
                return false;
            }

            // The request types have to be the same before any processing
            if (sourceEntity.PolicyType != targetEntity.PolicyType)
            {
                return false;
            }

            //build dictionary keyed on target content types, containing target content values
            Dictionary<string, List<string>> targetRoutingItemsDictionary = new Dictionary<string, List<string>>();
            foreach(IRoutingItem targetRoutingItem in targetEntity.Items)
            {
                if (targetRoutingItem.Properties.ContainsKey(RemovableDeviceItemPropertyKeys.ContentType))
                {
                    string key = targetRoutingItem.Properties[RemovableDeviceItemPropertyKeys.ContentType];
                    if (!targetRoutingItemsDictionary.ContainsKey(key))
                    {
                        List<string> routingItems = new List<string>();
                        routingItems.Add(targetRoutingItem.Content);
                        targetRoutingItemsDictionary.Add(key, routingItems);
                    }
                    else
                    {
                        targetRoutingItemsDictionary[key].Add(targetRoutingItem.Content);
                    }
                }
            }

            //now, check that all target types in the dictionary have a value that matches that of an item in the source
            //entity. This doesn't look particularly efficient, but I figure that we're never going to be
            //copying to a large number of devices at any one time and so performance won't take a big hit.
            int matchingParameters = 0;
            foreach (string contentType in targetRoutingItemsDictionary.Keys)
            {
                foreach (string value in targetRoutingItemsDictionary[contentType])
                {
                    bool foundValueMatchForThisContentType = false;
                    foreach (IRoutingItem sourceRoutingItem in sourceEntity.Items)
                    {
                        if (sourceRoutingItem.Properties.ContainsKey(RemovableDeviceItemPropertyKeys.ContentType))
                        {
                            if ((contentType == sourceRoutingItem.Properties[RemovableDeviceItemPropertyKeys.ContentType]) &&
                                (value == sourceRoutingItem.Content))
                            {
                                foundValueMatchForThisContentType = true;
                                matchingParameters++;
                                break;
                            }
                        }
                    }
                    if (foundValueMatchForThisContentType)
                    {
                        break;
                    }
                }
            }

            if (targetRoutingItemsDictionary.Keys.Count == matchingParameters)
            {
                return true;
            }

            return false;
        }
Beispiel #11
0
        internal static string FormatRoutingEntity(IUniversalRoutingEntity dest)
        {
            StringBuilder sb = new StringBuilder();
            Dictionary<string, bool> duplicateMap = new Dictionary<string, bool>();

            if (dest != null &&
                 dest.Items != null &&
                 dest.Items.Count > 0)
            {
                for (int i = 0; i < dest.Items.Count; ++i)
                {
                    IRoutingItem item = dest.Items[i];

                    if ( item.Content == null 
                        || duplicateMap.ContainsKey(item.Content))
                        continue;

                    if (i > 0)
                        sb.Append(';');

                    sb.Append(FormatRoutingItem(item));
                    duplicateMap[item.Content] = true;
                }
            }
            else
            {
                return string.Empty;
            }

            return sb.ToString();
        }
Beispiel #12
0
        public bool AddressMatch(IFile file, IUniversalRoutingEntity destination, IUniversalRoutingEntity source, string[] addressTypes, string[] content)
        {
            if (destination == null || source == null || addressTypes == null || content == null) 
                return false;
            
            foreach (string s in addressTypes)
            {
                List<RoutingItem> routingItems = null;
                if (s.Equals(AddressType.From.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    routingItems = GetRoutingItemOfType(source, s);
                }
                else
                {
                    routingItems = GetRoutingItemOfType(destination, s);
                }
                if (routingItems != null)
                {
                    foreach (RoutingItem ri in routingItems)
                    {
                        if (ri != null && Match(ri.Content, content))
                            return true;
                    }
                }
            }

            return false;
        }