Commit 2723ad7f authored by 潘栩锋's avatar 潘栩锋 🚴

添加 设备连接变量表 自动安装 PlcGroupInstall.exe

parent 97bedb41

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlcGroupInstall", "PlcGroupInstall\PlcGroupInstall.csproj", "{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EC4B56BA-A96C-4BE2-A5BF-4E10262B6D34}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<?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>{1B6D3452-BA17-4BF3-923F-3DDDF70067A4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PlcGroupInstall</RootNamespace>
<AssemblyName>PlcGroupInstall</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</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>
<ItemGroup>
<Reference Include="System" />
<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.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace PlcGroupInstall
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> keyValues = new Dictionary<string, string>();
keyValues.Add("IBC", "../Project.FLY.IBC/FLY.IBC.UI.Server/bin/Debug/Gage1");
keyValues.Add("IBC&收卷", "../Project.FLY.Integrated/FLY.Integrated.UI.Server/bin/Debug/Gage1");
keyValues.Add("称重", "../Project.FLY.Weight/FLY.Weight.UI.Server/bin/Debug/Gage1");
keyValues.Add("称重单组分", "../Project.FLY.Weight2/FLY.Weight2.UI.Server/bin/Debug/Gage1");
keyValues.Add("收卷", "../Project.FLY.Winder_20190413/FLY.Winder.UI.Server/bin/Debug/Gage1");
//for (int i = 0; i < args.Count(); i++)
// Console.WriteLine($"args[{i}]={args[i]}");
//Console.ReadLine();
//if (args.Count() < 2)
//{
// Console.WriteLine("args error!!!! eg: PlcGroupInstall.exe IBC ../Project.FLY.IBC/FLY.IBC.UI.Server/bin/Debug/Gage1");
// return;
//}
foreach(var kv in keyValues)
{
PlcGroupInstallOne(kv.Key, kv.Value);
}
}
/// <summary>
/// 在plcgroupDirPath目录下找到全部 设备连接变量表_xxx文件夹,且里面有Generated/plcgroup.json 复制 到 targetPath目录
/// </summary>
/// <param name="plcgroupDirPath"></param>
/// <param name="targetPath"></param>
static void PlcGroupInstallOne(string plcgroupDirPath, string targetPath)
{
string tempPath = Path.Combine(plcgroupDirPath, "plcgroups");
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
DirectoryInfo srcDi = new DirectoryInfo(plcgroupDirPath);
if (!srcDi.Exists) {
//异常,直接抛出错误
throw new Exception($"不存在 {plcgroupDirPath}");
}
foreach (var subDi in srcDi.GetDirectories("设备连接变量表_*")) {
string plcgroupFilePath = Path.Combine(subDi.FullName, "Generated", "plcgroup.json");
if (!File.Exists(plcgroupFilePath)) {
//异常,直接抛出错误
throw new Exception($"不存在 {plcgroupFilePath}");
}
//复制到目标位置
string plcgroupTempDirPath = Path.Combine(tempPath, subDi.Name, "Generated");
Directory.CreateDirectory(plcgroupTempDirPath);
File.Copy(plcgroupFilePath, Path.Combine(plcgroupTempDirPath, "plcgroup.json"));
}
//复制到最终位置
targetPath = Path.Combine(targetPath, "plcgroups");
if(Directory.Exists(targetPath))
Directory.Delete(targetPath,true );
CopyDirectory(tempPath, targetPath);
//删除临时文件夹
Directory.Delete(tempPath,true);
}
static void CopyDirectory(string sourceDirPath, string SaveDirPath)
{
//如果指定的存储路径不存在,则创建该存储路径
if (!Directory.Exists(SaveDirPath))
{
//创建
Directory.CreateDirectory(SaveDirPath);
}
//获取源路径文件的名称
string[] files = Directory.GetFiles(sourceDirPath);
//遍历子文件夹的所有文件
foreach (string file in files)
{
string pFilePath = Path.Combine(SaveDirPath, Path.GetFileName(file));
File.Copy(file, pFilePath, true);
}
string[] dirs = Directory.GetDirectories(sourceDirPath);
//递归,遍历文件夹
foreach (string dir in dirs)
{
CopyDirectory(dir, Path.Combine(SaveDirPath,Path.GetFileName(dir)));
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PlcGroupInstall")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlcGroupInstall")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("1b6d3452-ba17-4bf3-923f-3dddf70067a4")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment