Exemple #1
0
        /// <summary>
        /// Function to mimic the SQL LIKE clause for LINQ queries.
        /// </summary>
        private bool Like(string field, string pattern)
        {
            bool result = false;

            pattern = pattern.Trim();
            string contents = R.Strip(pattern, "BOTH", "%");

            if (pattern.StartsWith("%") && pattern.EndsWith("%"))
            {
                result = field.Contains(contents);
            }
            else if (pattern.StartsWith("%"))
            {
                result = field.EndsWith(contents);
            }
            else if (pattern.EndsWith("%"))
            {
                result = field.StartsWith(contents);
            }
            else
            {
                result = field == contents;
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Search the specified file using the specified criteria.
        /// </summary>
        private bool EvaluateLines(string fileSpec)
        {
            FileInfo fileInfo = null;
            string   header   = string.Empty;
            string   rec      = string.Empty;
            long     count    = 0;
            bool     first    = true;
            bool     pass     = false;
            bool     hits     = false;

            try
            {
                if (File.Exists(fileSpec))
                {
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        do
                        {
                            count++;
                            rec = sr.ReadLine();
                            if (_regex)
                            {
                                Regex regex = new Regex(_searchCriteria, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                                pass = regex.IsMatch(rec);
                            }
                            else
                            {
                                pass = _scanner.Evaluate(rec);
                            }
                            if (pass)
                            {
                                hits = true;
                                if (first)
                                {
                                    header  = "\r\n" + fileSpec + "\r\n";
                                    header += string.Empty.PadRight(fileSpec.Length, '-');
                                    SignalCriteriaPass(header);
                                    _log.WriteLn(header);
                                    first = false;
                                }
                                header = "(" + count.ToString("00000") + ") - " + rec;
                                SignalCriteriaPass(header);
                                _log.WriteLn(header);
                            }
                            if (_action == "Cancel")
                            {
                                break;
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                }
            }
            catch
            {
            }
            return(hits);
        }
Exemple #3
0
 /// <summary>
 /// Clear error information.
 /// </summary>
 public void Clear()
 {
     _Active   = false;
     _Number   = 0;
     _Source   = string.Empty;
     _Message  = string.Empty;
     _Serial   = R.Replicate(ZERO, 3);
     _Severity = SEVERITY_CODES.Substring(0, 1);
 }
Exemple #4
0
        /// <summary>
        /// Edit Layout file.
        /// </summary>
        /// <remarks>
        /// Apply global changes to one Layout file.
        /// </remarks>
        protected bool EditLayoutFile(string fileSpec)
        {
            layoutFileCount++;
            StringBuilder contents = new StringBuilder();
            string        line     = string.Empty;
            bool          first    = true;
            bool          hit      = false;
            bool          changed  = false;
            FileInfo      fileInfo = null;
            string        record   = string.Empty;
            long          count    = 0;

            try
            {
                if (File.Exists(fileSpec))
                {
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        do
                        {
                            count++;
                            layoutFileLineCount++;
                            record = sr.ReadLine();
                            line   = record;
                            //Replace all the old package names with the new package names.
                            foreach (KeyValuePair <string, string> entry in _packageNameMappings)
                            {
                                ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            //Replace all the old class names with the new class names.
                            //Mostly ViewModels but could also be Activities or Fragments for tool contexts.
                            foreach (KeyValuePair <string, string> entry in _classNameMappings)
                            {
                                ChangeOldClassNameToNewClassName(".", entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            contents.AppendLine(line);
                            if (_action == "Cancel")
                            {
                                break;
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                    if (changed)
                    {
                        FileHelper.WriteFile(fileSpec, contents.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(hit);
        }
Exemple #5
0
        /// <summary>
        /// Begin logging to the log file.
        /// </summary>
        /// <remarks>
        /// Mode "Create" creates a new log file.
        /// Mode "Append" appends to an existing log file.
        /// </remarks>
        public void Begin(string fileSpec, LogMode mode)
        {
            string filePath = string.Empty;
            string fileName = string.Empty;

            _Spec = fileSpec.Trim();
            try
            {
                if (mode == LogMode.Create)
                {
                    _FileStream   = null;
                    _StreamWriter = null;
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileSpec);
                    }
                    _StreamWriter = File.CreateText(fileSpec);
                    if (_Title != string.Empty)
                    {
                        WriteLn(_Title);
                        WriteLn(R.Replicate(DASH, _Title.Length));
                    }
                }
                else
                {
                    filePath = R.FileStem(fileSpec);
                    fileName = R.FileFullName(fileSpec);
                    if (File.Exists(fileName))
                    {
                        _FileStream   = new FileStream(fileSpec, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                        _StreamWriter = new StreamWriter(_FileStream);
                    }
                    else
                    {
                        _StreamWriter = File.CreateText(fileSpec);
                        if (_Title != string.Empty)
                        {
                            WriteLn(_Title);
                            WriteLn(R.Replicate(DASH, _Title.Length));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Exemple #6
0
        /// <summary>
        /// Keep track of the highest severity so far encountered.
        /// </summary>
        private void MonitorHighestSeverity(string severity)
        {
            int pos1 = 0;
            int pos2 = 0;

            severity = R.RPad(severity.Trim().ToUpper(), 1, " ");
            pos1     = SEVERITY_CODES.IndexOf(severity);
            if (pos1 > -1)
            {
                pos2 = SEVERITY_CODES.IndexOf(_HighestSeverity);
                if (pos2 > -1)
                {
                    if (pos1 > pos2)
                    {
                        _HighestSeverity = severity;
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Copy one old file to new file.
        /// </summary>
        private string PerformCopyOldToNew(ListViewItem selectedItem)
        {
            string       message  = string.Empty;
            ListViewItem listItem = selectedItem;
            string       compare  = listItem.Text;
            string       newSpec  = txtNewPath.Text + listItem.SubItems[1].Text;
            string       oldSpec  = txtOldPath.Text + listItem.SubItems[2].Text;

            if (listItem.SubItems[2].Text != string.Empty)
            {
                if (listItem.SubItems[1].Text != string.Empty)
                {
                    try
                    {
                        Models.Update.Copy(R.FileStem(oldSpec), R.FileStem(newSpec), R.FileFullName(oldSpec));
                        listItem.Text = "Same<";
                    }
                    catch
                    {
                    }
                }
                else
                {
                    try
                    {
                        Models.Update.Copy(R.FileStem(oldSpec), R.FileStem(txtNewPath.Text + listItem.SubItems[2].Text), R.FileFullName(oldSpec));
                        listItem.Text             = "Same<";
                        listItem.SubItems[1].Text = listItem.SubItems[2].Text;
                    }
                    catch
                    {
                    }
                }
                Refresh_Status();
            }
            else
            {
                message = "No old file available!";
            }
            return(message);
        }
Exemple #8
0
        /// <summary>
        /// Delete one selected old file.
        /// </summary>
        private string PerformDeleteOld(ListViewItem selectedItem)
        {
            string       message  = string.Empty;
            ListViewItem listItem = selectedItem;
            string       compare  = listItem.Text;
            string       newSpec  = txtNewPath.Text + listItem.SubItems[1].Text;
            string       oldSpec  = txtOldPath.Text + listItem.SubItems[2].Text;

            if (listItem.SubItems[2].Text != string.Empty)
            {
                try
                {
                    Models.Update.Delete("Old", R.FileStem(oldSpec), R.FileFullName(oldSpec));
                    if (listItem.SubItems[1].Text != string.Empty)
                    {
                        listItem.Text             = "New*";
                        listItem.SubItems[2].Text = string.Empty;
                    }
                    else
                    {
                        listItem.Text             = "Deleted*";
                        listItem.SubItems[2].Text = string.Empty;
                        lvwResults.Items.Remove(listItem);
                    }
                }
                catch
                {
                }
                Refresh_Status();
            }
            else
            {
                message = "No old file available!";
            }
            return(message);
        }
Exemple #9
0
 /// <summary>
 /// Terminate the log file.
 /// </summary>
 /// <remarks>
 /// If suYF18ied the viewer program will be automatically triggered to view the log file.
 /// </remarks>
 public void Terminate(string viewerProgram)
 {
     CalculateRunStatistics();
     WriteLn();
     WriteLn("JRN060I - Start   : " + R.FmtDate(_Start, "dd/mm/yyyy hh:nn:ss"));
     WriteLn("JRN070I - End     : " + R.FmtDate(_Finish, "dd/mm/yyyy hh:nn:ss"));
     WriteLn("JRN080I - Elapsed : " + "           " + R.FmtTimeSpan(_Elapsed, "hh:nn:ss"));
     try
     {
         _StreamWriter.Close();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
     finally
     {
         _StreamWriter = null;
     }
     if (viewerProgram != string.Empty)
     {
         View(viewerProgram);
     }
 }
Exemple #10
0
        /// <summary>
        /// Edit Java file.
        /// </summary>
        /// <remarks>
        /// Apply global changes to one Java file.
        /// </remarks>
        protected bool EditJavaFile(string fileSpec)
        {
            classFileCount++;
            StringBuilder contents             = new StringBuilder();
            string        line                 = string.Empty;
            bool          first                = true;
            bool          hit                  = false;
            bool          changed              = false;
            FileInfo      fileInfo             = null;
            string        record               = string.Empty;
            long          count                = 0;
            bool          activityInfoCaptured = true;
            string        currentClassName     = System.IO.Path.GetFileNameWithoutExtension(fileSpec);

            if (currentClassName.EndsWith("Activity"))
            {
                activityInfoCaptured = false;
            }
            try
            {
                if (File.Exists(fileSpec))
                {
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        do
                        {
                            count++;
                            classFileLineCount++;
                            record = sr.ReadLine();
                            line   = record;
                            if (line.Contains("MediaApproved"))
                            {
                                string temp = string.Empty;
                            }
                            //Replace all the old package names with the new package names.
                            foreach (KeyValuePair <string, string> entry in _packageNameMappings)
                            {
                                ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            //Replace all the old class names with the new class names.
                            foreach (KeyValuePair <string, string> entry in _classNameMappings)
                            {
                                // Originally added to support Java.
                                ChangeOldClassNameToNewClassName(".", entry, ";", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("<", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("<", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, "<", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("(", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("(", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, "(", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                // Added to support Kotlin.
                                ChangeOldClassNameToNewClassName(" ", entry, "?", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ":", ref line, ref changed, ref first, fileSpec, count, ref record);
                                // Originally added to support Java.
                                ChangeOldClassNameToNewClassName(string.Empty, entry, ".", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(string.Empty, entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                // Added to support Kotlin.
                                ChangeOldClassNameToNewClassName(" ", entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            //Replace all the old class variables with the new class variables.
                            foreach (KeyValuePair <string, string> entry in _classNameMappings)
                            {
                                ChangeOldClassVariableToNewClassVariable(entry, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            //Replace all the old exact variable names with the new exact variable names.
                            foreach (KeyValuePair <string, string> entry in _variableNameExacts)
                            {
                                ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            //Replace all the old layout names with the new layout names.
                            foreach (KeyValuePair <string, string> entry in _layoutNameMappings)
                            {
                                ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            if (!activityInfoCaptured)
                            {
                                //Capture package name after it ha been changed to the new package name.
                                if (line.StartsWith("package"))
                                {
                                    string package = line.Replace("package", string.Empty);
                                    package = package.Replace(";", string.Empty);
                                    package = package.Trim();
                                    if (package.StartsWith("com.sample.example"))
                                    {
                                        package = package.Replace("com.sample.example", string.Empty);
                                    }
                                    package  = package.Trim();
                                    package += "." + currentClassName;
                                    if (!_newActivitiesMapping.ContainsKey(package))
                                    {
                                        _newActivitiesMapping.Add(package, currentClassName);
                                    }
                                    activityInfoCaptured = true;
                                }
                            }
                            contents.AppendLine(line);
                            if (_action == "Cancel")
                            {
                                break;
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                    if (changed)
                    {
                        FileHelper.WriteFile(fileSpec, contents.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(hit);
        }
Exemple #11
0
        /// <summary>
        /// Edit Models file.
        /// </summary>
        /// <remarks>
        /// Apply global changes to one model file.
        /// </remarks>
        protected bool EditModelsFile(string fileSpec)
        {
            classFileCount++;
            _ignoreUntil = true;
            StringBuilder contents                 = new StringBuilder();
            List <string> memberVariableLines      = new List <string>();
            bool          memberVariableOnNextLine = false;
            bool          memberVariablesOpened    = false;
            bool          memberVariablesClosed    = false;
            string        line             = string.Empty;
            bool          first            = true;
            bool          hit              = false;
            bool          changed          = false;
            FileInfo      fileInfo         = null;
            string        record           = string.Empty;
            long          count            = 0;
            string        currentClassName = System.IO.Path.GetFileNameWithoutExtension(fileSpec);

            try
            {
                if (File.Exists(fileSpec))
                {
                    string modelClassName = System.IO.Path.GetFileNameWithoutExtension(fileSpec);
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        memberVariableOnNextLine = false;
                        memberVariablesOpened    = false;
                        memberVariablesClosed    = false;
                        do
                        {
                            count++;
                            classFileLineCount++;
                            record = sr.ReadLine();
                            line   = record;
                            if (memberVariableOnNextLine)
                            {
                                memberVariableLines.Add(line);
                                line = line.Replace(" Boolean ", " boolean ");
                                line = line.Replace(" Integer ", " int ");
                                line = line.Replace(" Int ", " int ");
                                line = line.Replace(" Long ", " long ");
                                line = line.Replace(" = null", string.Empty);
                                memberVariableOnNextLine = false;
                            }
                            if (memberVariablesOpened && !memberVariablesClosed)
                            {
                                if (line.Trim().Length == 0)
                                {
                                    memberVariablesClosed = true;
                                    Generator       generator = null;
                                    EntityMetaBlock block     = null;
                                    try
                                    {
                                        generator = new Generator(modelClassName, memberVariableLines, _apiToModelClassNameMapping);
                                        block     = generator.ImportMemberVariables();
                                    }
                                    catch (Exception e1)
                                    {
                                    }
                                    try
                                    {
                                        List <string> defaultConstructor = generator.GenerateDefaultConstructor(block);
                                        foreach (string ln in defaultConstructor)
                                        {
                                            contents.AppendLine(ln);
                                        }
                                    }
                                    catch (Exception e2)
                                    {
                                    }
                                    try
                                    {
                                        List <string> apiObjectConstructor = generator.GenerateApiObjectConstructor(block);
                                        foreach (string ln in apiObjectConstructor)
                                        {
                                            contents.AppendLine(ln);
                                        }
                                    }
                                    catch (Exception e3)
                                    {
                                    }
                                    try
                                    {
                                        List <string> parcelConstructor = generator.GenerateParameterisedParcelConstructor(block);
                                        foreach (string ln in parcelConstructor)
                                        {
                                            contents.AppendLine(ln);
                                        }
                                    }
                                    catch (Exception e4)
                                    {
                                    }
                                }
                            }
                            if (line.Contains("@Expose"))
                            {
                                memberVariablesOpened = true;
                                if (!memberVariablesClosed)
                                {
                                    memberVariableOnNextLine = true;
                                }
                                continue;
                            }
                            else if (line.Contains("Expose;"))
                            {
                                continue;
                            }
                            else if (line.Contains("@SerializedName"))
                            {
                                continue;
                            }
                            else if (line.Contains("SerializedName;"))
                            {
                                continue;
                            }
                            else if (line.Contains("package com.sample.example"))
                            {
                                continue;
                            }
                            if (_ignoreUntil)
                            {
                                if (line.Trim().Length == 0)
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("/*"))
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("*"))
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("*/"))
                                {
                                    continue;
                                }
                            }
                            if (line.Contains("public class"))
                            {
                                // Ignore all lines until the package is found.
                                _ignoreUntil = false;
                                // Insert package line.
                                string packageLine = "package com.example.kotlinmodelsexperiment.common.models.data;";
                                ConditionalAppendLine(ref contents, packageLine);
                                ConditionalAppendLine(ref contents, string.Empty);
                                // Insert comment block at start of class.
                                string[] parts = line.Split(' ');
                                if (parts.Length > 2)
                                {
                                    string className = parts[2];
                                    string comment1  = "/**";
                                    string comment2  = String.Format(" * {0} model state.", CommentFromClassName(className));
                                    string comment3  = " */";
                                    ConditionalAppendLine(ref contents, comment1);
                                    ConditionalAppendLine(ref contents, comment2);
                                    ConditionalAppendLine(ref contents, comment3);
                                    hit     = true;
                                    changed = true;
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment1);
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment2);
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment3);
                                }
                                ConditionalAppendLine(ref contents, "@Parcel");
                                //Replace all the API class names with the Model class names.
                                foreach (KeyValuePair <string, string> entry in _apiToModelClassNameMapping)
                                {
                                    //ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(".", entry, ";", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName("<", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName("<", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, "<", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName("(", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName("(", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, "(", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(" ", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(string.Empty, entry, ".", ref line, ref changed, ref first, fileSpec, count, ref record);
                                    ChangeOldClassNameToNewClassName(string.Empty, entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                }
                                ConditionalAppendLine(ref contents, line);
                                continue;
                            }
                            //Replace all the API class names with the Model class names.
                            foreach (KeyValuePair <string, string> entry in _apiToModelClassNameMapping)
                            {
                                //ChangeOldClassNameToNewClassName(string.Empty, entry, string.Empty, ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(".", entry, ";", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("<", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("<", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ",", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ">", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, "<", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("(", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName("(", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, "(", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, ")", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(" ", entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(string.Empty, entry, ".", ref line, ref changed, ref first, fileSpec, count, ref record);
                                ChangeOldClassNameToNewClassName(string.Empty, entry, " ", ref line, ref changed, ref first, fileSpec, count, ref record);
                            }
                            contents.AppendLine(line);
                            if (_action == "Cancel")
                            {
                                break;
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                    if (changed)
                    {
                        FileHelper.WriteFile(fileSpec, contents.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(hit);
        }
Exemple #12
0
        /// <summary>
        /// Edit Models file.
        /// </summary>
        /// <remarks>
        /// Apply global changes to one model file.
        /// </remarks>
        protected bool EditModelsFile(string fileSpec)
        {
            classFileCount++;
            _ignoreUntil = true;
            StringBuilder contents            = new StringBuilder();
            List <string> memberVariableLines = new List <string>();
            List <string> memberVarLines      = new List <string>();
            List <string> importModelClasses  = new List <string>();
            string        line             = string.Empty;
            bool          first            = true;
            bool          hit              = false;
            bool          changed          = false;
            FileInfo      fileInfo         = null;
            string        record           = string.Empty;
            long          count            = 0;
            string        currentClassName = System.IO.Path.GetFileNameWithoutExtension(fileSpec);
            var           importsBuffer    = new List <string>();

            // Read ahead to see which other model classes need import statements.
            try
            {
                if (File.Exists(fileSpec))
                {
                    string modelClassName    = System.IO.Path.GetFileNameWithoutExtension(fileSpec);
                    string apiModelClassName = modelClassName.Replace("ModelState", string.Empty);
                    importModelClasses.Add(apiModelClassName);
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        do
                        {
                            record = sr.ReadLine();
                            line   = record;
                            var trimmedLine = line.Trim();
                            if (trimmedLine.StartsWith("/*") && trimmedLine.EndsWith("*/"))
                            {
                                memberVarLines.Add(line);
                            }
                            else if (trimmedLine.StartsWith("val"))
                            {
                                memberVarLines.Add(line);
                            }
                            else if (trimmedLine.StartsWith(")"))
                            {
                                GeneratorKotlin generator = null;
                                EntityMetaBlock block     = null;
                                try
                                {
                                    generator = new GeneratorKotlin(modelClassName, memberVarLines, _apiToModelClassNameMapping);
                                    block     = generator.ImportMemberVariables();
                                    foreach (Vector vector in block.MemberVariables)
                                    {
                                        string apiType      = vector.ApiType;
                                        string apiInnerType = InnerType(vector.ApiType);
                                        if (_apiToModelClassNameMapping.ContainsKey(apiType))
                                        {
                                            if (!importModelClasses.Contains(apiType))
                                            {
                                                //importModelClasses.Add(apiType);
                                            }
                                        }
                                        if (_apiToModelClassNameMapping.ContainsKey(apiInnerType))
                                        {
                                            if (!importModelClasses.Contains(apiInnerType))
                                            {
                                                //importModelClasses.Add(apiInnerType);
                                            }
                                        }
                                    }
                                }
                                catch (Exception e1)
                                {
                                    string msg = e1.Message;
                                }
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                }
            }
            catch (Exception ex)
            {
            }
            // Now process file normally.
            try
            {
                if (File.Exists(fileSpec))
                {
                    string modelClassName = System.IO.Path.GetFileNameWithoutExtension(fileSpec);
                    fileInfo = R.GetFileInfo(fileSpec);
                    StreamReader sr = new StreamReader(fileSpec);
                    if (sr.Peek() >= 0)
                    {
                        do
                        {
                            count++;
                            classFileLineCount++;
                            record = sr.ReadLine();
                            line   = record;
                            var trimmedLine = line.Trim();
                            if (line.Contains("package com.ubtsupport.streamline3admin"))
                            {
                                continue;
                            }
                            if (line.Contains("import"))
                            {
                                importsBuffer.Add(line);
                                continue;
                            }
                            if (_ignoreUntil)
                            {
                                if (line.Trim().Length == 0)
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("/*"))
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("*"))
                                {
                                    continue;
                                }
                                else if (line.Trim().StartsWith("*/"))
                                {
                                    continue;
                                }
                            }
                            if (trimmedLine.StartsWith("/*") && trimmedLine.EndsWith("*/"))
                            {
                                memberVariableLines.Add(line);
                            }
                            if (trimmedLine.StartsWith("val"))
                            {
                                memberVariableLines.Add(line);
                            }
                            if (trimmedLine.StartsWith(")"))
                            {
                                GeneratorKotlin generator = null;
                                EntityMetaBlock block     = null;
                                try
                                {
                                    generator = new GeneratorKotlin(modelClassName, memberVariableLines, _apiToModelClassNameMapping);
                                    block     = generator.ImportMemberVariables();
                                    int counter = 0;
                                    int maximum = block.MemberVariables.Count;
                                    foreach (Vector vector in block.MemberVariables)
                                    {
                                        counter++;
                                        if (vector.Summary.Trim().Length > 0)
                                        {
                                            string comment = "    " + vector.Summary;
                                            contents.AppendLine(comment);
                                        }
                                        StringBuilder output = new StringBuilder("    var ");
                                        output.Append(vector.Variable);
                                        output.Append(": ");
                                        output.Append(vector.Type);
                                        output.Append(" = ");
                                        output.Append(vector.DefaultValue);
                                        if (counter < maximum)
                                        {
                                            output.Append(",");
                                        }
                                        contents.AppendLine(output.ToString());
                                    }
                                    contents.AppendLine(@") {");
                                }
                                catch (Exception e1)
                                {
                                }
                                try
                                {
                                    List <string> apiObjectConstructor = generator.GenerateApiObjectConstructor(block);
                                    foreach (string ln in apiObjectConstructor)
                                    {
                                        contents.AppendLine(ln);
                                    }
                                    contents.AppendLine(@"}");
                                }
                                catch (Exception e3)
                                {
                                }
                            }
                            if (line.Contains("data class"))
                            {
                                // Ignore all lines until the package is found.
                                _ignoreUntil = false;
                                // Insert package line.
                                string packageLine = "package " + FeaturesModelsPackageName;
                                ConditionalAppendLine(ref contents, packageLine);
                                ConditionalAppendLine(ref contents, string.Empty);
                                // Insert constants import line.
                                string importLine = "import com.ubtsupport.streamline3admin.common.constants.Constants";
                                ConditionalAppendLine(ref contents, importLine);
                                //if (FeaturesModelsPackageName != CommonModelsPackageName)
                                //{
                                //    // Insert API models import line.
                                //    importLine = "import " + CommonModelsPackageName;
                                //    ConditionalAppendLine(ref contents, importLine);
                                //}
                                // Insert referenced API model class import lines.
                                foreach (var modelClass in importModelClasses)
                                {
                                    importLine = "import " + CommonModelsPackageName + "." + modelClass;
                                    ConditionalAppendLine(ref contents, importLine);
                                }
                                // Insert referenced modelState class import lines.
                                //foreach (var import in importsBuffer)
                                //{
                                //    var impLine = import;
                                //    impLine = impLine.Replace(CommonModelsPackageName, FeaturesModelsPackageName);
                                //    //Replace all the API class names with the Model class names.
                                //    impLine = EditLine(_apiToModelClassNameEditRules, impLine);
                                //    ConditionalAppendLine(ref contents, impLine);
                                //}
                                // Insert parceler import line.
                                importLine = "import org.parceler.Parcel";
                                ConditionalAppendLine(ref contents, importLine);
                                ConditionalAppendLine(ref contents, string.Empty);
                                // Insert comment block at start of class.
                                string[] parts = line.Split(' ');
                                if (parts.Length > 2)
                                {
                                    string className = parts[2];
                                    string comment1  = "/**";
                                    string comment2  = String.Format(" * {0} model state.", CommentFromClassName(className));
                                    string comment3  = " */";
                                    ConditionalAppendLine(ref contents, comment1);
                                    ConditionalAppendLine(ref contents, comment2);
                                    ConditionalAppendLine(ref contents, comment3);
                                    hit     = true;
                                    changed = true;
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment1);
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment2);
                                    RecordInsert(hit, ref first, fileSpec, count, record, comment3);
                                }
                                ConditionalAppendLine(ref contents, "@Parcel(Parcel.Serialization.BEAN)");
                                //Replace all the API class names with the Model class names.
                                line = EditLine(_apiToModelClassNameEditRules, line);
                                line = line.Replace(" (", "(");
                                ConditionalAppendLine(ref contents, line);
                                continue;
                            }
                            //Replace all the API class names with the Model class names.
                            line = EditLine(_apiToModelClassNameEditRules, line);
                            //contents.AppendLine(line);
                            if (_action == "Cancel")
                            {
                                break;
                            }
                        } while (sr.Peek() >= 0);
                    }
                    sr.Close();
                    if (changed)
                    {
                        FileHelper.WriteFile(fileSpec, contents.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(hit);
        }
Exemple #13
0
 /// <summary>
 /// Write timed message to log file in standard fashion.
 /// </summary>
 /// <remarks>
 /// Message severities are:
 /// "I" - Informational, not an error.
 /// "W" - Warning, draws attention to something unusual but not an error.
 /// "E" - Error, requires some kind of action to fix, maybe just a rerun.
 /// "S" - Severe, major operating system or server error beyond our control.
 /// </remarks>
 public void WriteTimedMsg(string serial, string severity, string message)
 {
     message = R.FmtDate(DateTime.Now, "hh:nn:ss") + " " + message;
     WriteMsg(serial, severity, message);
 }