Beispiel #1
0
        /// <summary>
        /// Scans the specified directories for composite components.
        /// </summary>
        /// <param name="componentsDirectoryPath">Directories to be scanned.</param>
        /// <param name="cachedFiles">Paths of files already stored in the cache.</param>
        private void ScanForCompositeComponents(IEnumerable <string> componentsDirectoryPath, ISet <string> cachedFiles)
        {
            var pathSet    = new HashSet <string>(componentsDirectoryPath);
            var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(CompositeComponentMetadataDefinition), null);

            foreach (var dir in pathSet)
            {
                string[] filePaths = GetCompositeComponentFiles(dir);

                if (filePaths == null)
                {
                    continue;
                }

                foreach (var filename in filePaths)
                {
                    string fullPath = Path.GetFullPath(filename);

                    if (cachedFiles.Contains(fullPath))
                    {
                        FilesToGetFromCache.Add(fullPath);
                    }
                    else
                    {
                        CompositeComponentFileDescriptor compFile = ReadCompositeComponentFile(serializer, filename);
                        if (compFile != null)
                        {
                            NewFilesLoaded.Add(compFile);
                            FilesToGetFromCache.Add(fullPath);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Processes the ComponentScanResults by extracting the new files read during scanning and
 /// by adding the requested MetadataDefinition to the results.
 /// </summary>
 /// <param name="results">The results from scanning.</param>
 public void ProcessComponentScanResults(ComponentScanResults results)
 {
     foreach (string filePath in results.RequestedFiles)
     {
         try
         {
             FileDescriptor file = this.m_componentFiles[filePath];
             if (file is AssemblyFileDescriptor)
             {
                 AssemblyFileDescriptor assembly = (AssemblyFileDescriptor)file;
                 foreach (ComponentMetadataDefinition metadata in assembly.MetadataCollection)
                 {
                     if (!results.Components.Contains(metadata.ID))
                     {
                         results.Components.Add(metadata);
                         string GuidID;
                         if (assembly.NewGuidToOldGuid.TryGetValue(metadata.ID, out GuidID))
                         {
                             results.OldGuidToNewGuidMap.Add(GuidID, metadata.ID);
                         }
                     }
                     else
                     {
                         MetadataDefinition oldMetadata = results.Components[metadata.ID];
                         string             msg         = String.Format(Messages.SameComponents, oldMetadata.Classname, oldMetadata.Assembly,
                                                                        metadata.Classname, metadata.Assembly);
                         NLog.LogManager.GetCurrentClassLogger().Warn(msg);
                         results.Errors.Add(msg);
                     }
                 }
             }
             else if (file is CompositeComponentFileDescriptor)
             {
                 CompositeComponentFileDescriptor component = (CompositeComponentFileDescriptor)file;
                 if (!results.CompositeComponents.Contains(component.MetadataDefinition.ID))
                 {
                     results.CompositeComponents.Add(component.MetadataDefinition);
                 }
                 else
                 {
                     MetadataDefinition oldMetadata = results.CompositeComponents[component.MetadataDefinition.ID];
                     string             msg         = String.Format(Messages.SameComponents, oldMetadata.Classname, oldMetadata.Assembly,
                                                                    component.MetadataDefinition.Classname, component.MetadataDefinition.Assembly);
                     NLog.LogManager.GetCurrentClassLogger().Warn(msg);
                     results.Errors.Add(msg);
                 }
             }
         }
         catch (KeyNotFoundException)
         {
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Reads the composite component file. It deserializes the xml file of composite component.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        private CompositeComponentFileDescriptor ReadCompositeComponentFile(XmlSerializer serializer, string filename)
        {
            CompositeComponentFileDescriptor file = null;

            try
            {
                var reader = XmlReader.Create(filename);
                var compositeComponentDefinition = (CompositeComponentMetadataDefinition)serializer.Deserialize(reader);
                compositeComponentDefinition.Assembly = filename;

                file = new CompositeComponentFileDescriptor(filename, compositeComponentDefinition);
            }
            catch (Exception e)
            {
                // Catch everything, just log
                // Basically, if an exception is thrown, then this is not a valid Component.
                file = null;
                var message = e.InnerException != null ? e.InnerException.Message : e.Message;
                message = string.Format("Unable to load composite component {0}: {1}", filename, message);
                Errors.Add(message);
            }

            return(file);
        }
Beispiel #4
0
        /// <summary>
        /// Reads the composite component file. It deserializes the xml file of composite component. 
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        private CompositeComponentFileDescriptor ReadCompositeComponentFile(XmlSerializer serializer, string filename)
        {
            CompositeComponentFileDescriptor file = null;

            try
            {
                var reader = XmlReader.Create(filename);
                var compositeComponentDefinition = (CompositeComponentMetadataDefinition)serializer.Deserialize(reader);
                compositeComponentDefinition.Assembly = filename;

                file = new CompositeComponentFileDescriptor(filename, compositeComponentDefinition);
            }
            catch (Exception e)
            {
                // Catch everything, just log
                // Basically, if an exception is thrown, then this is not a valid Component.
                file = null;
                var message = e.InnerException != null ? e.InnerException.Message : e.Message;
                message = string.Format("Unable to load composite component {0}: {1}", filename, message);
                Errors.Add(message);
            }

            return file;
        }