Exemple #1
0
        private static void savePrefs(PrefsData userPrefs)
        {
            string filePath = System.Environment.CurrentDirectory + m_fileName;

            int logInterval = userPrefs.getInt(PrefsData.PrefInt.LogInterval);
            int idleTime    = userPrefs.getInt(PrefsData.PrefInt.IdleTime);
            int timeoutTime = userPrefs.getInt(PrefsData.PrefInt.TimeoutTime);
            int activeSheet = userPrefs.getInt(PrefsData.PrefInt.ActiveLog);

            string data =
                m_versionToken + Environment.getVersion() +
                "\n// Log interval, poll interval, time until idle and time until timeout" +
                "\n" + m_intToken + m_dataTokens[(int)PrefsData.PrefInt.LogInterval] + m_dataSeperator + logInterval +
                "\n" + m_intToken + m_dataTokens[(int)PrefsData.PrefInt.IdleTime] + m_dataSeperator + idleTime +
                "\n" + m_intToken + m_dataTokens[(int)PrefsData.PrefInt.TimeoutTime] + m_dataSeperator + timeoutTime +
                "\n" + m_intToken + m_dataTokens[(int)PrefsData.PrefInt.ActiveLog] + m_dataSeperator + activeSheet +
                "\n//";

            for (PrefsData.PrefLogIndex i = 0; i < PrefsData.PrefLogIndex.Count; i++)
            {
                data += "\n" +
                        m_stringToken + userPrefs.getLogName(i) +
                        m_sheetsSeperator + userPrefs.getProjectName(i) +
                        m_sheetsSeperator + userPrefs.getProjectDescription(i) +
                        m_sheetsSeperator + userPrefs.getLogGoogleId(i);
            }

            File.WriteAllText(filePath, data);
            Console.WriteLine("Pref file saved");
        }
Exemple #2
0
 private void updateTodaysLogEntries()
 {
     PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();
     LocalLogger.updateTodaysLogs(m_timeStr,
                                  m_userPrefs.getLogName(index),
                                  m_userPrefs.getProjectName(index),
                                  m_userPrefs.getProjectDescription(index));
 }
Exemple #3
0
        /// <summary>
        /// Changes the active log to the input log.
        /// <para>Returns false if the log doesn't exist</para>
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool setActiveLog(PrefsData.PrefLogIndex index)
        {
            if (m_userPrefs.setActiveLog(index) == false)
            {
                return(false);
            }

            changeActiveLogData(index);
            Console.WriteLine("Active Sheet set to " + (int)index);

            return(true);
        }
Exemple #4
0
        private void importFileData()
        {
            m_userPrefs = UserPrefs.getPrefs();

            PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

            LocalLogger.loadTodayLogsFromFile();
            m_timeStr = LocalLogger.getTodaysEntryData(
                m_userPrefs.getLogName(index),
                m_userPrefs.getProjectName(index),
                m_userPrefs.getProjectDescription(index),
                LocalLogger.EntryDataIndex.Time);
            m_timeConfirmed = timeStringToMilliseconds(m_timeStr);

            checkTimeLimits();
        }
Exemple #5
0
        /// <summary>
        /// Changes active the time and google sheets id to match the input log
        /// </summary>
        /// <param name="index"></param>
        private void changeActiveLogData(PrefsData.PrefLogIndex index)
        {
            // try to get time from memory
            m_timeStr = LocalLogger.getTodaysEntryData(
                m_userPrefs.getLogName(index),
                m_userPrefs.getProjectName(index),
                m_userPrefs.getProjectDescription(index),
                LocalLogger.EntryDataIndex.Time);
            m_timeConfirmed = timeStringToMilliseconds(m_timeStr);
            m_timePending   = 0;
            m_timeBuffer    = 0;

            // let the program know a valid log+project+desc has been set
            m_foundGoogleSheetAndTab = true;

            // compare data with google sheets and act accordingly
            googleSheetsInterfaceSetup();
        }
Exemple #6
0
        private void googleSheetsInterfaceSetup()
        {
            // not run if the target isn't set up within the program
            if (m_foundGoogleSheetAndTab == false)
            {
                return;
            }

            PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

            string googleSheetsId = m_userPrefs.getLogGoogleId(index);
            string tabName        = m_userPrefs.getProjectName(index);

            if (googleSheetsId == "" || tabName == "")
            {
                DialogMessage message = new DialogMessage("Information", "A Google Sheets id and tab name must be set in order to use google sheets interface.\nInteraction with google sheet will not function.");
                message.ShowDialog();
                return;
            }

            // check wth google sheets to see if the tab needs to be created
            if (!TCOSheetsInterface.tabExists(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index)))
            {
                System.Drawing.Size size = new System.Drawing.Size(5, 2);
                if (!TCOSheetsInterface.createTab(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index), size, 1))
                {
                    Console.WriteLine("Create new tab [" + m_userPrefs.getProjectName(index) + "] failed");
                }

                // create the header bar in the created tab
                SheetsLogEntry entryMaker = new SheetsLogEntry();
                List <Google.Apis.Sheets.v4.Data.RowData> rows = entryMaker.createTitleBar();
                TCOSheetsInterface.updateCells(
                    m_userPrefs.getLogGoogleId(index),
                    m_userPrefs.getProjectName(index),
                    "A1", "E2", rows);
            }
        }
Exemple #7
0
        public void logTime()
        {
            // run only if write to local file succeeds
            if (LocalLogger.writeToLogFile())
            {
                if (m_foundGoogleSheetAndTab == false)
                {
                    return;
                }

                PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

                if (TCOSheetsInterface.getIsServiceActive() == false)
                {
                    Console.WriteLine("Google Sheets service inactive.");
                }

                if (!TCOSheetsInterface.WriteTimeNowToCell(
                        m_userPrefs.getLogGoogleId(index),
                        m_userPrefs.getProjectName(index),
                        m_timeStr, m_userPrefs.getProjectDescription(index)))
                {
                    Console.WriteLine("Attempt to log to google sheets failed.");
                    return;
                }

                m_timeConfirmed     += m_timePending;
                m_timePending        = 0;
                m_logTimeAccumulator = 0;
                Console.WriteLine("Total time logged is " + m_timeStr);
            }
            else
            {
                Console.WriteLine("Log failed");
            }
        }
Exemple #8
0
        private static PrefsData loadPrefs()
        {
            PrefsData result = new PrefsData();

            string filePath = System.Environment.CurrentDirectory + m_fileName;

            if (File.Exists(filePath))
            {
                PrefsData.PrefLogIndex currentSpreadheetIndex = PrefsData.PrefLogIndex.Log01;
                foreach (string line in File.ReadLines(filePath))
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (line.StartsWith(m_commentToken))
                    {
                        continue;
                    }

                    if (line.StartsWith(m_versionToken))
                    {
                        checkVersion(line.TrimStart(m_versionToken.ToCharArray()));
                    }

                    // get ints
                    if (line.StartsWith(m_intToken))
                    {
                        // remove the line token that shows this line contains int data
                        string intData = line.Remove(0, m_intToken.Length);

                        string logInterval = m_dataTokens[(int)PrefsData.PrefInt.LogInterval];
                        string idleTime    = m_dataTokens[(int)PrefsData.PrefInt.IdleTime];
                        string timeoutTime = m_dataTokens[(int)PrefsData.PrefInt.TimeoutTime];
                        string ActiveLog   = m_dataTokens[(int)PrefsData.PrefInt.ActiveLog];

                        if (intData.StartsWith(logInterval))
                        {
                            int defaultValue = m_defaultLogInterval;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.LogInterval);
                        }

                        if (intData.StartsWith(idleTime))
                        {
                            int defaultValue = m_defaultIdleTime;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.IdleTime);
                        }

                        if (intData.StartsWith(timeoutTime))
                        {
                            int defaultValue = m_defaultTimeoutTime;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);
                            result.setInt(defaultValue, PrefsData.PrefInt.TimeoutTime);
                        }

                        if (intData.StartsWith(ActiveLog))
                        {
                            int defaultValue = m_defaultActiveLog;
                            int.TryParse(intData.Remove(0, intData.LastIndexOf(m_dataSeperator) + 1), out defaultValue);

                            result.setInt(defaultValue, PrefsData.PrefInt.ActiveLog);
                        }
                    } // END get ints

                    // get strings
                    if (line.StartsWith(m_stringToken))
                    {
                        // remove the line token shwoing this line contains a string of strings of data
                        // then split each string into its own string
                        string[] strData = (line.Remove(0, m_stringToken.Length))
                                           .Split(m_sheetsSeperator.ToCharArray());

                        // if token was the only character continue
                        if (strData.Length == 0)
                        {
                            continue;
                        }
                        // if data storage is full continue
                        if (currentSpreadheetIndex >= PrefsData.PrefLogIndex.Count)
                        {
                            continue;
                        }

                        result.setLogName(strData[0], currentSpreadheetIndex);
                        result.setProjectName(strData[1], currentSpreadheetIndex);
                        result.setProjectDescription(strData[2], currentSpreadheetIndex);
                        result.setLogGoogleId(strData[3], currentSpreadheetIndex);

                        currentSpreadheetIndex++;
                    } // END get strings
                }
                Console.WriteLine("Pref file loaded");
            }
            else // file did not exist
            {
                Console.WriteLine("Pref file not found");

                // create a default user preference file
                result.setInt(m_defaultLogInterval, PrefsData.PrefInt.LogInterval);
                result.setInt(m_defaultIdleTime, PrefsData.PrefInt.IdleTime);
                result.setInt(m_defaultTimeoutTime, PrefsData.PrefInt.TimeoutTime);
                result.setInt(m_defaultActiveLog, PrefsData.PrefInt.ActiveLog);

                // preset first log profile
                result.setLogName("Default Log", 0);
                result.setProjectName("Default Project", 0);
                result.setProjectDescription("Default Description", 0);
                result.setLogGoogleId("", 0);

                // set the other profiles as empty
                for (PrefsData.PrefLogIndex i = PrefsData.PrefLogIndex.Log02; i < PrefsData.PrefLogIndex.Count; i++)
                {
                    result.setLogName("", i);
                    result.setProjectName("", i);
                    result.setProjectDescription("", i);
                    result.setLogGoogleId("", i);
                }
            }

            return(result);
        }
Exemple #9
0
        public DialogSheetsWindow(PrefsData userPrefs)
        {
            m_userPrefs   = userPrefs;
            m_selectedLog = m_userPrefs.getActiveSheet();

            this.ShowInTaskbar   = false;
            this.BackColor       = Color.LightGray;
            this.Text            = m_stringTitle;
            this.StartPosition   = FormStartPosition.CenterParent;
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.ShowInTaskbar   = false;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;
            this.AutoSizeMode    = AutoSizeMode.GrowAndShrink;
            this.AutoSize        = true;

            m_labelText               = new Label();
            m_labelFilepath           = new Label();
            m_labelLogName            = new Label();
            m_labelProjectName        = new Label();
            m_labelProjectDescription = new Label();
            m_labelGoogleSheetId      = new Label();

            m_buttonConfirm = new Button();
            m_buttonCancel  = new Button();

            // Size
            m_labelText.Size                   = new Size(600, 130);
            m_labelFilepath.AutoSize           = true;
            m_labelLogName.AutoSize            = true;
            m_labelProjectName.AutoSize        = true;
            m_labelProjectDescription.AutoSize = true;
            m_labelGoogleSheetId.AutoSize      = true;
            m_buttonConfirm.Size               = new Size(80, 40);
            m_buttonCancel.Size                = new Size(80, 40);

            // Location
            m_labelText.Location               = new Point(0, 0);
            m_labelFilepath.Location           = new Point(20, 5 + m_labelText.Size.Height);
            m_labelLogName.Location            = new Point(63, 5 + m_labelText.Size.Height);
            m_labelProjectName.Location        = new Point(178, 5 + m_labelText.Size.Height);
            m_labelProjectDescription.Location = new Point(293, 5 + m_labelText.Size.Height);
            m_labelGoogleSheetId.Location      = new Point(565, 5 + m_labelText.Size.Height);
            m_buttonConfirm.Location           = new Point(290, 380);
            m_buttonCancel.Location            = new Point(190, 380);

            // Text
            m_labelText.Text               = m_stringLabelText;
            m_labelFilepath.Text           = m_stringLabelFilepath;
            m_labelLogName.Text            = m_stringLabelLogName;
            m_labelProjectName.Text        = m_stringLabelProjectName;
            m_labelProjectDescription.Text = m_stringLabelProjectDescription;
            m_labelGoogleSheetId.Text      = m_stringLabelGoogleSheetId;
            m_buttonConfirm.Text           = m_stringButtonConfirm;
            m_buttonCancel.Text            = m_stringButtonCancel;

            // lambdas
            m_buttonConfirm.MouseUp += (s, e) =>
            {
                if (TCOSheetsInterface.getIsServiceActive() == false)
                {
                    DialogMessage message = new DialogMessage("Google Sheets Service Inactive", "The Google Sheets service has not been set up correctly.");
                    message.ShowDialog();
                }

                m_userPrefs.setActiveLog(m_selectedLog);

                for (PrefsData.PrefLogIndex i = 0; i < PrefsData.PrefLogIndex.Count; i++)
                {
                    m_userPrefs.setLogName(m_logData[(int)i].getLogName(), i);
                    m_userPrefs.setProjectName(m_logData[(int)i].getProjectName(), i);
                    m_userPrefs.setProjectDescription(m_logData[(int)i].getProjectDescription(), i);
                    m_userPrefs.setLogGoogleId(m_logData[(int)i].getGoogleSheetsId(), i);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            };
            m_buttonCancel.MouseUp += (s, e) =>
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            };

            m_labelText.BackColor = Color.White;

            // create log data rows
            PrefsData.PrefLogIndex entryCount = UserPrefs.getMaxEntries();
            m_logData = new ControlLogData[(int)entryCount];
            for (PrefsData.PrefLogIndex i = 0; i < entryCount; i++)
            {
                m_logData[(int)i] = new ControlLogData();

                int Ypos = m_labelFilepath.Location.Y + m_labelFilepath.Size.Height + (int)i * (m_logData[(int)i].m_height + 5);

                // get the log profile data from user prefs
                m_logData[(int)i].setLogPath(""); // NOT IMPLEMENTED IN MAIN PROGRAM OR USER PREFERENCES
                m_logData[(int)i].setLogName(m_userPrefs.getLogName(i));
                m_logData[(int)i].setProjectName(m_userPrefs.getProjectName(i));
                m_logData[(int)i].setProjectDescription(m_userPrefs.getProjectDescription(i));
                m_logData[(int)i].setGoogleSheetsId(m_userPrefs.getLogGoogleId(i));

                // create a new instance of the iteration in memory to be used as an index in on CheckedChanged lambda
                PrefsData.PrefLogIndex radioIndex = i; // NOTE: if this isn't done the value used in the lambda will always be PrefLogIndex.Count

                // create radio buttun used to select the log
                RadioButton selectLog = new RadioButton();
                selectLog.Size     = new Size(15, 15);
                selectLog.Location = new Point(0, Ypos);

                if (i == m_selectedLog)
                {
                    selectLog.Checked = true;
                }

                selectLog.CheckedChanged += (s, e) => {
                    RadioButton rb = (RadioButton)s;
                    if (rb.Checked == true)
                    {
                        m_selectedLog = radioIndex;
                    }
                };

                // set position in dialog
                m_logData[(int)i].Location = new Point(selectLog.Location.X + selectLog.Size.Width + 5, Ypos);

                this.Controls.Add(selectLog);
                this.Controls.Add(m_logData[(int)i]);
            } // END create log data rows

            this.Controls.Add(m_labelText);
            this.Controls.Add(m_labelFilepath);
            this.Controls.Add(m_labelLogName);
            this.Controls.Add(m_labelProjectName);
            this.Controls.Add(m_labelProjectDescription);
            this.Controls.Add(m_labelGoogleSheetId);
            this.Controls.Add(m_buttonConfirm);
            this.Controls.Add(m_buttonCancel);
        }