Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne-KTCSZ committed Aug 4, 2023
1 parent 821b4e9 commit 0960aeb
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 303 deletions.
46 changes: 23 additions & 23 deletions src/EasyFrameWork/DataTransfer/ExcelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@

namespace Easy.DataTransfer
{
public class ExcelGenerator : IDisposable
public sealed class ExcelGenerator : IDisposable
{
private MemoryStream memoryStream;
private SheetData sheetData;
private WorkbookPart workbookpart;
private SpreadsheetDocument spreadsheetDocument;
private readonly MemoryStream _memoryStream;
private readonly SheetData _sheetData;
private readonly WorkbookPart _workbookpart;
private readonly SpreadsheetDocument _spreadsheetDocument;
public ExcelGenerator()
{
memoryStream = new MemoryStream();
spreadsheetDocument = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook);
workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
_memoryStream = new MemoryStream();
_spreadsheetDocument = SpreadsheetDocument.Create(_memoryStream, SpreadsheetDocumentType.Workbook);
_workbookpart = _spreadsheetDocument.AddWorkbookPart();
_workbookpart.Workbook = new Workbook();
var worksheetPart = _workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Sheet1" };
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet() { Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Sheet1" };
sheets.Append(sheet);
sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
_sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
}

public void Dispose()
{
spreadsheetDocument.Dispose();
memoryStream.Close();
memoryStream.Dispose();
_spreadsheetDocument.Dispose();
_memoryStream.Close();
_memoryStream.Dispose();
}
public void AddRow(Action<Row> newrow)
{
Row row = new Row();
sheetData.Append(row);
var row = new Row();
_sheetData.Append(row);
newrow(row);
}
public MemoryStream ToMemoryStream()
{
workbookpart.Workbook.Save();
spreadsheetDocument.Close();
memoryStream.Position = 0;
return new MemoryStream(memoryStream.ToArray());
_workbookpart.Workbook.Save();
_spreadsheetDocument.Dispose();
_memoryStream.Position = 0;
return new MemoryStream(_memoryStream.ToArray());
}
}
public static class OpenXmlExt
{
public static void AppendCell(this Row row, string value)
{
Cell dataCell = new Cell();
var dataCell = new Cell();
row.AppendChild(dataCell);
dataCell.CellValue = new CellValue(value);
dataCell.DataType = new EnumValue<CellValues>(CellValues.String);
Expand Down
10 changes: 5 additions & 5 deletions src/EasyFrameWork/EasyFrameWork.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
<FrameworkReference Include="Microsoft.AspNetCore.App"></FrameworkReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="FastExpressionCompiler" Version="3.3.4" />
<PackageReference Include="IdGen" Version="3.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="System.Reflection.Extensions" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="YamlDotNet" Version="13.0.2" />
<PackageReference Include="YamlDotNet" Version="13.1.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public object Evaluate(string expression, IEnumerable<IGlobalMethodProvider> pro
return result.Value;
}

private AbstractSyntaxTree ParseExpression(string expression)
private static AbstractSyntaxTree ParseExpression(string expression)
{
return new Parser(expression).Parse();
}

private EvaluationResult EvaluateExpression(AbstractSyntaxTree tree, IEnumerable<IGlobalMethodProvider> providers)
private static EvaluationResult EvaluateExpression(AbstractSyntaxTree tree, IEnumerable<IGlobalMethodProvider> providers)
{
var context = new EvaluationContext
{
Expand All @@ -57,7 +57,7 @@ private EvaluationResult EvaluateExpression(AbstractSyntaxTree tree, IEnumerable
return new Interpreter().Evalutate(context);
}

private object Evaluate(IEnumerable<IGlobalMethodProvider> globalMethodProviders, string name, IEnumerable<object> args)
private static object Evaluate(IEnumerable<IGlobalMethodProvider> globalMethodProviders, string name, IEnumerable<object> args)
{
var globalMethodContext = new GlobalMethodContext
{
Expand Down
142 changes: 0 additions & 142 deletions src/EasyFrameWork/Zip/ZipFile.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/EasyFrameWork/Zip/ZipFileInfo.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/EasyFrameWork/Zip/ZipFileInfoCollection.cs

This file was deleted.

26 changes: 13 additions & 13 deletions src/ZKEACMS.SectionWidget/Service/SectionWidgetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Easy.Extend;
using Newtonsoft.Json;
using ZKEACMS.Widget;
using Easy.Zip;
using Easy;
using Microsoft.EntityFrameworkCore;
using System;
Expand Down Expand Up @@ -60,7 +59,7 @@ private Models.SectionWidget InitSectionWidget(Models.SectionWidget widget)

widget.Groups = _sectionGroupService.Get(m => m.SectionWidgetId == widget.ID).OrderBy(m => m.Order).ToList();
var contents = _sectionContentProviderService.Get(m => m.SectionWidgetId == widget.ID);
List<SectionContent> filled = new List<SectionContent>();
var filled = new List<SectionContent>();
contents.AsParallel().Each(content =>
{
var contentFull = _sectionContentProviderService.FillContent(content);
Expand All @@ -78,13 +77,10 @@ private Models.SectionWidget InitSectionWidget(Models.SectionWidget widget)
}
public override void Remove(Models.SectionWidget item)
{
if (item != null)
{
item.Groups.Each(m =>
item?.Groups.Each(m =>
{
_sectionGroupService.Remove(m.ID);
});
}
base.Remove(item);
}

Expand Down Expand Up @@ -145,8 +141,10 @@ public override void InstallWidget(WidgetPackage pack)
var templateFiles = GetTemplateFiles(widget.Template);
pack.Files = pack.Files.Where(m => !templateFiles.Contains(m.FilePath)).ToList();
}
var filePackageInstaller = new FilePackageInstaller(ApplicationContext.HostingEnvironment);
filePackageInstaller.AddtionalUsing = new string[] { "@using ZKEACMS.SectionWidget", "@using ZKEACMS.SectionWidget.Models", "@using ZKEACMS.SectionWidget.Service" };
var filePackageInstaller = new FilePackageInstaller(ApplicationContext.HostingEnvironment)
{
AddtionalUsing = new string[] { "@using ZKEACMS.SectionWidget", "@using ZKEACMS.SectionWidget.Models", "@using ZKEACMS.SectionWidget.Service" }
};
filePackageInstaller.Install(pack);

widget.PageId = null;
Expand All @@ -158,12 +156,14 @@ public override void InstallWidget(WidgetPackage pack)
AddWidget(widget);
}

private HashSet<string> GetTemplateFiles(SectionTemplate template)
private static HashSet<string> GetTemplateFiles(SectionTemplate template)
{
HashSet<string> result = new HashSet<string>();
result.Add($"~/Plugins/ZKEACMS.SectionWidget/Views/{template.TemplateName}.cshtml".FormatWith(template.TemplateName));
result.Add($"~/Plugins/ZKEACMS.SectionWidget/{string.Join('/', template.Thumbnail.ToWebPath())}");
result.Add($"~/Plugins/ZKEACMS.SectionWidget/{string.Join('/', template.ExampleData.ToWebPath())}");
var result = new HashSet<string>
{
$"~/Plugins/ZKEACMS.SectionWidget/Views/{template.TemplateName}.cshtml".FormatWith(template.TemplateName),
$"~/Plugins/ZKEACMS.SectionWidget/{string.Join('/', template.Thumbnail.ToWebPath())}",
$"~/Plugins/ZKEACMS.SectionWidget/{string.Join('/', template.ExampleData.ToWebPath())}"
};
return result;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZKEACMS.WebHost/ZKEACMS.WebHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<RazorCompileOnPublish>true</RazorCompileOnPublish>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.9" />
<ProjectReference Include="..\EasyFrameWork\EasyFrameWork.csproj" />
<ProjectReference Include="..\ZKEACMS\ZKEACMS.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 0960aeb

Please sign in to comment.