示例#1
0
        private static Dictionary <string, PathEntry> GetLocalServices(bool withChildren)
        {
            return(LocalServicesCache.GetOrAdd(withChildren, wChildren =>
            {
                var logFilesServices = DiscoveryService.GetLocalRegisteredServices("LOG.FILE");
                var logHttpServices = DiscoveryService.GetLocalRegisteredServices("LOG.HTTP");
                var traceFilesServices = DiscoveryService.GetLocalRegisteredServices("TRACE.FILE");
                var statusHttpServices = DiscoveryService.GetRegisteredServices("STATUS.HTTP");
                var statusFilesServices = DiscoveryService.GetLocalRegisteredServices("STATUS.FILE");

                var appNames = traceFilesServices.Select(ts => ts.ApplicationName).ToArray();

                if (Core.Settings["ImportRemoteAssemblies"].ParseTo(false) && Core.Settings["ImportRemoteAssembliesPath"] != null)
                {
                    var folderServices = DiscoveryService.GetLocalRegisteredServices("FOLDERS");
                    var folderServicesData = folderServices
                                             .Where((s, names) => names.Contains(s.ApplicationName) && s.ApplicationName != Core.ApplicationName, appNames)
                                             .Select(s => s.Data.GetValue() is string[] strArray ? strArray[0] : null)
                                             .ToArray();

                    var destinationPath = Core.Settings["ImportRemoteAssembliesPath"];
                    foreach (var path in folderServicesData)
                    {
                        var localExeFiles = Directory.EnumerateFiles(path, "*.exe", SearchOption.AllDirectories);
                        var localDllFiles = Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories);
                        var localFiles = localExeFiles.Concat(localDllFiles);
                        foreach (var file in localFiles)
                        {
                            try
                            {
                                var name = AssemblyName.GetAssemblyName(file);
                                if (AssemblyResolver.IsExcludedAssembly(name.Name))
                                {
                                    continue;
                                }
                                var destinationFile = Path.Combine(destinationPath, Path.GetFileName(file));
                                if (!System.IO.File.Exists(destinationFile))
                                {
                                    System.IO.File.Copy(file, destinationFile);
                                }
                            }
                            catch (BadImageFormatException)
                            {
                                //
                            }
                            catch (Exception)
                            {
                                //
                            }
                        }
                    }

                    var asmResolver = AssemblyResolverManager.GetAssemblyResolver();
                    asmResolver?.AppendPath(destinationPath);
                }
示例#2
0
        public async Task <IActionResult> Index()
        {
            var request = HttpContext.Request;
            var global  = InstanceOf <Global>();
            var page    = global.Business.GetRuntimePageModel(request.Scheme, request.Host.Host, request.Host.Port ?? (request.IsHttps ? 443 : 80), request.Path);

            if (page == null)
            {
                return(Content("Page not found"));
            }

            var pageModel = page.Page.GetModel();
            var viewPath  = global.GetView(pageModel.ViewPath);

            _requestData.Context     = HttpContext;
            _requestData.CreateView  = false;
            _requestData.Page        = pageModel;
            _requestData.Route       = page.Route;
            _responseData.PageResult = View(viewPath, pageModel);

            if (pageModel.BehaviorPipeline != null && pageModel.BehaviorPipeline.Count > 0)
            {
                foreach (var bObj in pageModel.BehaviorPipeline)
                {
                    var bType = Core.GetType(bObj);
                    if (bType == null)
                    {
                        continue;
                    }
                    var processor = (IPageBehavior)Activator.CreateInstance(bType);
                    await processor.InvokeAsync(_requestData, _responseData).ConfigureAwait(false);
                }
            }

            if (ViewExist.GetOrAdd(viewPath, mPath => (System.IO.File.Exists(mPath), TimeSpan.FromSeconds(5))))
            {
                return(_responseData.PageResult);
            }

            _requestData.CreateView = true;
            var path = Path.GetDirectoryName(viewPath);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var content = PageConstructText;

            lock (page)
                System.IO.File.WriteAllText(viewPath, content);
            ViewExist.TryUpdate(viewPath, true, false);
            return(_responseData.PageResult);
        }