Exemple #1
0
        /// <summary>
        /// This method will check the cache for dependent objects that have yet to be received and make a SIF
        /// Request them.
        /// </summary>
        /// <param name="zones">Zones that the SIF Request need to be made on.</param>
        private void RequestDependentObjects(IZone[] zones)
        {
            foreach (IZone zone in zones)
            {
                ICollection <DependentObject> dependentObjects = cacheService.RetrieveNotYetRequested(SifObjectType.Name, ApplicationId, zone.ZoneId);
                if (log.IsDebugEnabled)
                {
                    log.Debug(this.GetType().Name + " found " + dependentObjects.Count + " " + SifObjectType.Name + " dependent objects for application " + ApplicationId + " in zone " + zone.ZoneId + ".");
                }

                foreach (DependentObject dependentObject in dependentObjects)
                {
                    // Create a Query for the SIF Data Object type.
                    Query query = new Query(SifObjectType);
                    // Without this, an error occurs.
                    query.SifVersions = new SifVersion[] { AgentConfiguration.Version };
                    ICollection <SifRefIdMetadata> metadataValues = SifDataObjectMetadata <T> .ParseSifUniqueId(dependentObject.ObjectKeyValue);

                    foreach (SifRefIdMetadata metadataValue in metadataValues)
                    {
                        query.AddCondition(metadataValue.XPath, ComparisonOperators.EQ, metadataValue.Value);
                    }

                    zone.Query(query);
                    cacheService.MarkAsRequested(dependentObject, AgentConfiguration.SourceId, zone.ZoneId);
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Made a request for " + SifObjectType.Name + " with SIF RefId credentials of " + dependentObject.ObjectKeyValue + ".");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// This method will check the cache for cached objects whose dependent objects have been received, and
        /// process them accordingly.
        /// </summary>
        /// <param name="zones">Zones that the cached objects will be processed against.</param>
        private void ProcessObjectsWithoutDependents(IZone[] zones)
        {
            ICollection <CachedObject> cachedObjects = cacheService.RetrieveByNoDependencies(SifObjectType.Name, ApplicationId, AgentConfiguration.SourceId);

            if (log.IsDebugEnabled)
            {
                log.Debug(this.GetType().Name + " found " + cachedObjects.Count + " objects with no dependencies for application " + ApplicationId + " and Agent " + AgentConfiguration.SourceId + ".");
            }
            IDictionary <string, IZone> zonesMap = new Dictionary <string, IZone>();

            // Create an indexed list of Zones for easy access.
            foreach (IZone zone in zones)
            {
                zonesMap.Add(zone.ZoneId, zone);
            }

            foreach (CachedObject cachedObject in cachedObjects)
            {
                T sifDataObject = SifDataObjectMetadata <T> .CreateFromXml(cachedObject.ObjectXml);

                IZone zone;

                if (cachedObject.IsEvent)
                {
                    EventAction  eventAction = (EventAction)Enum.Parse(typeof(EventAction), cachedObject.EventType, true);
                    SifEvent <T> sifEvent    = new SifEvent <T>(sifDataObject, eventAction);

                    if (zonesMap.TryGetValue(cachedObject.ZoneId, out zone))
                    {
                        ProcessEvent(sifEvent, zone);
                    }
                }
                else
                {
                    if (zonesMap.TryGetValue(cachedObject.ZoneId, out zone))
                    {
                        ProcessResponse(sifDataObject, zone);
                    }
                }

                cacheService.DeleteCachedObject(cachedObject);
                if (log.IsDebugEnabled)
                {
                    log.Debug("Processed " + cachedObject.SifObjectName + " (" + cachedObject.ObjectKeyValue + ") and removed from cache.");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// This method will check whether the specified sifDataObject exists as a dependent object in the cache. If
        /// it does, it is no longer required and can be removed.
        /// </summary>
        /// <param name="sifDataObject">SIF Data Object to check against the cache.</param>
        /// <param name="zone">Zone the SIF Data Object was received from.</param>
        /// <returns>This method will always return true.</returns>
        /// <exception cref="System.ArgumentException">sifDataObject or zone parameter is null.</exception>
        private bool PreProcessSifDataObject(T sifDataObject, IZone zone)
        {
            if (sifDataObject == null)
            {
                throw new ArgumentNullException("sifDataObject");
            }

            if (zone == null)
            {
                throw new ArgumentNullException("zone");
            }

            SifDataObjectMetadata <T> metadata = MetadataInstance(sifDataObject);

            if (log.IsDebugEnabled)
            {
                log.Debug(this.GetType().Name + " preprocessing " + metadata.ObjectName + " (" + metadata.SifUniqueId + ") for application " + ApplicationId + " in zone " + zone.ZoneId + ".");
            }
            DependentObject dependentObject = cacheService.RetrieveDependentObject(metadata.ObjectName, metadata.SifUniqueId, ApplicationId, zone.ZoneId);

            // If this object exists as a dependent object in the cache, it is now no longer required and can be
            // removed.
            if (dependentObject != null)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(metadata.ObjectName + " (" + metadata.SifUniqueId + ") removed from the cache as it has now been received.");
                }
                cacheService.DeleteDependentObject(dependentObject);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(metadata.ObjectName + " (" + metadata.SifUniqueId + ") did not exist in the cache.");
                }
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// This method will check the specified sifDataObject to see whether its dependent objects already exist in
        /// the target system or in the cache. If all the dependent objects exist in the target system, then the
        /// sifDataObject can be processed further (return true). If some dependent objects are have been cached, then
        /// the sifDataObject will be cached awaiting all outstanding dependent objects, and this method will return
        /// false.
        /// </summary>
        /// <param name="sifDataObject">SIF Data Object to check against the cache.</param>
        /// <param name="eventAction">The action associated with the SIF Data Object, i.e. add, change.</param>
        /// <param name="zone">Zone the SIF Data Object was received from.</param>
        /// <returns>True if all dependent objects exist in the target system; false otherwise.</returns>
        /// <exception cref="System.ArgumentException">sifDataObject or zone parameter is null.</exception>
        private bool PreProcessSifDataObject(T sifDataObject, EventAction?eventAction, IZone zone)
        {
            if (sifDataObject == null)
            {
                throw new ArgumentNullException("sifDataObject");
            }

            if (zone == null)
            {
                throw new ArgumentNullException("zone");
            }

            bool processFurther = true;
            SifDataObjectMetadata <T> metadata = MetadataInstance(sifDataObject);

            if (log.IsDebugEnabled)
            {
                log.Debug(this.GetType().Name + " preprocessing " + metadata.ObjectName + " (" + metadata.SifUniqueId + ") for application " + ApplicationId + " in zone " + zone.ZoneId + ".");
            }
            CachedObject cachedObject = cacheService.RetrieveCachedObject(metadata.ObjectName, metadata.SifUniqueId, ApplicationId, zone.ZoneId);

            // Previously cached SIF Data Objects/messages are currently ignored.
            // TODO: Implement a better solution that manages previously received messages.
            if (cachedObject == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(metadata.ObjectName + " (" + metadata.SifUniqueId + ") does not exist in the cache and it's dependents will be checked.");
                }
                ICollection <DependentObject> dependentObjects = metadata.DependentObjects;
                ICollection <DependentObject> existingObjects  = new Collection <DependentObject>();

                foreach (DependentObject dependentObject in dependentObjects)
                {
                    // The dependent object does not exist in the cache.
                    if (cacheService.RetrieveDependentObject(dependentObject.SifObjectName, dependentObject.ObjectKeyValue, ApplicationId, zone.ZoneId) == null)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Dependent " + dependentObject.SifObjectName + " (" + dependentObject.ObjectKeyValue + ") did NOT exist in the cache.");
                        }

                        // The dependent objects exists in the target system so there is no need to cache it.
                        if (DoesObjectExistInTargetSystem(dependentObject.SifObjectName, dependentObject.ObjectKeyValue))
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Dependent " + dependentObject.SifObjectName + " (" + dependentObject.ObjectKeyValue + ") did exist in the target system and will NOT be cached.");
                            }
                            existingObjects.Add(dependentObject);
                        }
                        else
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Dependent " + dependentObject.SifObjectName + " (" + dependentObject.ObjectKeyValue + ") did NOT exist in the target system and will be cached.");
                            }
                        }
                    }
                    // The dependent object exists in the cache so there is no need to cache it again.
                    else
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Dependent " + dependentObject.SifObjectName + " (" + dependentObject.ObjectKeyValue + ") did exist in the cache and will NOT be cached.");
                        }
                        existingObjects.Add(dependentObject);
                    }
                }

                foreach (DependentObject existingObject in existingObjects)
                {
                    dependentObjects.Remove(existingObject);
                }

                // There are outstanding dependent objects.
                if (dependentObjects.Count != 0)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(metadata.ObjectName + " (" + metadata.SifUniqueId + ") will be cached and as not all it's dependents exist in the target system.");
                    }
                    processFurther = false;
                    cacheService.StoreObjectInCache
                        (metadata.ObjectName,
                        metadata.SifUniqueId,
                        sifDataObject.ToXml(),
                        (eventAction == null ? null : eventAction.ToString()),
                        AgentConfiguration.SourceId,
                        ApplicationId,
                        zone.ZoneId,
                        ExpiryStrategy,
                        ExpiryPeriod,
                        dependentObjects);
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(metadata.ObjectName + " (" + metadata.SifUniqueId + ") will NOT be cached as all it's dependents exist in the target system.");
                    }
                }
            }
            else
            {
                processFurther = false;
                if (log.IsDebugEnabled)
                {
                    log.Debug(metadata.ObjectName + " (" + metadata.SifUniqueId + ") already exists in the cache and will be ignored.");
                }
            }

            return(processFurther);
        }