예제 #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");
        }
예제 #2
0
파일: Form1.cs 프로젝트: SuddenVacuity/TCO
        private void sheetsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrefsData prefData = m_program.getPrefData();

            // user preferences are updated directly from this dialog
            DialogSheetsWindow message = new DialogSheetsWindow(prefData);
            DialogResult       result  = message.ShowDialog();

            if (result == DialogResult.OK)
            {
                m_program.setActiveLog(message.m_selectedLog);
            }
        }
예제 #3
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();
        }
예제 #4
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);
        }
예제 #5
0
 // public middle-man class
 public static void setPrefs(PrefsData userPrefs)
 {
     savePrefs(userPrefs);
 }
예제 #6
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);
        }