Esempio n. 1
0
    private static void MainLoop(Reader reader,
                                 Writer writer,
                                 MidProcessTimer midPrcTimer)
    {
      midPrcTimer?.Start();
      while (true)
      {
        //読
        byte[] data = reader.Read();
        if (data == null) continue;        //パイプバッファ待ち、未書込エリアの読込み
        else if (data.Length == 0) break;  //パイプ切断 & ファイル終端
        //書
        writer.Write(data);
        if (writer.HasClient == false) break;

        UpdateStatus(Log.TotalRead.TotalPipeRead, Log.TotalRead.TotalFileRead);
        GC.Collect();
      }
      //close
      ProhibitFileMove_pfA.Lock();
      reader.Close();
      writer.Close();
      ProhibitFileMove_pfA.Lock();  //.noncapがwriter.Close()時に作成されるため
      Log.System.WriteLine();
      Log.System.WriteLine(Log.TotalRead.GetResult());
      midPrcTimer?.Stop();
    }
Esempio n. 2
0
    private static void Main(string[] AppArgs)
    {
      //AppArgs = new string[] { @"E:\TS_Samp\t2s.ts" };
      //AppArgs = new string[] { @"E:\TS_Samp\t2s.ts", "-xml", "pfAdapter-2.xml" };




      //例外を捕捉する
      AppDomain.CurrentDomain.UnhandledException += OctNov.Excp.ExceptionInfo.OnUnhandledException;


      Log.System.Enable = true;
      Log.System.OutConsole = true;
      Log.System.OutFile = true;
      Directory.SetCurrentDirectory(App.Dir);
      var setting = new AppSetting(AppArgs);
      setting.GetInput();


      //
      //パイプ接続、ファイル確認
      //
      Log.System.WriteLine("[ Connect Reader ]");
      Reader reader;
      {
        reader = new Reader();
        bool isConnected = reader.Connect(setting.Pipe, setting.File);
        /*  デバッグ用  入力ストリームのログ     log file size  8 MB/10 min  */
        //Log.Input.Enable = true;
        //Log.Input.OutFile = true;
        //Log.Input.AutoFlush = true;

        // no reader ?
        if (isConnected == false)
        {
          //設定ファイルが無ければ新規作成してから終了
          pfAdapter.Setting.Setting_File.LoadFile();
          Log.System.WriteLine("[ App CommandLine ]");
          Log.System.WriteLine(string.Join(" ", AppArgs));
          Log.System.WriteLine();
          Log.System.WriteLine("入力ファイルを読み込めません。");
          Log.System.WriteLine(setting.File);
          Log.System.WriteLine("exit");
          Log.System.WriteLine();
          Log.Close();
          Thread.Sleep(2 * 1000);
          return;//exit
        }
      }


      //load xml setting
      bool initialized = Initialize(setting);
      if (initialized == false)
      {
        Log.System.WriteLine("exit");
        Log.System.WriteLine();
        Log.Close();
        return;//exit
      }
      ProhibitFileMove_pfA.Initialize(setting.File, setting.LockMove);


      //Reader設定
      Log.System.WriteLine("[ Reader Param ]");
      reader.SetParam(setting.BuffSize_MiB, setting.ReadLimit_MiBsec);

      //ProcessList
      if (setting.PreProcess.IsEnable)
      {
        Log.System.WriteLine("[ PreProcess ]");
        setting.PreProcess.Wait_and_Run();
        Log.System.WriteLine();
      }
      MidProcessTimer midPrcTimer = null;
      if (setting.MidProcess.IsEnable)
      {
        //初期化のみ、タイマーは停止
        midPrcTimer = new MidProcessTimer(setting.MidProcess,
                                          setting.MidInterval_min);
      }

      //
      //Run Writer Client
      //
      Log.System.WriteLine("[ Register Writer ]");
      Writer writer;
      {
        writer = new Writer();
        writer.RegisterClient(setting.Client_Pipe);
        writer.Timeout = TimeSpan.FromSeconds(setting.PipeTimeout_sec);
        /*  デバッグ用 ファイル出力を登録  */
        //writer.RegisterOutFileClient(setting.File);

        // no writer ?
        if (writer.HasClient == false)
        {
          Log.System.WriteLine("出力先プロセスが起動していません。");
          Log.System.WriteLine("exit");
          Log.System.WriteLine();
          Log.Close();
          Thread.Sleep(2 * 1000);
          return;//exit
        }
      }


      //
      //MainLoop
      //
      Log.System.WriteLine("[ Main Loop ]");
      Log.Flush();
      MainLoop(reader, writer, midPrcTimer);


      //PostPrc
      if (setting.PostProcess.IsEnable)
      {
        Log.System.WriteLine("[ PostProcess ]");
        setting.PostProcess.Wait();
        ProhibitFileMove_pfA.Unlock();  //移動禁止は待機中だけ
        setting.PostProcess.Run();
      }

      Log.System.WriteLine();
      Log.System.WriteLine("elapse  {0,3:f0} min", App.Elapse.TotalMinutes);
      Log.System.WriteLine("exit");
      Log.System.WriteLine();
      Log.System.WriteLine();
      Log.Close();
    }//func