/// <summary>
		///   The ReadyEvent delegate will be invoked on the current thread (which should
		///   be the Gtk thread) when another thread wakes us up by calling WakeupMain
		/// </summary>
		public ThreadNotify (ReadyEvent re)
		{
			this.re = re;
			idle = new GLib.IdleHandler (CallbackWrapper);
		}
Exemple #2
0
 public static void DestroyInstance(ReadyEvent i)
 {
     RakNetPINVOKE.ReadyEvent_DestroyInstance(ReadyEvent.getCPtr(i));
 }
Exemple #3
0
        public void Update(string TableName, ValueList Values, ValueList Conditions)
        {
            // Check for bad values
            if (string.IsNullOrEmpty(TableName))
            {
                return;
            }
            if (Values == null || Values.Count == 0)
            {
                return;
            }
            if (Conditions == null || Conditions.Count == 0)
            {
                return;
            }

            // Begin constructing an SQL command
            string Data = $"UPDATE {TableName} SET ";

            // Loop through the given values
            for (int i = 0; i < Values.Count; i++)
            {
                // Add name to command string
                if (i > 0)
                {
                    Data += ", ";
                }
                Data += $"{Values[i].Name} = @{Values[i].Name}_1";
            }

            // Add conditions
            Data += " WHERE ";
            for (int i = 0; i < Conditions.Count; i++)
            {
                // Add name to command string
                if (i > 0)
                {
                    Data += " AND ";
                }
                Data += $"{Conditions[i].Name} = @{Conditions[i].Name}_2";
            }

            // Create SQL command
            var Command = new SqliteCommand(Data, Connection);

            // Add values from the value list
            foreach (var Value in Values)
            {
                Command.Parameters.AddWithValue($"{Value.Name}_1", Value.Value);
            }

            // Add conditions from the conditions list
            foreach (var Condition in Conditions)
            {
                Command.Parameters.AddWithValue($"{Condition.Name}_2", Condition.Value);
            }

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }
Exemple #4
0
        private static async Task Setup()
        {
            TccUtils.SetAlignment();

            NoticeChecker.Init();

            TccSplashScreen.InitOnNewThread();

            if (!ToolboxMode)
            {
                UpdateManager.TryDeleteUpdater();

                SplashScreen.VM.BottomText = "Checking for application updates...";
                await UpdateManager.CheckAppVersion();
            }

            // ----------------------------
            SplashScreen.VM.Progress   = 10;
            SplashScreen.VM.BottomText = "Loading settings...";
            Settings = SettingsContainer.Load();
            WindowManager.InitSettingsWindow(); // need it in case language is not correct

            SplashScreen.VM.Progress = 20;
            Process.GetCurrentProcess().PriorityClass = Settings.HighPriority
                ? ProcessPriorityClass.High
                : ProcessPriorityClass.Normal;
            if (Settings.ForceSoftwareRendering)
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            // ----------------------------
            SplashScreen.VM.Progress   = 30;
            SplashScreen.VM.BottomText = "Pre-loading databases...";
            UpdateManager.CheckDatabaseHash();
            SplashScreen.VM.Progress = 40;
            await Game.InitAsync();

            // ----------------------------
            SplashScreen.VM.Progress   = 50;
            SplashScreen.VM.BottomText = "Initializing widgets...";
            await WindowManager.Init();

            SplashScreen.VM.Progress = 60;
            StartDispatcherWatcher();

            // ----------------------------
            SplashScreen.VM.Progress   = 70;
            SplashScreen.VM.BottomText = "Checking for icon database updates...";
            _ = Task.Run(() => new IconsUpdater().CheckForUpdates());

            // ----------------------------
            SplashScreen.VM.BottomText     = "Initializing packet processor...";
            SplashScreen.VM.Progress       = 80;
            PacketAnalyzer.ProcessorReady += LoadModules;
            await PacketAnalyzer.InitAsync();

            // ----------------------------
            SplashScreen.VM.Progress   = 90;
            SplashScreen.VM.BottomText = "Starting";
            GameEventManager.Instance.SetServerTimeZone(Settings.LastLanguage);
            UpdateManager.StartPeriodicCheck();

            SplashScreen.VM.Progress = 100;
            SplashScreen.CloseWindowSafe();


            // ----------------------------
            Log.Chat($"{AppVersion} ready.");
            ReadyEvent?.Invoke();

            if (!Beta && Settings.BetaNotification && UpdateManager.IsBetaNewer())
            {
                Log.N("TCC beta available", SR.BetaAvailable, NotificationType.Success, 10000);
            }
        }
Exemple #5
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ReadyEvent obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Exemple #6
0
 /// <summary>
 ///   The ReadyEvent delegate will be invoked on the current thread (which should
 ///   be the Gtk thread) when another thread wakes us up by calling WakeupMain
 /// </summary>
 public ThreadNotify(ReadyEvent re)
 {
     this.re = re;
     idle    = new GLib.IdleHandler(CallbackWrapper);
 }
Exemple #7
0
 private void EventListener_Ready(object sender, ReadyEvent e)
 {
     message += "EventListener_ReadyEvent Fired.";
 }
        /// <summary>
        /// 出題按鍵點擊事件
        /// </summary>
        /// <returns>靜態頁面文件名</returns>
        public FileInfo Compile()
        {
            // HTML模板存放路徑
            string sourceFileName = Path.GetFullPath(ConfigurationUtil.HtmlTemplatePath);
            // 靜態頁面作成后存放的路徑(文件名:日期時間形式)
            string destFileName = Path.GetFullPath(ConfigurationUtil.GetKeyValue("HtmlWork")
                                                   + string.Format(CultureInfo.CurrentCulture, "{0}.html", DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.CurrentCulture)));

            // 文件移動
            File.Copy(sourceFileName, destFileName);

            StringBuilder htmlTemplate = new StringBuilder();

            // 讀取HTML模板內容
            htmlTemplate.Append(File.ReadAllText(destFileName, Encoding.UTF8));
            // 遍歷已選擇的題型
            foreach (KeyValuePair <string, ConcurrentDictionary <SubstituteType, string> > d in _htmlMaps)
            {
                LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0016L, d.Key));

                // 替換HTML模板中的預留內容(HTML、JS注入操作)
                foreach (KeyValuePair <SubstituteType, string> m in d.Value)
                {
                    LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0015L, m.Key));

                    switch (m.Key)
                    {
                    // 樣式庫引用注入
                    case SubstituteType.Stylesheet:
                        Stylesheet.AppendLine(m.Value);
                        break;

                    // 腳本引用注入
                    case SubstituteType.Script:
                        Script.AppendLine(m.Value);
                        break;

                    // 打印前設置事件注入
                    case SubstituteType.PrintSettingEvent:
                        PrintSettingEvent.AppendLine(m.Value);
                        break;

                    // 打印后設置事件注入
                    case SubstituteType.PrintAfterSettingEvent:
                        PrintAfterSettingEvent.AppendLine(m.Value);
                        break;

                    // 準備事件注入
                    case SubstituteType.ReadyEvent:
                        ReadyEvent.AppendLine(m.Value);
                        break;

                    // 交卷事件注入
                    case SubstituteType.TheirPapersEvent:
                        TictheirPapersEvent.AppendLine(m.Value);
                        break;

                    // 答題訂正事件注入
                    case SubstituteType.MakeCorrectionsEvent:
                        MakeCorrectionsEvent.AppendLine(m.Value);
                        break;

                    // 題型正文注入
                    case SubstituteType.Content:
                        Content.AppendLine(m.Value);
                        break;

                    default:
                        break;
                    }
                }
            }
            // 樣式庫注入
            htmlTemplate.Replace("<!--STYLESHEET-->", Stylesheet.ToString());
            // 腳本注入
            htmlTemplate.Replace("<!--SCRIPT-->", Script.ToString());
            // 打印前設置事件注入
            htmlTemplate.Replace("// PRINTSETTING", PrintSettingEvent.ToString());
            // 打印后設置事件注入
            htmlTemplate.Replace("// PRINTAFTERSETTING", PrintAfterSettingEvent.ToString());
            // 題型準備事件注入
            htmlTemplate.Replace("// READY", ReadyEvent.ToString());
            // 題型訂正事件注入
            htmlTemplate.Replace("// MAKECORRECTIONS", MakeCorrectionsEvent.ToString());
            // 題型交卷事件注入
            htmlTemplate.Replace("// TICTHEIRPAPERS", TictheirPapersEvent.ToString());
            // 題型正文注入
            htmlTemplate.Replace("<!--CONTENT-->", Content.Insert(0, IsEncryptScript).AppendLine().ToString());

            LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0017L));

            // 保存至靜態頁面
            File.WriteAllText(destFileName, htmlTemplate.ToString(), Encoding.UTF8);

            return(new FileInfo(destFileName));
        }
Exemple #9
0
        // Writes a log message to the console, as well as to an optional log file
        // TODO - this is kind of a monolith, it could probably be shortened
        private void Write()
        {
            // Create a wait handle array so we can cancel this thread if need be
            WaitHandle[] Wait = new[] { ReadyEvent, StopEvent };
            while (0 == WaitHandle.WaitAny(Wait))
            {
                // Check if we need to stop and ignore queue
                if (StopEvent.WaitOne(0) && IgnoreQueue)
                {
                    break;
                }

                // Lock the message queue to prevent race conditions
                lock (MessageQueue)
                {
                    // Check if there are any messages in the queue
                    if (MessageQueue.Count == 0)
                    {
                        ReadyEvent.Reset();
                        continue;
                    }

                    // Dequeue a message
                    var Message = MessageQueue.Dequeue();

                    // Check if logging is enabled
                    if (LogLevel <= LogLevel.NONE)
                    {
                        // Reset ready event
                        ReadyEvent.Reset();
                        continue;
                    }

                    // Create an output string builder
                    StringBuilder Output = new StringBuilder(Message.Message);

                    // Add time and label prefix
                    StringBuilder Prefix = new StringBuilder("");
                    if (Message.Prefix)
                    {
                        // Add time
                        if (LogLevel >= LogLevel.MAX)
                        {
                            Prefix.Append($"{Message.Timestamp.ToString("dd-MM-yyyy hh:mm:ss.ffffff")} [");
                        }
                        else if (LogLevel >= LogLevel.DEBUG)
                        {
                            Prefix.Append($"{Message.Timestamp.ToString("dd-MM-yyyy hh:mm:ss.ff")} [");
                        }
                        else
                        {
                            Prefix.Append($"{Message.Timestamp.ToString("dd-MM-yyyy hh:mm:ss")} [");
                        }

                        // Add custom prefix
                        if (!string.IsNullOrEmpty(CustomPrefix))
                        {
                            Prefix.Append($"{CustomPrefix} ");
                        }

                        // Add label
                        if (Message.Label != LogLabel.IMPORTANT)
                        {
                            Prefix.Append($"{Message.Label}]");
                        }
                        else
                        {
                            Prefix.Append($"{LogLabel.INFO}]");
                        }

                        // Pad prefix
                        if (LogLevel >= LogLevel.MAX)
                        {
                            Prefix.Append(' ', 37 - Prefix.Length);
                        }
                        else if (LogLevel >= LogLevel.DEBUG)
                        {
                            Prefix.Append(' ', 33 - Prefix.Length);
                        }
                        else
                        {
                            Prefix.Append(' ', 30 - Prefix.Length);
                        }
                        if (!string.IsNullOrEmpty(CustomPrefix))
                        {
                            Prefix.Append(' ');
                        }
                    }
                    Output.Insert(0, Prefix);

                    // Set console color
                    switch (Message.Label)
                    {
                    case LogLabel.IMPORTANT:
                        Console.ForegroundColor = ImportantColor;
                        break;

                    case LogLabel.INFO:
                        Console.ForegroundColor = InfoColor;
                        break;

                    case LogLabel.ERROR:
                        Console.ForegroundColor = ErrorColor;
                        break;

                    case LogLabel.WARNING:
                        Console.ForegroundColor = WarningColor;
                        break;

                    case LogLabel.DEBUG:
                        Console.ForegroundColor = DebugColor;
                        break;
                    }

                    // Write to console
                    Console.WriteLine(Output);

                    // Append to log file
                    if (!string.IsNullOrEmpty(LogFile))
                    {
                        try { File.AppendAllText(LogFile, $"{Output}\n"); }
                        catch { }
                    }

                    // Set console color back to default
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            }
        }
Exemple #10
0
 public void OnReady(ReadyEvent @event)
 {
     Ready?.Invoke(this, @event);
     // The Didomi is ready
 }