Exemplo n.º 1
0
        public static void TryReplace(string src, string dest)
        {
            var tmp = TempPath(dest);

            try {
                if (File.Exists(dest))
                {
                    // destがあればswap
                    File.Move(dest, tmp);
                    File.Move(src, dest);
                    File.Delete(src);
                }
                else
                {
                    // なければmove
                    File.Move(src, dest);
                }
            } catch (Exception e) {
                Debugs.Error("FileManager",
                             string.Format("failed to swap files: #{0}, #{1}, #{2}", src, dest, e.Message));
                throw;
            } finally {
                File.Delete(tmp);
            }
        }
Exemplo n.º 2
0
 public static bool HasBackup(string path)
 {
     try {
         return(File.Exists(BackupPath(path)));
     } catch (Exception e) {
         Debugs.Exception(e);
     }
     return(false);
 }
Exemplo n.º 3
0
 private static void CustomEvent(string eventName, IUnityAnalyticsExport data = null)
 {
     Debugs.Log("Analytics/CustomEvent", eventName);
     if (data != null)
     {
         var dict = GetDictionary();
         data.Export(ref dict, PrefixResolver.Default);
         UnityAnalytics.Analytics.CustomEvent(eventName, dict);
         EventCreator.AnalyticsEvent(eventName, dict);
     }
     else
     {
         UnityAnalytics.Analytics.CustomEvent(eventName);
         EventCreator.AnalyticsEvent(eventName, null);
     }
 }
Exemplo n.º 4
0
        public void Shuffle_ShouldShuffle()
        {
            var list  = new[] { 1, 2, 3, 4 };
            var list2 = new[] { 1, 2, 3, 4 };

            list.Shuffle();
            Debugs.Log(list.ToConcatenatedString());
            Debugs.Log(list2.ToConcatenatedString());
            var f = false;

            for (var i = 0; i < list.Length; i++)
            {
                if (list[i] != list2[i])
                {
                    f = true;
                }
            }
            Assert.AreEqual(true, f);
        }
Exemplo n.º 5
0
        public void TestAsync()
        {
            var finished = false;
            var hasError = false;
            var start    = new DateTime().Millisecond;

            Asyncs.Execute(() => { Thread.Sleep(100); })
            .Subscribe(_ => {
                Debugs.Log("completed");
                finished = true;
            }, e => {
                Debugs.Exception(e);
                hasError = true;
                finished = true;
            });
            Thread.Sleep(300);
            Assert.AreEqual(true, finished);
            Assert.AreEqual(false, hasError);
        }
Exemplo n.º 6
0
        public static bool Delete(string path)
        {
            var lck = Locks.Get(path);

            lock (lck) {
                try {
                    // 削除済みファイル名に変更
                    TryReplace(path, DeletedPath(path));
                    // そっちを消す
                    File.Delete(DeletedPath(path));
                    return(true);
                } catch (Exception e) {
                    Debugs.Error("Files", "failed delete file: " + path + "," + e.Message);
                    return(false);
                } finally {
                    lck.Dispose();
                }
            }
        }
Exemplo n.º 7
0
 public void TestFileLogger()
 {
     using (var logger = Loggers.NewFileLogger("test",
                                               "Temp/test.log",
                                               TimeSpan.FromMinutes(1),
                                               null,
                                               true,
                                               FileMode.Create)) {
         logger.Log("way", "loglog");
         var bytes = Files.TryRead("Temp/test.log");
         // 書き込まれてない
         Assert.AreEqual(0, bytes.Length);
         logger.Flush(true);
         // 書き込まれてる
         bytes = Files.TryRead("Temp/test.log");
         var line = Encoding.UTF8.GetString(bytes);
         Assert.AreEqual(true, bytes.Length > 0);
         Debugs.Log(line);
         var regex = new Regex(
             "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}:\\d{2} \\d{3}ms/\\d+?F <L> \\[test/way\\]: loglog$");
         Assert.AreEqual(true, regex.Match(line).Success);
     }
 }