public void Log(string s) { if (logTextPrefab == null) { return; } if (logWindow == null) { return; } if (logRoot == null) { return; } LogString str = new LogString() { text = s, obj = GameObject.Instantiate(logTextPrefab, logWindow.transform) as GameObject }; str.obj.SetActive(true); str.obj.transform.localScale = Vector3.one; str.obj.GetComponent <Text>().text = s; content.Enqueue(str); UpdateLog(); }
public void Given_empty_args_Should_return_empty_string() { var description = LogString.WithDescription(new Dictionary <string, string> { }); Assert.AreEqual(string.Empty, description); }
protected override void Analyze(FrameReadyEventArgs frameReadyEventArgs) { if (!Configuration.movementNavigation) { return; } var frames = _framesCollector.GetFrames().ToList(); if (frames.Count == 0) { return; } var joints = frames.Select(a => a.GetNearestSkeleton().Joints.First(j => j.JointType == _joint)).ToList(); Vector3 calculateDisplacementVector = CalculateDisplacement(joints); if (calculateDisplacementVector.Length > MinimalVectorLength) { _oldDisplacementVector = calculateDisplacementVector; } var duration = CalculateDuration(frames); LogString.Log("Event: ContinousMovementAnalyzer: " + calculateDisplacementVector.X + " " + calculateDisplacementVector.Y + " " + calculateDisplacementVector.Z); Raise(() => RaiseEvent(frames, _oldDisplacementVector, duration)); }
public void Learning() { lock (locker) LogString.Add("Начало обучения нейронной сети\n"); int counter = 0; double globalError = requiredErrorSize + 1; while (globalError > requiredErrorSize) { globalError = 0; counter++; lock (locker) LogString.Add("Эпоха: " + counter.ToString() + "\n"); for (int i = 0; i < dataToTrain.TrainSet.Count; i++) { layerPerceptron[0].AxonOnPreviousLayer = dataToTrain.TrainSet[i].InputSignal; Calculate(); layerPerceptron[layerPerceptron.Length - 1].LearningOutput(dataToTrain.TrainSet[i].ExpectedResponse); for (int j = layerPerceptron.Length - 2; j >= 0; j--) { layerPerceptron[j].LearningHidden(layerPerceptron[j + 1].SummMultiply); } Calculate(); CalculateLocalError(i); } globalError = CalculateGlobalError(); lock (locker) LogString.Add("Эпоха: " + counter.ToString() + " размер ошибки: " + globalError.ToString() + "\n"); } lock (locker) LogString.Add("Нейронная сеть успешно обучилась за " + counter.ToString() + " эпох.\n"); }
[Test] public void Implicit_invalid() { LogString s = new LogString("Foo", valid: false); Assert.Throws <ArgEx>( () => { var z = (ValidString)s; }); }
private void ShowMessage(string message) { string logString = $"{Time.ToString("HH:mm:ss")} # {VehicleBrand} {Model} - {message}"; Console.WriteLine(logString); LogString.Add(logString); }
protected override void Analyze(FrameReadyEventArgs frameReadyEventArgs) { if (!Configuration.dualSwipeNavigation) { return; } try { if (Math.Abs(_leftHandGestrue.Timestamp - _rightHandGestrue.Timestamp) > Epsilon) { return; } if (_leftHandGestrue.Gesture == GesturesEnum.SwipeToLeft && _rightHandGestrue.Gesture == GesturesEnum.SwipeToRight) { LogString.Log("Event: SwipeOut"); Raise(() => ParallelSwipeDetected(this, new SwipeEventArgs(GesturesEnum.SwipeOut))); } if (_leftHandGestrue.Gesture == GesturesEnum.SwipeToRight && _rightHandGestrue.Gesture == GesturesEnum.SwipeToLeft) { LogString.Log("Event: SwipeIn"); Raise(() => ParallelSwipeDetected(this, new SwipeEventArgs(GesturesEnum.SwipeIn))); } } catch (Exception e) { System.Console.WriteLine("wacek"); } }
protected override void Analyze(FrameReadyEventArgs frameReadyEventArgs) { var frames = _framesCollector.GetFrames(LastFrameTimestamp).ToList(); if (frames.Count == 0) { return; } var torsoPosHistory = frames.Select(a => a.GetNearestSkeleton().Joints.FirstOrDefault(b => b.JointType == TJointType.Spine)).ToList(); var LeftHandPosHistory = frames.Select(a => a.GetNearestSkeleton().Joints.FirstOrDefault(b => b.JointType == TJointType.HandLeft)).ToList(); var RightHandPosHistory = frames.Select(a => a.GetNearestSkeleton().Joints.FirstOrDefault(b => b.JointType == TJointType.HandRight)).ToList(); var lastLeftHandFrame = LeftHandPosHistory.Last(); var lastRightHandFrame = RightHandPosHistory.Last(); var lastTorsoFrame = torsoPosHistory.Last(); var diffLeft = lastTorsoFrame.Position.Z - lastLeftHandFrame.Position.Z; var diffRight = lastTorsoFrame.Position.Z - lastRightHandFrame.Position.Z; if (ignoredCalls > 0) { ignoreCallsTrigger = true; ignoredCalls--; return; } else if (ignoreCallsTrigger == true) { ignoreCallsTrigger = false; LeftLastPosition = lastLeftHandFrame.Position; RightLastPosition = lastRightHandFrame.Position; LastHandsDistance = CalculateDistance(lastLeftHandFrame, lastRightHandFrame); } Calibrate(diffLeft, diffRight); bool left = LeftHandActive(diffLeft, lastLeftHandFrame.Position); bool right = RightHandActive(diffRight, lastRightHandFrame.Position); if (left && right) { if (!bothHandsActivated) { bothHandsActivated = true; LastHandsDistance = CalculateDistance(lastLeftHandFrame, lastRightHandFrame); LogString.Log("BothHands Activated"); } NavigateByBothHands(lastLeftHandFrame, lastRightHandFrame, frames); } else if (left) { NavigateByLeftHand(lastLeftHandFrame, frames); } else if (right) { NavigateByRightHand(lastRightHandFrame, frames); } }
public void Given_args_Should_return_key_value_string() { var description = LogString.WithDescription(new Dictionary <string, string> { { "A", "a" }, { "B", "b" } }); Assert.AreEqual("A:a, B:b", description); }
/// <summary> /// 欢迎窗体的关闭方法 /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private static void StartupWindowClosing(object sender, EventArgs e) { if (_startupWindow == null) { return; } _startupWindow.Close(); _logger.Info(LogString.Normal(StringService.CoreWorkbenchAlreadyClosed)); }
public string[] GetLogInfo() { lock (locker) { string[] returnSring = LogString.ToArray(); LogString.Clear(); return(returnSring); } }
private void DrawItemHandler(object sender, DrawItemEventArgs e) { if (e.Index >= 0) { e.DrawBackground(); e.DrawFocusRectangle(); // SafeGuard against wrong configuration of list box if (!(((ListBox)sender).Items[e.Index] is LogString logEvent)) { logEvent = new LogString { LevelUppercase = @"FATAL", Message = ((ListBox)sender).Items[e.Index].ToString() }; } Color color; switch (logEvent.LevelUppercase) { case @"FATAL": color = Color.White; break; case @"ERROR": color = Color.Red; break; case @"WARN": color = Color.Goldenrod; break; case @"INFO": color = Color.Black; break; case @"DEBUG": color = Color.Gray; break; case @"TRACE": color = Color.DarkGray; break; default: color = Color.Black; break; } if (logEvent.LevelUppercase == @"FATAL") { e.Graphics.FillRectangle(Brushes.Red, e.Bounds); } // https://blogs.msdn.microsoft.com/cjacks/2006/05/19/gdi-vs-gdi-text-rendering-performance/ TextRenderer.DrawText(e.Graphics, logEvent.Message, listBoxInt.Font, new Point(0, e.Bounds.Y + 2), color, TextFormatFlags.ExternalLeading); } }
static void Main() { _logger.Info(LogString.NormalStart("=========")); _logger.Info(LogString.NormalStart("NLog服务.")); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new StartupWindow()); }
public static void ProcessLogQueue() { while (LogDisplayQueue.Any()) { LogString log = LogDisplayQueue.Dequeue(); Instance.Info(log.Message); } }
/// <summary> /// 初始化所有的服务 /// </summary> public static void InitializeService() { _informationsService.AddStartupInformation(StringService.ServiceManagerGettingStarted); #if DEBUG _informationsService.Demo_AddStartupInformation(8); #endif _logger.Info(LogString.Normal("ServiceManager")); //初始化完成,置完成状态为真 _initializeState = true; _informationsService.AddStartupInformation(StringService.ServiceManagerActivated); }
/// <summary> /// 调入EasternArt主窗体进行显示. /// </summary> public static void CallCoreWorkbench(Form window) { _startupWindow = window; CoreWorkbench bench = new CoreWorkbench(); bench.Closing += new CancelEventHandler(StartupWindowClosing); bench.Show(); window.Activate(); _logger.Info(LogString.Normal(StringService.CoreWorkbenchGettingOpened)); }
public static void CloseLog() { if (LogToFile && !string.IsNullOrEmpty(LogFileName)) { if (!Directory.Exists(FullLogPath)) { Directory.CreateDirectory(FullLogPath); } using (TextWriter tw = new StreamWriter(Path.Combine(FullLogPath, LogFileName))) { tw.Write(LogString.ToString()); } } }
private void CalculateLocalError(int indexTask) { double[] outputArray = new double[sizeOUT]; outputArray = layerPerceptron[layerPerceptron.Length - 1].AxonLayer; double[] answerArray = new double[sizeOUT]; answerArray = dataToTrain.TrainSet[indexTask].ExpectedResponse; double summ = 0; for (int i = 0; i < sizeOUT; i++) { summ += Math.Pow((answerArray[i] - outputArray[i]), 2); } lock (locker) LogString.Add("\tОбучающий сет: " + (indexTask + 1) + " размер локальной ошибки: " + (summ / dataToTrain.TrainSet.Count) + "\n"); }
public async Task InviteUser(string email, Guid applicationId) { var user = await authService.CurrentUser(); Guard.IsTrue(await hasApplicationPermission.ToWrite(user.Id, applicationId), new UnauthorizedException()); var invitations = unitOfWork.Repository <Domain.Invitation, Guid>(); var users = unitOfWork.Repository <Domain.User, Guid>(); var anyInvitationForThisEmail = await invitations.AnyAsync(Domain.Invitation.WithEmail(email).And(Domain.Invitation.WithApplication(applicationId))); Guard.IsFalse(anyInvitationForThisEmail, "You already invite this user"); var applications = unitOfWork.Repository <Domain.Application, Guid>(); var application = await applications.GetById(applicationId); var invitationUrl = urlService.GetBaseUrl(); //Check if the user exits var invitedUser = await users.FirstOrDefaultAsync(new DirectSpecification <Domain.User>(x => x.Account.Email == email), "Account"); if (invitedUser != null) { application.GrantPermissionForUser(invitedUser, Domain.ApplicationPermissions.Admin); invitationUrl += $"/account/login"; } else { var invitation = Domain.Invitation.NewInvitation(email, application); invitations.Insert(invitation); invitationUrl += $"/account/register?i={invitation.Token}&email={email}"; } activityService.Log( LogString.WithName("Invitation", "sent"), LogString.WithDescription(new Dictionary <string, string> { { "Email", email } }), applicationId, user.Id); await unitOfWork.SaveAsync(); await emailService.SendEmailAsync(new InvitationEmail(application.Name, invitationUrl, user.FullName) { To = email, Subject = $"{user.FullName} has invited you to join {application.Name}" }); }
public async Task NewToggle(Guid applicationId, string key, string description, bool enable) { var userId = authService.CurrentUserId(); Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, applicationId), "You don't have permissions to create feature toggle"); var applications = unitOfWork.Repository <Domain.Application, Guid>(); var application = await applications.FirstOrDefaultAsync(new DirectSpecification <Domain.Application>(x => x.Id == applicationId), "FeatureToggles,Environments.FeatureToggleValues"); application.AddNewFeatureToggleForDefaultEnv(key, description, enable); activityService.Log( LogString.WithName("Feature toggle", "created"), LogString.WithDescription(new Dictionary <string, string> { { "Name", key }, { "Value", enable.ToString() } }), applicationId, userId); await unitOfWork.SaveAsync(); }
public async Task RemoveFeatureToggle(Guid settingId) { var userId = authService.CurrentUserId(); var featureToggles = unitOfWork.Repository <FeatureToggle, Guid>(); var featureToggle = await featureToggles.GetById(settingId); Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, featureToggle.ApplicationId), "You don't have permissions to remove feature toggles"); featureToggles.Delete(featureToggle); activityService.Log( LogString.WithName("Feature toggle", "deleted"), LogString.WithDescription(new Dictionary <string, string> { { "Name", featureToggle.Key } }), featureToggle.ApplicationId, userId); await unitOfWork.SaveAsync(); }
public static void Log(string s) { if (Application.isPlaying && Settings.guiLoggingEnabled) { if (DevLog.Logger.logTextPrefab == null) { return; } if (DevLog.Logger.logWindow == null) { return; } if (DevLog.Logger.logRoot == null) { return; } LogString str = new LogString() { text = s, obj = GameObject.Instantiate(DevLog.Logger.logTextPrefab) as GameObject }; str.obj.transform.parent = DevLog.Logger.logWindow.transform; str.obj.SetActive(true); str.obj.transform.localScale = Vector3.one; str.obj.GetComponent <Text>().text = s; DevLog.Logger.content.Enqueue(str); DevLog.Logger.UpdateLog(); } if (Settings.loggingEnabled) { #if UNITY_EDITOR UnityEngine.Debug.Log(s); #else #if LOGLIB UnityEngine.Debug.Log(s); #else Wms.Framework.Trace.LogDebug(s); #endif #endif } }
public async Task <Guid> CreateApplication(string name) { var user = await authService.CurrentUser(); var application = Domain.Application.New(user, name); var applications = unitOfWork.Repository <Domain.Application, Guid>(); applications.Insert(application); activity.Log( LogString.WithName("Application", "created"), LogString.WithDescription(new Dictionary <string, string> { { "Name", name } }), application.Id, user.Id); await unitOfWork.SaveAsync(); return(application.Id); }
void UpdateLog() { float line_size = LineSize(); float total_size = content.Count * line_size; float max_size = logWindow.GetComponent <RectTransform>().rect.height; while (total_size > max_size) { LogString lString = content.Dequeue(); GameObject.Destroy(lString.obj.gameObject); total_size -= line_size; } while (content.Count > maxLines) { LogString lString = content.Dequeue(); GameObject.Destroy(lString.obj.gameObject); } UpdatePositions(); }
protected override void Analyze(FrameReadyEventArgs frameReadyEventArgs) { if (!Configuration.swipeNavigation) { return; } var frames = _framesCollector.GetFrames(LastFrameTimestamp).ToList(); if (frames.Count == 0) { return; } if (!EnsureDuration(frames)) { return; } var joints = frames.Select(a => a.GetNearestSkeleton().Joints.First(j => j.JointType == _joint)).ToList(); // Swipe to right if (ScanPositions(joints, (p1, p2) => Math.Abs(p2.Y - p1.Y) < SwipeMaximalHeight, // Height (p1, p2) => p2.X - p1.X > -0.01f, // Progression to right (p1, p2) => Math.Abs(p2.X - p1.X) > SwipeMinimalLength)) //Length { LogString.Log("Event: SwipeToRight"); Raise(() => RaiseGestureDetected(new SwipeEventArgs(GesturesEnum.SwipeToRight))); return; } // Swipe to left if (ScanPositions(joints, (p1, p2) => Math.Abs(p2.Y - p1.Y) < SwipeMaximalHeight, // Height (p1, p2) => p2.X - p1.X <0.01f, // Progression to right (p1, p2) => Math.Abs(p2.X - p1.X)> SwipeMinimalLength)) // Length { LogString.Log("Event: SwipeToLeft"); Raise(() => RaiseGestureDetected(new SwipeEventArgs(GesturesEnum.SwipeToLeft))); return; } }
public async Task EditToggle(Guid environmentId, Guid featureId, bool enable) { var userId = authService.CurrentUserId(); var environments = unitOfWork.Repository <Domain.ApplicationEnvironment, Guid>(); var features = unitOfWork.Repository <FeatureToggle, Guid>(); var featureToggle = await features.GetByIdAsync(featureId); var environment = await environments.GetById(environmentId, "Application.FeatureToggles,FeatureToggleValues"); Guard.IsNotNull(featureToggle, "Invalid feature toggle"); Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, environment.ApplicationId), "You don't have permissions to edit feature toggles"); environment.AddOrEditFeatureToggleValue(featureId, enable); activityService.Log( LogString.WithName("Feature toggle", "edited"), LogString.WithDescription(new Dictionary <string, string> { { "Name", featureToggle.Key }, { "Value", enable.ToString() }, { "Environment", environment.Name } }), environment.ApplicationId, userId); await unitOfWork.SaveAsync(); }
public async Task DeleteApplication(Guid id, string applicationName) { var userId = authService.CurrentUserId(); Guard.IsTrue(await hasApplicationPermission.ToDelete(userId, id), "Does not have permission for delete the application. Contact with the owner of this application"); var applications = unitOfWork.Repository <Domain.Application, Guid>(); var application = await applications.GetById(id); Guard.IsTrue(application.Name == applicationName, "The application name is not correct"); applications.Delete(application); activity.Log( LogString.WithName("Application", "deleted"), LogString.WithDescription(new Dictionary <string, string> { { "Name", applicationName } }), application.Id, userId); await unitOfWork.SaveAsync(); }
public async Task DeleteEnvironment(Guid environmentId) { var userId = authService.CurrentUserId(); var environments = unitOfWork.Repository <Domain.ApplicationEnvironment, Guid>(); var environment = await environments.GetById(environmentId, "Application.Environments"); Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, environment.ApplicationId), "Invalid permissions for remove environments"); var application = environment.Application; application.RemoveEnvironment(environment); activityService.Log( LogString.WithName("Environment", "deleted"), LogString.WithDescription(new Dictionary <string, string> { { "Name", environment.Name } }), environment.ApplicationId, userId); await unitOfWork.SaveAsync(); }
public async Task <Guid> CreateEnvironment(string name, Guid applicationId) { var userId = authService.CurrentUserId(); Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, applicationId), "Invalid permissions for create environments"); var applications = unitOfWork.Repository <Application, Guid>(); var application = await applications.FirstOrDefaultAsync(new DirectSpecification <Domain.Application>(x => x.Id == applicationId), "Environments"); var env = application.AddEnvironment(name); activityService.Log( LogString.WithName("Environment", "created"), LogString.WithDescription(new Dictionary <string, string> { { "Name", name } }), applicationId, userId); await unitOfWork.SaveAsync(); return(env.Id); }
private void MeasureItem(object sender, MeasureItemEventArgs e) { if (e.Index >= 0) { if (!(((ListBox)sender).Items[e.Index] is LogString logEvent)) { logEvent = new LogString { LevelUppercase = @"FATAL", Message = ((ListBox)sender).Items[e.Index].ToString() }; } Size sizeF = TextRenderer.MeasureText(e.Graphics, logEvent.Message, listBoxInt.Font); e.ItemHeight = sizeF.Height + 2; if (listBoxInt.HorizontalExtent < sizeF.Width) { listBoxInt.HorizontalExtent = sizeF.Width + 2; } } }