コード例 #1
0
ファイル: PActionManager.cs プロジェクト: peterhaneve/ONIMods
        private void RegisterKeyBindings()
        {
            int n = actions.Count;

            LogKeyBind("Registering {0:D} key bind(s) for mod {1}".F(n, Assembly.
                                                                     GetExecutingAssembly().GetNameSafe() ?? "?"));
            var currentBindings = new List <BindingEntry>(GameInputMapping.DefaultBindings);

            foreach (var action in actions)
            {
                var kAction = action.GetKAction();
                var binding = action.DefaultBinding;
                if (!FindKeyBinding(currentBindings, kAction))
                {
                    if (binding == null)
                    {
                        binding = new PKeyBinding();
                    }
                    // This constructor changes often enough to be worth detouring
                    currentBindings.Add(NEW_BINDING_ENTRY.Invoke(CATEGORY, binding.
                                                                 GamePadButton, binding.Key, binding.Modifiers, kAction));
                }
            }
            GameInputMapping.SetDefaultKeyBindings(currentBindings.ToArray());
            UpdateMaxAction();
        }
コード例 #2
0
        public IRobotLog AddEntry(RobotLogEntry entry)
        {
            MessagesList.Add(entry);

            NewEntry?.Invoke(this, new RobotLogNewEntryEventArgs(entry));

            return(this);
        }
コード例 #3
0
ファイル: Logger.cs プロジェクト: jorolf/osu-framework
        /// <summary>
        /// Log an arbitrary string to current log.
        /// </summary>
        /// <param name="message">The message to log. Can include newline (\n) characters to split into multiple lines.</param>
        /// <param name="level">The verbosity level.</param>
        public void Add(string message = @"", LogLevel level = LogLevel.Verbose)
        {
#if Public
            if (level < LogLevel.Important)
            {
                return;
            }
#endif

#if !DEBUG
            if (level <= LogLevel.Debug)
            {
                return;
            }
#endif

            if (!Enabled)
            {
                return;
            }

            message = ApplyFilters(message);

            //split each line up.
            string[] lines = message.TrimEnd().Replace(@"\r\n", @"\n").Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                string s = lines[i];
                lines[i] = $@"{DateTime.UtcNow.ToString(NumberFormatInfo.InvariantInfo)}: {s.Trim()}";
            }

            LogEntry entry = new LogEntry
            {
                Level   = level,
                Target  = Target,
                Message = message
            };

            NewEntry?.Invoke(entry);

            backgroundScheduler.Add(delegate
            {
                ensureLogDirectoryExists();
                if (!hasLogDirectory.Value)
                {
                    return;
                }

                try
                {
                    File.AppendAllLines(Filename, lines);
                }
                catch
                {
                }
            });
        }
コード例 #4
0
 public void StartListener()
 {
     entryListener = instance.AddEntryListener("", (in RefEntryNotification notification) =>
     {
         if (notification.Flags.HasFlag(NotifyFlags.New))
         {
             NewEntry?.Invoke(notification.Name, notification.Entry, notification.Value.ToValue());
         }
         else if (notification.Flags.HasFlag(NotifyFlags.Delete))
         {
             DeletedEntry?.Invoke(notification.Name);
         }
     }, NotifyFlags.New | NotifyFlags.Delete | NotifyFlags.Immediate | NotifyFlags.Local);
コード例 #5
0
        public void Entry(JournalEntry je, bool stored, bool recent)        // on UI thread. hooked into journal monitor and receives new entries.. Also call if you programatically add an entry
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);

            if (je.EventTimeUTC >= lastutc)     // in case we get them fed in the wrong order, or during stored reply we have two playing, only take the latest one
            {
                System.Diagnostics.Debug.WriteLine("JE " + stored + ":" + recent + ":" + EDCommander.GetCommander(je.CommanderId).Name + ":" + je.EventTypeStr);

                if (je.CommanderId != currentcmdrnr)
                {
                    Reset(false);
                    currentcmdrnr             = je.CommanderId;
                    EDCommander.CurrentCmdrID = currentcmdrnr;
                }

                HistoryEntry he = HistoryEntry.FromJournalEntry(je, currenthe, false, out bool unusedjournalupdate);
                he.UpdateMaterials(je, currenthe);

                cashledger.Process(je);
                he.Credits = cashledger.CashTotal;

                he.UpdateMissionList(missionlistaccumulator.Process(je, he.System, he.WhereAmI));

                currenthe = he;
                lastutc   = je.EventTimeUTC;
                outfitting.Process(je);

                Tuple <ShipInformation, ModulesInStore> ret = shipinformationlist.Process(je, he.WhereAmI, he.System);
                he.UpdateShipInformation(ret.Item1);
                he.UpdateShipStoredModules(ret.Item2);

                NewEntry?.Invoke(he, stored, recent);
            }
            else
            {
                //System.Diagnostics.Debug.WriteLine("Rejected older JE " + stored + ":" + recent + ":" + EDCommander.GetCommander(je.CommanderId).Name + " " + je.EventTypeStr);
            }
        }
コード例 #6
0
        private void add(string message = @"", LogLevel level = LogLevel.Verbose, bool outputToListeners = true)
        {
            if (!Enabled || level < Level)
            {
                return;
            }

            ensureHeader();

#if DEBUG
            if (outputToListeners)
            {
                var debugLine = $"[{Target?.ToString().ToLower() ?? Name}:{level.ToString().ToLower()}] {message}";

                // fire to all debug listeners (like visual studio's output window)
                System.Diagnostics.Debug.Print(debugLine);

                // fire for console displays (appveyor/CI).
                Console.WriteLine(debugLine);
            }
#endif

#if Public
            if (level < LogLevel.Important)
            {
                return;
            }
#endif

#if !DEBUG
            if (level <= LogLevel.Debug)
            {
                return;
            }
#endif

            message = ApplyFilters(message);

            //split each line up.
            string[] lines = message.Replace(@"\r\n", @"\n").Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                string s = lines[i];
                lines[i] = $@"{DateTime.UtcNow.ToString(NumberFormatInfo.InvariantInfo)}: {s.Trim()}";
            }

            if (outputToListeners)
            {
                NewEntry?.Invoke(new LogEntry
                {
                    Level      = level,
                    Target     = Target,
                    LoggerName = Name,
                    Message    = message
                });
            }

            if (Target == LoggingTarget.Information)
            {
                // don't want to log this to a file
                return;
            }

            lock (flush_sync_lock)
            {
                // we need to check if the logger is still enabled here, since we may have been waiting for a
                // flush and while the flush was happening, the logger might have been disabled. In that case
                // we want to make sure that we don't accidentally write anything to a file after that flush.
                if (!Enabled)
                {
                    return;
                }

                backgroundScheduler.Add(delegate
                {
                    try
                    {
                        using (var stream = Storage.GetStream(Filename, FileAccess.Write, FileMode.Append))
                            using (var writer = new StreamWriter(stream))
                                foreach (var line in lines)
                                {
                                    writer.WriteLine(line);
                                }
                    }
                    catch
                    {
                    }
                });
            }
        }
コード例 #7
0
ファイル: Logger.cs プロジェクト: Epikem/osu-framework
        /// <summary>
        /// Log an arbitrary string to current log.
        /// </summary>
        /// <param name="message">The message to log. Can include newline (\n) characters to split into multiple lines.</param>
        /// <param name="level">The verbosity level.</param>
        public void Add(string message = @"", LogLevel level = LogLevel.Verbose)
        {
#if DEBUG
            var debugLine = $"[{Target.ToString().ToLower()}:{level.ToString().ToLower()}] {message}";
            // fire to all debug listeners (like visual studio's output window)
            System.Diagnostics.Debug.Print(debugLine);
            // fire for console displays (appveyor/CI).
            Console.WriteLine(debugLine);
#endif

#if Public
            if (level < LogLevel.Important)
            {
                return;
            }
#endif

#if !DEBUG
            if (level <= LogLevel.Debug)
            {
                return;
            }
#endif

            if (!Enabled)
            {
                return;
            }

            message = ApplyFilters(message);

            //split each line up.
            string[] lines = message.TrimEnd().Replace(@"\r\n", @"\n").Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                string s = lines[i];
                lines[i] = $@"{DateTime.UtcNow.ToString(NumberFormatInfo.InvariantInfo)}: {s.Trim()}";
            }

            LogEntry entry = new LogEntry
            {
                Level   = level,
                Target  = Target,
                Message = message
            };

            NewEntry?.Invoke(entry);

            if (Target == LoggingTarget.Information)
            {
                // don't want to log this to a file
                return;
            }

            background_scheduler.Add(delegate
            {
                if (Storage == null)
                {
                    return;
                }

                try
                {
                    using (var stream = Storage.GetStream(Filename, FileAccess.Write, FileMode.Append))
                        using (var writer = new StreamWriter(stream))
                            foreach (var line in lines)
                            {
                                writer.WriteLine(line);
                            }
                }
                catch
                {
                }
            });
        }