Пример #1
0
        /// <summary>上传成果</summary>
        public void UploadProduct(IndexSubmissionContext context, SubmissionProduct product)
        {
            var file = product.File;

            try
            {
                product.AppData.UploadFileId = context.AppDataService.Upload(product.File, product.CharSet, this.UploadChunkSize);
                var appDataResult = context.AppDataService.Save(product.AppData);
                product.IndexData.DataId = appDataResult.DataId;
                if (product.AppData.GenerateThumbnail && !appDataResult.Thumbnail.IsNullOrEmpty())
                {
                    product.IndexData.Thumbnail = appDataResult.Thumbnail;
                }
                if (product.AppData.GenerateFulltext && !appDataResult.Fulltext.IsNullOrEmpty())
                {
                    product.IndexData.Fulltext = appDataResult.Fulltext;
                }
                var indexSaveRequest = new IndexSaveRequest();
                indexSaveRequest.Replace   = true;
                indexSaveRequest.Metadatas = new MetadataCollection();
                indexSaveRequest.Metadatas.Add(product.IndexData);
                context.IndexerService.Save(indexSaveRequest);
                context.View.RefreshProductStatus(product, "提交成功", string.Empty);
            }
            catch (Exception ex)
            {
                ModuleBootstrapper.Error(this, nameof(UploadProduct), ex);
                context.FailureValues.Enqueue(product);
                context.View.RefreshProductStatus(product, "提交失败", ex.GetFullMessage());
            }
            context.NextProgress();
        }
Пример #2
0
        /// <summary>生成应用数据</summary>
        private AppDataSaveRequest BuildAppData(SubmissionProduct product, Metadata indexData)
        {
            var appData = new AppDataSaveRequest();

            appData.GenerateThumbnail = false;
            appData.GenerateFulltext  = false;
            var fileName = Path.GetFileName(product.File);

            appData.Name = fileName;
            var indexShowType = indexData.ShowType.ToEnum <IndexShowType>(true);

            switch (indexShowType)
            {
            case IndexShowType.Html:
                appData.ContentType = IndexAppContentType.Html;
                break;

            case IndexShowType.Table:
            case IndexShowType.PropertyGrid:
                appData.ContentType = IndexAppContentType.Json;
                if (ExcelUtil.Support(product.Ext))
                {
                    appData.Content = new object[] { ExcelBuilder.BuildTable(product) };
                }
                break;

            case IndexShowType.Chart:
                appData.ContentType = IndexAppContentType.Json;
                if (ExcelUtil.Support(product.Ext))
                {
                    appData.Content = ExcelBuilder.BuildChart(product.File);
                }
                break;

            default:
                appData.ContentType = IndexAppContentType.File;
                appData.StorageType = FileStorageType.FileSystem;
                appData.IsOnline    = true;
                if (indexData.Thumbnail.IsNullOrEmpty())
                {
                    appData.GenerateThumbnail = true;
                }
                if (indexData.Fulltext.IsNullOrEmpty())
                {
                    appData.GenerateFulltext = true;
                }
                break;
            }
            appData.Uploader     = this.Config.ApiService.UserName;
            appData.System       = indexData.System;
            appData.ResourceType = indexData.ResourceType;
            appData.ResourceKey  = indexData.ResourceKey;
            return(appData);
        }
Пример #3
0
        /// <summary>刷新产品状态</summary>
        public void RefreshProductStatus(SubmissionProduct product, string status, string error)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <SubmissionProduct, string, string>(RefreshProductStatus), product, status, error);
                return;
            }
            var lvwItem = product.ListViewItem;

            lvwItem.SubItems[2].Text = status;
            lvwItem.SubItems[3].Text = error;
            lvwItem.EnsureVisible();
        }
Пример #4
0
        /// <summary>生成表</summary>
        public static HtmlTable BuildTable(SubmissionProduct product)
        {
            var match = Regex.Match(product.Options, ExcelTableOptions.Pattern);

            if (!match.Success)
            {
                throw new Exception("Excel表格选项无效!");
            }
            var options = new ExcelTableOptions();

            options.TitleRow       = match.Groups[nameof(options.TitleRow)].Value.ToInt32();
            options.BeginColumnRow = match.Groups[nameof(options.BeginColumnRow)].Value.ToInt32();
            options.EndColumnRow   = match.Groups[nameof(options.EndColumnRow)].Value.ToInt32();
            options.RememberFormat = match.Groups[nameof(options.RememberFormat)].Value.ToInt32() == 1;
            return(BuildTable(product.File, options));
        }
Пример #5
0
        /// <summary>从Excel文件加载成果集合</summary>
        public void LoadProducts(IndexSubmissionContext context)
        {
            context.StartProgress("正在加载Excel文件...", -1);
            var excelFile      = this.Config.Product.ExcelFile;
            var excelSheet     = ExcelUtil.OpenFirst(excelFile);
            var excelTable     = excelSheet.ToDataTable(1, 2);
            var orderColumn    = excelTable.Columns[SubmissionConsts.ST_ProductOrder];
            var encodingColumn = excelTable.Columns[SubmissionConsts.ST_TextEncoding];
            var ptFileColumn   = excelTable.Columns[SubmissionConsts.ST_ProductFile];
            var optionsColumn  = excelTable.Columns[SubmissionConsts.ST_Options];
            var total          = excelTable.Rows.Count;

            context.StartProgress("正在生成成果数据...", total);
            for (int i = 0; i < total; i++)
            {
                var row     = excelTable.Rows[i];
                var product = new SubmissionProduct();
                product.ID = row[orderColumn].ConvertTo <int>();
                if (encodingColumn != null)
                {
                    product.CharSet = row[encodingColumn]?.ToString();
                }
                product.File = row[ptFileColumn].ToString();
                product.Ext  = product.File.GetExtension();
                if (optionsColumn != null)
                {
                    product.Options = row[optionsColumn]?.ToString();
                }
                try
                {
                    product.IndexData = BuildIndexData(excelSheet, row);
                    BuildPageData(product.IndexData);
                    product.AppData = BuildAppData(product, product.IndexData);
                    context.Values.Enqueue(product);
                    context.NextProgress();
                }
                catch (Exception ex)
                {
                    var tag     = ex.Data["IndexTag"]?.ToString() ?? string.Empty;
                    var message = $"序号={product.ID.ToString()},成果文件=[{product.File}]生成索引数据失败[标签={tag}]," + ex.Message;
                    throw new Exception(message, ex);
                }
            }
        }