public void ProcessedEntity(IsolatedStorageOfflineEntity entity)
        {
            string           atomId = entity.ServiceMetadata.Id;
            OfflineEntityKey key    = entity.GetIdentity() as OfflineEntityKey;

            key.TypeName = entity.GetType().FullName;

            if (entity.IsTombstone)
            {
                if (String.IsNullOrEmpty(atomId))
                {
                    _pkeySet.Add(key);
                }
                else
                {
                    _atomIdSet.Add(atomId);
                }
            }
            else
            {
                _pkeySet.Add(key);

                if (!String.IsNullOrEmpty(atomId))
                {
                    _atomIdSet.Add(atomId);
                }
            }
        }
        public bool ContainsEntity(IsolatedStorageOfflineEntity entity)
        {
            // If the entity is a tombstone, use the atom id
            if (entity.IsTombstone)
            {
                if (String.IsNullOrEmpty(entity.ServiceMetadata.Id))
                {
                    // if it's a tombstone and the id is null, it means it is a delete of
                    // a local insert that can be skipped, so we report it as already written
                    return(true);
                }
                else
                {
                    return(_atomIdSet.Contains(entity.ServiceMetadata.Id));
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(entity.ServiceMetadata.Id))
                {
                    return(_atomIdSet.Contains(entity.ServiceMetadata.Id));
                }

                OfflineEntityKey key = entity.GetIdentity() as OfflineEntityKey;
                key.TypeName = entity.GetType().FullName;

                if (_pkeySet.Contains(key))
                {
                    return(true);
                }

                return(false);
            }
        }
        /// <summary>
        /// Compares two OfflineEntityKey objects to determine if they are equal.  This must be implemented for the Dictionary.
        /// </summary>
        /// <param name="obj">Object to which to compare this object.</param>
        /// <returns>Whether or not this object equals the object passed in.</returns>
        public override bool Equals(object obj)
        {
            OfflineEntityKey other = obj as OfflineEntityKey;

            if (other != null)
            {
                if (_type != other._type)
                {
                    return(false);
                }

                if (_keys.Count != other._keys.Count)
                {
                    return(false);
                }

                // Loop over each key and value.  This is where the sorting comes in.
                for (int i = 0; i < _keys.Count; ++i)
                {
                    if (!_keys[i].Key.Equals(other._keys[i].Key))
                    {
                        return(false);
                    }

                    if (!_keys[i].Value.Equals(other._keys[i].Value))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Reflects on the keys for the entity and returns a representation of its key.
        /// </summary>
        /// <returns>The object which is the key for the entity</returns>
        internal object GetIdentity()
        {
            OfflineEntityKey key = new OfflineEntityKey();

            PropertyInfo[] propInfos = GetEntityKeyProperties();

            foreach (PropertyInfo propInfo in propInfos)
            {
                key.AddKey(propInfo.Name, propInfo.GetGetMethod().Invoke(this, new object[] { }));
            }

            return(key);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reflects on the keys for the entity and returns a representation of its key.
        /// </summary>
        /// <returns>The object which is the key for the entity</returns>
        internal object GetIdentity()
        {
            OfflineEntityKey key = new OfflineEntityKey();

            IEnumerable<PropertyInfo> propInfos = GetEntityKeyProperties();

            foreach (PropertyInfo propInfo in propInfos)
            {
                key.AddKey(propInfo.Name, propInfo.GetMethod.Invoke(this, new object[] { }));
            }

            return key;
        }