ResxCheck.cs does not belong in XenAdmin but rather in devtools (needs further updating before becoming fully usable).

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-07-02 18:12:53 +01:00
parent 1979258607
commit 3e0804af27
6 changed files with 634 additions and 451 deletions

View File

@ -1088,7 +1088,6 @@
<Compile Include="LicenseTimer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ResxCheck.cs" />
<Compile Include="SettingsPanels\BootDevice.cs" />
<Compile Include="SettingsPanels\CPUMemoryEditPage.cs">
<SubType>UserControl</SubType>

View File

@ -0,0 +1,46 @@
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ResxCheck
{
class Program
{
static void Main(string[] args)
{
ResxCheck.FindUnusedMessages(@"..\..\..\..",false);
}
}
}

View File

@ -0,0 +1,67 @@
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
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("ResxCheck")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ResxCheck")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[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("8c91561e-914f-4514-91a7-42c22ea012bc")]
// 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")]

View File

@ -1,4 +1,4 @@
/* Copyright (c) Citrix Systems Inc.
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@ -32,45 +32,46 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
namespace XenAdmin
namespace ResxCheck
{
static class ResxCheck
{
/// <summary>
/// Produces a list of unused resources in Messages and FriendlyErrorNames.
///
/// Try running from the VS immediate window:
/// ResxCheck.Run(@"C:\Documents and Settings\hwarrington\xenadmin-unstable.hg\XenAdmin", false)
/// Produces a list of unused resources in Messages and FriendlyNames.
/// </summary>
/// <param name="removeUnused">If true, will actually purge unused messages from the Messages.resx file.</param>
/// <param name="removeUnused">If true, will actually purge unused messages from the Messages.resx file</param>
public static void FindUnusedMessages(string rootDir, bool removeUnused)
{
Assembly assembly = Assembly.LoadFrom(Path.Combine(rootDir, @"XenModel\bin\Debug\XenModel.dll"));
int totalMessages = 0, totalFriendlyErrorNames = 0;
List<string> resources = new List<string>();
foreach (PropertyInfo property in typeof(Messages).GetProperties(BindingFlags.Static | BindingFlags.NonPublic))
var resources = new List<string>();
Type messagesType = assembly.GetType("XenAdmin.Messages");
Type friendlyNamesType = assembly.GetType("XenAdmin.FriendlyNames");
foreach (PropertyInfo property in messagesType.GetProperties(BindingFlags.Static | BindingFlags.NonPublic))
{
resources.Add("Messages." + property.Name.Trim());
totalMessages++;
}
foreach (PropertyInfo property in typeof(XenAPI.FriendlyErrorNames).GetProperties(BindingFlags.Static | BindingFlags.NonPublic))
foreach (PropertyInfo property in friendlyNamesType.GetProperties(BindingFlags.Static | BindingFlags.NonPublic))
{
resources.Add("FriendlyErrorNames." + property.Name.Trim());
resources.Add("FriendlyNames." + property.Name.Trim());
totalFriendlyErrorNames++;
}
// Build file list for project
List<FileInfo> files = new List<FileInfo>();
RecursiveGetCsFiles(new DirectoryInfo(rootDir), files);
files.RemoveAll((Predicate<FileInfo>)delegate(FileInfo f)
{
return f.Name.StartsWith("Messages.") || f.Name.StartsWith("FriendlyErrorNames.");
});
files.RemoveAll(f => f.Name.StartsWith("Messages.") || f.Name.StartsWith("FriendlyNames."));
Console.WriteLine(string.Format("Looking in {0} files", files.Count));
// Now remove resources from the list if they appear in source files
@ -79,18 +80,8 @@ namespace XenAdmin
string[] lines = File.ReadAllLines(fileinfo.FullName);
foreach (string line in lines)
{
resources.RemoveAll((Predicate<string>)delegate(string resource)
{
if (line.Contains(resource))
{
//Console.WriteLine(line + " ::: " + resource);
return true;
}
else
{
return false;
}
});
string curLine = line;
resources.RemoveAll(resource => curLine.Contains(resource));
}
}
@ -101,14 +92,14 @@ namespace XenAdmin
{
messages++;
}
else if (unused.StartsWith("FriendlyErrorNames."))
else if (unused.StartsWith("FriendlyNames."))
{
friendlyErrorNames++;
}
Console.WriteLine(unused);
}
Console.WriteLine(string.Format("Messages.resx: {0}/{1} are unused", messages, totalMessages));
Console.WriteLine(string.Format("FriendlyErrorNames.resx: {0}/{1} are unused", friendlyErrorNames, totalFriendlyErrorNames));
Console.WriteLine(string.Format("FriendlyNames.resx: {0}/{1} are unused", friendlyErrorNames, totalFriendlyErrorNames));
// Remove unused messages from Messages.rex. Note that this method is extremely
// crude and depends on the exact format of the XML.
@ -330,7 +321,7 @@ namespace XenAdmin
// Go through all the ja nodes, keeping only the ones where their values differ from the en original
// Don't bother to do this for the messages files.
if (enResxFile.Name != "Messages.resx" && enResxFile.Name != "FriendlyErrorNames.resx" &&
if (enResxFile.Name != "Messages.resx" && enResxFile.Name != "FriendlyNames.resx" &&
enResxFile.Name != "FriendlyNames.resx")
{
foreach (XmlNode jaNode in jaDataNodeList)

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ResxCheck</RootNamespace>
<AssemblyName>ResxCheck</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<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">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResxCheck.cs" />
</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>

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResxCheck", "ResxCheck.csproj", "{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B61063FC-FCCB-4D4D-BA7B-CB0E674F1B16}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal