Skip to content

Commit

Permalink
1.0.0 Released
Browse files Browse the repository at this point in the history
  • Loading branch information
lixianguser committed May 27, 2022
0 parents commit 7a20f84
Show file tree
Hide file tree
Showing 12 changed files with 611 additions and 0 deletions.
Binary file added PublicAPI/Siemens.Engineering.AddIn.Publisher.exe
Binary file not shown.
Binary file added PublicAPI/Siemens.Engineering.AddIn.dll
Binary file not shown.
22 changes: 22 additions & 0 deletions TIA_Add-In_BlockAutoNumber.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIA_Add-In_BlockAutoNumber", "TIA_Add-In_BlockAutoNumber\TIA_Add-In_BlockAutoNumber.csproj", "{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIA_Add-In_BlockAutoNumber_UI", "TIA_Add-In_BlockAutoNumber_UI\TIA_Add-In_BlockAutoNumber_UI.csproj", "{5425301C-F2C6-451F-847D-F18213AE1AE7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}.Release|Any CPU.Build.0 = Release|Any CPU
{5425301C-F2C6-451F-847D-F18213AE1AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5425301C-F2C6-451F-847D-F18213AE1AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5425301C-F2C6-451F-847D-F18213AE1AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5425301C-F2C6-451F-847D-F18213AE1AE7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
97 changes: 97 additions & 0 deletions TIA_Add-In_BlockAutoNumber/AddIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Siemens.Engineering;
using Siemens.Engineering.AddIn.Menu;
using Siemens.Engineering.HW;
using Siemens.Engineering.Online;
using Siemens.Engineering.SW.Blocks;
using TIA_Add_In_BlockAutoNumber_UI;

namespace TIA_Add_In_BlockAutoNumber
{
public class AddIn : ContextMenuAddIn
{
private readonly TiaPortal _tiaPortal;

public AddIn(TiaPortal tiaPortal) : base("BlockAutoNumber")
{
_tiaPortal = tiaPortal;
}

protected override void BuildContextMenuItems(ContextMenuAddInRoot addInRootSubmenu)
{
addInRootSubmenu.Items.AddActionItem<PlcBlock>("Number", Number_OnClick);
addInRootSubmenu.Items.AddActionItem<IEngineeringObject>("Number",
menuSelectionProvider => { }, TextInfoStatus);
}

private static void Number_OnClick(MenuSelectionProvider<PlcBlock> menuSelectionProvider)
{
BlockAutoNumberForm numberForm = new BlockAutoNumberForm();
if (numberForm.ShowDialog() != DialogResult.OK)
return;
int startingNumber = numberForm.StartingNumber;
int increment = numberForm.Increment;
DeviceItem deviceItem = FindDeviceItem(menuSelectionProvider.GetSelection());
if (IsOffline(deviceItem))
{
try
{
foreach (PlcBlock plcBlocks in menuSelectionProvider.GetSelection())
{
if (plcBlocks.AutoNumber)
plcBlocks.AutoNumber = false;
if (plcBlocks.Number != startingNumber)
plcBlocks.Number = startingNumber;
startingNumber += increment;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("PLC device not offline", "Offline Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private static DeviceItem FindDeviceItem(IEnumerable<object> menuSelectionProvider)
{
foreach (IEngineeringObject engineeringObject in menuSelectionProvider)
{
IEngineeringObject parent = engineeringObject.Parent;
while (!(parent is DeviceItem))
{
parent = parent.Parent;
}

return (DeviceItem)parent;
}
return null;
}

private static bool IsOffline(IEngineeringServiceProvider item)
{
OnlineProvider onlineProvider = item.GetService<OnlineProvider>();
return (onlineProvider.State == OnlineState.Offline);
}

private static MenuStatus TextInfoStatus(MenuSelectionProvider<IEngineeringObject> menuSelectionProvider)
{
bool show = false;

foreach (IEngineeringObject engineeringObject in menuSelectionProvider.GetSelection())
{
if (engineeringObject is PlcBlock) continue;
show = true;
break;
}

return show ? MenuStatus.Disabled : MenuStatus.Hidden;
}
}
}

22 changes: 22 additions & 0 deletions TIA_Add-In_BlockAutoNumber/AddInProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Siemens.Engineering;
using Siemens.Engineering.AddIn;
using Siemens.Engineering.AddIn.Menu;
using System.Collections.Generic;

namespace TIA_Add_In_BlockAutoNumber
{
public sealed class AddInProvider : ProjectTreeAddInProvider
{
private readonly TiaPortal _tiaPortal;

public AddInProvider(TiaPortal tiaPortal)
{
_tiaPortal = tiaPortal;
}

protected override IEnumerable<ContextMenuAddIn> GetContextMenuAddIns()
{
yield return new AddIn(_tiaPortal);
}
}
}
55 changes: 55 additions & 0 deletions TIA_Add-In_BlockAutoNumber/Configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<PackageConfiguration xmlns="http://www.siemens.com/automation/Openness/AddIn/Publisher/V16">
<Author>lixianguser</Author>
<AddInVersion>V16</AddInVersion>
<Description>Block autonumber for TIA Portal V16 </Description>

<Product>
<Name>TIA_Add-In_BlockAutoNumber</Name>
<Id>TIA_Add-In_BlockAutoNumber</Id>
<Version>1.0.0</Version>
</Product>

<FeatureAssembly>
<AssemblyInfo>
<Assembly>bin\Debug\TIA_Add_In_BlockAutoNumber.dll</Assembly>
</AssemblyInfo>
</FeatureAssembly>

<AdditionalAssemblies>
<AssemblyInfo>
<Assembly>bin\Debug\TIA_Add_In_BlockAutoNumber_UI.dll</Assembly>
</AssemblyInfo>
</AdditionalAssemblies>

<DisplayInMultiuser />

<RequiredPermissions>
<TIAPermissions>
<TIA.ReadWrite />
</TIAPermissions>
<SecurityPermissions>
<System.Configuration.ConfigurationPermission />
<System.Data.Odbc.OdbcPermission />
<System.Data.OleDb.OleDbPermission />
<System.Data.SqlClient.SqlClientPermission />
<System.Diagnostics.EventLogPermission />
<System.Drawing.Printing.PrintingPermission />
<System.Net.Mail.SmtpPermission />
<System.Net.NetworkInformation.NetworkInformationPermission />
<System.Net.SocketPermission />
<System.Net.WebPermission />
<System.Security.Permissions.EnvironmentPermission />
<System.Security.Permissions.FileDialogPermission />
<System.Security.Permissions.FileIOPermission />
<System.Security.Permissions.IsolatedStorageFilePermission />
<System.Security.Permissions.KeyContainerPermission />
<System.Security.Permissions.RegistryPermission />
<System.Security.Permissions.StorePermission />
<System.Security.Permissions.UIPermission />
<System.Security.Permissions.WebBrowserPermission />
<System.Security.Permissions.MediaPermission />
<System.Security.Permissions.SecurityPermission.UnmanagedCode />
<Siemens.Engineering.AddIn.Permissions.ProcessStartPermission />
</SecurityPermissions>
</RequiredPermissions>
</PackageConfiguration>
35 changes: 35 additions & 0 deletions TIA_Add-In_BlockAutoNumber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TIA_Add_In_BlockAutoNumber")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TIA_Add_In_BlockAutoNumber")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
69 changes: 69 additions & 0 deletions TIA_Add-In_BlockAutoNumber/TIA_Add-In_BlockAutoNumber.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{CF2FA028-8E66-4771-8FEE-BBF2A0D5C6B1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TIA_Add_In_BlockAutoNumber</RootNamespace>
<AssemblyName>TIA_Add_In_BlockAutoNumber</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<PropertyGroup>
<PostBuildEvent>"$(SolutionDir)PublicAPI\Siemens.Engineering.AddIn.Publisher.exe" --configuration ..\..\Configuration.xml --logfile .\Log.txt --verbose</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Siemens.Engineering.AddIn">
<HintPath>..\PublicAPI\Siemens.Engineering.AddIn.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddIn.cs" />
<Compile Include="AddInProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TIA_Add-In_BlockAutoNumber_UI\TIA_Add-In_BlockAutoNumber_UI.csproj">
<Project>{5425301c-f2c6-451f-847d-f18213ae1ae7}</Project>
<Name>TIA_Add-In_BlockAutoNumber_UI</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Configuration.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 7a20f84

Please sign in to comment.