init: 导入项目到 meswork Gitea
This commit is contained in:
110
Common/02WebApiCall/02_02WebApiCallPLC.csproj
Normal file
110
Common/02WebApiCall/02_02WebApiCallPLC.csproj
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{3E6D1DD5-01C9-435F-9941-61F906CE35BB}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>WebApiCall</RootNamespace>
|
||||
<AssemblyName>02WebApiCall</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\dll\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="WebApiCall\CallWebApi.cs" />
|
||||
<Compile Include="WebApiCall\CallWebApi.SQLCommon.cs" />
|
||||
<Compile Include="WebApiCall\CallWebApiDT.cs" />
|
||||
<Compile Include="WebApiCall\CallWebApiDT.SQLCommon.cs" />
|
||||
<Compile Include="WebApiCall\Opc.SaveData.cs" />
|
||||
<Compile Include="WebApiCall\ReadPLC.cs" />
|
||||
<Compile Include="WebApiCall\ReadWritePLCMesRead.cs" />
|
||||
<Compile Include="WebApiCall\WritePLC.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WebApiCall\Opc.Demo.cs" />
|
||||
<Compile Include="WebApiCall\WbApi.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\00-1Json8.3\Json8.3\00-0Json8.3.1.csproj">
|
||||
<Project>{1a10fdb2-1a6a-44a8-ab4d-33387563247e}</Project>
|
||||
<Name>00-0Json8.3.1</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\01DoWhatPlc\01_01DoWhatPlc.csproj">
|
||||
<Project>{0d1af432-439a-4920-8692-43ae139f5530}</Project>
|
||||
<Name>01_01DoWhatPlc</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
25
Common/02WebApiCall/02_02WebApiCallPLC.sln
Normal file
25
Common/02WebApiCall/02_02WebApiCallPLC.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32901.82
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02_02WebApiCallPLC", "02_02WebApiCallPLC.csproj", "{3E6D1DD5-01C9-435F-9941-61F906CE35BB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3E6D1DD5-01C9-435F-9941-61F906CE35BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3E6D1DD5-01C9-435F-9941-61F906CE35BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3E6D1DD5-01C9-435F-9941-61F906CE35BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3E6D1DD5-01C9-435F-9941-61F906CE35BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C034F50A-F3DF-47DC-ADB2-3724C1B74818}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
11
Common/02WebApiCall/App.config
Normal file
11
Common/02WebApiCall/App.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
|
||||
<add key="Url_WebApi" value="http://localhost:41181"/>
|
||||
|
||||
</appSettings>
|
||||
</configuration>
|
||||
48
Common/02WebApiCall/Form1.Designer.cs
generated
Normal file
48
Common/02WebApiCall/Form1.Designer.cs
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
namespace WebApiCall
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 525);
|
||||
this.Name = "Form1";
|
||||
this.Text = "Form1";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
20
Common/02WebApiCall/Form1.cs
Normal file
20
Common/02WebApiCall/Form1.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WebApiCall
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
Common/02WebApiCall/Form1.resx
Normal file
120
Common/02WebApiCall/Form1.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
22
Common/02WebApiCall/Program.cs
Normal file
22
Common/02WebApiCall/Program.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WebApiCall
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Common/02WebApiCall/Properties/AssemblyInfo.cs
Normal file
36
Common/02WebApiCall/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("WebApiCall")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WebApiCall")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("3e6d1dd5-01c9-435f-9941-61f906ce35bb")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
63
Common/02WebApiCall/Properties/Resources.Designer.cs
generated
Normal file
63
Common/02WebApiCall/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WebApiCall.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WebApiCall.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Common/02WebApiCall/Properties/Resources.resx
Normal file
117
Common/02WebApiCall/Properties/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
26
Common/02WebApiCall/Properties/Settings.Designer.cs
generated
Normal file
26
Common/02WebApiCall/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WebApiCall.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Common/02WebApiCall/Properties/Settings.settings
Normal file
7
Common/02WebApiCall/Properties/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
132
Common/02WebApiCall/WebApiCall/CallWebApi.SQLCommon.cs
Normal file
132
Common/02WebApiCall/WebApiCall/CallWebApi.SQLCommon.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class DataAccess
|
||||
{
|
||||
|
||||
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery1";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", JsonConvert.SerializeObject(sql));
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "POST";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteOutNum";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
count = new CallWebApi().InvokeWebapiInt(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataset";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
ds = new CallWebApi().InvokeWebapiDataSet(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataReader";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dr = new CallWebApi().InvokeWebapiSqlDataReader(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSql";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSqlDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
448
Common/02WebApiCall/WebApiCall/CallWebApi.cs
Normal file
448
Common/02WebApiCall/WebApiCall/CallWebApi.cs
Normal file
@@ -0,0 +1,448 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class OutGUID
|
||||
{
|
||||
/// <summary>
|
||||
/// 2021.10.25.LLX
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Get_CS_GUID()
|
||||
{
|
||||
return Guid.NewGuid().ToString().ToUpper();
|
||||
}
|
||||
|
||||
}
|
||||
public partial class CallWebApi
|
||||
{
|
||||
public string InvokeWebapiString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return result;
|
||||
}
|
||||
public DataTable InvokeWebapiDataTable(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
DataTable dt = new DataTable();
|
||||
dt = JsonConvert.DeserializeObject<DataTable>(task.Result);
|
||||
return dt;
|
||||
}
|
||||
public DataSet InvokeWebapiDataSet(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
ds = JsonConvert.DeserializeObject<DataSet>(task.Result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return ds;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public SqlDataReader InvokeWebapiSqlDataReader(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
SqlDataReader dr;
|
||||
dr = JsonConvert.DeserializeObject<SqlDataReader>(task.Result);
|
||||
return dr;
|
||||
}
|
||||
|
||||
public bool InvokeWebapiBool(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToBoolean(result);
|
||||
}
|
||||
public int InvokeWebapiInt(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
#region WinFrom调用webapi接口通用方法
|
||||
public EngineValue InvokeWebapiEngineValue(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rt = JsonConvert.DeserializeObject<EngineValue>(task.Result);
|
||||
return rt;
|
||||
}
|
||||
public ReturnValueObject InvokeWebapiReturnValueObject(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rs = JsonConvert.DeserializeObject<ReturnValueString>(task.Result);
|
||||
if (rs == null) return null;
|
||||
var ro = rs.ReturnValueToObject();
|
||||
return ro;
|
||||
}
|
||||
public List<ReturnValueObject> InvokeWebapiReturnValueObjectList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rsList = JsonConvert.DeserializeObject< List < ReturnValueString > >(task.Result);
|
||||
List<ReturnValueObject> roList = new List<ReturnValueObject>();
|
||||
foreach(var rs in rsList)
|
||||
{
|
||||
var ro = rs.ReturnValueToObject();
|
||||
roList.Add(ro);
|
||||
}
|
||||
|
||||
return roList;
|
||||
}
|
||||
public void InvokeWebapiWritePLC(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
|
||||
}
|
||||
//public List<ReturnValueObject> InvokeWebapiReturnValueObjectList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
//{
|
||||
// string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
// Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
// //反序列化Json
|
||||
// var rtList = JsonConvert.DeserializeObject<List<ReturnValueString>>(task.Result);
|
||||
|
||||
// List<ReturnValueObject> roList = new List<ReturnValueObject>();
|
||||
// foreach(var rt in rtList)
|
||||
// {
|
||||
// var ro = rt.ReturnValueToObject();
|
||||
// roList.Add(ro);
|
||||
// }
|
||||
// return roList;
|
||||
//}
|
||||
|
||||
public HashtableList InvokeWebapiHashtableList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<HashtableList>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new HashtableList();
|
||||
}
|
||||
|
||||
}
|
||||
public List<TagIDTagFormat> InvokeWebapiListTagFormat(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics=null)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<List<TagIDTagFormat>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
public QualityDataSaveList InvokeWebapiQualityDataSaveList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<QualityDataSaveList>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
public List<string> InvokeWebapiListString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<List<string>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
catch(Exception err)
|
||||
{
|
||||
return new List<string>();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ConcurrentDictionary<string, TagFormat> InvokeWebapiConcurrentDictionaryTagFormat(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics = null)
|
||||
{
|
||||
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
//反序列化Json
|
||||
var rtList = JsonConvert.DeserializeObject<ConcurrentDictionary<string, TagFormat>>(task.Result);
|
||||
|
||||
return rtList;
|
||||
}
|
||||
|
||||
private async Task<string> InvokeWebapi(string url, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string result = string.Empty;
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("authorization", "Basic YWRtaW46cGFzc3dvcmRAcmljZW50LmNvbQ==");//basic编码后授权码
|
||||
client.BaseAddress = new Uri(url);
|
||||
|
||||
client.Timeout = TimeSpan.FromSeconds(510);
|
||||
|
||||
if (type.ToLower() == "put")
|
||||
{
|
||||
HttpResponseMessage response;
|
||||
//包含复杂类型
|
||||
if (dics.Keys.Contains("input"))
|
||||
{
|
||||
if (dics != null)
|
||||
{
|
||||
foreach (var item in dics.Keys)
|
||||
{
|
||||
api = api.Replace(item, dics[item]).Replace("{", "").Replace("}", "");
|
||||
}
|
||||
}
|
||||
var contents = new StringContent(dics["input"], Encoding.UTF8, "application/json");
|
||||
response = client.PutAsync(api, contents).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
response = client.PutAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "post")
|
||||
{
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "get")
|
||||
{
|
||||
HttpResponseMessage response = client.GetAsync(api).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
public static string Url_WebApi = System.Configuration.ConfigurationManager.AppSettings["Url_WebApi"];
|
||||
private string GetUrlWebApi(string controlStr,string actionStr,Dictionary<string,string> dic=null)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//"+actionStr;
|
||||
//string url = Url_WebApi + "//api//" + controlStr+"1" + "//"+actionStr;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
if(dic!=null)
|
||||
{
|
||||
foreach (var item in dic)
|
||||
{
|
||||
string item_Value = Utils.UrlEncode(item.Value);
|
||||
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item_Value);
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
url = url + "//?" + builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
private string GetUrlWebApi(string controlStr, string actionStr)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
#region 获取APP升级版本信息
|
||||
//public List<Versions> GetVersList()
|
||||
//{
|
||||
// string api = "";
|
||||
// List<Versions> list = new List<Versions>();
|
||||
// string url = "http://域名/api/Config/GetVersionList?ClientType=android";
|
||||
// Dictionary<string, string> dics = new Dictionary<string, string>();
|
||||
// Task<string> task = InvokeWebapi(url, api, "GET", dics);
|
||||
// string result = task.Result;
|
||||
// #region 解析结果集
|
||||
// if (result != null)
|
||||
// {
|
||||
// JObject jsonObj = null;
|
||||
// jsonObj = JObject.Parse(result);
|
||||
// DataInfo info = new DataInfo();
|
||||
// info.statusCode = Convert.ToInt32(jsonObj["statusCode"]);
|
||||
// info.message = jsonObj["message"].ToString();
|
||||
// if (info.statusCode == 1)
|
||||
// {
|
||||
// JArray jlist = JArray.Parse(jsonObj["data"].ToString());
|
||||
// for (int i = 0; i < jlist.Count; ++i) //遍历JArray
|
||||
// {
|
||||
// Versions ver = new Versions();
|
||||
// JObject tempo = JObject.Parse(jlist[i].ToString());
|
||||
// ver.VersionId = Convert.ToInt32(tempo["versionId"]);
|
||||
// ver.VersionNumber = tempo["versionNumber"].ToString();
|
||||
// ver.Description = tempo["description"].ToString();
|
||||
// ver.FilePath = tempo["filePath"].ToString();
|
||||
// ver.ClientType = tempo["clientType"].ToString();
|
||||
// ver.IsForce = Convert.ToInt32(tempo["isForce"]);
|
||||
// list.Add(ver);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
// return list;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Post
|
||||
{
|
||||
public static string Postring(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Proxy = null;
|
||||
|
||||
req.KeepAlive = false;
|
||||
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Postring1(string url, string token, Dictionary<string, string> dic)
|
||||
{
|
||||
string results = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Headers.Add("Authorization", "Bearer " + token);
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
try
|
||||
{
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
results = reader.ReadToEnd();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return e.Message;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
188
Common/02WebApiCall/WebApiCall/CallWebApiDT.SQLCommon.cs
Normal file
188
Common/02WebApiCall/WebApiCall/CallWebApiDT.SQLCommon.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApiDT
|
||||
{
|
||||
public class PLC
|
||||
{
|
||||
public static void WritePLC(string tagID, string tagValue)
|
||||
{
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
dic.Add("tagValue", tagValue);
|
||||
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
public static string ReadPLC(string tagID)
|
||||
{
|
||||
string tagValue;
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
tagValue = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return tagValue;
|
||||
}
|
||||
}
|
||||
public class DataAccess
|
||||
{
|
||||
|
||||
|
||||
public static void GetProjectCodeAndProjectName(out string ProjectCode,out string ProjectName)
|
||||
{
|
||||
ProjectCode = "";
|
||||
ProjectName = "";
|
||||
//return PP.ProjectCode + "|" + PP.ProjectName;
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "GetProjectCodeAndProjectName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
string[] strList = str.Split('|');
|
||||
try
|
||||
{
|
||||
ProjectCode = strList[0];
|
||||
ProjectName = strList[1];
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery1";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", JsonConvert.SerializeObject(sql));
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteNonQuery";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteOutNum";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
|
||||
count = new CallWebApi().InvokeWebapiInt(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataset";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
|
||||
dic.Add("sql", sql);
|
||||
ds = new CallWebApi().InvokeWebapiDataSet(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteDataReader";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dr = new CallWebApi().InvokeWebapiSqlDataReader(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSql";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
errorMessage = "";
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "SQLCommon";
|
||||
string actionStr = "ExecuteSqlDataTable";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("sql", sql);
|
||||
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
407
Common/02WebApiCall/WebApiCall/CallWebApiDT.cs
Normal file
407
Common/02WebApiCall/WebApiCall/CallWebApiDT.cs
Normal file
@@ -0,0 +1,407 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApiDT
|
||||
{
|
||||
public class OutGUID
|
||||
{
|
||||
/// <summary>
|
||||
/// 2021.10.25.LLX
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Get_CS_GUID()
|
||||
{
|
||||
return Guid.NewGuid().ToString().ToUpper();
|
||||
}
|
||||
|
||||
}
|
||||
public class CallWebApi
|
||||
{
|
||||
|
||||
#region WinFrom调用webapi接口通用方法
|
||||
|
||||
public ReturnResult InvokeWebapiReturnResult(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
return JsonConvert.DeserializeObject<ReturnResult>(task.Result);
|
||||
}
|
||||
|
||||
public DataTable InvokeWebapiDataTable(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
DataTable dt = new DataTable();
|
||||
dt = JsonConvert.DeserializeObject<DataTable>(task.Result);
|
||||
return dt;
|
||||
}
|
||||
public DataSet InvokeWebapiDataSet(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
ds = JsonConvert.DeserializeObject<DataSet>(task.Result);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
public SqlDataReader InvokeWebapiSqlDataReader(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
SqlDataReader dr;
|
||||
dr = JsonConvert.DeserializeObject<SqlDataReader>(task.Result);
|
||||
return dr;
|
||||
}
|
||||
|
||||
public Dictionary<String, String> InvokeWebapiDictionary(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<Dictionary<String, String>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public List<String> InvokeWebapiList(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<String>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="controlStr"></param>
|
||||
/// <param name="actionStr"></param>
|
||||
/// <param name="api"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="dics"></param>
|
||||
/// <returns>List<double[]> </returns>
|
||||
public List<double[]> InvokeWebapiListDoubleArray(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<double[]>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="controlStr"></param>
|
||||
/// <param name="actionStr"></param>
|
||||
/// <param name="api"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="dics"></param>
|
||||
/// <returns>List<List<double>></returns>
|
||||
public List<List<double>> InvokeWebapiListListDouble(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<List<List<double>>>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public double[] InvokeWebapiDoubleArray(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
var result = task.Result;
|
||||
//反序列化Json
|
||||
var dc = JsonConvert.DeserializeObject<double[]>(task.Result);
|
||||
return dc;
|
||||
}
|
||||
public string InvokeWebapiString(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = "";
|
||||
try
|
||||
{
|
||||
result = task.Result;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public bool InvokeWebapiBool(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToBoolean(result);
|
||||
}
|
||||
public int InvokeWebapiInt(string controlStr, string actionStr, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string url = GetUrlWebApi(controlStr, actionStr, dics);
|
||||
Task<string> task = InvokeWebapi(url, api, type, dics);
|
||||
string result = task.Result;
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> InvokeWebapi(string url, string api, string type, Dictionary<string, string> dics)
|
||||
{
|
||||
string result = string.Empty;
|
||||
HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("authorization", "Basic YWRtaW46cGFzc3dvcmRAcmljZW50LmNvbQ==");//basic编码后授权码
|
||||
client.BaseAddress = new Uri(url);
|
||||
|
||||
client.Timeout = TimeSpan.FromSeconds(510);
|
||||
|
||||
if (type.ToLower() == "put")
|
||||
{
|
||||
HttpResponseMessage response;
|
||||
//包含复杂类型
|
||||
if (dics.Keys.Contains("input"))
|
||||
{
|
||||
if (dics != null)
|
||||
{
|
||||
foreach (var item in dics.Keys)
|
||||
{
|
||||
api = api.Replace(item, dics[item]).Replace("{", "").Replace("}", "");
|
||||
}
|
||||
}
|
||||
var contents = new StringContent(dics["input"], Encoding.UTF8, "application/json");
|
||||
response = client.PutAsync(api, contents).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
response = client.PutAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "post")
|
||||
{
|
||||
var content = new FormUrlEncodedContent(dics);
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(api, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (type.ToLower() == "get")
|
||||
{
|
||||
HttpResponseMessage response = client.GetAsync(api).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
public static string Url_WebApi = System.Configuration.ConfigurationManager.AppSettings["Url_WebApiDT"];
|
||||
private string GetUrlWebApi(string controlStr, string actionStr, Dictionary<string, string> dic)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
//sql = Utils.UrlEncode(sql);
|
||||
|
||||
foreach (var item in dic)
|
||||
{
|
||||
|
||||
string item_Value = Utils.UrlEncode(item.Value);
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item_Value);
|
||||
i++;
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
url = url + "//?" + builder.ToString();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
private string GetUrlWebApi(string controlStr, string actionStr)
|
||||
{
|
||||
string url = Url_WebApi + "//api//" + controlStr + "//" + actionStr;
|
||||
|
||||
return url;
|
||||
}
|
||||
#region 获取APP升级版本信息
|
||||
//public List<Versions> GetVersList()
|
||||
//{
|
||||
// string api = "";
|
||||
// List<Versions> list = new List<Versions>();
|
||||
// string url = "http://域名/api/Config/GetVersionList?ClientType=android";
|
||||
// Dictionary<string, string> dics = new Dictionary<string, string>();
|
||||
// Task<string> task = InvokeWebapi(url, api, "GET", dics);
|
||||
// string result = task.Result;
|
||||
// #region 解析结果集
|
||||
// if (result != null)
|
||||
// {
|
||||
// JObject jsonObj = null;
|
||||
// jsonObj = JObject.Parse(result);
|
||||
// DataInfo info = new DataInfo();
|
||||
// info.statusCode = Convert.ToInt32(jsonObj["statusCode"]);
|
||||
// info.message = jsonObj["message"].ToString();
|
||||
// if (info.statusCode == 1)
|
||||
// {
|
||||
// JArray jlist = JArray.Parse(jsonObj["data"].ToString());
|
||||
// for (int i = 0; i < jlist.Count; ++i) //遍历JArray
|
||||
// {
|
||||
// Versions ver = new Versions();
|
||||
// JObject tempo = JObject.Parse(jlist[i].ToString());
|
||||
// ver.VersionId = Convert.ToInt32(tempo["versionId"]);
|
||||
// ver.VersionNumber = tempo["versionNumber"].ToString();
|
||||
// ver.Description = tempo["description"].ToString();
|
||||
// ver.FilePath = tempo["filePath"].ToString();
|
||||
// ver.ClientType = tempo["clientType"].ToString();
|
||||
// ver.IsForce = Convert.ToInt32(tempo["isForce"]);
|
||||
// list.Add(ver);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
// return list;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Post
|
||||
{
|
||||
public static string Postring(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Proxy = null;
|
||||
|
||||
req.KeepAlive = false;
|
||||
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Postring1(string url, string token, Dictionary<string, string> dic)
|
||||
{
|
||||
string results = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Headers.Add("Authorization", "Bearer " + token);
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
try
|
||||
{
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
results = reader.ReadToEnd();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return e.Message;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
123
Common/02WebApiCall/WebApiCall/Opc.Demo.cs
Normal file
123
Common/02WebApiCall/WebApiCall/Opc.Demo.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using DoWhatPlc;
|
||||
using DtWebApi;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class OpcDemo
|
||||
{
|
||||
public static HashtableList GetHashtableList()
|
||||
{
|
||||
try
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "GetHashtableList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
var rc = new CallWebApi().InvokeWebapiHashtableList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
return new HashtableList();
|
||||
|
||||
}
|
||||
}
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupMonitor(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupMonitor";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupData_Qd(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData_Qd";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static List<TagIDTagFormat> ReadPLC_GroupData(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiListTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<string> Get_opNameList()
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_opNameList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiListString(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
public static List<string> Get_ipList()
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_ipList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiListString(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static ConcurrentDictionary<string, TagFormat> Get_TagAdrListTagFormat(string ip, string group)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Get_TagAdrListTagFormat";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("ip", ip);
|
||||
dic.Add("group", group);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static ConcurrentDictionary<string, TagFormat> ReadTagValue_tagAdrListTagFormat(string readWhat, string opOrIp)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadTagValue_tagAdrListTagFormat";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("readWhat", readWhat);
|
||||
dic.Add("opOrIp", opOrIp);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
43
Common/02WebApiCall/WebApiCall/Opc.SaveData.cs
Normal file
43
Common/02WebApiCall/WebApiCall/Opc.SaveData.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using DoWhatPlc;
|
||||
using DtWebApi;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public class SaveData
|
||||
{
|
||||
|
||||
public static QualityDataSaveList ReadPLC_Sync_DataList_MesRead(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_Sync_DataList_MesRead";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
var rc = new CallWebApi().InvokeWebapiQualityDataSaveList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static object SaveQualityData_ByOnlyDataGroup(string opName, string tagID)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "SaveQualityData_ByOnlyDataGroup";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
dic.Add("tagID", tagID);
|
||||
var rc = new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
//SaveQualityData_ByOnlyDataGroup(string opName, string tagID)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
181
Common/02WebApiCall/WebApiCall/ReadPLC.cs
Normal file
181
Common/02WebApiCall/WebApiCall/ReadPLC.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
//http://localhost:41186//api//PLC1//Write_TagValueByTagTypeName//?cmd=ConfirmOkGo&opName=OP020&tagValue=True
|
||||
//http://localhost:41186//api//PLC1//Read_TagValueByTagTypeName//?cmd=PalletInfo&opName=OP020
|
||||
public static object Read_TagValueByTagTypeName(string cmd, string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Read_TagValueByTagTypeName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("cmd", cmd);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
if(rc.ValueType=="bool" || rc.ValueType == "boolean")
|
||||
{
|
||||
return Convert.ToInt32(rc.TagValue);
|
||||
}
|
||||
return rc.TagValue;
|
||||
}
|
||||
|
||||
public static object ReadPLC(string tagID)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
return rc.TagValue;
|
||||
}
|
||||
public static object ReadPLC(string tagTypeCodeID, string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
return rc.TagValue;
|
||||
}
|
||||
public static byte[] ReadByteData_Op(string OpName, string Adr, ushort Length)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadByteData_Op";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", OpName);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("Length", Length.ToString());
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return JsonToByte(rc.TagValue.ToString());
|
||||
}
|
||||
|
||||
public static byte[] ReadByteData_Ip(string Ip, string Adr, ushort Length)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadByteData_Ip";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("Ip", Ip);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("Length", Length.ToString());
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return JsonToByte(rc.TagValue.ToString());
|
||||
}
|
||||
|
||||
public static object WritePLC_Bytes_Op(string OpName, string Adr, byte[] bytes)
|
||||
{
|
||||
string bytesStr = ByteToJson(bytes);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_Bytes_Op";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", OpName);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("bytes", bytesStr);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return rc.TagValue;
|
||||
}
|
||||
|
||||
public static object WritePLC_Bytes_Ip(string Ip, string Adr, byte[] bytes)
|
||||
{
|
||||
string bytesStr = ByteToJson(bytes);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_Bytes_Ip";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("OpName", Ip);
|
||||
dic.Add("Adr", Adr);
|
||||
dic.Add("bytes", bytesStr);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
return rc.TagValue;
|
||||
}
|
||||
static public string ByteToJson(byte[] bytes)
|
||||
{
|
||||
string convertJson = System.Text.Encoding.UTF8.GetString(bytes);
|
||||
return convertJson;
|
||||
}
|
||||
|
||||
static public byte[] JsonToByte(string strjson)
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strjson);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
public static List<ReturnValueObject> ReadPLC(List<string> tagTypeCodeIDList, List<string> opNameList)
|
||||
{
|
||||
string tagTypeCodeID = JsonConvert.SerializeObject(tagTypeCodeIDList);
|
||||
string opName = JsonConvert.SerializeObject(opNameList);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_TagTypeCodeIDList";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObjectList(controlStr, actionStr, api, type, dic);
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static List<ReturnValueObject> ReadPLC_GroupData(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_GroupData";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
|
||||
return new CallWebApi().InvokeWebapiReturnValueObjectList(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
public static ConcurrentDictionary<string, TagFormat> ReadPLC_OpName(string opName)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "ReadPLC_OpName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("opName", opName);
|
||||
|
||||
return new CallWebApi().InvokeWebapiConcurrentDictionaryTagFormat(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Common/02WebApiCall/WebApiCall/ReadWritePLCMesRead.cs
Normal file
67
Common/02WebApiCall/WebApiCall/ReadWritePLCMesRead.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
/// <summary>
|
||||
///<add key="9" value="EngineTypeID"/>
|
||||
///<add key = "10" value="EngineID"/>
|
||||
///<add key = "11" value="EngineType"/>
|
||||
///<add key = "80" value="PartPalletCode"/>
|
||||
///<add key = "22" value="PalletInfo"/>
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="EngineTypeID">9</param>
|
||||
/// <param name="EngineType">11</param>
|
||||
/// <param name="EngineID">10</param>
|
||||
/// <param name="PartPallet_Code">80</param>
|
||||
public static void GetEngineTypeFromPLC(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out int PartPallet_Code)
|
||||
{
|
||||
EngineTypeID = 0;
|
||||
EngineID = "-2";
|
||||
EngineType = "-2";
|
||||
PartPallet_Code = 0;
|
||||
|
||||
List<string> tagTypeCodeIDList = new List<string>();
|
||||
List<string> opNameList = new List<string>();
|
||||
tagTypeCodeIDList.Add("9");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("10");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("11");
|
||||
opNameList.Add(opName);
|
||||
tagTypeCodeIDList.Add("80");
|
||||
opNameList.Add(opName);
|
||||
List<ReturnValueObject> roList = ReadPLC(tagTypeCodeIDList, opNameList);
|
||||
foreach(var item in roList)
|
||||
{
|
||||
switch(item.TagTypeCodeID)
|
||||
{
|
||||
case "9":
|
||||
EngineTypeID = Convert.ToInt32( item.TagValue);
|
||||
break;
|
||||
case "10":
|
||||
EngineID = item.TagValue.ToString();
|
||||
break;
|
||||
case "11":
|
||||
EngineType = item.TagValue.ToString();
|
||||
break;
|
||||
case "80":
|
||||
PartPallet_Code = Convert.ToInt32(item.TagValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Common/02WebApiCall/WebApiCall/Utils.cs
Normal file
82
Common/02WebApiCall/WebApiCall/Utils.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Text;
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
public static string UrlEncode(this string str)
|
||||
{
|
||||
var encoding = UTF8Encoding.UTF8;
|
||||
byte[] bytes = encoding.GetBytes(str);
|
||||
int IsSafe = 0;
|
||||
int NoSafe = 0;
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
char ch = (char)bytes[i];
|
||||
if (ch == ' ')
|
||||
{
|
||||
IsSafe++;
|
||||
}
|
||||
else if (!IsSafeChar(ch))
|
||||
{
|
||||
NoSafe ++;
|
||||
}
|
||||
}
|
||||
if (IsSafe== 0 && NoSafe == 0)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
byte[] buffer = new byte[bytes.Length + (NoSafe * 2)];
|
||||
int num1 = 0;
|
||||
for (int j = 0; j < bytes.Length; j++)
|
||||
{
|
||||
byte num2 = bytes[j];
|
||||
char ch2 = (char)num2;
|
||||
if (IsSafeChar(ch2))
|
||||
{
|
||||
buffer[num1++] = num2;
|
||||
}
|
||||
else if (ch2 == ' ')
|
||||
{
|
||||
buffer[num1++] = 0x2B;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[num1++] = 0x25;
|
||||
buffer[num1++] = (byte)IntToHex((num2 >> 4) & 15);
|
||||
buffer[num1++] = (byte)IntToHex(num2 & 15);
|
||||
}
|
||||
}
|
||||
return encoding.GetString(buffer);
|
||||
}
|
||||
|
||||
private static bool IsSafeChar(char ch)
|
||||
{
|
||||
if ((((ch < 'a') || (ch > 'z')) && ((ch < 'A') || (ch > 'Z'))) && ((ch < '0') || (ch > '9')))
|
||||
{
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '-':
|
||||
case '.':
|
||||
break; //安全字符
|
||||
case '+':
|
||||
case ',':
|
||||
return false; //非安全字符
|
||||
default: //非安全字符
|
||||
if (ch != '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static char IntToHex(int n)
|
||||
{
|
||||
if (n <= 9)
|
||||
{
|
||||
return (char)(n + 0x30);
|
||||
}
|
||||
return (char)((n - 10) + 0x41);
|
||||
}
|
||||
}
|
||||
15
Common/02WebApiCall/WebApiCall/WbApi.cs
Normal file
15
Common/02WebApiCall/WebApiCall/WbApi.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebApiCall
|
||||
{
|
||||
public class WbApi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
133
Common/02WebApiCall/WebApiCall/WritePLC.cs
Normal file
133
Common/02WebApiCall/WebApiCall/WritePLC.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using DoWhatPlc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DtWebApi
|
||||
{
|
||||
public partial class ReadWritePLC
|
||||
{
|
||||
static object lockerReadWritePLC = new object();
|
||||
|
||||
public static void Write_TagValueByTagTypeID(string tagTypeCodeID, string opName, object tagValue)
|
||||
{
|
||||
lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagTypeCodeID = tagTypeCodeID;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
}
|
||||
public static void Write_TagValueByTagID(string TagID, object tagValue)
|
||||
{
|
||||
WritePLC(TagID, tagValue);
|
||||
}
|
||||
public static void WritePLC(string tagTypeCodeID, string opName, object tagValue)
|
||||
{
|
||||
lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC_TagTypeCodeID";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagTypeCodeID = tagTypeCodeID;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void WritePLC(string tagID, object tagValue)
|
||||
{
|
||||
lock (lockerReadWritePLC)
|
||||
{
|
||||
var rs = new ReturnValueString(tagID, tagValue, "", "");
|
||||
var tagvalue = JsonConvert.SerializeObject(rs);
|
||||
|
||||
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "WritePLC";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("tagID", tagID);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.TagID = tagID;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
||||
|
||||
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void Write_TagValueByTagTypeName(string cmd, string opName, object tagValue)
|
||||
{
|
||||
lock (lockerReadWritePLC)
|
||||
{
|
||||
string api = "";
|
||||
string type = "GET";
|
||||
string controlStr = "PLC1";
|
||||
string actionStr = "Write_TagValueByTagTypeName";
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("cmd", cmd);
|
||||
dic.Add("opName", opName);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = cmd;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
dic.Add("tagValue", JsonConvert.SerializeObject(rv)); ;
|
||||
|
||||
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
4
Common/02WebApiCall/packages.config
Normal file
4
Common/02WebApiCall/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user