예제 #1
0
        /// <summary>
        /// Used to deserialize a file.
        /// </summary>
        public static csLog deserializeFile(string _sFileLoc)
        {
            csLog logReadIn = null;

            XmlSerializer serRead = new XmlSerializer(typeof(csLog));
            StreamReader  sr      = null;

            try
            {
                sr        = new StreamReader(_sFileLoc);
                logReadIn = (csLog)serRead.Deserialize(sr);
                sr.Close();
                sr = null;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error while reading in log file.\n\nError Message: " + ex.Message);
                if (sr != null)
                {
                    sr.Close();
                }
                sr = null;
            }

            return(logReadIn);
        }
예제 #2
0
        public static void DisplayLog(System.Windows.Controls.RichTextBox _rtb, csLogging.LogState _ls, csLog _log, bool bClearRTB)
        {
            if (bClearRTB)
            {
                _rtb.Document.Blocks.Clear();
            }

            string sLogData = $"{_log.Tech} began this entry at {_log.LogCreationTime.ToString("MM/dd/yyyy hh:mm:ss tt")}.\n";

            sLogData += "*** Filtered Actions Associated With This Log File*** \n";

            for (int i = 0; i < _log.lActions.Count; i++)
            {
                if (_ls.Equals(_log.lActions[i].EventType) || _ls.Equals(csLogging.LogState.NONE))
                {
                    sLogData += $"Event Type: {_log.lActions[i].EventType.ToString()}\n";

                    if (_log.lActions[i].LogNote != null)
                    {
                        sLogData += $"Log Action: {_log.lActions[i].LogNote}\n";
                    }
                    if (_log.lActions[i].ControlType != null)
                    {
                        sLogData += $"Control Type: {_log.lActions[i].ControlType}\n";
                    }
                    if (_log.lActions[i].ControlName != null)
                    {
                        sLogData += $"Control Name: {_log.lActions[i].ControlName}\n";
                    }
                    if (_log.lActions[i].ControlContent != null)
                    {
                        sLogData += $"Control Content: {_log.lActions[i].ControlContent}\n";
                    }

                    sLogData += "Event Timing: " + _log.lActions[i].EventTiming.ToString("MM/dd/yyyy hh:mm:ss tt") + "\n";

                    sLogData += "----------------------------\n";
                }
            }

            sLogData += "This log was completed on " + _log.LogSubmitTime.ToString("MM/dd/yyyy hh:mm:ss tt") + "\n";
            sLogData += "*** End of Log ***";

            _rtb.AppendText(sLogData);
        }
예제 #3
0
        /// <summary>
        /// Used to serialize a file.
        /// </summary>
        public static bool serializeFile(string tech, DateTime dtLC, List <csLogAction> lLA, string sFileLoc, string sFileName)
        {
            csLog csL = new csLog();

            csL.buildCSLog(tech, dtLC, lLA);

            StreamWriter sw = null;

            try
            {
                XmlSerializer _ser = new XmlSerializer(typeof(csLog));
                sw = new StreamWriter(sFileLoc + sFileName, false);
                _ser.Serialize(sw, csL);
                sw.Close();
                sw = null;


                #region Submit Log to DB

                using (SqlConnection conn = new SqlConnection(csObjectHolder.csObjectHolder.ObjectHolderInstance().RepairConnectionString))
                {
                    conn.Open();

                    /* [1.] Get ActionID index to increment by 1. */
                    var actionID = 0;
                    using (SqlCommand cmd = new SqlCommand("SELECT ActionID FROM TechLogActions ORDER BY ActionID DESC", conn))
                    {
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                actionID = reader.GetInt32(0) + 1;
                            }
                            else
                            {
                                throw new IOException("ActionID could not be set.\nPlease confirm validity in the Database.");
                            }
                        }
                    }

                    /* [2.] Insert initial log details into TechLogs table. */
                    using (SqlCommand cmd = new SqlCommand("INSERT INTO TechLogs (ActionID, Tech, LogCreationTime, LogSubmitTime) " +
                                                           "VALUES (@aid, @tech, @createtime, @submittime)", conn))
                    {
                        cmd.Parameters.AddWithValue("@aid", actionID);
                        cmd.Parameters.AddWithValue("@tech", csL.Tech);
                        cmd.Parameters.AddWithValue("@createtime", csL.LogCreationTime);
                        cmd.Parameters.AddWithValue("@submittime", csL.LogSubmitTime);

                        if (cmd.ExecuteNonQuery() == 0)
                        {
                            return(false);
                        }
                    }

                    /* [3.] Get newest LogID after instering log entry (Auto Increment ID)*/
                    using (SqlCommand cmd = new SqlCommand("SELECT ID FROM TechLogs ORDER BY ID DESC", conn))
                    {
                        using (SqlDataReader reader = cmd.ExecuteReader())
                            if (reader.Read())
                            {
                                CurrLogIDToUse = reader.GetInt32(0) + 1;
                            }
                            else
                            {
                                throw new IOException("LogID could not be set.\nPlease confirm validity in the Database.");
                            }
                    }

                    /* [4.] Insert all relevant actions into TechLogActions table with ActionID as the pairing column. */
                    foreach (csLogAction action in csL.lActions)
                    {
                        using (SqlCommand cmd = new SqlCommand("INSERT INTO TechLogActions (ActionID, ControlType, ControlName, " +
                                                               "ControlContent, LogState, EventTiming, LogNote, LogError)" +
                                                               "VALUES (@aid, @cType, @cName, @cContent, @state, @time, @note, @error)", conn))
                        {
                            cmd.Parameters.AddWithValue("@aid", actionID);
                            cmd.Parameters.AddWithValue("@cType", action.ControlType ?? "");
                            cmd.Parameters.AddWithValue("@cName", action.ControlName ?? "");
                            cmd.Parameters.AddWithValue("@cContent", action.ControlContent ?? "");
                            cmd.Parameters.AddWithValue("@state", action.EventType.ToString() ?? "");
                            cmd.Parameters.AddWithValue("@time", action.EventTiming.ToString("yyyy-MM-dd HH:mm:ss.fff")
                                                        ?? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                            cmd.Parameters.AddWithValue("@note", action.LogNote ?? "");
                            cmd.Parameters.AddWithValue("@error", action.LogError);

                            if (cmd.ExecuteNonQuery() == 0)
                            {
                                return(false);
                            }
                        }
                    }
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Windows.MessageBox.Show("Error writing log to file.\n\nError Message: " + ex.Message);
#endif
                if (sw != null)
                {
                    sw.Close();
                }
                sw = null;
                return(false);
            }
        }