Skip to content

Commit

Permalink
Create plugin classes
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualEvan committed Nov 22, 2018
1 parent 280be64 commit 7a871eb
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 32 deletions.
4 changes: 2 additions & 2 deletions updates.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Debug|Any CPU.Build.0 = Release|Any CPU
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CBF534F-0A59-4C9B-906B-A2BB812C7776}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
12 changes: 0 additions & 12 deletions updates/Class1.cs

This file was deleted.

9 changes: 9 additions & 0 deletions updates/IInputPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Newtonsoft.Json.Linq;

namespace plugin
{
public interface IInputPlugin
{
string Execute();
}
}
87 changes: 87 additions & 0 deletions updates/IUpdates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using WUApiLib;
using Newtonsoft.Json.Linq;

namespace plugin
{
[PluginAttribute(PluginName = "Updates")]
public class IUpdates : IInputPlugin
{
public string Execute()
{
dynamic package = new JObject();
package.automaticUpdates = null;
package.numInstalledUpdates = null;
package.installedUpdates = new JArray();
package.numUpdatesAvailable = null;
package.updatesAvailable = new JArray();
dynamic update = new JObject();

// Checks if automatic updates are enabled
AutomaticUpdates automaticUpdates = new AutomaticUpdates();
package.automaticUpdates = automaticUpdates.ServiceEnabled;


// Checks installed updates
UpdateSession uSession = new UpdateSession();

// IUpdateSearcher class
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-iupdatesearcher
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
uSearcher.ServerSelection = ServerSelection.ssDefault;
uSearcher.IncludePotentiallySupersededUpdates = true;
uSearcher.Online = false;
try
{
// Number of installed updates
ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0");

package.numInstalledUpdates = sResult.Updates.Count;

// IUpdate class
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-iupdate
foreach (IUpdate iupdate in sResult.Updates)
{
update.id = iupdate.Identity.UpdateID;
update.date = iupdate.LastDeploymentChangeTime;
update.title = iupdate.Title;
update.categories = new JArray();
// IUpdate class
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-icategory
foreach (ICategory icategory in iupdate.Categories)
{
update.categories.Add(icategory.Name);
}

package.installedUpdates.Add(update);
}


// Number of non installed updates

sResult = uSearcher.Search("IsInstalled=0 And IsHidden=0");

package.numUpdatesAvailable = sResult.Updates.Count;

foreach (IUpdate iupdate in sResult.Updates)
{
update.id = iupdate.Identity.UpdateID;
update.date = iupdate.LastDeploymentChangeTime;
update.title = iupdate.Title;

package.updatesAvailable.Add(update);
}

return package.ToString();
}

catch (Exception ex)
{
Console.WriteLine("Something went wrong: " + ex.Message);
}

return null;
}

}
}
9 changes: 9 additions & 0 deletions updates/PluginAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace plugin
{
public class PluginAttribute : Attribute
{
public string PluginName { get; set; }
}
}
16 changes: 16 additions & 0 deletions updates/PluginDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace plugin
{
public class PluginDefinition
{
public Attribute Attribute { get; set; }
public Type ImplementationType { get; set; }

public PluginDefinition(Attribute Attribute, Type implementationType)
{
this.Attribute = Attribute;
this.ImplementationType = implementationType;
}
}
}
4 changes: 4 additions & 0 deletions updates/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1-beta1" targetFramework="net461" />
</packages>
50 changes: 32 additions & 18 deletions updates/updates.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?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>7cbf534f-0a59-4c9b-906b-a2bb812c7776</ProjectGuid>
<ProjectGuid>{7CBF534F-0A59-4C9B-906B-A2BB812C7776}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>updates</RootNamespace>
Expand All @@ -31,24 +31,38 @@
<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"/>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<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="Class1.cs" />
<Compile Include="IInputPlugin.cs" />
<Compile Include="IUpdates.cs" />
<Compile Include="PluginAttribute.cs" />
<Compile Include="PluginDefinition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<COMReference Include="WUApiLib">
<Guid>{B596CC9F-56E5-419E-A622-E01BB457431E}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

0 comments on commit 7a871eb

Please sign in to comment.