Beispiel #1
0
        private void LoadStats(string fileName)
        {
            try
            {
                //ensure logdel file exists
                if (File.Exists(fileName))
                {
                    //load it to a DataTable
                    var logLoad = LogReader.TableFromFile(fileName, false);

                    //null validation
                    if (logLoad != null)
                    {
                        //ensure it contains a token column
                        if (logLoad.Columns.Contains("Token"))
                        {
                            //reset token lists
                            AllTokens   = new List <string>();
                            ValidTokens = new List <string>();

                            //reset token counters
                            TotalCount     = logLoad.Rows.Count;
                            InvalidCount   = 0;
                            ValidCount     = 0;
                            DuplicateCount = 0;

                            //each row in the log file
                            foreach (DataRow r in logLoad.Rows)
                            {
                                //skip over a blank token
                                if (r["Token"] == null)
                                {
                                    continue;
                                }

                                //the token is converted to a string
                                var t = r["Token"].ToString();

                                //if we haven't already processed this token
                                if (!AllTokens.Contains(t))
                                {
                                    //add it to the global list of current tokens
                                    AllTokens.Add(t);

                                    //is the token of the correct Plex length and is it a valid string?
                                    if (t.Length == 20 && !string.IsNullOrWhiteSpace(t))
                                    {
                                        //increment valid tokens
                                        ValidCount++;

                                        //add it to the list of valid tokens
                                        ValidTokens.Add(t);
                                    }
                                    else
                                    {
                                        //token was invalid, increment invalid tokens
                                        InvalidCount++;
                                    }
                                }
                                else
                                {
                                    //token was already processed, increment duplicate tokens
                                    DuplicateCount++;
                                }
                            }

                            //setup GUI
                            lblDuplicatesValue.Text = DuplicateCount.ToString();
                            lblInvalidValue.Text    = InvalidCount.ToString();
                            lblTotalValue.Text      = TotalCount.ToString();
                            lblValidValue.Text      = ValidCount.ToString();

                            //inform user
                            UIMessages.Info(@"Load succeeded");

                            //enable the translator button
                            btnTranslate.Enabled = true;
                        }
                        else
                        {
                            //alert the user of the error
                            UIMessages.Error(@"Invalid table layout");
                        }
                    }
                    else
                    {
                        //alert the user of the error
                        UIMessages.Error(@"Null table data");
                    }
                }
                else
                {
                    //alert the user of the error
                    UIMessages.Error(@"File doesn't exist");
                }
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"TokenTranslatorError");

                //alert the user
                UIMessages.Error(ex.ToString());
            }
        }
Beispiel #2
0
        private void LoadStats(string fileName)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    var logLoad = LogReader.TableFromFile(fileName, false);
                    if (logLoad != null)
                    {
                        if (logLoad.Columns.Contains("Token"))
                        {
                            AllTokens      = new List <string>();
                            ValidTokens    = new List <string>();
                            TotalCount     = logLoad.Rows.Count;
                            InvalidCount   = 0;
                            ValidCount     = 0;
                            DuplicateCount = 0;
                            foreach (DataRow r in logLoad.Rows)
                            {
                                if (r["Token"] == null)
                                {
                                    continue;
                                }

                                var t = r["Token"].ToString();

                                if (!AllTokens.Contains(t))
                                {
                                    AllTokens.Add(t);
                                    if (t.Length == 20 && !string.IsNullOrWhiteSpace(t))
                                    {
                                        ValidCount++;
                                        ValidTokens.Add(t);
                                    }
                                    else
                                    {
                                        InvalidCount++;
                                    }
                                }
                                else
                                {
                                    DuplicateCount++;
                                }
                            }

                            //gui settings
                            lblDuplicatesValue.Text = DuplicateCount.ToString();
                            lblInvalidValue.Text    = InvalidCount.ToString();
                            lblTotalValue.Text      = TotalCount.ToString();
                            lblValidValue.Text      = ValidCount.ToString();

                            UIMessages.Info(@"Load succeeded");
                            btnTranslate.Enabled = true;
                        }
                        else
                        {
                            UIMessages.Error(@"Invalid table layout");
                        }
                    }
                    else
                    {
                        UIMessages.Error(@"Null table data");
                    }
                }
                else
                {
                    UIMessages.Error(@"File doesn't exist");
                }
            }
            catch (Exception ex)
            {
                UIMessages.Error(ex.ToString());
            }
        }