Example #1
0
 public void RegisterComponent <T>(string componentName, Func <T> componentInitializer, bool overwrite) where T : class
 {
     ChangeRegistry(
         () =>
     {
         var key = new ComponentKey(componentName, typeof(T));
         if (!_componentRegistry.ContainsKey(key) || overwrite)
         {
             if (_componentRegistry.ContainsKey(key) && overwrite)
             {
                 var existed = _componentRegistry[key];
                 if (existed is IAzureSessionListener existedListener)
                 {
                     _eventHandler -= existedListener.OnEvent;
                 }
             }
             var component           = componentInitializer();
             _componentRegistry[key] = component;
             if (component is IAzureSessionListener listener)
             {
                 _eventHandler += listener.OnEvent;
             }
         }
     });
 }
Example #2
0
        public void InsertSubComp(ComponentKey id, TransformableObject insert)
        {
            if (_subComps.ContainsKey(id))
            {
                return;
            }

            _subComps.Add(id, insert);
        }
 public ComponentInfo GetComponentInfo(ComponentKey key)
 {
     ComponentInfo info;
     if (_infoMap.TryGetValue(key, out info))
     {
         return info;
     }
     throw new OpenGammaException(string.Format("ComponentRepository did not include service {0}, {1}", key, this));
 }
Example #4
0
        public virtual string GetTempFilePathForComponent(ComponentKey componentKey)
        {
            string combine = Path.Combine(CurrentProject.TempFolder, componentKey.ToString());

            return(combine);

            /*
             *                      return PathHelper.GetTempFilePathFor("ArchAngel", CurrentProject.ProjectFile, componentKey);
             */
        }
Example #5
0
        public TransformableObject GetSubComp(ComponentKey compID)
        {
            TransformableObject comp;

            if (_subComps.TryGetValue(compID, out comp))
            {
                return(comp);
            }
            throw new InvalidHierarchicalAccessException();
        }
 public void UnregisterComponent <T>(string componentName) where T : class
 {
     ChangeRegistry(
         () =>
     {
         var key = new ComponentKey(componentName, typeof(T));
         if (_componentRegistry.ContainsKey(key))
         {
             _componentRegistry.Remove(key);
         }
     });
 }
 public void RegisterComponent <T>(string componentName, Func <T> componentInitializer, bool overwrite) where T : class
 {
     ChangeRegistry(
         () =>
     {
         var key = new ComponentKey(componentName, typeof(T));
         if (!_componentRegistry.ContainsKey(key) || overwrite)
         {
             _componentRegistry[key] = componentInitializer();
         }
     });
 }
        public bool TryGetComponent <T>(string componentName, out T component) where T : class
        {
            var key = new ComponentKey(componentName, typeof(T));

            component = null;
            if (_componentRegistry.ContainsKey(key))
            {
                component = _componentRegistry[key] as T;
            }

            return(component != null);
        }
Example #9
0
        /// <summary>
        /// The temp path will be of the form Temp/ArchAngel/Guid/ComponentKey
        /// where Temp is the system temp folder, the Guid is generated from the
        /// project filename, and the ComponentKey is the string representation of 
        /// the part of the ArchAngel system that needs a temp folder.
        /// </summary>
        /// <param name="product">The product we need a temp folder for.</param>
        /// <param name="projectFile">The filename of the project this is for</param>
        /// <param name="componentKey">The part of the ArchAngel system that needs the
        /// temp path.</param>
        /// <returns>Path of the form Temp/ArchAngel/Guid/ComponentKey. For a given project,
        /// the temp path will be the same as long as the project filename does not change.</returns>
        public static string GetTempFilePathFor(string product, string projectFile, ComponentKey componentKey)
        {
            if(string.IsNullOrEmpty(product))
                throw new ArgumentException("Product cannot be null");

            // Convert projectFile into a Guid string in the form {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
            byte[] hash = Utility.GetMD5FromString(projectFile ?? "");
            string filename = new Guid(hash).ToString("B").ToUpper();

            string path = Path.GetTempPath().PathSlash(product).PathSlash(filename).PathSlash(componentKey.ToString());

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            return path;
        }
Example #10
0
        public override String ToString()
        {
            var str = "CCMModelItem Data:\n";

            try
            {
                str += ComponentKey.ToString();
                str += Attributes.ToString();
            }
            catch (Exception e)
            {
                var sMsg = String.Format("Failed to print CCMModelItem contents: {0}", e.Message);
            }

            return(str);
        }
Example #11
0
 public void UnregisterComponent <T>(string componentName) where T : class
 {
     ChangeRegistry(
         () =>
     {
         var key = new ComponentKey(componentName, typeof(T));
         if (_componentRegistry.ContainsKey(key))
         {
             var component = _componentRegistry[key];
             if (component is IAzureSessionListener listener)
             {
                 _eventHandler -= listener.OnEvent;
             }
             _componentRegistry.Remove(key);
         }
     });
 }
        private ComponentRepository GetComponentRepository(IFudgeFieldContainer configMsg)
        {
            var componentInfos = new Dictionary<ComponentKey, ComponentInfo>();
            foreach (var userDataField in configMsg.GetMessage("infos"))
            {
                if (!(userDataField.Value is IFudgeFieldContainer))
                {
                    continue;
                }

                var component = (IFudgeFieldContainer)userDataField.Value;
                var uri = new Uri(_rootUri, component.GetString("uri"));
                var componentKey = new ComponentKey(component.GetString("type"), component.GetString("classifier"));
                Dictionary<string, string> attributes = component.GetMessage("attributes").ToDictionary(f => f.Name, f => (string) f.Value);
                componentInfos.Add(componentKey, new ComponentInfo(componentKey, uri, attributes));
            }
            return new ComponentRepository(componentInfos);
        }
Example #13
0
        /// <summary>
        /// The temp path will be of the form Temp/ArchAngel/Guid/ComponentKey
        /// where Temp is the system temp folder, the Guid is generated from the
        /// project filename, and the ComponentKey is the string representation of
        /// the part of the ArchAngel system that needs a temp folder.
        /// </summary>
        /// <param name="product">The product we need a temp folder for.</param>
        /// <param name="projectFile">The filename of the project this is for</param>
        /// <param name="componentKey">The part of the ArchAngel system that needs the
        /// temp path.</param>
        /// <returns>Path of the form Temp/ArchAngel/Guid/ComponentKey. For a given project,
        /// the temp path will be the same as long as the project filename does not change.</returns>
        public static string GetTempFilePathFor(string product, string projectFile, ComponentKey componentKey)
        {
            if (string.IsNullOrEmpty(product))
            {
                throw new ArgumentException("Product cannot be null");
            }

            // Convert projectFile into a Guid string in the form {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
            byte[] hash     = Utility.GetMD5FromString(projectFile ?? "");
            string filename = new Guid(hash).ToString("B").ToUpper();

            string path = Path.GetTempPath().PathSlash(product).PathSlash(filename).PathSlash(componentKey.ToString());

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            return(path);
        }
Example #14
0
 public ComponentInfo(ComponentKey key, Uri uri, Dictionary<string, string> attributes)
 {
     _key = key;
     _attributes = attributes;
     _uri = uri;
 }
Example #15
0
        public int CompareTo(object obj)
        {
            var other = (CCMModelItem)obj;

            return(ComponentKey.CompareTo(other.ComponentKey));
        }
 public virtual string GetTempFilePathForComponent(ComponentKey componentKey)
 {
     string combine = Path.Combine(CurrentProject.TempFolder, componentKey.ToString());
     return combine;
     /*
                 return PathHelper.GetTempFilePathFor("ArchAngel", CurrentProject.ProjectFile, componentKey);
     */
 }