diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo.sln b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo.sln new file mode 100644 index 00000000..d35f655b --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo.sln @@ -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 diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/App.config b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/App.config new file mode 100644 index 00000000..bbb5bdd8 --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/App.config @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/ChangeCopyrightInfo.csproj b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/ChangeCopyrightInfo.csproj new file mode 100644 index 00000000..e49f5a4d --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/ChangeCopyrightInfo.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {15354A48-20F3-4583-9A51-AE9923249631} + Exe + Properties + ChangeCopyrightInfo + ChangeCopyrightInfo + v4.0 + 512 + + + + AnyCPU + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Log.cs b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Log.cs new file mode 100644 index 00000000..23fbf250 --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Log.cs @@ -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 +{ + /// + /// Simple log + /// + public sealed class Log + { + /// + /// Initializes a new instance of the class. + /// + private Log() + { + } + + private static string logFile = "WebsitePanel.Import.CsvBulk.log"; + + /// + /// Initializes trace listeners. + /// + 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; + } + + /// + /// Write error to the log. + /// + /// Error message. + /// Exception. + 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 { } + } + + /// + /// Write error to the log. + /// + /// Error message. + internal static void WriteError(string message) + { + try + { + string line = string.Format("[{0:G}] ERROR: {1}", DateTime.Now, message); + Trace.WriteLine(line); + } + catch { } + } + + /// + /// Write to log + /// + /// + internal static void Write(string message) + { + try + { + string line = string.Format("[{0:G}] {1}", DateTime.Now, message); + Trace.Write(line); + } + catch { } + } + + + /// + /// Write line to log + /// + /// + internal static void WriteLine(string message) + { + try + { + string line = string.Format("[{0:G}] {1}", DateTime.Now, message); + Trace.WriteLine(line); + } + catch { } + } + + /// + /// Write info message to log + /// + /// + internal static void WriteInfo(string message) + { + try + { + string line = string.Format("[{0:G}] INFO: {1}", DateTime.Now, message); + Trace.WriteLine(line); + } + catch { } + } + + /// + /// Write start message to log + /// + /// + internal static void WriteStart(string message) + { + try + { + string line = string.Format("[{0:G}] START: {1}", DateTime.Now, message); + Trace.WriteLine(line); + } + catch { } + } + + /// + /// Write end message to log + /// + /// + 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 { } + } + + /// + /// Opens notepad to view log file. + /// + public static void ShowLogFile() + { + try + { + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logFile); + Process.Start("notepad.exe", path); + } + catch { } + } + } +} diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs new file mode 100644 index 00000000..400eb1af --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Program.cs @@ -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 copyrigth = null; + static List Copyrigth + { + get { + if (copyrigth != null) return copyrigth; + copyrigth = new List(); + 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 lines = new List(); + 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); + } + } +} diff --git a/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Properties/AssemblyInfo.cs b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e5c99579 --- /dev/null +++ b/WebsitePanel/Sources/Tools/ChangeCopyrightInfo/Properties/AssemblyInfo.cs @@ -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")]