Last active
December 22, 2015 08:30
-
-
Save ljinke/6445064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class LinqExtension | |
{ | |
public static void ForEach<T>(this IEnumerable<T> dataSource, Action<T> act) | |
{ | |
if (dataSource != null) | |
{ | |
foreach (var item in dataSource) | |
{ | |
act(item); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<log4net> | |
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender"> | |
<file type="log4net.Util.PatternString"> | |
<converter> | |
<name value="folder" /> | |
<type value="Utilities.SpecialFolderPatternConverter,Common" /> | |
</converter> | |
<conversionPattern value="%folder{CommonApplicationData}\log.txt" /> | |
</file> | |
<appendToFile value="true" /> | |
<maximumFileSize value="100KB" /> | |
<maxSizeRollBackups value="2" /> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionPattern value="[%date] [%5level] [%logger] [%thread] - %message%newline" /> | |
</layout> | |
</appender> | |
<root> | |
<level value="DEBUG" /> | |
<appender-ref ref="RollingFile" /> | |
</root> | |
</log4net> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "log4net.config"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project DefaultTargets="" InitialTargets="" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> | |
<!--Add your own condition with a specific COMPUTERNAME--> | |
<Choose> | |
<When Condition="'$(Version)' == '2014' AND '$(COMPUTERNAME)' == 'SHACNG130WYJQ'"> | |
<PropertyGroup> | |
<NW>C:\Program Files\Autodesk\Navisworks Manage 2014</NW> | |
</PropertyGroup> | |
</When> | |
<When Condition="'$(Version)' == '2013' AND '$(COMPUTERNAME)' == 'SHACNG130WYJQ'"> | |
<PropertyGroup> | |
<NW>C:\Program Files\Autodesk\Navisworks Manage 2013</NW> | |
</PropertyGroup> | |
</When> | |
<When Condition="'$(Version)' == '2012' AND '$(COMPUTERNAME)' == 'SHACNG130WYJQ'"> | |
<PropertyGroup> | |
<NW>C:\Program Files\Autodesk\Navisworks Manage 2012</NW> | |
</PropertyGroup> | |
</When> | |
</Choose> | |
<Target Name="CopyPluginFiles"> | |
<PropertyGroup> | |
<NW-Common>$(NW)\Dependencies</NW-Common> | |
<NW-GluePlugin>$(NW)\Plugins\$(TargetName)</NW-GluePlugin> | |
<NW-GluePluginResources>$(NW)\Plugins\$(TargetName)\en-US</NW-GluePluginResources> | |
</PropertyGroup> | |
<Message Text="*** Copy files to Navisworks folders ***" Importance="high" /> | |
<MakeDir Directories="$(NW-Common)" ContinueOnError="true"/> | |
<MakeDir Directories="$(NW-GluePlugin)" ContinueOnError="true"/> | |
<MakeDir Directories="$(NW-GluePluginResources)" ContinueOnError="true"/> | |
<ItemGroup> | |
<PluginFiles Include="$(TargetDir)$(TargetName).*"/> | |
</ItemGroup> | |
<ItemGroup> | |
<CommonFiles Include="$(TargetDir)BIM360GlueAddinsCommon.*"/> | |
<CommonFiles Include="$(TargetDir)log4net.*"/> | |
</ItemGroup> | |
<ItemGroup> | |
<ResourceFiles Include="$(TargetDir)Resources\*.*"/> | |
<ResourceFiles Include="$(TargetDir)*.name"/> | |
<ResourceFiles Include="$(TargetDir)*.xaml"/> | |
</ItemGroup> | |
<!--Common dll and pdb--> | |
<Copy SourceFiles="@(CommonFiles)" DestinationFolder="$(NW-Common)" ContinueOnError="true"/> | |
<!--Plgin dll and pdb--> | |
<Copy SourceFiles="@(PluginFiles)" DestinationFolder="$(NW-GluePlugin)" ContinueOnError="true"/> | |
<!--Resources--> | |
<Copy SourceFiles="@(ResourceFiles)" DestinationFolder="$(NW-GluePluginResources)" ContinueOnError="true"/> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetryHelper | |
{ | |
/// <summary> | |
/// Execut a function with retry logic. | |
/// </summary> | |
/// <typeparam name="TResult">Return type.</typeparam> | |
/// <param name="times">retry times.</param> | |
/// <param name="job">function to retry</param> | |
/// <param name="exceptionHandler">Handle the exceptions if necessary, e.g. log.</param> | |
/// <returns>default(T) if failed for every time.</returns> | |
public static TResult Do<TResult>(int times, Func<TResult> job, Action<Exception> exceptionHandler = null) | |
{ | |
TResult result = default(TResult); | |
for (int i = 0; i < times; i++) | |
{ | |
try | |
{ | |
result = job(); | |
break; | |
} | |
catch(Exception e) | |
{ | |
if (exceptionHandler != null) | |
{ | |
exceptionHandler(e); | |
} | |
} | |
} | |
return result; | |
} | |
/// <summary> | |
/// Execut a function with retry logic. | |
/// </summary> | |
/// <param name="times">retry times.</param> | |
/// <param name="job"></param> | |
/// <param name="exceptionHandler">Handle the exceptions if necessary, e.g. log.</param> | |
/// <returns>true if succeeeded, false if failed for all retries.</returns> | |
public static bool Do(int times, Action job, Action<Exception> exceptionHandler = null) | |
{ | |
for (int i = 0; i < times; i++) | |
{ | |
try | |
{ | |
job(); | |
return true; | |
} | |
catch(Exception e) | |
{ | |
if (exceptionHandler != null) | |
{ | |
exceptionHandler(e); | |
} | |
} | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Converter for log4net to allow special folders to be included using a pattern of %folder(<i>specialFolderName</i>). | |
/// </summary> | |
public class SpecialFolderPatternConverter : log4net.Util.PatternConverter | |
{ | |
/// <summary> | |
/// Converts the specified writer. | |
/// </summary> | |
/// <param name="writer">The writer.</param> | |
/// <param name="state">The state.</param> | |
override protected void Convert(System.IO.TextWriter writer, object state) | |
{ | |
Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), base.Option, true); | |
writer.Write(Environment.GetFolderPath(specialFolder)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment