Beispiel #1
0
        /// <summary>
        /// Loads the module.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="moduleWorkItem">The module work item.</param>
        /// <returns>The loaded module assembly.</returns>
        private Assembly LoadModule(string assemblyName, WorkItem moduleWorkItem)
        {
            //// check the assemly in the loaded modules
            if (!CheckModuleLoaded(assemblyName, moduleWorkItem))
            {
                IModuleInfo[] objModuleInfo = new IModuleInfo[1];
                ModuleInfo    moduleInfo    = new ModuleInfo(assemblyName);
                objModuleInfo[0] = moduleInfo;
                ////load the module and add it to moduleWorkItem using moduleLoaderService
                moduleWorkItem.Services.Get <IModuleLoaderService>().Load(moduleWorkItem, objModuleInfo);
            }

            ////enumerate the loaded modules in the application and get the assembly
            IList <LoadedModuleInfo> listLoadedModules;

            listLoadedModules = moduleWorkItem.Services.Get <IModuleLoaderService>().LoadedModules;
            foreach (LoadedModuleInfo loadedModule in listLoadedModules)
            {
                if (loadedModule.Assembly.ManifestModule.Name.Equals(assemblyName))
                {
                    return(loadedModule.Assembly);
                }
            }

            return(null);
        }
Beispiel #2
0
        public void AddModule(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException("moduleInfo");
            }

            // check for completeness of the provided thing
            if (moduleInfo.Manifest == null || moduleInfo.ModuleData == null)
            {
                throw new ArgumentException("Module Info incomplete", "moduleInfo");
            }

            // check for duplications
            IEnumerable <IModuleInfo> avaliableModules = _storageProvider.GetAvaliableModules();

            if (avaliableModules.Any(module => module.Manifest.ModuleName.Equals(moduleInfo.Manifest.ModuleName) &&
                                     avaliableModules.Any(info => info.Manifest.ModuleVersion.Equals(moduleInfo.Manifest.ModuleVersion))))
            {
                throw new ArgumentException("Duplicate module", "moduleInfo");
            }

            // save into storage
            _storageProvider.SaveModule(moduleInfo);
        }
        // See CompilePartInfo
        public static AvailablePart.ModuleInfo GetModuleInfo(PartModule pm)
        {
            AvailablePart.ModuleInfo moduleInfo = new AvailablePart.ModuleInfo();
            if (pm is IModuleInfo)
            {
                IModuleInfo iModuleInfo = pm as IModuleInfo;
                moduleInfo.moduleName  = iModuleInfo.GetModuleTitle();
                moduleInfo.info        = iModuleInfo.GetInfo().Trim();
                moduleInfo.primaryInfo = iModuleInfo.GetPrimaryField();
            }
            else
            {
                moduleInfo.moduleName = (pm.GUIName ?? KSPUtil.PrintModuleName(pm.moduleName));
                moduleInfo.info       = pm.GetInfo().Trim();
            }

            if (pm.showUpgradesInModuleInfo && pm.HasUpgrades())
            {
                moduleInfo.info += "\n" + pm.PrintUpgrades();
            }

            moduleInfo.moduleDisplayName = pm.GetModuleDisplayName();
            if (moduleInfo.moduleDisplayName == string.Empty)
            {
                moduleInfo.moduleDisplayName = moduleInfo.moduleName;
            }
            return(moduleInfo);
        }
Beispiel #4
0
        public ActionResult Details(string itemId)
        {
            if (string.IsNullOrEmpty(itemId))
            {
                ViewData["Message"] = "No key provided";
                return(View("Error"));
            }

            IModuleInfo selectedModel = _repositoryModel.ModuleInfosList
                                        .Where(x => x.Id.Equals(itemId))
                                        .Select(x => x)
                                        .DefaultIfEmpty(null)
                                        .SingleOrDefault();

            // check validity of the moduleInfo
            if (selectedModel == null)
            {
                return(View("FileNotFound"));
            }

            if (selectedModel.Manifest == null || selectedModel.ModuleData == null)
            {
                return(View("FileNotFound"));
            }

            // if everything's ok go to details
            return(View("Details", selectedModel));
        }
Beispiel #5
0
 public void CancelRealtimeFeed(
     IModuleInfo clientInfo,
     Guid subscriptionId,
     AsyncQueueCallback <QuotedAssetSet> callback)
 {
     _mds.CancelRealtimeFeed(clientInfo, subscriptionId, callback);
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModuleDownloadProgressChangedEventArgs"/> class.
 /// </summary>
 /// <param name="moduleInfo">The module info.</param>
 /// <param name="bytesReceived">The bytes received.</param>
 /// <param name="totalBytesToReceive">The total bytes to receive.</param>
 public ModuleDownloadProgressChangedEventArgs(IModuleInfo moduleInfo, long bytesReceived, long totalBytesToReceive)
     : base(CalculateProgressPercentage(bytesReceived, totalBytesToReceive), null)
 {
     ModuleInfo          = moduleInfo ?? throw new ArgumentNullException(nameof(moduleInfo));
     BytesReceived       = bytesReceived;
     TotalBytesToReceive = totalBytesToReceive;
 }
Beispiel #7
0
        public ActionResult Remove(string itemId)
        {
            if (string.IsNullOrEmpty(itemId))
            {
                ViewData["Message"] = "No key provided";
                return(View("Error"));
            }

            IModuleInfo item = _repositoryModel.ModuleInfosList
                               .Where(x => x.Id.Equals(itemId))
                               .Select(x => x)
                               .DefaultIfEmpty(null)
                               .SingleOrDefault();

            if (item == null)
            {
                ViewData["Message"] = "Key could not be found in database";
                return(View("Error"));
            }

            try
            {
                _repositoryModel.RemoveModule(item);
            }
            catch (Exception e)
            {
                ViewData["Message"] = e.Message;
                return(View("Error"));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        /// <summary>
        /// Handles any exception occurred in the module Initialization process,
        /// This method can be overridden to provide a different behavior.
        /// </summary>
        /// <param name="moduleInfo">The module metadata where the error happened.</param>
        /// <param name="assemblyName">The assembly name.</param>
        /// <param name="exception">The exception thrown that is the cause of the current error.</param>
        /// <exception cref="ModuleInitializeException"></exception>
        public virtual void HandleModuleInitializationError(IModuleInfo moduleInfo, string assemblyName, Exception exception)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            Exception moduleException;

            if (exception is ModuleInitializeException)
            {
                moduleException = exception;
            }
            else
            {
                if (!string.IsNullOrEmpty(assemblyName))
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, assemblyName, exception.Message, exception);
                }
                else
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, exception.Message, exception);
                }
            }

            throw moduleException;
        }
Beispiel #9
0
        public void Initialize(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            IModule moduleInstance = null;

            try
            {
                moduleInstance = this.CreateModule(moduleInfo);
                if (moduleInstance != null)
                {
                    moduleInstance.RegisterTypes(_containerExtension);
                    moduleInstance.OnInitialized(_containerExtension);
                }
            }
            catch (Exception ex)
            {
                this.HandleModuleInitializationError(
                    moduleInfo,
                    moduleInstance?.GetType().Assembly.FullName,
                    ex);
            }
        }
Beispiel #10
0
        public ActionResult UploadPackage(HttpPostedFileBase file)
        {
            if (file == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // save file into memory stream
            using (var memoryStream = new MemoryStream())
            {
                file.InputStream.Position = 0;
                while (file.InputStream.Position < file.InputStream.Length)
                {
                    var dataSinge = (byte)file.InputStream.ReadByte();
                    memoryStream.WriteByte(dataSinge);
                }

                // get the module info from stream
                try
                {
                    IModuleInfo moduleInfo = _zipPackager.UnPack(memoryStream.ToArray());
                    _repositoryModel.AddModule(moduleInfo);
                }
                catch (Exception e)
                {
                    ViewData["Message"] = e.Message;
                    return(View("Error"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #11
0
        private static IModuleInfo GetMatch(List <IModuleInfo> matches, string relativeRequestUrl)
        {
            bool isRoot = false;

            if (VirtualPathUtility.GetDirectory(relativeRequestUrl).Equals("~/", StringComparison.InvariantCultureIgnoreCase))
            {
                isRoot = true;
            }

            IModuleInfo longestMatch = matches[0];

            foreach (IModuleInfo match in matches)
            {
                if (isRoot && match.VirtualPath.Equals("~/", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(match);
                }

                if (match.VirtualPath.Length > longestMatch.VirtualPath.Length)
                {
                    longestMatch = match;
                }
            }
            return(longestMatch);
        }
Beispiel #12
0
 private void CmdReceived(IModuleInfo obj)
 {
     if (obj.ModuleType == typeof(EncodeModule).AssemblyQualifiedName)
     {
         _eventAggregator.GetEvent <MessageSentEvent>().Publish(new EventWithPater(obj, Message));
     }
 }
Beispiel #13
0
        public V221OutputQuotedAssetSet GetPricingStructureV221(V221Header header, V221ProviderId provider, Guid requestId, string requestParams, string structureProperties)
        {
            IModuleInfo connection = null;

            _connectionIndex.Locked(connections =>
            {
                if (!connections.TryGetValue(header.SessionId, out connection))
                {
                    throw new ApplicationException("Ignoring request from unknown client!");
                }
            });
            //var errors = new List<V221ErrorDetail>();
            string step = "GetPricingStructureV221: unknown";

            try
            {
                step = "GetPricingStructureV221: calling GetPricingStructure";
                // run each provider request
                MDSProviderId defaultProvider     = V221Helpers.ToProviderId(provider);
                MDSResult <QuotedAssetSet> result = _providers[(int)defaultProvider].GetPricingStructure(
                    defaultProvider, connection, requestId, true,
                    new NamedValueSet(requestParams),
                    new NamedValueSet(structureProperties));
                step = "GetPricingStructureV221: compressing";
                return(new V221OutputQuotedAssetSet(
                           CompressionHelper.CompressToBuffer(XmlSerializerHelper.SerializeToString(result)),
                           null));
            }
            catch (Exception excp)
            {
                Logger.LogError("Exception: step='{0}': {1}", step, excp);
                return(new V221OutputQuotedAssetSet(null, new V221ErrorDetail(excp)));
            }
        }
Beispiel #14
0
        /// <summary>
        /// Handles any exception occurred in the module Initialization process,
        /// logs the error using the <see cref="ILoggerFacade"/> and throws a <see cref="ModuleInitializeException"/>.
        /// This method can be overridden to provide a different behavior.
        /// </summary>
        /// <param name="moduleInfo">The module metadata where the error happenened.</param>
        /// <param name="assemblyName">The assembly name.</param>
        /// <param name="exception">The exception thrown that is the cause of the current error.</param>
        /// <exception cref="ModuleInitializeException"></exception>
        public virtual void HandleModuleInitializationError(IModuleInfo moduleInfo, string assemblyName, Exception exception)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            Exception moduleException;

            if (exception is ModuleInitializeException)
            {
                moduleException = exception;
            }
            else
            {
                if (!string.IsNullOrEmpty(assemblyName))
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, assemblyName, exception.Message, exception);
                }
                else
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, exception.Message, exception);
                }
            }

            this._loggerFacade.Log(moduleException.ToString(), Category.Exception, Priority.High);

            throw moduleException;
        }
Beispiel #15
0
 // constructors
 /// <summary>
 ///
 /// </summary>
 /// <param name="moduleInfo"></param>
 /// <param name="cryptoManager"></param>
 /// <param name="itemKind"></param>
 /// <param name="transient"></param>
 /// <param name="appScope"></param>
 /// <param name="name"></param>
 /// <param name="props"></param>
 /// <param name="data"></param>
 /// <param name="dataType"></param>
 /// <param name="serialFormat"></param>
 /// <param name="lifetime"></param>
 public ServerItem(
     IModuleInfo moduleInfo,
     ICryptoManager cryptoManager,
     ItemKind itemKind,
     bool transient,
     string appScope,
     string name,
     NamedValueSet props,
     object data,
     Type dataType,
     SerialFormat serialFormat,
     TimeSpan lifetime)
     : base(itemKind, transient, name, appScope)
 {
     _moduleInfo    = moduleInfo ?? throw new ArgumentNullException(nameof(moduleInfo));
     _cryptoManager = cryptoManager ?? throw new ArgumentNullException(nameof(cryptoManager));
     if (dataType == null)
     {
         throw new ArgumentNullException(nameof(dataType));
     }
     SysProps.Set(SysPropName.SAlg, (int)serialFormat);
     AppProps.Add(props);
     _data         = data;
     _dataTypeType = dataType;
     DataTypeName  = dataType.FullName;
     _lifetime     = lifetime;
 }
Beispiel #16
0
        public void Initialize(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            IModule moduleInstance = null;

            try
            {
                moduleInstance = this.CreateModule(moduleInfo);
                if (moduleInstance != null)
                {
                    var mutableContainer = _containerExtension.GetMutableContainer();
                    mutableContainer.RegisterTypes(builder =>
                    {
                        var registry = new AutofacContainerRegistry(builder, mutableContainer);
                        moduleInstance.RegisterTypes(registry);
                        registry.FinalizeRegistry();
                    });

                    moduleInstance.OnInitialized(_containerExtension);
                }
            }
            catch (Exception ex)
            {
                this.HandleModuleInitializationError(
                    moduleInfo,
                    moduleInstance != null ? moduleInstance.GetType().Assembly.FullName : null,
                    ex);
            }
        }
Beispiel #17
0
        public void SaveModule(IModuleInfo moduleInfo)
        {
            // get the max
            var     maxes = _db.Modules.Select(x => x.Id).ToList();
            decimal max;

            if (maxes.Count == 0)
            {
                max = 0;
            }
            else
            {
                max = maxes.Max(x => x);
                max++;
            }


            var module = new Module()
            {
                Id         = max,
                Manifest   = XmlSerializerHelper.Serialize(moduleInfo.Manifest),
                ModuleData = moduleInfo.ModuleData,
            };

            _db.Modules.InsertOnSubmit(module);
            _db.SubmitChanges();
        }
Beispiel #18
0
 public void Add(IModuleInfo module)
 {
     if (module != null)
     {
         m_modules.Add(module);
     }
 }
 public void SaveModule(IModuleInfo moduleInfo)
 {
     IModuleInfo existingItem =
         _modulesInfos.Where(x => x.Id == moduleInfo.Id).FirstOrDefault();
     if (existingItem != null)
         _modulesInfos.Remove(existingItem);
     _modulesInfos.Add(moduleInfo);
 }
Beispiel #20
0
 public ViewInfo(string viewName, Type viewType, IModuleInfo module, bool isSingleton, bool needAccess, SingletonTypes type)
 {
     m_viewType      = viewType;
     m_viewName      = viewName;
     m_module        = module;
     m_isSingleton   = isSingleton;
     m_needAccess    = needAccess;
     m_singletonType = type;
 }
Beispiel #21
0
        protected override IModule CreateModule(IModuleInfo moduleInfo)
        {
            if (ModuleIsInUserRole(moduleInfo))
            {
                return(base.CreateModule(moduleInfo));
            }

            return(null);
        }
Beispiel #22
0
        IEnumerable <IModuleInfo> IModuleCatalog.GetDependentModules(IModuleInfo moduleInfo)
        {
            if (GetDependentModules == null)
            {
                return(new List <IModuleInfo>());
            }

            return(GetDependentModules(moduleInfo));
        }
Beispiel #23
0
        /// <summary>
        /// Evaluates the <see cref="IModuleInfo.Ref"/> property to see if the current typeloader will be able to retrieve the <paramref name="moduleInfo"/>.
        /// Returns true if the <see cref="IModuleInfo.Ref"/> property starts with "file://", because this indicates that the file
        /// is a local file.
        /// </summary>
        /// <param name="moduleInfo">Module that should have it's type loaded.</param>
        /// <returns>
        ///     <see langword="true"/> if the current typeloader is able to retrieve the module, otherwise <see langword="false"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">An <see cref="ArgumentNullException"/> is thrown if <paramref name="moduleInfo"/> is null.</exception>
        public bool CanLoadModuleType(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            return(moduleInfo.Ref != null && moduleInfo.Ref.StartsWith(RefFilePrefix, StringComparison.Ordinal));
        }
        public static bool HasRole(this IModuleInfo moduleInfo, string role)
        {
            if (moduleInfo.HasAttribute(out ModuleRoleAttribute moduleRoleAttribute))
            {
                return(moduleRoleAttribute.SupportsRole(role));
            }

            return(false);
        }
        public static bool HasAttribute <TAttribute>(this IModuleInfo moduleInfo, out TAttribute attribute)
            where TAttribute : Attribute
        {
            var moduleType = Type.GetType(moduleInfo.ModuleType);

            attribute = moduleType.GetCustomAttributes <TAttribute>().FirstOrDefault();

            return(attribute != null);
        }
Beispiel #26
0
 void InitializeModule(IModuleInfo moduleInfo)
 {
     if (moduleInfo.State == ModuleState.Initializing)
     {
         _moduleInitializer.Initialize(moduleInfo);
         moduleInfo.State = ModuleState.Initialized;
         RaiseLoadModuleCompleted(moduleInfo, null);
     }
 }
Beispiel #27
0
 public void PublishMarketData(
     IModuleInfo clientInfo,
     Guid requestId,
     NamedValueSet requestParams,
     TimeSpan dataLifetime,
     QuotedAssetSet marketDataSet)
 {
     OnPublishMarketData(requestId, requestParams, dataLifetime, marketDataSet);
 }
Beispiel #28
0
        /// <summary>
        /// Uses the container to resolve a new <see cref="IModule"/> by specifying its <see cref="Type"/>.
        /// </summary>
        /// <param name="moduleInfo">The module to create.</param>
        /// <returns>A new instance of the module specified by <paramref name="moduleInfo"/>.</returns>
        protected virtual IModule CreateModule(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            return(this.CreateModule(moduleInfo.ModuleType));
        }
        public void RemoveModule(IModuleInfo moduleInfo)
        {
            IModuleInfo existingItem =
                _modulesInfos.Where(x => x.Id == moduleInfo.Id).FirstOrDefault();

            if (existingItem != null)
                _modulesInfos.Remove(existingItem);
            else
                throw new InvalidOperationException("Specified item does not exist!");
        }
        public void Initialize(IModuleInfo moduleInfo)
        {
            var module = CreateModule(Type.GetType(moduleInfo.ModuleType, true));

            if (module != null)
            {
                module.RegisterTypes(_container);
                module.OnInitialized(_container);
            }
        }
Beispiel #31
0
 protected virtual MDSResult <QuotedAssetSet> OnRequestPricingStructure(
     IModuleInfo clientInfo,
     Guid requestId,
     MDSRequestType requestType,
     NamedValueSet requestParams,
     DateTimeOffset subsExpires,
     NamedValueSet structureParams)
 {
     throw new NotSupportedException("This provider (" + ProviderId.ToString() + ") does not support the OnRequestPricingStructure method!");
 }
Beispiel #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadModuleCompletedEventArgs"/> class.
        /// </summary>
        /// <param name="moduleInfo">The module info.</param>
        /// <param name="error">Any error that occurred during the call.</param>
        public LoadModuleCompletedEventArgs(IModuleInfo moduleInfo, Exception error)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            this.ModuleInfo = moduleInfo;
            this.Error      = error;
        }
        public void RemoveModule(IModuleInfo moduleInfo)
        {
            var module = _db.Modules
                .Where( x => x.Id.ToString().Equals(moduleInfo.Id))
                .Select(x => x)
                .Single();

            _db.Modules.DeleteOnSubmit(module);
            _db.SubmitChanges();
        }
 public void SaveModule(IModuleInfo moduleInfo)
 {
     // make the new id for newly saved thing
     var info = new ModuleInfo()
                           {
                               Id = GetNewId(),
                               Manifest = moduleInfo.Manifest,
                               ModuleData = moduleInfo.ModuleData,
                           };
     _moduleInfos.Add(info);
 }
Beispiel #35
0
 internal static VModuleInfo C2V(IModuleInfo contract)
 {
     if (!System.Runtime.Remoting.RemotingServices.IsObjectOutOfAppDomain(contract) &&
         (contract.GetType().Equals(typeof(ModuleInfoV2C))))
     {
         return ((ModuleInfoV2C)(contract)).GetSourceView();
     }
     else
     {
         return new ModuleInfoC2V(contract);
     }
 }
        private GuidancePackageModuleInfo Translate(IModuleInfo moduleInfo)
        {
            DependantModuleInfo dependantModuleInfo = moduleInfo as DependantModuleInfo;

            GuidancePackageModuleInfo wcsfModuleInfo = new GuidancePackageModuleInfo(moduleInfo.Name, moduleInfo.AssemblyName, moduleInfo.VirtualPath);

            if (dependantModuleInfo != null)
            {
                wcsfModuleInfo.Dependencies = dependantModuleInfo.Dependencies;
            }

            return wcsfModuleInfo;
        }
Beispiel #37
0
        public void RemoveModule(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException("moduleInfo");

            // check for existence
            IEnumerable<IModuleInfo> modules = _storageProvider.GetAvaliableModules();
            if (!modules.Any(module => module.Id.Equals(moduleInfo.Id)))
                throw new ArgumentException("No such module info in collection", "moduleInfo");

            // remove from storage
            _storageProvider.RemoveModule(moduleInfo);
        }
        public GuidancePackageModuleInfo[] Translate(IModuleInfo[] dependantModules)
        {
            if (dependantModules == null)
            {
                return null;
            }

            GuidancePackageModuleInfo[] moduleInfo = new GuidancePackageModuleInfo[dependantModules.Length];

            for (int i = 0; i < dependantModules.Length; i++)
            {
                moduleInfo[i] = Translate(dependantModules[i]);
            }

            return moduleInfo;
        }
        public AssemblyNode CreateAssemblyNode(IModuleInfo module,
            CciMethodMatcher methodMatcher)
        {
            var matcher = methodMatcher.Join(new SolutionTypesManager.ProperlyNamedMatcher());
            var assemblyNode = new AssemblyNode(module.Name);
            assemblyNode.AssemblyPath = module.Module.Location.ToFilePathAbs();
            System.Action<CheckedNode, ICollection<INamedTypeDefinition>> typeNodeCreator = (parent, leafTypes) =>
            {
                foreach (INamedTypeDefinition typeDefinition in leafTypes)
                {
                    if (matcher.Matches(typeDefinition))
                    {
                        var type = new TypeNode(parent, typeDefinition.Name.Value);
                        foreach (var method in typeDefinition.Methods)
                        {
                            if (matcher.Matches(method))
                            {
                                type.Children.Add(new MethodNode(type, method.Name.Value, method, false));
                                return;
                            }
                        }
                        parent.Children.Add(type);
                    }
                }
            };
            Func<INamedTypeDefinition, string> namespaceExtractor = typeDef =>
                TypeHelper.GetDefiningNamespace(typeDef).Name.Value;


            NamespaceGrouper<INamespaceTypeDefinition, CheckedNode>.
                GroupTypes(assemblyNode,
                    namespaceExtractor,
                    (parent, name) => new TypeNamespaceNode(parent, name),
                    typeNodeCreator,
                        module.Module.GetAllTypes().ToList());


            //remove empty amespaces. 
            //TODO to refactor...
            List<TypeNamespaceNode> checkedNodes = assemblyNode.Children.OfType<TypeNamespaceNode>().ToList();
            foreach (TypeNamespaceNode node in checkedNodes)
            {
                RemoveFromParentIfEmpty(node);
            }
            return assemblyNode;
        }
Beispiel #40
0
        public void AddModule(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException("moduleInfo");

            // check for completeness of the provided thing
            if ( moduleInfo.Manifest == null || moduleInfo.ModuleData == null)
                throw new ArgumentException("Module Info incomplete", "moduleInfo");

            // check for duplications
            IEnumerable<IModuleInfo> avaliableModules = _storageProvider.GetAvaliableModules();
            if (avaliableModules.Any(module => module.Manifest.ModuleName.Equals(moduleInfo.Manifest.ModuleName) &&
                avaliableModules.Any(info => info.Manifest.ModuleVersion.Equals(moduleInfo.Manifest.ModuleVersion))))
                throw new ArgumentException("Duplicate module", "moduleInfo");

            // save into storage
            _storageProvider.SaveModule(moduleInfo);
        }
        public void SaveModule(IModuleInfo moduleInfo)
        {
            // get the max
            var maxes = _db.Modules.Select(x => x.Id).ToList();
            decimal max;
            if (maxes.Count == 0)
                max = 0;
            else
            {
                max = maxes.Max(x => x);
                max++;
            }

            var module = new Module()
                                {
                                    Id = max,
                                    Manifest = XmlSerializerHelper.Serialize(moduleInfo.Manifest),
                                    ModuleData = moduleInfo.ModuleData,
                                };

            _db.Modules.InsertOnSubmit(module);
            _db.SubmitChanges();
        }
        private void LoadAssemblies(IModuleInfo[] modules)
        {
            foreach (IModuleInfo module in modules)
            {
                GuardLegalAssemblyFile(module);
                Assembly assembly = LoadAssembly(module.AssemblyFile);

                if (!loadedModules.ContainsKey(assembly))
                    loadedModules.Add(assembly, new ModuleMetadata(assembly, traceSource, module));
            }
        }
        private void InnerLoad(WorkItem workItem, IModuleInfo[] modules)
        {
            if (modules.Length == 0)
                return;

            IModuleInfo[] allowedModules = FilterModulesBasedOnRole(modules);
            LoadAssemblies(allowedModules);
            List<ModuleMetadata> loadOrder = GetLoadOrder();

            foreach (ModuleMetadata module in loadOrder)
                module.LoadServices(workItem);

            foreach (ModuleMetadata module in loadOrder)
                module.InitializeWorkItemExtensions(workItem);

            foreach (ModuleMetadata module in loadOrder)
                module.InitializeModuleClasses(workItem);

            foreach (ModuleMetadata module in loadOrder)
                module.NotifyOfLoadedModule(OnModuleLoaded);
        }
        private void GuardLegalAssemblyFile(IModuleInfo modInfo)
        {
            Guard.ArgumentNotNull(modInfo, "modInfo");
            Guard.ArgumentNotNull(modInfo.AssemblyFile, "modInfo.AssemblyFile");

            string assemblyFilePath = GetModulePath(modInfo.AssemblyFile);

            if (!File.Exists(assemblyFilePath))
                throw new ModuleLoadException(
                    string.Format(CultureInfo.CurrentCulture,
                        Properties.Resources.ModuleNotFound, assemblyFilePath));
        }
        private IModuleInfo[] FilterModulesBasedOnRole(IModuleInfo[] modules)
        {
            List<IModuleInfo> allowedModules = new List<IModuleInfo>();

            foreach (IModuleInfo module in modules)
            {
                if (module.AllowedRoles.Count == 0)
                    allowedModules.Add(module);
                else
                {
                    foreach (string role in module.AllowedRoles)
                    {
                        if (Thread.CurrentPrincipal.IsInRole(role))
                        {
                            allowedModules.Add(module);
                            break;
                        }
                    }
                }
            }

            return allowedModules.ToArray();
        }
 private IModuleInfo FindRootVirtualPathModuleInfo(IModuleInfo[] moduleInfos)
 {
     foreach (IModuleInfo moduleInfo in moduleInfos)
     {
         if (moduleInfo.VirtualPath != null && RemoveTrailingWack(moduleInfo.VirtualPath).Equals("~", StringComparison.InvariantCultureIgnoreCase))
         {
             return moduleInfo;
         }
     }
     return null;
 }
        void Module_Loaded(IModuleInfo module)
        {
            _loaded_modules.Add(module.Name);

            _need_to_refresh_parts = true;
        }
        public void WriteToStream(IModuleInfo moduleInfo, FileStream stream, string filePath)
        {
            var module = (ModuleInfo)moduleInfo;
            if (module.PdbReader == null)
            {
                PeWriter.WritePeToStream(module.Module, _host, stream);
            }
            else
            {

                using (var pdbWriter = new PdbWriter(Path.ChangeExtension(filePath, "pdb"), module.PdbReader))
                {
                    PeWriter.WritePeToStream(module.Module, _host, stream, module.PdbReader,
                        module.PdbReader, pdbWriter);
                }
            }
        }
Beispiel #49
0
 public void Initialize(IPlatform platform, ILogger logger, IModuleInfo moduleInfo, int secret)
 {
     _view.Initialize(PlatformAdapter.C2V(platform), LoggerAdapter.C2V(logger), ModuleInfoAdapter.C2V(moduleInfo), secret);
 }
        private IModuleInfo FindModuleInfoInSubWebProject(IModuleInfo[] moduleInfos, Project webProject)
        {
            string projectAbosultePath = RemoveTrailingWack(webProject.Properties.Item("FullPath").Value.ToString());

            while (projectAbosultePath.Length > 0)
            {
                foreach (IModuleInfo moduleInfo in moduleInfos)
                {
                    if (moduleInfo.VirtualPath != null)
                    {
                        string moduleInfoAbsolutePath = BuildModuleAbsoluteFolderPath(webProject, moduleInfo);
                        if (String.Equals(projectAbosultePath, moduleInfoAbsolutePath, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return moduleInfo;
                        }
                    }
                }
                projectAbosultePath = Path.GetDirectoryName(projectAbosultePath);
            }
            return null;
        }
 private IProjectItemModel SelectWebFolder(IList<IProjectItemModel> moduleFolders, IProjectModel moduleProject, IProjectModel webProject, IModuleInfo[] moduleInfoCollection)
 {
     if (moduleInfoCollection != null)
     {
         foreach (IModuleInfo moduleInfo in moduleInfoCollection)
         {
             if (String.Compare(moduleInfo.AssemblyName, moduleProject.AssemblyName, StringComparison.InvariantCultureIgnoreCase) == 0)
             {
                 foreach (IProjectItemModel moduleFolder in moduleFolders)
                 {
                     if (moduleInfo.VirtualPath != null)
                     {
                         string moduleFolderPath = Path.Combine(webProject.ProjectPath, ConvertToPhysicalPath(moduleInfo.VirtualPath));
                         if (String.Compare(moduleFolder.ItemPath, moduleFolderPath, StringComparison.InvariantCultureIgnoreCase) == 0)
                         {
                             return moduleFolder;
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
 private List<IProjectModel> FilterProjectsWithVirtualPath(List<IProjectModel> moduleProjects, IModuleInfo[] moduleInfos)
 {
     List<IProjectModel> filtered = new List<IProjectModel>();
     foreach (IProjectModel project in moduleProjects)
     {
         IModuleInfo projectModuleInfo = FindModuleInfo(project.AssemblyName, moduleInfos);
         if (projectModuleInfo != null)
         {
             if (!string.IsNullOrEmpty(projectModuleInfo.VirtualPath))
             {
                 filtered.Add(project);
             }
         }
     }
     return filtered;
 }
 public CatalogueModuleLayout(IModuleInfo module)
 {
     this.InitializeComponent();
     this.module = module;
     this.moduleName.Text = module.Name;
 }
            public ModuleMetadata(Assembly assembly, TraceSource traceSource, IModuleInfo moduleInfo)
            {
                this.assembly = assembly;
                this.traceSource = traceSource;

                if (moduleInfo is IDependentModuleInfo)
                {
                    name = ((IDependentModuleInfo)moduleInfo).Name;
                    dependencies.AddRange(((IDependentModuleInfo)moduleInfo).Dependencies);
                }
                else
                {
                    foreach (ModuleAttribute attr in assembly.GetCustomAttributes(typeof(ModuleAttribute), true))
                        name = attr.Name;

                    foreach (ModuleDependencyAttribute attr in assembly.GetCustomAttributes(typeof(ModuleDependencyAttribute), true))
                        dependencies.Add(attr.Name);
                }

                foreach (Type type in assembly.GetExportedTypes())
                {
                    foreach (ServiceAttribute attr in type.GetCustomAttributes(typeof(ServiceAttribute), true))
                        services.Add(new ServiceMetadata(type, attr.RegisterAs ?? type, attr.AddOnDemand));

                    foreach (WorkItemExtensionAttribute attr in type.GetCustomAttributes(typeof(WorkItemExtensionAttribute), true))
                        workItemExtensions.Add(new KeyValuePair<Type, Type>(attr.WorkItemType, type));

                    foreach (RootWorkItemExtensionAttribute attr in type.GetCustomAttributes(typeof(RootWorkItemExtensionAttribute), true))
                        workItemRootExtensions.Add(type);

                    if (!type.IsAbstract && typeof(IModule).IsAssignableFrom(type))
                        moduleTypes.Add(type);
                }
            }
Beispiel #55
0
 public void LoadModule(IModuleInfo module)
 {
     //_moduleLoaderService.ModuleLoaded += new EventHandler<DataEventArgs<LoadedModuleInfo>>(OnModuleLoaded);
     _moduleLoaderService.Load(_workItem, module);
 }
        public MemoryStream WriteToStream(IModuleInfo moduleInfo)
        {
            var module = (ModuleInfo)moduleInfo;
            _log.Info("CommonCompilerInfra.WriteToFile:" + module.Name);
            MemoryStream stream = new MemoryStream();

            if (module.PdbReader == null)
            {
                PeWriter.WritePeToStream(module.Module, _host, stream);

            }
            else
            {
                throw new NotImplementedException();
                //                using (var pdbWriter = new PdbWriter(Path.ChangeExtension(filePath, "pdb"), module.PdbReader))
                //                {
                //                    PeWriter.WritePeToStream(module.Module, _host, stream, module.SourceLocationProvider,
                //                        module.LocalScopeProvider, pdbWriter);
                //                }
            }
            stream.Position = 0;

            return stream;
        }
 public void RemoveModule(IModuleInfo moduleInfo)
 {
     _moduleInfos.Remove(moduleInfo);
 }
 private IModuleInfo FindModuleInfo(string assemblyName, IModuleInfo[] modules)
 {
     List<IModuleInfo> moduleList = new List<IModuleInfo>(modules);
     return moduleList.Find(delegate(IModuleInfo match)
     {
         return match.AssemblyName == assemblyName;
     });
 }
 public ModuleInfoC2V(IModuleInfo contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
        private static void LoadServices(CompositionContainer container, IModuleInfo moduleInfo)
        {
            IServiceLoaderService serviceLoader = container.Services.Get<IServiceLoaderService>();

            if (serviceLoader == null)
                return;

            DependantModuleInfo dependantModuleInfo = moduleInfo as DependantModuleInfo;

            if (dependantModuleInfo != null && dependantModuleInfo.Services != null)
            {
                serviceLoader.Load(container, dependantModuleInfo.Services);
            }
        }