Beispiel #1
0
        private void AddNetwork(InProcessNetwork network)
        {
            Contract.Requires(!Networks.Contains(network));

            Networks.Add(this);
        }
Beispiel #2
0
        public void AddObjectsToNetwork(string networkName)
        {
            if (Networks.Contains(networkName))
            {
                return;
            }
            Networks.Add(networkName);
            bool addToHash = networkName == Name;

            // Do we not have a Type cache?
            if (TypeCache == null)
            {
                // Create the type cache, and populate it this time around
                TypeCache = new List <Type>();

                // Get all the currently loaded assemblies
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in assemblies)
                {
                    // Get the Types in this assembly
                    Type[] types = assembly.Types().ToArray();
                    foreach (Type type in types)
                    {
                        // If this type a ToffeeStructure?
                        if (type.HasAttribute <ToffeeStructureAttribute>())
                        {
                            ToffeeStructureAttribute attribute = type.Attribute <ToffeeStructureAttribute>();
                            if (attribute.NetworkName == networkName)
                            {
                                AddStructure(type, addToHash);
                            }
                            TypeCache.Add(type);
                        }

                        // If this type a ToffeeClass?
                        if (type.HasAttribute <ToffeeClassAttribute>())
                        {
                            ToffeeClassAttribute attribute = type.Attribute <ToffeeClassAttribute>();
                            if (attribute.NetworkName == networkName)
                            {
                                AddClass(type, addToHash);
                            }
                            TypeCache.Add(type);
                        }
                        // If this type a ToffeeService?
                        else if (type.HasAttribute <ToffeeServiceAttribute>())
                        {
                            ToffeeServiceAttribute attribute = type.Attribute <ToffeeServiceAttribute>();
                            if (attribute.NetworkName == networkName)
                            {
                                AddService(type, addToHash);
                            }
                            TypeCache.Add(type);
                        }
                    }
                }
            }
            else
            {
                // We already have a cache of types that are usable to Toffee
                foreach (Type type in TypeCache)
                {
                    // If this type a ToffeeStructure?
                    if (type.HasAttribute <ToffeeStructureAttribute>())
                    {
                        ToffeeStructureAttribute attribute = type.Attribute <ToffeeStructureAttribute>();
                        if (attribute.NetworkName == networkName)
                        {
                            AddStructure(type, addToHash);
                        }
                    }

                    // If this type a ToffeeClass?
                    if (type.HasAttribute <ToffeeClassAttribute>())
                    {
                        ToffeeClassAttribute attribute = type.Attribute <ToffeeClassAttribute>();
                        if (attribute.NetworkName == networkName)
                        {
                            AddClass(type, addToHash);
                        }
                    }
                    // If this type a ToffeeService?
                    else if (type.HasAttribute <ToffeeServiceAttribute>())
                    {
                        ToffeeServiceAttribute attribute = type.Attribute <ToffeeServiceAttribute>();
                        if (attribute.NetworkName == networkName)
                        {
                            AddService(type, addToHash);
                        }
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Checks if specified network is allowed by the current permission.
 /// </summary>
 /// <param name="network">Network to check.</param>
 /// <returns>True if passed network is allowed.</returns>
 public bool IsNetworkAllowed(int?network)
 {
     return(Networks == null || (network != null && Networks.Contains(network.Value)));
 }
Beispiel #4
0
 public bool ContainsNetwork(string networkName)
 {
     return(Networks.Contains(networkName));
 }