1
This commit is contained in:
44
iMES.WebApi/Helper/Appsettings.cs
Normal file
44
iMES.WebApi/Helper/Appsettings.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using System;
|
||||
|
||||
namespace iMES.Bi
|
||||
{
|
||||
/// <summary>
|
||||
/// appsettings.json操作类
|
||||
/// </summary>
|
||||
public class Appsettings
|
||||
{
|
||||
static IConfiguration Configuration { get; set; }
|
||||
static Appsettings()
|
||||
{
|
||||
//ReloadOnChange = true 当appsettings.json被修改时重新加载
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })//请注意要把当前appsetting.json 文件->右键->属性->复制到输出目录->始终复制
|
||||
.Build();
|
||||
}
|
||||
/// <summary>
|
||||
/// 封装要操作的字符
|
||||
/// </summary>
|
||||
/// <param name="sections"></param>
|
||||
/// <returns></returns>
|
||||
public static string app(params string[] sections)
|
||||
{
|
||||
try
|
||||
{
|
||||
var val = string.Empty;
|
||||
for (int i = 0; i < sections.Length; i++)
|
||||
{
|
||||
val += sections[i] + ":";
|
||||
}
|
||||
|
||||
return Configuration[val.TrimEnd(':')];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
42
iMES.WebApi/Helper/BackService.cs
Normal file
42
iMES.WebApi/Helper/BackService.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using iMES.Bi.API;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace iMES.Bi
|
||||
{
|
||||
|
||||
public class BackService : BackgroundService
|
||||
{
|
||||
public ILogger _logger;
|
||||
public BackService(ILogger<BackService> logger)
|
||||
{
|
||||
this._logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
Random rd = new Random();
|
||||
string strUrl = Appsettings.app("APITX");
|
||||
HttpWebResponse ResponseDataXS = CommonHelp.CreateHttpResponse(strUrl, null, 0, "", null, "GET");
|
||||
string Returndata = new StreamReader(ResponseDataXS.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
||||
await Task.Delay(5000, stoppingToken); //启动后5秒执行一次 (用于测试)
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommonHelp.WriteLOG(ex.Message.ToString());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
iMES.WebApi/Helper/ControHelp.cs
Normal file
47
iMES.WebApi/Helper/ControHelp.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using iMES.Bi.API;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace iMES.Bi
|
||||
{
|
||||
public class ControHelp
|
||||
{
|
||||
public static string CovJson(Msg_Result Model)
|
||||
{
|
||||
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
|
||||
timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
string Result = JsonConvert.SerializeObject(Model, Formatting.Indented, timeConverter).Replace("null", "\"\"");
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
public class NPOIMemoryStream : MemoryStream
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取流是否关闭
|
||||
/// </summary>
|
||||
public bool IsColse
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public NPOIMemoryStream(bool colse = false)
|
||||
{
|
||||
IsColse = colse;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
if (IsColse)
|
||||
{
|
||||
base.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
17
iMES.WebApi/Helper/HttpHelp.cs
Normal file
17
iMES.WebApi/Helper/HttpHelp.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace iMES.Bi
|
||||
{
|
||||
public class HttpHelp
|
||||
{
|
||||
|
||||
public static string getIP()
|
||||
{
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
52
iMES.WebApi/Helper/UploadHelp.cs
Normal file
52
iMES.WebApi/Helper/UploadHelp.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace iMES.Bi
|
||||
{
|
||||
public class UploadHelp
|
||||
{
|
||||
|
||||
public static string GetFileType(string extname)
|
||||
{
|
||||
switch (extname.ToLower())
|
||||
{
|
||||
case "gif":
|
||||
case "jpg":
|
||||
case "bmp":
|
||||
case "jpeg":
|
||||
case "tiff":
|
||||
case "png":
|
||||
return "pic";
|
||||
default:
|
||||
return extname.ToLower().TrimStart('.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成指定长度的随机码。
|
||||
/// </summary>
|
||||
public static string CreateRandomCode(int length)
|
||||
{
|
||||
string[] codes = new string[36] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
|
||||
StringBuilder randomCode = new StringBuilder();
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
randomCode.Append(codes[rand.Next(codes.Length)]);
|
||||
}
|
||||
return randomCode.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示图片的上传结果。
|
||||
/// </summary>
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user