{
TinyUrl,
Isgd,
- Twurl,
Bitly,
Jmp,
Uxnu,
Nicoms,
//廃止
Unu = -1,
+ Twurl = -1,
}
public enum HITRESULT
}
public static string GetErrorLogPath()
- {
- return Path.Combine(Path.GetDirectoryName(MyCommon.EntryAssembly.Location), "ErrorLogs");
- }
+ => Path.Combine(Path.GetDirectoryName(MyCommon.EntryAssembly.Location), "ErrorLogs");
public static void TraceOut(WebApiException ex)
{
}
public static void TraceOut(string Message)
- {
- TraceOut(TraceFlag, Message);
- }
+ => TraceOut(TraceFlag, Message);
public static void TraceOut(bool OutputFlag, string Message)
{
if (!Directory.Exists(logPath))
Directory.CreateDirectory(logPath);
- var now = DateTime.Now;
- var fileName = string.Format("{0}Trace-{1:0000}{2:00}{3:00}-{4:00}{5:00}{6:00}.log", GetAssemblyName(), now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
+ var now = DateTimeUtc.Now;
+ var fileName = $"{ApplicationSettings.AssemblyName}Trace-{now.ToLocalTime():yyyyMMdd-HHmmss}.log";
fileName = Path.Combine(logPath, fileName);
using (var writer = new StreamWriter(fileName))
{
- writer.WriteLine("**** TraceOut: {0} ****", DateTime.Now);
+ writer.WriteLine("**** TraceOut: {0} ****", now.ToLocalTimeString());
writer.WriteLine(Properties.Resources.TraceOutText1, ApplicationSettings.FeedbackEmailAddress);
writer.WriteLine(Properties.Resources.TraceOutText2, ApplicationSettings.FeedbackTwitterName);
writer.WriteLine();
writer.WriteLine(Properties.Resources.TraceOutText3);
writer.WriteLine(Properties.Resources.TraceOutText4, Environment.OSVersion.VersionString);
writer.WriteLine(Properties.Resources.TraceOutText5, Environment.Version);
- writer.WriteLine(Properties.Resources.TraceOutText6, MyCommon.GetAssemblyName(), FileVersion);
+ writer.WriteLine(Properties.Resources.TraceOutText6, ApplicationSettings.AssemblyName, FileVersion);
writer.WriteLine(Message);
writer.WriteLine();
}
public static string ExceptionOutMessage(Exception ex)
{
- bool IsTerminatePermission = true;
+ var IsTerminatePermission = true;
return ExceptionOutMessage(ex, ref IsTerminatePermission);
}
var ident = WindowsIdentity.GetCurrent();
var princ = new WindowsPrincipal(ident);
+ var now = DateTimeUtc.Now;
var errorReport = string.Join(Environment.NewLine,
- string.Format(Properties.Resources.UnhandledExceptionText1, DateTime.Now),
+ string.Format(Properties.Resources.UnhandledExceptionText1, now.ToLocalTimeString()),
// 権限書き出し
string.Format(Properties.Resources.UnhandledExceptionText11 + princ.IsInRole(WindowsBuiltInRole.Administrator)),
string.Format(Properties.Resources.UnhandledExceptionText4),
string.Format(Properties.Resources.UnhandledExceptionText5, Environment.OSVersion.VersionString),
string.Format(Properties.Resources.UnhandledExceptionText6, Environment.Version),
- string.Format(Properties.Resources.UnhandledExceptionText7, MyCommon.GetAssemblyName(), FileVersion),
+ string.Format(Properties.Resources.UnhandledExceptionText7, ApplicationSettings.AssemblyName, FileVersion),
ExceptionOutMessage(ex, ref IsTerminatePermission));
if (!Directory.Exists(logPath))
Directory.CreateDirectory(logPath);
- var now = DateTime.Now;
- var fileName = string.Format("{0}-{1:0000}{2:00}{3:00}-{4:00}{5:00}{6:00}.log", GetAssemblyName(), now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
+ var fileName = $"{ApplicationSettings.AssemblyName}-{now.ToLocalTime():yyyyMMdd-HHmmss}.log";
using (var writer = new StreamWriter(Path.Combine(logPath, fileName)))
{
writer.Write(errorReport);
}
/// <summary>
- /// URLに含まれているマルチバイト文字列を%xx形式でエンコードします。
- /// <newpara>
- /// マルチバイト文字のコードはUTF-8またはUnicodeで自動的に判断します。
- /// </newpara>
- /// </summary>
- /// <param name="_input">エンコード対象のURL</param>
- /// <returns>マルチバイト文字の部分をUTF-8/%xx形式でエンコードした文字列を返します。</returns>
-
- public static string urlEncodeMultibyteChar(string _input)
- {
- Uri uri = null;
- var sb = new StringBuilder(256);
- var result = "";
- var c_ = 'd';
- foreach (var c in _input)
- {
- c_ = c;
- if (Convert.ToInt32(c) > 127 || c == '%') break;
- }
- if (Convert.ToInt32(c_) <= 127 && c_ != '%') return _input;
-
- var input = Uri.UnescapeDataString(_input);
- retry:
- foreach (char c in input)
- {
- if (Convert.ToInt32(c) > 255)
- {
- // Unicodeの場合(1charが複数のバイトで構成されている)
- // Uriクラスをnewして再構成し、入力をPathAndQueryのみとしてやり直す
- foreach (var b in Encoding.UTF8.GetBytes(c.ToString()))
- {
- sb.AppendFormat("%{0:X2}", b);
- }
- }
- else if (Convert.ToInt32(c) > 127 || c == '%')
- {
- // UTF-8の場合
- // Uriクラスをnewして再構成し、入力をinputからAuthority部分を除去してやり直す
- if (uri == null)
- {
- uri = new Uri(input);
- input = input.Remove(0, uri.GetLeftPart(UriPartial.Authority).Length);
- sb.Length = 0;
- goto retry;
- }
- else
- {
- sb.Append("%" + Convert.ToInt16(c).ToString("X2").ToUpperInvariant());
- }
- }
- else
- {
- sb.Append(c);
- }
- }
-
- if (uri == null)
- {
- result = sb.ToString();
- }
- else
- {
- result = uri.GetLeftPart(UriPartial.Authority) + sb;
- }
-
- return result;
- }
-
- /// <summary>
/// URLのドメイン名をPunycode展開します。
/// <para>
/// ドメイン名がIDNでない場合はそのまま返します。
}
catch (Exception)
{
- return null;
+ return inputUrl;
}
}
// Punycodeをデコードする
outputUrl = MyCommon.IDNDecode(outputUrl);
- if (outputUrl == null)
- return inputUrl;
// URL内で特殊な意味を持つ記号は元の文字に変換されることを避けるために二重エスケープする
// 参考: Firefoxの losslessDecodeURI() 関数
desdecrypt = des.CreateEncryptor();
//書き込むためのCryptoStreamの作成
- using (CryptoStream cryptStream = new CryptoStream(msOut, desdecrypt, CryptoStreamMode.Write))
+ using (var cryptStream = new CryptoStream(msOut, desdecrypt, CryptoStreamMode.Write))
{
//Disposeが重複して呼ばれないようにする
- MemoryStream msTmp = msOut;
+ var msTmp = msOut;
msOut = null;
desdecrypt = null;
desdecrypt = null;
//復号化されたデータを取得するためのStreamReader
- using (StreamReader srOut = new StreamReader(cryptStreem, Encoding.UTF8))
+ using (var srOut = new StreamReader(cryptStreem, Encoding.UTF8))
{
//Disposeが重複して呼ばれないようにする
cryptStreem = null;
/// <param name="keys">状態を調べるキー</param>
/// <returns><paramref name="keys"/> で指定された修飾キーがすべて押されている状態であれば true。それ以外であれば false。</returns>
public static bool IsKeyDown(params Keys[] keys)
- {
- return MyCommon._IsKeyDown(Control.ModifierKeys, keys);
- }
+ => MyCommon._IsKeyDown(Control.ModifierKeys, keys);
internal static bool _IsKeyDown(Keys modifierKeys, Keys[] targetKeys)
{
- foreach (Keys key in targetKeys)
+ foreach (var key in targetKeys)
{
if ((modifierKeys & key) != key)
{
/// </remarks>
/// <returns>アプリケーションのアセンブリ名</returns>
public static string GetAssemblyName()
- {
- return MyCommon.EntryAssembly.GetName().Name;
- }
+ => MyCommon.EntryAssembly.GetName().Name;
/// <summary>
/// 文字列中に含まれる %AppName% をアプリケーション名に置換する
/// <param name="orig">対象となる文字列</param>
/// <returns>置換後の文字列</returns>
public static string ReplaceAppName(string orig)
- {
- return MyCommon.ReplaceAppName(orig, Application.ProductName);
- }
+ => MyCommon.ReplaceAppName(orig, ApplicationSettings.ApplicationName);
/// <summary>
/// 文字列中に含まれる %AppName% をアプリケーション名に置換する
/// <param name="appname">アプリケーション名</param>
/// <returns>置換後の文字列</returns>
public static string ReplaceAppName(string orig, string appname)
- {
- return orig.Replace("%AppName%", appname);
- }
+ => orig.Replace("%AppName%", appname);
/// <summary>
/// 表示用のバージョン番号の文字列を生成する
{
versionNum[2] = versionNum[2] + 1;
- // 10を越えたら桁上げ
- if (versionNum[2] >= 10)
- {
- versionNum[1] += versionNum[2] / 10;
- versionNum[2] %= 10;
-
- if (versionNum[1] >= 10)
- {
- versionNum[0] += versionNum[1] / 10;
- versionNum[1] %= 10;
- }
- }
-
if (versionNum[3] == 1)
return string.Format("{0}.{1}.{2}-dev", versionNum[0], versionNum[1], versionNum[2]);
else
- return string.Format("{0}.{1}.{2}-dev (Build {3})", versionNum[0], versionNum[1], versionNum[2], versionNum[3]);
+ return string.Format("{0}.{1}.{2}-dev+build.{3}", versionNum[0], versionNum[1], versionNum[2], versionNum[3]);
}
}
}
public static string GetStatusUrl(string screenName, long statusId)
- {
- return TwitterUrl + screenName + "/status/" + statusId;
- }
+ => TwitterUrl + screenName + "/status/" + statusId;
/// <summary>
/// 指定された IDictionary を元にクエリ文字列を生成します
public static string UrlEncode(string stringToEncode)
{
const string UnreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";
- StringBuilder sb = new StringBuilder();
- byte[] bytes = Encoding.UTF8.GetBytes(stringToEncode);
+ var sb = new StringBuilder();
+ var bytes = Encoding.UTF8.GetBytes(stringToEncode);
- foreach (byte b in bytes)
+ foreach (var b in bytes)
{
if (UnreservedChars.IndexOf((char)b) != -1)
sb.Append((char)b);