Esempio n. 1
0
        public virtual void Update(float time)
        {
            if (!IsFocused)
            {
                _window.CursorGrabbed = false;
                return;
            }
            if (KeyboardState.IsKeyDown(Keys.Escape))
            {
                this.Stop();
            }
            if (_firstMove)
            {
                _lastPos   = new Vector2(MouseState.X, MouseState.Y);
                _firstMove = false;
            }
            else
            {
                var deltaX = MouseState.X - _lastPos.X;
                var deltaY = MouseState.Y - _lastPos.Y;
                _lastPos = new Vector2(MouseState.X, MouseState.Y);

                // Apply the camera pitch and yaw (we clamp the pitch in the camera class)
                Camera.Yaw   += deltaX * Camera.Sensivity;
                Camera.Pitch -= deltaY * Camera.Sensivity;
            }
            Camera.Update(KeyboardState, MouseState, time);
            LogExtensions.LogGLError();
        }
Esempio n. 2
0
        public static bool InvokeShortCuts(Key key, ModifierKeys modifiers)
        {
            var tempShortKey = new ShortKey(key, modifiers);

            if (shortCommandSource.ContainsKey(tempShortKey))
            {
                try
                {
                    var now = DateTime.Now.Ticks;
                    if (now - lastTimeSpan < TimeSpan.FromMilliseconds(800).Ticks)
                    {
                        LogExtensions.Info(null, $"Skip shrortCuts {tempShortKey} with duration too small");
                        return(true);
                    }
                    lastTimeSpan = now;
                    LogExtensions.Info(null, "Invoke ShortKey:{0}", tempShortKey);
                    var tempCommand = shortCommandSource[tempShortKey];
                    tempCommand.Execute(null);
                    LogExtensions.Info(null, "Invoke ShortKey:{0} Succ", tempShortKey);
                }
                catch (Exception ex)
                {
                    LogExtensions.Error(null, ex, "Invoke ShortKey:{0} faild", tempShortKey);
                }
                return(true);
            }
            return(false);
        }
        public bool TryDecrypt(out string username, out string password)
        {
            RunSettings runSettings = this._settings.Of <RunSettings>();

            username = runSettings.get_Username();
            password = runSettings.get_Password();
            if (!username.IsNullOrEmpty() && !password.IsNullOrEmpty())
            {
                bool result;
                try
                {
                    username = MachineProtectedData.Decrypt(username);
                    password = MachineProtectedData.Decrypt(password);
                    goto IL_56;
                }
                catch (CryptographicException ex)
                {
                    LogExtensions.Error(this._log, ex);
                    result = false;
                }
                return(result);

IL_56:
                return(!username.IsNullOrEmpty() && !password.IsNullOrEmpty());
            }
            return(false);
        }
Esempio n. 4
0
        public override void Setup()
        {
            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(0.2f, 0.5f, 0.4f, 1.0f);
            var cubeData  = GetCubeData().Select(d => new ColoredVertex(d)).ToArray();
            var positions = Enumerable.Range(0, 10).Select(i =>
            {
                float x      = MathF.PI * i;
                float y      = 4 * MathF.Sin(x);
                float z      = -1.0f;
                var position = new Vector3(x, y, z);
                return(position);
            }).ToArray();
            var attributes = new [] {
                new VertexAttribute("aPosition", 3, VertexAttribPointerType.Float, sizeof(float) * (3 + 4), 0),
                new VertexAttribute("aColor", 4, VertexAttribPointerType.Float, sizeof(float) * (3 + 4), sizeof(float) * 3)
            };
            var shader = ShaderProgram.CreateShaderProgram("Assets/Shaders/vertex.shader", "Assets/Shaders/frag.shader", attributes);

            _shader = shader;
            _graph  = Graph <ColoredVertex> .CreateGraph(cubeData, positions, shader);

            base.Setup();
            LogExtensions.LogGLError();
        }
Esempio n. 5
0
        static ShortKeyManager()
        {
            var    tempConfigPath = Extensions.Extensions.GetPhysicalPath(_configFile);
            string configContent  = "";

            if (File.Exists(tempConfigPath))
            {
                configContent = File.ReadAllText(tempConfigPath);
            }
            if (string.IsNullOrEmpty(configContent))
            {
                Config = new ShortKeyCaches();
                UpdateDisplayConfig();
                return;
            }
            try
            {
                var config = configContent.ToObjectFromXml <ShortKeyCaches>();
                if (config != null)
                {
                    Config = config;
                }
            }
            catch (Exception e)
            {
                LogExtensions.Error(null, e);
                Config = new ShortKeyCaches();
            }
        }
Esempio n. 6
0
 /// <summary>
 ///   Sets up logging to be with a certain type
 /// </summary>
 /// <typeparam name="T">The type of ILog for the application to use</typeparam>
 /// <param name="resetLoggers">Should other loggers be reset?</param>
 public static void InitializeWith <T>(bool resetLoggers = true) where T : ILog, new()
 {
     _logType = typeof(T);
     if (resetLoggers)
     {
         LogExtensions.ResetLoggers();
     }
 }
Esempio n. 7
0
            public void Should_Not_Throw_If_Log_Is_Null_When_Logging_With_Custom_Verbosity()
            {
                // Given, When
                var result = Record.Exception(() => LogExtensions.Verbose(null, Verbosity.Normal, "Hello World"));

                // Then
                Assert.Null(result);
            }
        public void EnvironmentIsUnknownIfBuildVariablesDontHaveValues()
        {
            AutomationEnvironmentProvider.environmentVariableReader = new ServerEnvironmentVariablesForTest(string.Empty, string.Empty);

            Log.EnableServiceMessages();

            Assert.IsFalse(LogExtensions.IsKnownEnvironment());
        }
            public void Should_Throw_If_Log_Null()
            {
                // When
                var result = Record.Exception(() => LogExtensions.WithVerbosity(null, Verbosity.Diagnostic));

                // Then
                AssertEx.IsArgumentNullException(result, "log");
            }
Esempio n. 10
0
        static int PrintError(Exception ex)
        {
            var agg = ex as AggregateException;

            if (agg != null)
            {
                var errors = new HashSet <Exception>(agg.InnerExceptions);
                if (agg.InnerException != null)
                {
                    errors.Add(ex.InnerException);
                }

                var lastExit = 0;
                foreach (var inner in errors)
                {
                    lastExit = PrintError(inner);
                }

                return(lastExit);
            }

            var cmd = ex as CommandException;

            if (cmd != null)
            {
                Log.Error(ex.Message);
                if (LogExtensions.IsKnownEnvironment())
                {
                    Log.Error("This error is most likely ocurring while executing Octo.exe as part of an automated build process. The following doc is recommended to get some tips on how to troubleshoot this: https://g.octopushq.com/OctoexeTroubleshooting");
                }
                return(-1);
            }
            var reflex = ex as ReflectionTypeLoadException;

            if (reflex != null)
            {
                Log.Error(ex, "");

                foreach (var loaderException in reflex.LoaderExceptions)
                {
                    Log.Error(loaderException, "");
                }

                return(-43);
            }

            var octo = ex as OctopusException;

            if (octo != null)
            {
                Log.Information("{HttpErrorMessage:l}", octo.Message);
                Log.Error("Error from Octopus server (HTTP {StatusCode} {StatusDescription})", octo.HttpStatusCode, (HttpStatusCode)octo.HttpStatusCode);
                return(-7);
            }

            Log.Error(ex, "");
            return(-3);
        }
Esempio n. 11
0
 /// <summary>
 ///   Sets up logging to be with a certain instance. The other method is preferred.
 /// </summary>
 /// <param name="loggerType">Type of the logger.</param>
 /// <param name="resetLoggers">Should other loggers be reset?</param>
 /// <remarks>Resetting the loggers is mostly geared towards testing</remarks>
 public static void InitializeWith(ILog loggerType, bool resetLoggers = true)
 {
     _logType = loggerType.GetType();
     _logger  = loggerType;
     if (resetLoggers)
     {
         LogExtensions.ResetLoggers();
     }
 }
Esempio n. 12
0
        public ILog Log()
        {
            if (LogService.IsInitialized())
            {
                LogService.Instance = _logservice;
            }

            return(LogExtensions.Log <PoshHostUserInterface>(this));
        }
Esempio n. 13
0
        private void StartOperation(int groupSelectedIndex, PortReaderOperation operation)
        {
            IEnumerable <XmlTelephoneItem> telephones = groupSelectedIndex == 0 ? _xmlWrapper.TelephoneItems
                : _xmlWrapper.TelephoneItems.Where(x => x.GroupName == cbGroupFilter.Items[groupSelectedIndex].ToString());
            var nonActiveTelephones = telephones.Where(tel => !tel.IsActivated()).ToList();

            LogExtensions.WriteSettingsLog(_xmlWrapper.CallSettings, _xmlWrapper.GroupSettings, _workingDirectory);
            StartOperation(nonActiveTelephones, operation);
        }
Esempio n. 14
0
        public static void Unbind <BuffType>(GLBufferDynamic <BuffType> buffer) where BuffType : struct
        {
            // Check if buffer is null
            if (buffer == null)
            {
                LogExtensions.ThrowStatic("Cannot unbind buffer: buffer is null");
            }

            GL.BindBuffer(buffer.Settings.Target, 0);
        }
Esempio n. 15
0
        /// <summary>
        /// Bind the specified buffer.
        /// </summary>
        /// <param name="buffer">Buffer.</param>
        /// <typeparam name="BuffType">The 1st type parameter.</typeparam>
        public static void Bind <BuffType> (GLBuffer <BuffType> buffer) where BuffType : struct
        {
            // Check if the buffer is null
            if (buffer == null)
            {
                LogExtensions.ThrowStatic("Cannot bind buffer: buffer is null");
            }

            // Bind the buffer
            GL.BindBuffer(buffer.Settings.Target, buffer.BufferId);
        }
 public static void WriteMessage(string logMessage, bool isError)
 {
     if (isError)
     {
         LogExtensions.LogError(typeof(WriteLogMessage), logMessage, null);
     }
     else
     {
         LogExtensions.LogInfo(typeof(WriteLogMessage), logMessage);
     }
 }
Esempio n. 17
0
 private static void ParseVerbosity(Arguments arguments, string value)
 {
     // first try the old version, this check will be removed in version 6.0.0, making it a breaking change
     if (Enum.TryParse(value, true, out LogLevel logLevel))
     {
         arguments.Verbosity = LogExtensions.GetVerbosityForLevel(logLevel);
     }
     else if (!Enum.TryParse(value, true, out arguments.Verbosity))
     {
         throw new WarningException($"Could not parse Verbosity value '{value}'");
     }
 }
    public void GetSerializeObjectString_StateUnderTest_ExpectedBehavior()
    {
        // Arrange
        EmployeeModel objectToSerialize = default;

        // Act
        var result = LogExtensions.GetSerializeObjectString(
            objectToSerialize);

        // Assert
        Assert.IsNotNull(result);
    }
Esempio n. 19
0
        internal void SetLogExtensions(string extensionList)
        {
            IEnumerable <string> extensions = extensionList
                                              .Split(';')
                                              .Select(extension => extension.Trim())
                                              .Where(extension => extension.Length > 0);

            foreach (string e in extensions)
            {
                LogExtensions.Add((e[0] == '.') ? e : string.Format(".{0}", e));
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Parse a floating-point number.
        /// </summary>
        /// <returns>The float.</returns>
        /// <param name="str">String.</param>
        float ParseFloat(string str)
        {
            var   format = NumberFormatInfo.InvariantInfo;
            var   styles = NumberStyles.Float;
            float parsed;

            if (!float.TryParse(str, styles, format, out parsed))
            {
                LogExtensions.ThrowStatic("Invalid obj file: Expected float at line {0}:{1}", line, linepos);
            }
            return(parsed);
        }
    public void GetSerializeObjectString_StateUnderTest_ExpectedBehavior1()
    {
        // Arrange
        List <EmployeeModel> lstObjectToSerialize = new();

        // Act
        var result = LogExtensions.GetSerializeObjectString(
            lstObjectToSerialize);

        // Assert
        Assert.IsNotNull(result);
    }
    public void IsSimpleType_StateUnderTest_ExpectedBehaviorFalse()
    {
        // Arrange
        EmployeeModel type = new();

        // Act
        var result = LogExtensions.IsSimpleType(
            type.GetType());

        // Assert
        Assert.IsNotNull(result);
        Assert.IsFalse(result);
    }
    public void IsSimpleType_StateUnderTest_ExpectedBehaviorTrue()
    {
        // Arrange
        string type = "test";

        // Act
        var result = LogExtensions.IsSimpleType(
            type.GetType());

        // Assert
        Assert.IsNotNull(result);
        Assert.IsTrue(result);
    }
Esempio n. 24
0
 /// <summary>
 /// When implemented in a derived class, performs the execution of the activity.
 /// </summary>
 /// <param name="context">The execution context under which the activity executes.</param>
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         var inWorkItem = context.GetValue <WorkItem>(WorkItem);
         context.SetValue(this.CurrentRevision, this.GetCurrentWIRevision(inWorkItem));
         LogExtensions.LogInfo(this, string.Format("Activity GetCurrentRevision: Latest revision of workitem {0} returned.", inWorkItem.Id));
     }
     catch (Exception ex)
     {
         throw new Exception("Activity GetCurrentRevision:", ex);
     }
 }
Esempio n. 25
0
 /// <summary>
 /// When implemented in a derived class, performs the execution of the activity.
 /// </summary>
 /// <param name="context">The execution context under which the activity executes.</param>
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         var inWorkItem = context.GetValue <WorkItem>(WorkItem);
         context.SetValue(CollectionOfNotValidFields, GetValidationOfWorkitem(inWorkItem));
         LogExtensions.LogInfo(this, string.Format("Activity GetValidationOfWorkItem: Workitem {0} validated.", inWorkItem.Id));
     }
     catch (Exception ex)
     {
         throw new Exception("Activity GetValidationOfWorkItem:", ex);
     }
 }
Esempio n. 26
0
        public async Task ComputeDataAsync(List <string> data)
        {
            //first data filtering
            data = data.Where(RegexExtensions.IsCorrectRecord).ToList();
            //convert string to row item
            List <RowLogItem> rowLogItems = data
                                            .Select(x => new RowLogItem(x))
                                            .Select(LogExtensions.GetIP)
                                            .Where(x => x != null)
                                            .ToList();

            //get unique Ips from incoming data
            var uniqueIps = rowLogItems
                            .Select(x => x.IP)
                            .Distinct()
                            .Except(_badIp)
                            .ToList();

            //get all ips from db
            var dbIps = _context.Addresses.Include(x => x.Country)
                        .Where(x => uniqueIps.Any(xx => xx.IsEqual(x.Ip)))
                        .ToList();

            //exclude ips from collection
            uniqueIps = uniqueIps
                        .Where(x => !dbIps.Any(mm => mm.Ip.IsEqual(x)))
                        .ToList();

            List <IpGeoLocation> ipGeoLocations = GetIpGeoLocations(uniqueIps, dbIps);

            rowLogItems = rowLogItems
                          .Select(LogExtensions.UpdateRootObject(ipGeoLocations))
                          .Where(LogExtensions.CheckIpGeoLocation)
                          .ToList();

            var routes = await _context.Routes
                         .Where(route => rowLogItems.Any(r => r.Route.IsEqual(route.Name)))
                         .ToListAsync();

            List <Country> countries = await _context.Countries
                                       .Where(country => rowLogItems.Any(r => r.IpGeoLocation.CountryName.IsEqual(country.Name)))
                                       .ToListAsync();

            var dataForSaveToDb = rowLogItems
                                  .Select(CreateRequestUrl(dbIps, routes, countries))
                                  .ToList();

            await _context.RequestUrls.AddRangeAsync(dataForSaveToDb);

            await _context.SaveChangesAsync();
        }
        public void EnvironmentIsKnownIfBuildVariablesHaveValues()
        {
            foreach (var knownEnvironmentVariable in AutomationEnvironmentProvider.KnownEnvironmentVariables)
            {
                foreach (var variable in knownEnvironmentVariable.Value)
                {
                    AutomationEnvironmentProvider.environmentVariableReader = new ServerEnvironmentVariablesForTest(variable, "whatever value");

                    Log.EnableServiceMessages();

                    Assert.IsTrue(LogExtensions.IsKnownEnvironment());
                }
            }
        }
Esempio n. 28
0
 /// <summary>
 /// When implemented in a derived class, performs the execution of the activity.
 /// </summary>
 /// <param name="context">The execution context under which the activity executes.</param>
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         var           inWorkItem = context.GetValue <WorkItem>(WorkItem);
         List <string> fieldsList = context.GetValue <List <string> >(WorkItemFieldsList);
         context.SetValue(ChildWorkItems, GetChildWorkitems(inWorkItem, fieldsList));
         LogExtensions.LogInfo(this, string.Format("Activity GetChildWorkItems: All child workitems of workitem {0} collected.", inWorkItem.Id));
     }
     catch (Exception ex)
     {
         throw new Exception("Activity GetChildWorkItems:", ex);
     }
 }
        protected override void Execute(CodeActivityContext context)
        {
            bool   isError    = context.GetValue(this.IsError);
            string logMessage = context.GetValue(this.LogMessage);

            if (isError)
            {
                LogExtensions.LogError(this, logMessage, null);
            }
            else
            {
                LogExtensions.LogInfo(this, logMessage);
            }
        }
Esempio n. 30
0
 public static void ExcuteCommandWithoutDispatcher <T>(this IRegistorCommand <T> command, object param)
 {
     try
     {
         if (command.CanExecute(param))
         {
             command.Execute(param);
         }
     }
     catch (Exception ex)
     {
         LogExtensions.Critical(null, ex);
     }
 }