private void Application_Startup(object sender, StartupEventArgs e) { DispatcherHelper.UIDispatcher = Dispatcher; NativeTime.BeginPeriod(1); CorbaUtility.Initialize(); LogManager.Initialize(); SettingHolder.BaseDirectory = Settings.Default.DataDirectory; var dir = SettingHolder.BaseDirectory; try { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // データベースファイルが見つからなかった場合は、空のファイルを作成 var filePath = dir + "RecordDescriptions.db"; if (!File.Exists(filePath)) { using (var writer = new BinaryWriter(File.Create(filePath))) { writer.Write(RtStorage.Properties.Resources.RecordDescriptions); } } } catch (Exception ex) { //TODO: ユーザーへのエラー通知が必要 } #if !USE_MOCK NamingServiceManager.Default.Initialize(); #endif #if !DEBUG AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; #endif #if USE_MOCK var ns = MockFactory.CreateNamingService("MockServer", 2809); var inport = new DelegateInPortCdr(_ => PortStatus.PORT_OK); ns.RtObjects = new Dictionary <string, RTObject>() { { "SampleIn0.rtc", MockFactory.CreateRTObject("SampleIn", "SampleIn0", MockFactory.CreateInPortService("SampleIn0.in", "IDL:RTC/TimedLong:1.0", inport)) }, { "SampleIn1.rtc", MockFactory.CreateRTObject("SampleIn", "SampleIn1", MockFactory.CreateInPortService("SampleIn1.in", "IDL:RTC/TimedLong:1.0", inport)) }, { "SampleOut0.rtc", MockFactory.CreateRTObject("SampleOut", "SampleOut0", MockFactory.CreateOutPortService("SampleOut0.out", "IDL:RTC/TimedLong:1.0")) }, { "SampleOut1.rtc", MockFactory.CreateRTObject("SampleOut", "SampleOut1", MockFactory.CreateOutPortService("SampleOut1.out", "IDL:RTC/TimedLong:1.0")) }, }; Observable.Start(() => { NamingServiceManager.Default.AddNamingService(new NamingService(ns)); NamingServiceManager.Default.UpdateAsync(); }); var repository = RepositoryFactory.CreateRepository(); var data = new List <RecordDescription>() { new RecordDescription() { CreatedDateTime = DateTime.Now, TimeSpan = 10000, NamingName = "MockServer/ConsoleIn0.rtc", ComponentType = "ConsoleIn", PortName = "ConsoleIn0.out", DataType = "IDL:RTC/TimedLong:1.0", SumSize = 120000000000, Count = 10, IsLittleEndian = 1, IndexFileName = "Data/hoge.index", DataFileName = "Data/hoge.data", }, new RecordDescription() { CreatedDateTime = DateTime.Now, TimeSpan = 10000, NamingName = "MockServer/SampleInOut0.rtc", ComponentType = "SampleInOut", PortName = "SampleInOut0.in", DataType = "IDL:RTC/TimedDouble:1.0", SumSize = 120, Count = 10, IsLittleEndian = 1, IndexFileName = "Data/hoge.index", DataFileName = "Data/hoge.data", }, new RecordDescription() { CreatedDateTime = DateTime.Now, TimeSpan = 10000, NamingName = "MockServer/SampleInOut0.rtc", ComponentType = "SampleInOut", PortName = "SampleInOut0.out", DataType = "IDL:RTC/TimedDouble:1.0", SumSize = 120, Count = 10, IsLittleEndian = 1, IndexFileName = "Data/hoge.index", DataFileName = "Data/hoge.data", }, new RecordDescription() { CreatedDateTime = DateTime.Now, TimeSpan = 10000, NamingName = "MockServer/SampleComp0.rtc", ComponentType = "SampleComp", PortName = "SampleComp0.out", DataType = "IDL:RTC/TimedString:1.0", SumSize = 120, Count = 10, IsLittleEndian = 1, IndexFileName = "Data/hoge.index", DataFileName = "Data/hoge.data", } }; data.ForEach(repository.Insert); // 通信遅延を発生させて、UIがロックしないことを確認する //MockProxy<NamingServiceMock>.WaitTime = TimeSpan.FromSeconds(1); //MockProxy<MockRecordDescriptionRepository>.WaitTime = TimeSpan.FromSeconds(1); // ネーミングサービスに接続できないエラーが発生した場合の挙動を確認する。 //MockProxy<NamingServiceMock>.ErrorMap.Add("GetObjectNames", new TRANSIENT()); // ネーミングサービスに登録されていたコンポーネントに接続できない場合の挙動を確認する //MockProxy<RTObjectMock>.ErrorMap.Add("get_ports", new TRANSIENT()); //MockProxy<RTObjectMock>.ErrorMap.Add("get_component_profile", new TRANSIENT()); //MockProxy<MockRecordDescriptionRepository>.ErrorMap.Add("*", new Exception()); #endif }
private void Start() { lock (_lockObject) { if (!IsAlive) { return; } if (IsRecording) { return; } IsRecording = true; try { var adapter = new DelegateInPortCdr(Write); var orb = OrbServices.GetSingleton(); var ior = orb.object_to_string(adapter); var prof = new ConnectorProfile(); prof.ports = new[] { _portService }; prof.name = "dummy"; // 名前見直し? prof.connector_id = ""; ConnectorProfileExtension.AddDataFlowType(ref prof, "push"); ConnectorProfileExtension.AddInterfaceType(ref prof, "corba_cdr"); ConnectorProfileExtension.AddSubscriptionType(ref prof, "new"); ConnectorProfileExtension.AddInPortIor(ref prof, ior); var ret = _portService.connect(ref prof); if (ret != ReturnCode_t.RTC_OK) { throw new Exception("接続に失敗しました。"); } _connectorId = prof.connector_id; //TODO: エンディアンチェックしたいけど、ミドルウェアが対応してない。 //name = "dataport.serializer.cdr.endian" } catch (Exception) { IsAlive = false; NotifyError("ポートの接続に失敗しました。"); return; } var now = DateTime.Now; RecordDescription.CreatedDateTime = now; RecordDescription.Count = 0; RecordDescription.SumSize = 0; RecordDescription.IsLittleEndian = 1; var fileName = FileUtility.ValidFileName(now.ToString("yyyyMMdd_HHmmss") + "_" + Key); RecordDescription.DataFileName = fileName + ".data"; RecordDescription.IndexFileName = fileName + ".index"; try { if (!Directory.Exists(SettingHolder.BaseDirectory)) { Directory.CreateDirectory(SettingHolder.BaseDirectory); } _dataFileWriter = new BinaryWriter( File.Create(SettingHolder.BaseDirectory + RecordDescription.DataFileName)); _indexFileWriter = new BinaryWriter( File.Create(SettingHolder.BaseDirectory + RecordDescription.IndexFileName)); } catch (Exception) { IsAlive = false; NotifyError("ファイルを開くことができませんでした。"); return; } try { if (AutoActivate) { var comp = NamingServiceManager.Default.GetComponent(_namingName); if (comp.GetState(0) == LifeCycleState.INACTIVE_STATE) { comp.Activate(0); } comp.WaitState(LifeCycleState.ACTIVE_STATE, TimeSpan.FromSeconds(5)); } } catch (Exception) { IsAlive = false; NotifyError("RTコンポーネントの活性化に失敗しました。"); return; } _stopWatch.Start(); IsRecording = true; } }