public void TestSetup()
        {
            AppContext = new TraceLabTestApplication(TestContext);

            //set current location
            currentLocation = AppContext.BaseTestDirectory;

            //create config definition using createwrapper method of the ComponentMetadataDefinition class
            var configDef = ComponentScannerHelper_Accessor.CreateConfigWrapperDefinition(typeof(MockConfig));
            testConfig = new ConfigWrapper(configDef);

            //set the values of MockConfig
            mockFileAbsolutePath = Path.Combine(currentLocation, mockFile);
            Stream file = File.Create(mockFileAbsolutePath);
            file.Close(); //close file so that it is not being used by this process anymore

            configFilePath = new FilePath();
            configFilePath.Init(mockFileAbsolutePath, currentLocation);
            //the key matches property name in the MockConfig
            testConfig.ConfigValues["MockFile"].Value = configFilePath;

            mockDirAbsolutePath = Path.Combine(currentLocation, mockDir);
            Directory.CreateDirectory(mockDirAbsolutePath);
            Assert.IsTrue(Directory.Exists(mockDirAbsolutePath));

            configDirPath = new DirectoryPath();
            configDirPath.Init(mockDirAbsolutePath, currentLocation);
            //the key matches property name in the MockConfig
            testConfig.ConfigValues["MockDirectory"].Value = configDirPath;
        }
        protected ConfigWrapper(ConfigWrapper other)
        {
            if (other == null)
                throw new ArgumentNullException();

            m_configWrapperDefinition = other.m_configWrapperDefinition;
            InitDefaultConfigWrapper();

            foreach (KeyValuePair<string, ConfigPropertyObject> pair in other.m_configValues)
            {
                var property = new ConfigPropertyObject(pair.Value);
                m_configValues[pair.Key] = property;
                property.PropertyChanged += property_PropertyChanged;
            }
        }
 /// <summary>
 /// Inits the default component metadata based on its definition
 /// </summary>
 /// <param name="enforce">if set to <c>true</c> [enforce].</param>
 private void InitDefaultComponentMetadata(bool enforce)
 {
     if (IOSpec == null || enforce)
     {
         IOSpec = new IOSpec(ComponentMetadataDefinition.IOSpecDefinition);
     }
     if (Label == null || enforce)
     {
         Label = ComponentMetadataDefinition.Label;
     }
     if (ConfigWrapper == null || enforce)
     {
         ConfigWrapper = new ConfigWrapper(ComponentMetadataDefinition.ConfigurationWrapperDefinition);
         if (m_experimentLocationRoot != null) //location may be null if metadata definition does not belong to any graph
         {
             ConfigWrapper.SetExperimentLocationRoot(m_experimentLocationRoot, true);
         }
     }
 }
Пример #4
0
        private void AttachListenerToIOSpecHighlights(ExperimentNode node)
        {
            // HERZUM SPRINT 4: TLAB-238
            ComponentMetadata meta = ExperimentNode.Data.Metadata as ComponentMetadata;

            if (meta != null)
            {
                TraceLab.Core.Components.ConfigWrapper configWrapper = meta.ConfigWrapper as TraceLab.Core.Components.ConfigWrapper;
                if (configWrapper != null)
                {
                    TraceLab.Core.Components.ConfigPropertyObject value = new TraceLab.Core.Components.ConfigPropertyObject();
                    // HERZUM SPRINT 4.3: TLAB-238 TLAB-243
                    // ADD configWrapper.ConfigValues.TryGetValue ("ConfigurationFile", out value)
                    if (configWrapper.ConfigValues.TryGetValue("Directory", out value) || configWrapper.ConfigValues.TryGetValue("ConfigurationFile", out value))
                    {
                        if (value != null)
                        {
                            value.SetExperimentLocationRoot(System.IO.Path.GetDirectoryName(m_applicationContext.Application.Experiment.ExperimentInfo.FilePath), true);
                        }
                    }
                    // END HERZUM SPRINT 4.2: TLAB-202
                }
            }
            // HERZUM SPRINT 4: TLAB-238

            //set convenience metadata field
            m_componentMetadata = node.Data.Metadata as IConfigurableAndIOSpecifiable;
            if (m_componentMetadata != null)
            {
                m_componentMetadata.IOSpec.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
                {
                    if (e.PropertyName.Equals("IsInputHighlighted") || e.PropertyName.Equals("IsOutputHighlighted"))
                    {
                        //redraw component
                        Invalidate();
                    }
                };
            }
        }
 internal void Merge(string idPrefix, ConfigWrapper configWrapper)
 {
     foreach (KeyValuePair<string, ConfigPropertyObject> pair in configWrapper.m_configValues)
     {
         string extendedParameterName = String.Format("{0}:{1}", idPrefix, pair.Key);
         if (ConfigValues.ContainsKey(extendedParameterName) == false)
         {
             var configValue = pair.Value;
             var property = new ConfigPropertyObject(extendedParameterName, configValue.Value, configValue.Type, configValue.AssemblyQualifiedName, configValue.IsEnum, configValue.DisplayName, configValue.Description);
             ConfigValues.Add(extendedParameterName, property);
             property.PropertyChanged += property_PropertyChanged;
         }
     }
 }
 internal static ConfigWrapper ReadConfig(XPathNavigator nav)
 {
     ConfigWrapper tmpConfigWrapper = new ConfigWrapper();
     tmpConfigWrapper.ReadXml(nav.ReadSubtree());
     return tmpConfigWrapper;
 }
        /// <summary>
        /// Creates a new instances of the ConfigWrapper with references to the ConfigPropertiesObjects in this ConfigWrapper,
        /// that within their name they contain the given id.
        /// </summary>
        /// <param name="id">The node id.</param>
        /// <param name="ignoreVisible">if set to <c>true</c> the ConfigPropertyObjects visibility parameters are ignored in the returned ConfigWrapper. All ConfigPropertyObjects are going to be visible.</param>
        /// <returns>
        /// New instance of ConfigWrapper with references to ConfigValues for the given node.
        /// </returns>
        public ConfigWrapper CreateViewForId(string id, bool ignoreVisible) 
        {
            ConfigWrapper localConfigWrapper = new ConfigWrapper();

            foreach (KeyValuePair<string, ConfigPropertyObject> pair in ConfigValues)
            {
                if (pair.Value.Name.Contains(id))
                {
                    localConfigWrapper.ConfigValues.Add(pair.Key, pair.Value);
                }
            }

            // ignore the ConfigPropertyObjectsVisibility
            localConfigWrapper.m_ignoreVisibility = ignoreVisible;

            return localConfigWrapper;
        }
 internal void UpdateConfigValuesBasedOn(ConfigWrapper tmpConfigWrapper)
 {
     foreach (ConfigPropertyObject tmpPropertyObject in tmpConfigWrapper.ConfigValues.Values)
     {
         ConfigPropertyObject propertyObject;
         if (ConfigValues.TryGetValue(tmpPropertyObject.Name, out propertyObject))
         {
             propertyObject.Value = tmpPropertyObject.Value;
         }
     }
 }
        /// <summary>
        /// Performs a deep copy of the data in this object to another instance of the Metadata.
        /// </summary>
        /// <param name="other">The other.</param>
        protected override void CopyFrom(Metadata other)
        {
            if (other == null)
                throw new ArgumentNullException("other");
            
            base.CopyFrom(other);

            CompositeComponentMetadata metadata = (CompositeComponentMetadata)other;
            m_IOSpec = metadata.m_IOSpec.Clone();
            m_configWrapper = metadata.m_configWrapper.Clone();
            m_experimentLocationRoot = metadata.m_experimentLocationRoot;
            m_compositeComponentMetadataDefinition = metadata.m_compositeComponentMetadataDefinition;
            m_componentMetadataDefinitionID = metadata.m_componentMetadataDefinitionID;

            HasDeserializationError = metadata.HasDeserializationError;
            if (HasDeserializationError)
            {
                DeserializationErrorMessage = metadata.DeserializationErrorMessage;
            } 

            // if composite component was not present in the library, then corresponding component graph may be null.
            // the deserialization has already set the corresponding error above, nevertheless subgraph cannot be cloned obviously
            if (HasDeserializationError == false && metadata.m_compositeComponentGraph != null)
            {
                m_compositeComponentGraph = (CompositeComponentGraph)(metadata.m_compositeComponentGraph.Clone());
            }

            m_tempConfigWrapper = metadata.m_tempConfigWrapper;
            m_tempIoSpec = metadata.m_tempIoSpec;
            m_tempLabel = metadata.m_tempLabel;
        }
        /// <summary>
        /// Gets the definition for this Metadata and sets up the configuration based on it.
        /// </summary>
        /// <param name="library">The library.</param>
        /// <param name="experimentLocationRoot">The experiment location root.</param>
        private void GetDefinitionAndSet(Components.IComponentsLibrary library, string experimentLocationRoot)
        {
            m_experimentLocationRoot = experimentLocationRoot;

            //reload component metadata definition
            MetadataDefinition metadataDefinition;
            if (library.TryGetComponentDefinition(ComponentMetadataDefinitionID, out metadataDefinition))
            {
                ComponentMetadataDefinition = metadataDefinition as CompositeComponentMetadataDefinition;
            }

            //if definition has been found override matching parameters (but don't override definition)
            if (ComponentMetadataDefinition != null)
            {
                InitDefaultComponentMetadata(true);
                IOSpec.UpdateMappingsBasedOn(m_tempIoSpec);
                ConfigWrapper.UpdateConfigValuesBasedOn(m_tempConfigWrapper);
                Label = m_tempLabel;
                WaitsForAllPredecessors = m_tempWaitsForAllPredecessors;
                //clear error - there might have been errors regarding existence of composite component, but referencing new package might fix this problem.
                DeserializationErrorMessage = null;
                HasDeserializationError = false;
            }
            else
            {
                //otherwise set values to temporary IOSpec and configWrapper (just not to lose data in case user resave experiment), and rethrow exception
                IOSpec = m_tempIoSpec;
                ConfigWrapper = m_tempConfigWrapper;
                HasDeserializationError = true;
                Label = m_tempLabel;
                WaitsForAllPredecessors = m_tempWaitsForAllPredecessors;
                DeserializationErrorMessage = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Component library does not contain any Composite Component of the given ID {0}", ComponentMetadataDefinitionID);
            }

            if (experimentLocationRoot != null) //it may be null if it is a component residing in the graph of composite component that is the library (was not added to any experiment)
            {
                ConfigWrapper.SetExperimentLocationRoot(experimentLocationRoot, true);
            }

            m_tempConfigWrapper = null;
            m_tempIoSpec = null;
            m_tempLabel = null;
        }
        public override void UpdateFromDefinition(IComponentsLibrary library)
        {
            HasDeserializationError = false;
            m_tempConfigWrapper = ConfigWrapper;
            m_tempIoSpec = IOSpec;
            m_tempLabel = Label;
            m_tempWaitsForAllPredecessors = WaitsForAllPredecessors;
            ComponentMetadataDefinition = null;

            GetDefinitionAndSet(library, m_experimentLocationRoot);
        }
        public override void ReadXml(System.Xml.XmlReader reader)
        {
            IsInitialized = false;

            XPathDocument doc = new XPathDocument(reader);
            XPathNavigator nav = doc.CreateNavigator();

            XPathNavigator iter = nav.SelectSingleNode("/Metadata");
            //read component metadata definition id 
            ComponentMetadataDefinitionID = iter.GetAttribute("ComponentMetadataDefinitionID", String.Empty);
            m_tempLabel = iter.GetAttribute("Label", String.Empty);

            //read attribute indicating if component should wait for all predecessors
            var wait = iter.GetAttribute("WaitsForAllPredecessors", String.Empty);
            if (String.IsNullOrEmpty(wait) || (wait != Boolean.TrueString && wait != Boolean.FalseString)) //if value has not been found set it to true
                m_tempWaitsForAllPredecessors = true; //default value
            else
                m_tempWaitsForAllPredecessors = Convert.ToBoolean(wait);
            
            //read iospec and config wrapper from xml
            m_tempIoSpec = IOSpec.ReadIOSpec(nav.SelectSingleNode("/Metadata/IOSpec"));
            m_tempConfigWrapper = ConfigWrapper.ReadConfig(nav);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ComponentMetadata"/> class.
 /// </summary>
 /// <param name="info">The info.</param>
 /// <param name="context">The context.</param>
 protected ComponentMetadata(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     m_IOSpec = (IOSpec)info.GetValue("m_IOSpec", typeof(IOSpec));
     m_configWrapper = (ConfigWrapper)info.GetValue("m_configWrapper", typeof(ConfigWrapper));
     m_componentMetadataDefinitionID = (string)info.GetValue("m_componentMetadataDefinitionID", typeof(string));
     m_componentMetadataDefinition = (ComponentMetadataDefinition)info.GetValue("m_componentMetadataDefinition", typeof(ComponentMetadataDefinition));
 }
 /// <summary>
 /// Inits the default component metadata based on its component metadata definition
 /// </summary>
 /// <param name="enforce">if set to <c>true</c> [enforce].</param>
 private void InitDefaultComponentMetadata(bool enforce)
 {
     if (IOSpec == null || enforce)
     {
         IOSpec = new IOSpec(ComponentMetadataDefinition.IOSpecDefinition);
     }
     if (Label == null || enforce)
     {
         Label = ComponentMetadataDefinition.Label;
     }
     if (ConfigWrapper == null || enforce)
     {
         ConfigWrapper = new ConfigWrapper(ComponentMetadataDefinition.ConfigurationWrapperDefinition);
         ConfigWrapper.SetExperimentLocationRoot(m_experimentLocationRoot, true);
     }
 }