Example #1
0
        public async Task ExportFormAsync(int siteId, string directoryPath, int formId)
        {
            var formInfo = await _formRepository.GetFormInfoAsync(siteId, formId);

            var filePath = PathUtils.Combine(directoryPath, formInfo.Id + ".xml");

            var feed = GetEmptyFeed();

            foreach (var tableColumn in _formRepository.TableColumns)
            {
                SetValue(feed.AdditionalElements, tableColumn, formInfo);
            }

            //var styleDirectoryPath = PathUtils.Combine(directoryPath, formInfo.Id.ToString());

            var relatedIdentities = GetRelatedIdentities(formInfo.Id);

            await _pathManager.ExportStylesAsync(siteId, FormUtils.TableNameData, relatedIdentities);

            //await ExportFieldsAsync(formInfo.Id, styleDirectoryPath);

            var dataInfoList = await _dataRepository.GetAllDataInfoListAsync(formInfo);

            foreach (var dataInfo in dataInfoList)
            {
                var entry = GetAtomEntry(dataInfo);
                feed.Entries.Add(entry);
            }
            feed.Save(filePath);

            var plugin = _pluginManager.GetPlugin(PluginId);

            await FileUtils.WriteTextAsync(PathUtils.Combine(directoryPath, VersionFileName), plugin.Version);
        }
Example #2
0
        private async Task DownloadChapterImpl(DownloadChapterRequest task, IProgress <string> progress, CancellationToken cancellationToken)
        {
            progress.Report("Starting...");
            var plugin = pluginManager.GetPlugin(task.Url);
            var images = await plugin.GetImages(task.Url, new Progress <string>(count =>
            {
                progress.Report(count.ToString());
            }), cancellationToken);

            var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            var index = 1;

            foreach (var image in images)
            {
                progress.Report($"Download: {index}/{images.Count()}");
                await downloader.GetFileAsync(image, tempFolder, cancellationToken);

                index++;
            }

            foreach (var format in task.Formats)
            {
                var factory = outputFactory.Create(format);
                factory.Save(tempFolder, task.SaveToFolder);
            }

            progress.Report("Done");
        }
Example #3
0
        public async void HandleEvent(AlbumdownloadEventData eventData)
        {
            if (GlobalContext.Instance.MusicInfos.Count == 0 || GlobalContext.Instance.UIContext.Center_ListViewNF_MusicList.Items.Count == 0)
            {
                MessageBox.Show("你还没有添加歌曲文件!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            var _albumPlugin = _pluginManager.GetPlugin <IPluginAlbumDownloader>(_configMgr.ConfigModel.PluginOptions);
            var _tagPlugin   = _pluginManager.GetPlugin <IPluginAcquireMusicInfo>(_configMgr.ConfigModel.PluginOptions);

            await Task.Run(() =>
            {
                Parallel.ForEach(eventData.MusicInfos, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = _configMgr.ConfigModel.DownloadThreadNumber
                }, (_info) =>
                {
                    if (!_albumPlugin.DownlaodAblumImage(_info, out byte[] _imgData))
                    {
                        GlobalContext.Instance.SetItemStatus(_info.Index, AppConsts.Status_Music_Failed);
                        return;
                    }
                    if (!_tagPlugin.SaveAlbumImage(_info.FilePath, _imgData))
                    {
                        GlobalContext.Instance.SetItemStatus(_info.Index, AppConsts.Status_Music_Failed);
                        return;
                    }

                    GlobalContext.Instance.SetItemStatus(_info.Index, AppConsts.Status_Music_Success);
                });
            });
Example #4
0
        /// <summary>
        /// Erstellt, konfiguriert und initialisiert ein Plugin aus einer Datei.
        /// </summary>
        /// <param name="name">Name des Plugins</param>
        /// <returns>Plugininstanz</returns>
        public virtual IPlugin LoadPlugin(string name)
        {
            var config = manager.GetPlugin(name);

            Type    type   = Type.GetType(config.Type);
            IPlugin result = (IPlugin)factory.Create(type, new Dictionary <string, object> {
                { "Plugins", plugins }
            });

            SetupPlugin(result, config);
            return(result);
        }
Example #5
0
 /// <summary>
 /// Gets the <see cref="IPlugin"/> of the specified type, with the specified name
 /// </summary>
 /// <typeparam name="TPlugin">The type of the <see cref="IPlugin"/> to get</typeparam>
 /// <param name="pluginManager">The extended <see cref="IPluginManager"/></param>
 /// <param name="name">The name of the <see cref="IPlugin"/> to get</param>
 /// <returns>The <see cref="IPlugin"/> of the specified type</returns>
 public static TPlugin?GetPlugin <TPlugin>(this IPluginManager pluginManager, string name)
     where TPlugin : IPlugin
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     return((TPlugin)pluginManager.GetPlugin(name));
 }
Example #6
0
        public IActionResult Enable(Guid id)
        {
            var module = _pluginManager.GetPlugin(id);

            _pluginManager.EnablePlugin(id);
            var moduleName = module.Name;

            var assembly = Assembly.LoadFile($"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll");

            var controllerAssemblyPart = new AssemblyPart(assembly);

            _partManager.ApplicationParts.Add(controllerAssemblyPart);

            MyActionDescriptorChangeProvider.Instance.HasChanged = true;
            MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();

            return(RedirectToAction("Index"));
        }
Example #7
0
 /// <summary>
 /// Attempts to get the <see cref="IPlugin"/> with the specified name
 /// </summary>
 /// <param name="pluginManager">The extended <see cref="IPluginManager"/></param>
 /// <param name="name">The name of the <see cref="IPlugin"/> to get</param>
 /// <param name="plugin">The matched plugin</param>
 /// <returns>A boolean indicating whether or an <see cref="IPlugin"/> with the specified name could be found</returns>
 public static bool TryGetPlugin(this IPluginManager pluginManager, string name, out IPlugin plugin)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     plugin = pluginManager.GetPlugin(name) !;
     return(plugin != null);
 }
Example #8
0
        public void PluginImplementation()
        {
            IPluginManager pluginManager = Runtime.Container.Resolve <IPluginManager>();
            TestPlugin     plugin        = (TestPlugin)pluginManager.GetPlugin("TestPlugin");

            Assert.IsTrue(plugin.IsAlive);

            Assert.IsNull(plugin.Configuration); //No config for test plugin
            Assert.IsNull(plugin.Translations);  //No translations for test plugin
        }
Example #9
0
        public void InitializePlugin(IPluginManager plugManager)
        {
            GlobalContext.Instance.UIContext.Right_PictureBox_AlbumImage.ContextMenu = new ContextMenu(new[]
            {
                new MenuItem("保存专辑图像",
                             ((sender, args) =>
                {
                    if (GlobalContext.Instance.UIContext.Right_PictureBox_AlbumImage.Image != null)
                    {
                        var dlg = new SaveFileDialog();
                        dlg.Title = "保存专辑图像";
                        dlg.Filter = "*.png|*.png|*.bmp|*.bmp|*.jpg|*.jpg";
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            using (var newFile = File.Create(dlg.FileName))
                            {
                                GlobalContext.Instance.UIContext.Right_PictureBox_AlbumImage.Image.Save(newFile, ConvertFormat(Path.GetExtension(dlg.FileName)));
                                newFile.Flush();
                            }
                        }
                    }
                })),
                new MenuItem("替换专辑图像",
                             ((sender, args) =>
                {
                    if (GlobalContext.Instance.UIContext.Center_ListViewNF_MusicList.SelectedItems.Count == 1)
                    {
                        var dlg = new OpenFileDialog();
                        dlg.Title = "准备替换的专辑图像";
                        dlg.Filter = "*.png|*.png|*.bmp|*.bmp|*.jpg|*.jpg";
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            using (var imageFileStream = File.Open(dlg.FileName, FileMode.Open))
                            {
                                using (var ms = new MemoryStream())
                                {
                                    byte[] buffer = new byte[1024 * 16];
                                    int readCount;
                                    while ((readCount = imageFileStream.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        ms.Write(buffer, 0, readCount);
                                    }

                                    var infoPlug = plugManager.GetPlugin <IPluginAcquireMusicInfo>();
                                    if (!infoPlug.SaveAlbumImage(GlobalContext.Instance.MusicInfos[GlobalContext.Instance.UIContext.Center_ListViewNF_MusicList.SelectedItems[0].Index].FilePath, ms.ToArray()))
                                    {
                                        MessageBox.Show("替换专辑图像失败.", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                            }
                        }
                    }
                }))
            });
        }
Example #10
0
        /// <summary>
        /// Gets the <see cref="IPlugin"/> of the specified type
        /// </summary>
        /// <typeparam name="TPlugin">The type of the <see cref="IPlugin"/> to get</typeparam>
        /// <param name="pluginManager">The extended <see cref="IPluginManager"/></param>
        /// <returns>The <see cref="IPlugin"/> of the specified type</returns>
        public static TPlugin GetRequiredPlugin <TPlugin>(this IPluginManager pluginManager)
            where TPlugin : IPlugin
        {
            var plugin = pluginManager.GetPlugin <TPlugin>();

            if (plugin == null)
            {
                throw new NullReferenceException($"Failed to find the required plugin of type '{typeof(TPlugin).FullName}'");
            }
            return(plugin);
        }
Example #11
0
        public IActionResult Enable(Guid id)
        {
            var module = _pluginManager.GetPlugin(id);

            if (!PluginsLoadContexts.Any(module.Name))
            {
                var context = new CollectibleAssemblyLoadContext();

                _pluginManager.EnablePlugin(id);
                var moduleName = module.Name;

                var filePath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll";
                using (var fs = new FileStream(filePath, FileMode.Open))
                {
                    var assembly = context.LoadFromStream(fs);

                    var controllerAssemblyPart = new MyAssemblyPart(assembly);

                    AdditionalReferencePathHolder.AdditionalReferencePaths.Add(filePath);
                    _partManager.ApplicationParts.Add(controllerAssemblyPart);
                }

                MyActionDescriptorChangeProvider.Instance.HasChanged = true;
                MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();

                PluginsLoadContexts.AddPluginContext(module.Name, context);
            }
            else
            {
                var context = PluginsLoadContexts.GetContext(module.Name);
                var controllerAssemblyPart = new AssemblyPart(context.Assemblies.First());
                _partManager.ApplicationParts.Add(controllerAssemblyPart);
                _pluginManager.EnablePlugin(id);

                MyActionDescriptorChangeProvider.Instance.HasChanged = true;
                MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
            }

            return(RedirectToAction("Index"));
        }
Example #12
0
        public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version)
        {
            var plugin = _pluginManager.GetPlugin(pluginId, version);
            if (plugin == null)
            {
                return NotFound();
            }

            _pluginManager.EnablePlugin(plugin);
            return NoContent();
        }
Example #13
0
        private void AssignPlugin(MenuItemDefault menuItem)
        {
            if (menuItem.PluginId != null &&
                !menuItem.HasPluginAssigned)
            {
                IPlugin plugin = _pluginManager.GetPlugin(menuItem.PluginId);

                if (plugin != null)
                {
                    menuItem.Plugin      = plugin;
                    menuItem.Caption     = plugin.Description;
                    menuItem.Image       = plugin.Image;
                    menuItem.ToolTipText = plugin.Description;
                }
            }
        }
Example #14
0
        public void HandleEvent(SingleMusicInfoLoadEventData eventData)
        {
            ListViewNF listView = GlobalContext.Instance.UIContext.Center_ListViewNF_MusicList;

            int selectIndex = listView.SelectedItems[0].Index;

            IPluginAcquireMusicInfo acquire = _plugManager.GetPlugin <IPluginAcquireMusicInfo>();
            MusicInfoModel          info    = GlobalContext.Instance.MusicInfos[selectIndex];
            Stream imgStream = acquire.LoadAlbumImage(info.FilePath);

            // 填充歌曲信息到 UI
            if (imgStream != null)
            {
                GlobalContext.Instance.UIContext.Right_PictureBox_AlbumImage.Image = Image.FromStream(imgStream);
            }
            GlobalContext.Instance.UIContext.Right_TextBox_MusicTitle.Text        = info.Song;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicArtist.Text       = info.Artist;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicAblum.Text        = info.Album;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicBuildInLyric.Text = info.BuildInLyric;
        }
Example #15
0
        public void InitializePlugin(IPluginManager plugManager)
        {
            GlobalContext.Instance.UIContext.AddPluginButton("批量专辑图像导出", async(sender, args) =>
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.Description         = "请选择导出的文件夹";
                dialog.ShowDialog();
                if (!Directory.Exists(dialog.SelectedPath))
                {
                    MessageBox.Show(caption: "提示", text: "请选择有效目录!", icon: MessageBoxIcon.Information, buttons: MessageBoxButtons.OK);
                    return;
                }

                string dirPath = dialog.SelectedPath;

                IEnumerable <MusicInfoModel> exports = GlobalContext.Instance.MusicInfos.Where(z => z.IsAlbumImg);

                var exportList = exports.ToList();
                GlobalContext.Instance.UIContext.Bottom_ProgressBar.Maximum = exportList.Count;
                GlobalContext.Instance.UIContext.DisableTopButtons();
                GlobalContext.Instance.SetBottomStatusText($"正在导出专辑图像");

                await Task.Run(() =>
                {
                    foreach (var item in exportList)
                    {
                        var plugin     = plugManager.GetPlugin <IPluginAcquireMusicInfo>();
                        string srcName = Path.GetFileNameWithoutExtension(item.FilePath);
                        string newName = $"{srcName}.png";
                        Image.FromStream(plugin.LoadAlbumImage(item.FilePath)).Save(Path.Combine(dirPath, newName));
                        GlobalContext.Instance.SetItemStatus(item.Index, "导出成功");
                        GlobalContext.Instance.UIContext.Bottom_ProgressBar.Value++;
                    }
                });

                GlobalContext.Instance.UIContext.EnableTopButtons();
                GlobalContext.Instance.SetBottomStatusText($"专辑图像导出成功,请到 {dirPath} 查看");
            });
        }
 public ILifecycleObject GetOwner(ICommand command)
 {
     return(_pluginManager.GetPlugin("MessageAnnouncer"));
 }
Example #17
0
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            if (context.ActionContext.ActionDescriptor is PageActionDescriptor page)
            {
                var pageViewLocations = PageViewLocations().ToList();
                pageViewLocations.AddRange(viewLocations);
                return(pageViewLocations);

                IEnumerable <string> PageViewLocations()
                {
                    if (page.RelativePath.Contains("/Pages/") && !page.RelativePath.StartsWith("/Pages/", StringComparison.Ordinal))
                    {
                        yield return(page.RelativePath.Substring(0, page.RelativePath.IndexOf("/Pages/", StringComparison.Ordinal))
                                     + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
                    }
                }
            }

            var plugin = _pluginManager.GetPlugin(context.AreaName);

            if (!plugin.Exists)
            {
                return(viewLocations);
            }

            var result = new List <string>();

            var pluginViewsPath = '/' + plugin.SubPath + "/Views";

            result.Add(pluginViewsPath + "/{1}/{0}" + RazorViewEngine.ViewExtension);

            if (!context.ViewName.StartsWith("Components/", StringComparison.Ordinal))
            {
                result.Add(pluginViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
            }
            else
            {
                if (!_memoryCache.TryGetValue(CacheKey, out IEnumerable <string> moduleComponentViewLocations))
                {
                    var enabledIds = _pluginManager.GetFeatures().Where(f => _engineDescriptor
                                                                        .Features.Any(sf => sf.Id == f.Id)).Select(f => f.Plugin.Id).Distinct().ToArray();

                    var enabledExtensions = _pluginManager.GetPlugins()
                                            .Where(e => enabledIds.Contains(e.Id)).ToArray();

                    var sharedViewsPath = "/Views/Shared/{0}" + RazorViewEngine.ViewExtension;

                    moduleComponentViewLocations = _modulesWithComponentViews
                                                   .Where(m => enabledExtensions.Any(e => e.Id == m.Id))
                                                   .Select(m => '/' + m.SubPath + sharedViewsPath);

                    _memoryCache.Set(CacheKey, moduleComponentViewLocations);
                }

                result.AddRange(moduleComponentViewLocations);
            }

            result.AddRange(viewLocations);

            return(result);
        }
Example #18
0
        private string GetTemplatesDirectoryPath()
        {
            var plugin = _pluginManager.GetPlugin(PluginId);

            return(PathUtils.Combine(plugin.WebRootPath, "assets/login/templates"));
        }
 public IPlugin GetPlugin(string pluginId)
 {
     return(_pluginManager.GetPlugin(pluginId));
 }
Example #20
0
        public BlockManager(ISettingsManager settingsManager, IPluginManager pluginManager, IAnalysisRepository analysisRepository, IRuleRepository ruleRepository)
        {
            _settingsManager    = settingsManager;
            _analysisRepository = analysisRepository;
            _ruleRepository     = ruleRepository;

            var plugin = pluginManager.GetPlugin(PluginId);

            if (_areas == null)
            {
                _areas = new List <Area>();

                var locationsEn =
                    PathUtils.Combine(plugin.WebRootPath,
                                      "assets/block/GeoLite2-Country-CSV_20190423/GeoLite2-Country-Locations-en.csv");
                var locationsCn =
                    PathUtils.Combine(plugin.WebRootPath,
                                      "assets/block/GeoLite2-Country-CSV_20190423/GeoLite2-Country-Locations-zh-CN.csv");
                var enCsv = File.ReadAllLines(locationsEn);
                var cnCsv = File.ReadAllLines(locationsCn);

                for (var i = 0; i < enCsv.Length; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var enSplits = enCsv[i].Split(',');
                    var cnSplits = cnCsv[i].Split(',');

                    var geoNameIdEn = TranslateUtils.ToInt(enSplits[0]);
                    var areaEn      = enSplits[5].Trim('"');
                    var geoNameIdCn = TranslateUtils.ToInt(cnSplits[0]);
                    var areaCn      = cnSplits[5].Trim('"');

                    if (geoNameIdEn == geoNameIdCn && !string.IsNullOrEmpty(areaEn) && !string.IsNullOrEmpty(areaCn))
                    {
                        _areas.Add(new Area
                        {
                            GeoNameId = geoNameIdEn,
                            AreaEn    = areaEn,
                            AreaCn    = areaCn
                        });
                    }
                }

                _areas = _areas.OrderBy(x => x.AreaEn).ToList();

                _areas.Insert(0, new Area
                {
                    GeoNameId = LocalGeoNameId,
                    AreaEn    = LocalAreaEn,
                    AreaCn    = LocalAreaCn
                });
            }

            if (_reader == null)
            {
                var filePath = PathUtils.Combine(plugin.WebRootPath,
                                                 "assets/block/GeoLite2-Country_20190423/GeoLite2-Country.mmdb");
                _reader = new DatabaseReader(filePath);
            }
        }
Example #21
0
 public ILifecycleObject GetOwner(ICommand command)
 {
     return(_pluginManager.GetPlugin("WebsiteCommands"));
 }
        private string GetMailTemplatesDirectoryPath()
        {
            var plugin = _pluginManager.GetPlugin(PluginId);

            return(PathUtils.Combine(plugin.WebRootPath, "assets/comments/mail"));
        }