ChangeCopyrightInfo tool
This commit is contained in:
parent
4efda60872
commit
fe517c0569
6 changed files with 475 additions and 0 deletions
22
WebsitePanel/Sources/Tools/ChangeCopyrightInfo.sln
Normal file
22
WebsitePanel/Sources/Tools/ChangeCopyrightInfo.sln
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChangeCopyrightInfo", "ChangeCopyrightInfo\ChangeCopyrightInfo.csproj", "{15354A48-20F3-4583-9A51-AE9923249631}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{15354A48-20F3-4583-9A51-AE9923249631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{15354A48-20F3-4583-9A51-AE9923249631}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{15354A48-20F3-4583-9A51-AE9923249631}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{15354A48-20F3-4583-9A51-AE9923249631}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
36
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/App.config
Normal file
36
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/App.config
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="LogFile" value="ChangeCopyrightInfo.log"/>
|
||||
<add key="path" value="..\..\..\"/>
|
||||
<add key="files" value="*.cs"/>
|
||||
<add key="startcopyrigth" value="// Copyright"/>
|
||||
<add key="copyrigth" value="// Copyright (c) 2014, Outercurve Foundation.
|
||||
// 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.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// 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."/>
|
||||
</appSettings>
|
||||
</configuration>
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.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>{15354A48-20F3-4583-9A51-AE9923249631}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ChangeCopyrightInfo</RootNamespace>
|
||||
<AssemblyName>ChangeCopyrightInfo</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</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\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</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.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</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>
|
204
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Log.cs
Normal file
204
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Log.cs
Normal file
|
@ -0,0 +1,204 @@
|
|||
// Copyright (c) 2014, Outercurve Foundation.
|
||||
// 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.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// 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.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace ChangeCopyrightInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple log
|
||||
/// </summary>
|
||||
public sealed class Log
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the class.
|
||||
/// </summary>
|
||||
private Log()
|
||||
{
|
||||
}
|
||||
|
||||
private static string logFile = "WebsitePanel.Import.CsvBulk.log";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes trace listeners.
|
||||
/// </summary>
|
||||
public static void Initialize(string fileName)
|
||||
{
|
||||
logFile = fileName;
|
||||
FileStream fileLog = new FileStream(logFile, FileMode.Append);
|
||||
TextWriterTraceListener fileListener = new TextWriterTraceListener(fileLog);
|
||||
fileListener.TraceOutputOptions = TraceOptions.DateTime;
|
||||
Trace.UseGlobalLock = true;
|
||||
Trace.Listeners.Clear();
|
||||
Trace.Listeners.Add(fileListener);
|
||||
TextWriterTraceListener consoleListener = new TextWriterTraceListener(System.Console.Out);
|
||||
Trace.Listeners.Add(consoleListener);
|
||||
Trace.AutoFlush = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write error to the log.
|
||||
/// </summary>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="ex">Exception.</param>
|
||||
internal static void WriteError(string message, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] ERROR: {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
Trace.WriteLine(ex);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write error to the log.
|
||||
/// </summary>
|
||||
/// <param name="message">Error message.</param>
|
||||
internal static void WriteError(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] ERROR: {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write to log
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
internal static void Write(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] {1}", DateTime.Now, message);
|
||||
Trace.Write(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write line to log
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
internal static void WriteLine(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write info message to log
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
internal static void WriteInfo(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] INFO: {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write start message to log
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
internal static void WriteStart(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] START: {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write end message to log
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
internal static void WriteEnd(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
string line = string.Format("[{0:G}] END: {1}", DateTime.Now, message);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void WriteApplicationStart()
|
||||
{
|
||||
try
|
||||
{
|
||||
string name = typeof(Log).Assembly.GetName().Name;
|
||||
string version = typeof(Log).Assembly.GetName().Version.ToString(3);
|
||||
string line = string.Format("[{0:G}] ***** {1} {2} Started *****", DateTime.Now, name, version);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void WriteApplicationEnd()
|
||||
{
|
||||
try
|
||||
{
|
||||
string name = typeof(Log).Assembly.GetName().Name;
|
||||
string line = string.Format("[{0:G}] ***** {1} Ended *****", DateTime.Now, name);
|
||||
Trace.WriteLine(line);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens notepad to view log file.
|
||||
/// </summary>
|
||||
public static void ShowLogFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logFile);
|
||||
Process.Start("notepad.exe", path);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
116
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs
Normal file
116
WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs
Normal file
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
|
||||
namespace ChangeCopyrightInfo
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static string Path
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["path"]; }
|
||||
}
|
||||
|
||||
static string Files
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["files"]; }
|
||||
}
|
||||
|
||||
static List<string> copyrigth = null;
|
||||
static List<string> Copyrigth
|
||||
{
|
||||
get {
|
||||
if (copyrigth != null) return copyrigth;
|
||||
copyrigth = new List<string>();
|
||||
string text = ConfigurationManager.AppSettings["copyrigth"];
|
||||
if (text == null) return copyrigth;
|
||||
copyrigth.AddRange( text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) );
|
||||
return copyrigth;
|
||||
}
|
||||
}
|
||||
static string startcopyrigth
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["startcopyrigth"]; }
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Log.Initialize(ConfigurationManager.AppSettings["LogFile"]);
|
||||
Log.WriteApplicationStart();
|
||||
|
||||
if (Path != null)
|
||||
CheckDirectory(Path);
|
||||
|
||||
Log.WriteApplicationEnd();
|
||||
}
|
||||
|
||||
static void CheckDirectory(string directory)
|
||||
{
|
||||
Log.WriteLine("Check " + directory);
|
||||
|
||||
string[] dirFiles = Directory.GetFiles(directory, Files);
|
||||
|
||||
foreach (string file in dirFiles)
|
||||
CheckFile(file);
|
||||
|
||||
string[] dirDirs = Directory.GetDirectories(directory);
|
||||
|
||||
foreach(string dir in dirDirs)
|
||||
CheckDirectory(dir);
|
||||
}
|
||||
|
||||
static void CheckFile(string file)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
lines.AddRange(File.ReadAllLines(file));
|
||||
|
||||
bool copyrigthExist = false;
|
||||
if (Copyrigth.Count <= lines.Count)
|
||||
{
|
||||
for (int i = 0; i < Copyrigth.Count; i++)
|
||||
if (Copyrigth[i].Trim().ToLower() != lines[i].Trim().ToLower())
|
||||
break;
|
||||
|
||||
copyrigthExist = true;
|
||||
}
|
||||
|
||||
if (copyrigthExist)
|
||||
return;
|
||||
|
||||
Log.WriteLine("Change copyrigth : " + file);
|
||||
|
||||
// skip copyrigth
|
||||
int skip = 0;
|
||||
if (lines.Count>0)
|
||||
{
|
||||
if (lines[0].StartsWith(startcopyrigth, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
for (int i = 1; i < lines.Count; i++)
|
||||
{
|
||||
if (!lines[i].StartsWith("//"))
|
||||
break;
|
||||
skip = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// skip WhiteSpace
|
||||
for (int i = skip+1; i < lines.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(lines[i]))
|
||||
break;
|
||||
skip = i;
|
||||
}
|
||||
|
||||
lines.RemoveRange(0, skip);
|
||||
|
||||
File.WriteAllLines(file, Copyrigth);
|
||||
File.AppendAllText(file, Environment.NewLine);
|
||||
File.AppendAllLines(file, lines);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
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("ChangeCopyrightInfo")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ChangeCopyrightInfo")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[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("1ff22360-5cb8-4388-a568-ff20134c811e")]
|
||||
|
||||
// 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")]
|
Loading…
Add table
Add a link
Reference in a new issue