private void TrySearchObject() { if (Interlocked.CompareExchange(ref _detectionCompleted, 0, 1) == 1) { if (_cachedCameraMain == null) { _cachedCameraMain = Camera.main; } var cameraLocation = new ObjectAnchorsLocation { Position = _cachedCameraMain.transform.position, Orientation = _cachedCameraMain.transform.rotation, }; var coordinateSystem = ObjectAnchorsWorldManager.GlobalCoordinateSystem; Task.Run(async() => { try { await DetectObjectAsync(coordinateSystem, cameraLocation); } catch (Exception ex) { UnityEngine.WSA.Application.InvokeOnAppThread(() => { TextLogger.Log($"Detection failed. Exception message: {ex.ToString()}"); }, false); } Interlocked.CompareExchange(ref _detectionCompleted, 1, 0); }); } }
void OnApplicationFocus(bool focus) { var service = ObjectAnchorsService.GetService(); if (focus) { service.Resume(); if (GetComponent <ObjectSearch>().IsDiagnosticsCaptureEnabled) { TextLogger.Log("Start capture diagnostics."); service.StartDiagnosticsSession(); } } else { // Pause could block the UI for a very short time, application can put it // into a coroutine or background task. service.Pause(); // This method can run asynchronously if the Unity app supports background running. // Here we wait until the diagnostics data has been fully committed to the storage since this app // doesn't support background running. service.StopDiagnosticsSessionAsync().Wait(); } }
public void ShouldWriteToTextWriter() { TextWriter writer = new StringWriter(); ILoggerFacade logger = new TextLogger(writer); logger.Log("Test", Category.Debug, Priority.Low); StringAssert.Contains(writer.ToString(), "Test"); StringAssert.Contains(writer.ToString(), "DEBUG"); StringAssert.Contains(writer.ToString(), "Low"); }
public void WritesFormattedMessageToTextWriter(LogSeverity severity, string message, bool includeException, string expectedText) { StringWriter writer = new StringWriter(); writer.NewLine = "\n"; TextLogger logger = new TextLogger(writer); logger.Log(severity, message, includeException ? new Exception("Foo") : null); Assert.AreEqual(expectedText, writer.ToString()); }
public void ShouldWriteToTextWriter() { TextWriter writer = new StringWriter(); ILoggerFacade logger = new TextLogger() { Writer = writer }; logger.Log("Test", Category.Debug, Priority.Low); Assert.Contains("Test", writer.ToString()); Assert.Contains("DEBUG", writer.ToString()); Assert.Contains("Low", writer.ToString()); }
public async Task SaveToRepositoryAsync(string Key, string value, bool Encypt = false) { try { await localStorage.SetItemAsync(Key, value); // var test = await SecureStorage.GetAsync(Key); } catch (Exception ex) { // Possible that device doesn't support secure storage on device. TextLogger.Log(ex); } }
private void HandleObjectAnchorsServiceEvent() { Func <IObjectAnchorsServiceEventArgs, string> EventArgsFormatter = args => { return($"[{args.LastUpdatedTime.ToLongTimeString()}] ${TextLogger.Truncate(args.InstanceId.ToString(), 5)}"); }; ObjectAnchorsServiceEvent _event; while (_objectAnchorsEventQueue.TryDequeue(out _event)) { switch (_event.Kind) { case ObjectAnchorsServiceEventKind.DetectionAttempted: { TextLogger.Log($"detection attempted"); break; } case ObjectAnchorsServiceEventKind.Added: { TextLogger.LogRaw($"{EventArgsFormatter(_event.Args)} found, coverage {_event.Args.SurfaceCoverage.ToString("0.00")}"); DrawBoundingBox(_event.Args); break; } case ObjectAnchorsServiceEventKind.Updated: { TextLogger.LogRaw($"{EventArgsFormatter(_event.Args)} updated, coverage {_event.Args.SurfaceCoverage.ToString("0.00")}"); DrawBoundingBox(_event.Args); break; } case ObjectAnchorsServiceEventKind.Removed: { TextLogger.LogRaw($"{EventArgsFormatter(_event.Args)} removed"); var bbox = _boundingBoxes[_event.Args.InstanceId]; _boundingBoxes.Remove(_event.Args.InstanceId); bbox.gameObject.SetActive(false); DestroyImmediate(bbox); break; } } } }
private async void Start() { try { await _objectAnchorsService.InitializeAsync(); } catch (System.ArgumentException ex) { #if WINDOWS_UWP string message = ex.Message; Windows.Foundation.IAsyncOperation <Windows.UI.Popups.IUICommand> dialog = null; UnityEngine.WSA.Application.InvokeOnUIThread(() => dialog = new Windows.UI.Popups.MessageDialog(message, "Invalid account information").ShowAsync(), true); await dialog; #elif UNITY_EDITOR UnityEditor.EditorUtility.DisplayDialog("Invaild account information", ex.Message, "OK"); #endif // WINDOWS_UWP throw ex; } TextLogger.Log($"Object search initialized."); foreach (var file in FileHelper.GetFilesInDirectory(Application.persistentDataPath, "*.ou")) { TextLogger.Log($"Loading model ({Path.GetFileNameWithoutExtension(file)})"); await _objectAnchorsService.AddObjectModelAsync(file.Replace('/', '\\')); } #if WINDOWS_UWP StorageFolder objects3d = KnownFolders.Objects3D; foreach (string filePath in FileHelper.GetFilesInDirectory(objects3d.Path, "*.ou")) { TextLogger.Log($"Loading model ({Path.GetFileNameWithoutExtension(filePath)})"); byte[] buffer = await ReadFileBytesAsync(filePath); await _objectAnchorsService.AddObjectModelAsync(buffer); } #endif _objectQueries = InitializeObjectQueries(); if (IsDiagnosticsCaptureEnabled) { TextLogger.Log($"Start capture diagnostics."); _objectAnchorsService.StartDiagnosticsSession(); } }
private async void Start() { await _objectAnchorsService.InitializeAsync(); TextLogger.Log($"Object search initialized."); foreach (var file in FileHelper.GetFilesInDirectory(Application.persistentDataPath, "*.ou")) { TextLogger.Log($"Loading model ({Path.GetFileNameWithoutExtension(file)})"); await _objectAnchorsService.AddObjectModelAsync(file.Replace('/', '\\')); } if (IsDiagnosticsCaptureEnabled) { TextLogger.Log($"Start capture diagnostics."); _objectAnchorsService.StartDiagnosticsSession(); } }
private void ObjectAnchorsService_RunningChanged(object sender, ObjectAnchorsServiceStatus status) { TextLogger.Log($"Object search {status}"); }