Example #1
0
        void runScriptTimer_Tick(object sender, EventArgs e)
        {
            runScriptTimer.Stop();

            if (null == Toggl.ScriptPath)
            {
                return;
            }

            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                if (!File.Exists(Toggl.ScriptPath))
                {
                    Console.WriteLine("Script file does not exist: " + Toggl.ScriptPath);
                    TogglDesktop.Program.Shutdown(0);
                }

                string script = File.ReadAllText(Toggl.ScriptPath);

                Int64 err     = 0;
                string result = Toggl.RunScript(script, ref err);
                if (0 != err)
                {
                    Console.WriteLine("Failed to run script, err = {0}", err);
                }
                Console.WriteLine(result);

                if (0 == err)
                {
                    TogglDesktop.Program.Shutdown(0);
                }
            }, null);
        }
        private void runScript()
        {
            if (!File.Exists(Toggl.ScriptPath))
            {
                Toggl.Debug("Script file does not exist: " + Toggl.ScriptPath);
                this.shutdown(0);
            }

            var script = File.ReadAllText(Toggl.ScriptPath);

            long errorCode = 0;
            var  result    = Toggl.RunScript(script, ref errorCode);

            if (errorCode != 0)
            {
                Toggl.Debug(string.Format("Failed to run script, err = {0}", errorCode));
            }
            Toggl.Debug(result);

            if (errorCode == 0)
            {
                this.shutdown(0);
            }
        }