Ejemplo n.º 1
0
        /// <summary>
        /// This method returns a list of Code Lines
        /// </summary>
        public static List <CodeLine> CreateCodeLinesFromText(string text)
        {
            // initial value
            List <CodeLine> codeLines = null;
            List <TextLine> textLines = null;

            // If the text string exists
            if (TextHelper.Exists(text))
            {
                // get the textLines
                textLines = WordParser.GetTextLines(text);
            }

            // now create the codeLines from the textLines
            codeLines = CreateCodeLines(textLines);

            // return value
            return(codeLines);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method returns a list of Code Lines
        /// </summary>
        public static List <CodeLine> CreateCodeLines(string filePath)
        {
            // initial value
            List <CodeLine> codeLines = null;

            // if the filePath exists
            if ((TextHelper.Exists(filePath)) && (File.Exists(filePath)))
            {
                // get the text for the path
                string text = File.ReadAllText(filePath);

                // get the textLines
                List <TextLine> textLines = WordParser.GetTextLines(text);

                // set the return value
                codeLines = CreateCodeLines(textLines);
            }

            // return value
            return(codeLines);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method Parse Projects
        /// </summary>
        public List <VSProject> ParseProjects(Solution solution)
        {
            // initial value
            List <VSProject> projects = new List <VSProject>();

            // typical delimiter characters
            char[] commaDelimiter = { ',' };

            // If the solutionFilePath string exists
            if ((NullHelper.Exists(solution)) && (File.Exists(solution.Path)))
            {
                // read the text of the file
                string fileText = File.ReadAllText(solution.Path);

                // parse the textLines
                List <TextLine> lines = WordParser.GetTextLines(fileText);

                // If the lines collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(lines))
                {
                    // get the projectLines
                    List <TextLine> projectLines = lines.Where(x => x.Text.StartsWith("Project")).Where(x => x.Text.Contains(".csproj")).ToList();

                    // if there are one or more projectLines
                    if (ListHelper.HasOneOrMoreItems(projectLines))
                    {
                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in projectLines)
                        {
                            // if the line.Text exists
                            if (TextHelper.Exists(line.Text))
                            {
                                // get the equalSignIndex
                                int equalSignIndex = line.Text.IndexOf("=");

                                // if the EqualSignIndex exists
                                if (equalSignIndex >= 0)
                                {
                                    // get the text of the word on the right side of the equal sign
                                    string wordsOnRightSideOfEqualSign = line.Text.Substring(equalSignIndex + 1).Trim();

                                    // If the wordsOnRightSideOfEqualSign string exists
                                    if (TextHelper.Exists(wordsOnRightSideOfEqualSign))
                                    {
                                        // get the words
                                        List <Word> words = WordParser.GetWords(wordsOnRightSideOfEqualSign, commaDelimiter);

                                        // if there are at least two words
                                        if ((words != null) && (words.Count >= 3))
                                        {
                                            // create a project
                                            VSProject project = new VSProject();

                                            // get the text
                                            string projectPath = words[1].Text.Substring(2, words[1].Text.Length - 3);

                                            // Create a directory
                                            DirectoryInfo directory = new DirectoryInfo(solution.Path);

                                            // combine the solutoin and the path
                                            string path = Path.Combine(directory.Parent.FullName, projectPath);

                                            // set the path
                                            project.Path = path;

                                            // Get the projectName
                                            project.Name = words[0].Text.Replace("\"", "");

                                            // set the solution
                                            project.Solution = solution;

                                            string temp = words[2].Text.Substring(2, words[2].Text.Length - 3).Replace(@"\", "").Replace("{", "").Replace("}", "").Trim();

                                            // get the tempId
                                            Guid tempId = Guid.Empty;

                                            // parse the Guid
                                            Guid.TryParse(temp, out tempId);

                                            // set the projectId
                                            project.Id = tempId;

                                            // now find the index of this project so the same project is not added twice
                                            int index = GetProjectIndex(project.Id);

                                            // if the index was found
                                            if (index < 0)
                                            {
                                                // Add this project
                                                projects.Add(project);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(projects);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the DataOperationsManager.
        /// </summary>
        public bool CreateDataManager(List <DataTable> dataTables)
        {
            // Initial Value
            bool created = false;

            // Set Indent To 0
            Indent = 0;

            // file name variable
            string fileName = null;

            // verify DataTable exist
            if (dataTables != null)
            {
                // Get DataWatcherFileName
                fileName = CreateFileName();

                // Create Writer
                CreateFile(fileName, DataManager.ProjectTypeEnum.DAC);

                // Write References
                WriteReferences(this.ObjectReferences);

                // Write Blank Line
                WriteLine();

                // Write NameSpace
                string nameSpace = "namespace " + this.NameSpaceName;
                WriteLine(nameSpace);

                // Write Open Brack
                WriteOpenBracket();

                // Write Blank Line
                WriteLine();

                // Increase Indent
                Indent++;

                // Get ClassName
                string className = "DataManager";

                // Write Region for this reader
                BeginRegion("class " + className);

                // Write Object Reader Summary
                WriteClassSummary();

                // get class line
                string classLine = "public class " + className;

                // Write ClassLine
                WriteLine(classLine);

                // Write Open Bracket
                WriteOpenBracket(true);

                // Write Blank Line
                WriteLine();

                // Write The Private Variables Region
                WritePrivateVariables();

                // Write Constructor
                WriteConstructor();

                // Write Methods
                WriteMethods();

                // Write Properties
                WriteProperties();

                // Decrease Indent
                Indent--;

                // Write Close Bracket
                WriteCloseBracket();

                // Write EndRegion For Class
                EndRegion();

                // Write Blank Line
                WriteLine();

                // Decrease Indent
                Indent--;

                // Write Close Bracket
                WriteCloseBracket();

                // Close This File
                this.Writer.Close();
            }

            // if file name is not null
            if (!String.IsNullOrEmpty(fileName))
            {
                // if file exists on hard drive
                if (File.Exists(fileName))
                {
                    // get the text
                    string text = File.ReadAllText(fileName);

                    // if the text exists
                    if (TextHelper.Exists(text))
                    {
                        // get the lines from this file text
                        List <TextLine> lines = WordParser.GetTextLines(text);

                        // If there are not multiple lines, this was not created
                        created = ListHelper.HasOneOrMoreItems(lines);
                    }
                }
            }

            // return value
            return(created);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method returns the number of items imported
        /// </summary>
        /// <param name="text">The contents to be imported.</param>
        /// <param name="tableName">Only used in cases where more than one import takes place.</param>
        /// <param name="expectedCount">Number of expected columns in the csv file</param>
        /// <param name="callback">The method to call to update progress</param>
        /// <returns></returns>
        public static int ImportData(string text, string tableName, int expectedCount, ImportProgressCallback callback)
        {
            // initial value
            int savedCount = 0;

            // locals
            char[]      delimiters  = { ',' };
            int         count       = 0;
            int         totalCount  = 0;
            int         refreshRate = 5;
            List <Word> words       = null;
            RawImport   rawImport   = null;

            // if the fileExists
            if (TextHelper.Exists(text))
            {
                // Create a new instance of a 'Gateway' object.
                Gateway gateway = new Gateway();

                // set the textLines
                List <TextLine> textLines = WordParser.GetTextLines(text.Trim());

                // If the textLines collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(textLines))
                {
                    // If the callback object exists
                    if (NullHelper.Exists(callback))
                    {
                        // notify the delegate to setup the Graph
                        callback(textLines.Count, tableName);
                    }

                    // change the RefreshRate
                    if (textLines.Count > 1000)
                    {
                        // change this to whatever makes since for your app
                        refreshRate = 25;
                    }

                    // set the totalCount
                    totalCount = textLines.Count - 1;

                    // Iterate the collection of TextLine objects
                    foreach (TextLine textLine in textLines)
                    {
                        // Increment the value for count
                        count++;

                        // skip the first row
                        if (count > 1)
                        {
                            // get the list of words
                            words = WordParser.GetWords(textLine.Text, delimiters, true);

                            // if the words collection has exactly the right amount
                            if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == expectedCount))
                            {
                                // Create a new instance of a 'RawImport' object.
                                rawImport = new RawImport();

                                // Load the RawImport with the words
                                SetRawImportProperties(ref rawImport, words);

                                // save the rawImport object
                                bool saved = gateway.SaveRawImport(ref rawImport);

                                // if the value for saved is true
                                if (saved)
                                {
                                    // Increment the value for savedCount
                                    savedCount++;

                                    // refresh every x number of records
                                    if (savedCount % refreshRate == 0)
                                    {
                                        // update the graph (for a large project, you might want to update every 25, 50 or 100 records or so
                                        callback(savedCount, tableName);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(savedCount);
        }
        /// <summary>
        /// This method returns the Connection String Line
        /// </summary>
        public TextLine GetConnectionStringLine()
        {
            // initial value
            TextLine connectionStringLine = null;

            // Set the ConnectionStringIndex
            ConnectionStringIndex = -1;

            // local
            int index = -1;

            // set the appConfig file location relative to bin\debug
            string appConfig = "../../App.config";

            // if the file exists
            if (File.Exists(appConfig))
            {
                // get the full path
                string fullPath = Path.GetFullPath(appConfig);

                // Set the AppConfigPath
                AppConfigPath = fullPath;

                // read the text of the AppConfig
                string appConfigText = File.ReadAllText(fullPath);

                // If the appConfigText string exists
                if (TextHelper.Exists(appConfigText))
                {
                    // get the textLines
                    List <TextLine> textLines = WordParser.GetTextLines(appConfigText);

                    // If the textLines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(textLines))
                    {
                        // store the textLines so they can be updated in the next step
                        AppConfigTextLines = textLines;

                        // Iterate the collection of TextLine objects
                        foreach (TextLine textLine in textLines)
                        {
                            // Increment the value for tempIndex
                            index++;

                            // if this is not a comment line
                            if (!textLine.Text.Trim().StartsWith(HTMLCommentStart))
                            {
                                // if this is the ConnectionStringLine
                                if (textLine.Text.Trim().StartsWith(ConnectionStringStart))
                                {
                                    // get the textLine
                                    connectionStringLine = textLine;

                                    // Set the ConnectionStringIndex
                                    ConnectionStringIndex = index;

                                    // break out of this loop
                                    break;
                                }
                                else if (textLine.Text.Trim().StartsWith(SetupCompleteStart))
                                {
                                    // Set the SetupCompleteIndex
                                    SetupCompleteIndex = index;
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(connectionStringLine);
        }
        /// <summary>
        /// event is fired when the 'ImportZipButton' is clicked.
        /// </summary>
        private void ImportZipButton_Click(object sender, EventArgs e)
        {
            // locals
            bool        zipCodeSaved = false;
            string      fileName     = "";
            string      temp         = "";
            List <Word> words        = null;

            char[] delimiter     = { '\t' };
            string zip           = "";
            string cityName      = "";
            string stateName     = "";
            int    lineCount     = 0;
            int    stateId       = 0;
            string lastStateName = "";

            try
            {
                // get the text of the USA-Zip.txt file
                string zipTextFile = ZipCodeControl.Text;

                // attempt to read all the text
                string textFileContents = File.ReadAllText(zipTextFile);

                // If the textFileContents string exists
                if (TextHelper.Exists(textFileContents))
                {
                    // create the fileInfo
                    FileInfo fileInfo = new FileInfo(zipTextFile);

                    // set the name of the file
                    fileName = fileInfo.Name;

                    // get the text lines (this file is one entry per row)
                    List <TextLine> lines = WordParser.GetTextLines(textFileContents);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // Setup Graph4
                        Graph4.Visible = true;
                        Graph4.Maximum = lines.Count;
                        Graph4.Value   = 0;

                        // refresh everything
                        Refresh();

                        // Create a new instance of a 'Gateway' object.
                        Gateway gateway = new Gateway();

                        // first pass handle only columns 0 - 3
                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // Increment the value for lineCount
                            lineCount++;

                            // get the current line
                            temp = line.Text.Trim();

                            // get the words
                            words = WordParser.GetWords(temp, delimiter);

                            // If the words collection exists and has one or more items
                            if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == 4))
                            {
                                // Append columns 0 - 3
                                zip       = words[0].Text;
                                cityName  = words[1].Text;
                                stateName = words[2].Text;

                                // if we just reached a new stateId
                                if (stateName != lastStateName)
                                {
                                    // find the state
                                    dataObjects.State state = gateway.FindStateByName(stateName);

                                    // If the state object exists
                                    if (NullHelper.Exists(state))
                                    {
                                        // set the StateId
                                        stateId = state.Id;
                                    }
                                }

                                // if the stateId were set
                                if (stateId > 0)
                                {
                                    // insert a ZipCode object
                                    dataObjects.ZipCode zipCode = new dataObjects.ZipCode();

                                    // set the properties on the zipCode object
                                    zipCode.Name     = zip;
                                    zipCode.CityName = cityName;
                                    zipCode.StateId  = stateId;

                                    // perform the save
                                    zipCodeSaved = gateway.SaveZipCode(ref zipCode);
                                }

                                // if the zipCode was saved
                                if (zipCodeSaved)
                                {
                                    // increment the value for the graph
                                    Graph4.Value++;
                                }

                                // set the lastStateName
                                lastStateName = stateName;
                            }
                        }

                        // Show finished
                        MessageBoxHelper.ShowMessage("The file '" + fileName + "' has been imported.", "Import Complete");
                    }
                }
                else
                {
                    // Show an error
                    MessageBoxHelper.ShowMessage("The selected import file could not be read.", "Import File Error");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("ImportZipButton_Click", this.Name, error);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This method is used to handle a MemoryStream returned from the uploaded file,
        /// and the memory stream is going to be attempted to be converted to an Xml string.
        /// </summary>
        private void OnFileUploaded2(UploadedFileInfo uploadedFileInfo)
        {
            try
            {
                // if aborted
                if (uploadedFileInfo.Aborted)
                {
                    // get the status
                    XmlString = (MarkupString)uploadedFileInfo.ErrorMessage;
                }
                else
                {
                    // if the MemoryStream was uploaded
                    if (uploadedFileInfo.HasStream)
                    {
                        System.Text.Encoding encoding = System.Text.Encoding.UTF8;
                        string temp = encoding.GetString(uploadedFileInfo.Stream.ToArray());

                        // Get the lines
                        List <TextLine> lines = WordParser.GetTextLines(temp.TrimEnd());

                        // If the lines collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(lines))
                        {
                            // local
                            int count = 0;

                            // Create the lines
                            this.Lines = new List <XmlLine>();

                            // Iterate the collection of TextLine objects
                            foreach (TextLine line in lines)
                            {
                                if (TextHelper.Exists(line.Text))
                                {
                                    // cast the XmlLine as a Line
                                    XmlLine xmlLine = new XmlLine();

                                    // Set the properties
                                    xmlLine.Text = line.Text;

                                    // not the first line or the last line
                                    if (count != 0)
                                    {
                                        // Indent
                                        xmlLine.Indent = true;
                                    }

                                    // Add this line
                                    this.Lines.Add(xmlLine);

                                    // increment the count
                                    count++;
                                }
                            }

                            // Make sure we indent
                            this.Lines[this.Lines.Count - 1].Indent = false;
                        }
                    }
                }
            }
            catch (Exception error)
            {
                // for debugging only for this sample
                string err = error.ToString();
            }
            finally
            {
                // Might be needed ?
                StateHasChanged();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// This method returns a GatewayInfo object
        /// </summary>
        public static GatewayInfo GetGatewayInfo(string gatewayFilePath, List <string> methodNames)
        {
            // initial value
            GatewayInfo gatewayInfo = new GatewayInfo();

            // locals
            List <GatewayMethodInfo> methodInformation = new List <GatewayMethodInfo>();
            int  index                   = -1;
            bool methodRegionOn          = false;
            GatewayMethodInfo methodInfo = null;

            // Set the MethodInformation
            gatewayInfo.MethodInformation = methodInformation;

            // if the gatewayFilePath exists
            if ((TextHelper.Exists(gatewayFilePath)) && (File.Exists(gatewayFilePath)) && (ListHelper.HasOneOrMoreItems(methodNames)))
            {
                // Get the fileText
                string fileText = File.ReadAllText(gatewayFilePath);

                // If the fileText string exists
                if (TextHelper.Exists(fileText))
                {
                    // Parse the lines
                    List <TextLine> lines = WordParser.GetTextLines(fileText);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // set the lines
                        gatewayInfo.TextLines = lines;

                        // Iterate the collection of string objects
                        foreach (string methodName in methodNames)
                        {
                            // reset
                            methodRegionOn = false;
                            index          = -1;

                            // Iterate the collection of TextLine objects
                            foreach (TextLine line in lines)
                            {
                                // Increment the value for index
                                index++;

                                // Create a codeLine
                                CodeLine codeLine = new CodeLine(line.Text);

                                // if the TextLine exists
                                if (codeLine.HasTextLine)
                                {
                                    // Get the words for this line
                                    codeLine.TextLine.Words = WordParser.GetWords(line.Text);
                                }

                                // if the value for methodRegionOn is true
                                if (methodRegionOn)
                                {
                                    // if this is the
                                    if ((codeLine.IsEndRegion) && (NullHelper.Exists(methodInfo)))
                                    {
                                        // turn this off
                                        methodRegionOn = false;

                                        // Set the methodInfo
                                        methodInfo.EndIndex = index;

                                        // break out of the loop
                                        break;
                                    }
                                }
                                else
                                {
                                    // if this is a Region
                                    if (codeLine.IsRegion)
                                    {
                                        // if this is the method being sought
                                        if (methodName == codeLine.RegionName)
                                        {
                                            // set to true
                                            methodRegionOn = true;

                                            // Create a new instance of a 'MethodInfo' object.
                                            methodInfo = new GatewayMethodInfo();

                                            // Set the methodName
                                            methodInfo.Name = methodName;

                                            // Set the startIndex
                                            methodInfo.StartIndex = index;

                                            // Add this item
                                            methodInformation.Add(methodInfo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(gatewayInfo);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This method prepares this control to be shown
        /// </summary>
        public void Setup(MethodInfo methodInfo, Project openProject, CustomReader customReader = null, DTNField orderByField = null, FieldSet orderByFieldSet = null)
        {
            // store the args
            this.MethodInfo  = methodInfo;
            this.OpenProject = openProject;

            // locals
            DataJuggler.Net.DataField        parameter  = null;
            List <DataJuggler.Net.DataField> parameters = null;
            ProcedureWriter writer = null;

            // If the MethodInfo object exists
            if (this.HasMethodInfo)
            {
                // create a new
                MethodsWriter methodsWriter = new MethodsWriter();

                // get the StoredXml
                StoredXml = methodsWriter.ExportMethodInfo(this.MethodInfo);

                // if the OrderByFieldSet object exists
                if (NullHelper.Exists(orderByFieldSet))
                {
                    // set the gateway
                    Gateway gateway = new Gateway();

                    // load the orderByFields
                    orderByFieldSet.FieldSetFields = gateway.LoadFieldSetFieldViewsByFieldSetId(orderByFieldSet.FieldSetId);
                }

                // Set the Name of the Table
                this.SelectedTableControl.Text = this.MethodInfo.SelectedTable.TableName;

                // set the procedureName
                this.ProcedureNameControl.Text = MethodInfo.ProcedureName;

                // Check the button for Manual Update (user clicks Copy and goes to their SQL instance and executes).
                this.ManualUpdateRadioButton.Checked = true;

                // Check the box if UseCustomReader is true
                this.CustomWhereCheckBox.Checked = MethodInfo.UseCustomWhere;

                // Set the CustomWhereText (if any)
                this.WhereTextBox.Text = MethodInfo.WhereText;

                // convert the table
                DataJuggler.Net.DataTable table = DataConverter.ConvertDataTable(MethodInfo.SelectedTable, this.OpenProject);

                // if this is a Single Field Parameter and the Parameter Field exists
                if ((MethodInfo.ParameterType == ParameterTypeEnum.Single_Field) && (MethodInfo.HasParameterField))
                {
                    // convert the field from a DTNField to a DataJuggler.Net.DataField
                    parameter = DataConverter.ConvertDataField(MethodInfo.ParameterField);

                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameter);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameter, customReader, orderByField, orderByFieldSet, methodInfo.OrderByDescending, methodInfo.TopRows);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // If the orderByField object exists
                            if (NullHelper.Exists(orderByFieldSet))
                            {
                                // if there are not any fields loaded
                                if (!ListHelper.HasOneOrMoreItems(orderByFieldSet.Fields))
                                {
                                    // load the Fields
                                    orderByFieldSet.Fields = FieldSetHelper.LoadFieldSetFields(orderByFieldSet.FieldSetId);
                                }
                            }

                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameter, customReader, orderByField, orderByFieldSet, methodInfo.OrderByDescending, methodInfo.TopRows);
                        }
                    }
                }
                else if ((MethodInfo.ParameterType == ParameterTypeEnum.Field_Set) && (MethodInfo.HasParameterFieldSet) && (MethodInfo.ParameterFieldSet.HasFields))
                {
                    // convert the DTNFields to DataFields
                    parameters = DataConverter.ConvertDataFields(MethodInfo.ParameterFieldSet.Fields);

                    // If the parameters collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(parameters))
                    {
                        // set the FieldSetName so the description writes the method description correctly
                        parameters[0].FieldSetName = MethodInfo.ParameterFieldSet.Name;
                    }

                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameters);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                    }
                }
                else if ((MethodInfo.ParameterType == ParameterTypeEnum.No_Parameters))
                {
                    // Create a new instance of a 'ProcedureWriter' object (in TextWriter mode).
                    writer = new ProcedureWriter(true);

                    // if this is a FindByField method
                    if (writer.HasTextWriter)
                    {
                        // If Delete By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Delete_By)
                        {
                            // Write out the Delete Proc
                            writer.CreateDeleteProc(table, MethodInfo.ProcedureName, parameters);
                        }
                        // If Find By is the Method Type
                        if (MethodInfo.MethodType == MethodTypeEnum.Find_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, false, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                        // if Load By is the Method Type
                        else if (MethodInfo.MethodType == MethodTypeEnum.Load_By)
                        {
                            // create a find procedure
                            writer.CreateFindProc(table, true, MethodInfo.ProcedureName, parameters, MethodInfo.CustomReader, orderByField, orderByFieldSet);
                        }
                    }
                }

                // if the writer exists
                if (NullHelper.Exists(writer))
                {
                    // get the procedureText
                    string procedureText = writer.TextWriter.ToString();

                    // Show the Where Panel if CustomWhere is true
                    WherePanel.Visible = MethodInfo.UseCustomWhere;

                    // if CustomWhere
                    if (MethodInfo.UseCustomWhere)
                    {
                        // now the existing where text must be replaced
                        int whereIndex = procedureText.ToLower().IndexOf("where [");

                        // if the WhereText does not exist yet
                        if ((!MethodInfo.HasWhereText) && (whereIndex > 0))
                        {
                            // Set the text as it is now
                            string whereText = procedureText.Substring(whereIndex);

                            // If the whereText string exists
                            if (TextHelper.Exists(whereText))
                            {
                                // get the textLines
                                List <TextLine> textLines = WordParser.GetTextLines(whereText);

                                // If the textLines collection exists and has one or more items
                                if (ListHelper.HasOneOrMoreItems(textLines))
                                {
                                    // Create a new instance of a 'StringBuilder' object.
                                    StringBuilder sb = new StringBuilder();

                                    // add each textLine of the Where Clause except the last one
                                    foreach (TextLine textLine in textLines)
                                    {
                                        // if this is the End line
                                        if (!textLine.Text.ToLower().StartsWith("end"))
                                        {
                                            // Add this line
                                            sb.Append(textLine.Text);
                                        }
                                    }

                                    // Get the Where Clause
                                    MethodInfo.WhereText = sb.ToString().Trim();
                                }
                            }
                        }

                        // Set the WhereText
                        WhereTextBox.Text = MethodInfo.WhereText;

                        // if the whereIndex was found
                        if (whereIndex >= 0)
                        {
                            // if the WhereText does not already exist
                            if (!TextHelper.Exists(MethodInfo.WhereText))
                            {
                                // Set the default WhereText
                                MethodInfo.WhereText = procedureText.Substring(whereIndex);
                            }

                            // set the new ProcedureText
                            procedureText = procedureText.Substring(0, whereIndex) + MethodInfo.WhereText + Environment.NewLine + Environment.NewLine + "END";
                        }
                    }

                    // Remove any double blank lines
                    procedureText = CodeLineHelper.RemoveDoubleBlankLines(procedureText);

                    // display the procedure As Is for now.
                    this.ProcedureTextBox.Text = procedureText;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// event is fired when Where Text Box _ Text Changed
        /// </summary>
        private void WhereTextBox_TextChanged(object sender, EventArgs e)
        {
            // locals
            bool whereStarted  = false;
            bool whereFinished = false;

            // if the MethodInfo object exists
            if (HasMethodInfo)
            {
                // Get the new text
                string whereText = WhereTextBox.Text;

                // set the value in the MethodInfo object
                MethodInfo.WhereText = whereText + Environment.NewLine;

                // get the procedureText
                string procedureText = ProcedureTextBox.Text;

                // now the existing where text must be replaced
                int whereIndex = procedureText.ToLower().IndexOf("where [");

                // if the whereIndex was found
                if (whereIndex >= 0)
                {
                    // get all the lines after the where
                    string temp = procedureText.Substring(whereIndex);

                    // get the textLines after this whereIndex
                    List <TextLine> endProcedureTextLines = WordParser.GetTextLines(temp);
                    List <TextLine> linesAfterOrderBy     = new List <TextLine>();
                    string          postWhereText         = "";

                    // if there are one or more items
                    if (ListHelper.HasOneOrMoreItems(endProcedureTextLines))
                    {
                        // Iterate the collection of TextLine objects
                        foreach (TextLine textLine in endProcedureTextLines)
                        {
                            // if where has not been encountered yet
                            if (!whereStarted)
                            {
                                // if this is not the where line
                                if (textLine.Text.TrimStart().ToLower().StartsWith("where ["))
                                {
                                    // where has Started
                                    whereStarted = true;
                                }
                            }
                            else if (!whereFinished)
                            {
                                // if the Text exists
                                if (!TextHelper.Exists(textLine.Text))
                                {
                                    // where has finished
                                    whereFinished = true;

                                    // Add this line
                                    linesAfterOrderBy.Add(textLine);
                                }
                                else if (textLine.Text.TrimStart().ToLower().StartsWith("order by"))
                                {
                                    // Add this line
                                    linesAfterOrderBy.Add(textLine);
                                }
                                else if (textLine.Text.TrimStart().ToLower().StartsWith("end"))
                                {
                                    // Add this line
                                    linesAfterOrderBy.Add(textLine);
                                }
                            }
                            else
                            {
                                // Add this line
                                linesAfterOrderBy.Add(textLine);
                            }
                        }
                    }

                    // if there are NOT any lines after order by
                    if ((ListHelper.HasOneOrMoreItems(linesAfterOrderBy)) && (HasLinesAfterOrderBy))
                    {
                        // use the linesAftterOrderBy previously stored
                        linesAfterOrderBy = this.LinesAfterOrderBy;
                    }

                    // if there are any lines after order by
                    if (ListHelper.HasOneOrMoreItems(linesAfterOrderBy))
                    {
                        // store the linesAfterOrderBy, because sometimes typing goes too fast
                        // for the parsing to keep up (I think)
                        this.LinesAfterOrderBy = linesAfterOrderBy;

                        // Create a new instance of a 'StringBuilder' object.
                        StringBuilder sb = new StringBuilder();

                        // Iterate the collection of TextLine objects
                        foreach (TextLine textLine in linesAfterOrderBy)
                        {
                            // Add this item
                            sb.Append(textLine.Text);
                            sb.Append(Environment.NewLine);
                        }

                        // set the postWhereText
                        postWhereText = sb.ToString();
                    }

                    // set the new ProcedureText
                    procedureText = procedureText.Substring(0, whereIndex) + MethodInfo.WhereText + postWhereText;

                    // set the updated text
                    this.ProcedureTextBox.Text = procedureText;
                }

                // Show the save button if there are any changes
                UIEnable();
            }
        }
        /// <summary>
        /// This class is used to parse querries from the queryText given
        /// </summary>
        public static PixelQuery ParsePixelQuery(string queryText)
        {
            // initial value
            PixelQuery pixelQuery = new PixelQuery();

            // locals
            int           count        = 0;
            StringBuilder sb           = null;
            string        criteriaText = String.Empty;
            string        updateText   = String.Empty;

            // If the queryText string exists
            if (TextHelper.Exists(queryText))
            {
                // get the lowercase version of the text
                queryText = queryText.ToLower().Trim();

                // parse the ActionType (Show Pixels, Hide Pixels, Draw Line, Update)
                pixelQuery.ActionType = ParseActionType(queryText);

                // if we are doing an update query, we have to modify this a little
                if (pixelQuery.ActionType == ActionTypeEnum.Update)
                {
                    // for an update query, the second line sets the color values to update to
                    // and the third line starts the where clause.

                    // Get the text lines
                    List <TextLine> lines = WordParser.GetTextLines(queryText);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // Create a string builder
                        sb = new StringBuilder();

                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // Increment the value for count
                            count++;

                            // skip the first line, as it is not really needed
                            if (count > 2)
                            {
                                // Add this lines test
                                sb.Append(line.Text + Environment.NewLine);
                            }

                            // if the value of count equals 2
                            if (count == 2)
                            {
                                // Set the UpdateText
                                updateText = line.Text;
                            }
                        }

                        // Set the criteria text
                        criteriaText = sb.ToString();

                        // Parse the Criteria (this is the matching part)
                        pixelQuery.Criteria = ParseCriteria(criteriaText, pixelQuery.ActionType);

                        // If the updateText string exists
                        if (TextHelper.Exists(updateText))
                        {
                            // Set the update values
                            SetUpdateParameters(updateText, ref pixelQuery);
                        }
                    }
                }
                else if (pixelQuery.ActionType == ActionTypeEnum.HideFrom)
                {
                    // hide from (Left, Right, Up, Down, All)

                    // set the directionsText
                    string directionsText = queryText.Substring(10).Trim();

                    // Parse the directions
                    pixelQuery.Directions = ParseDirections(directionsText);
                }
                else
                {
                    // This is a Hide or Show Query or DrawLine
                    // and the second line starts the where clause.

                    // Parse the Criteria (this is the matching part)
                    pixelQuery.Criteria = ParseCriteria(queryText, pixelQuery.ActionType);
                }
            }

            // return value
            return(pixelQuery);
        }
        /// <summary>
        /// This method returns a list of Criteria
        /// </summary>
        public static List <PixelCriteria> ParseCriteria(string queryText, ActionTypeEnum actionType)
        {
            // initial value
            List <PixelCriteria> criteria = null;

            // locals
            int           count         = 0;
            string        text          = "";
            PixelCriteria pixelCriteria = null;

            // If the queryText string exists
            if (TextHelper.Exists(queryText))
            {
                // Get the lines of text
                List <TextLine> lines = WordParser.GetTextLines(queryText);

                // If the lines collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(lines))
                {
                    // Create a new collection of 'PixelCriteria' objects.
                    criteria = new List <PixelCriteria>();

                    // parse the text lines
                    foreach (TextLine textLine in lines)
                    {
                        // Increment the value for count
                        count++;

                        // Get the text
                        text = textLine.Text.ToLower();

                        // verify the line has text in case the user hit enter at the end of the line
                        if (TextHelper.Exists(text))
                        {
                            // if this is DrawLine
                            if (actionType == ActionTypeEnum.DrawLine)
                            {
                                // if this is the first line
                                if (count == 1)
                                {
                                    // Create the pixelCriteria based upon this text
                                    pixelCriteria = CreatePixelCriteria(text, actionType, count);

                                    // verify the pixelCriteria exists before adding
                                    if (pixelCriteria != null)
                                    {
                                        // Add this criteria
                                        criteria.Add(pixelCriteria);
                                    }
                                }
                                else if (count == 2)
                                {
                                    // Set the ComparisonText
                                    SetComparisonType(text, ref pixelCriteria);
                                }
                                else
                                {
                                    // Create the pixelCriteria based upon this text
                                    pixelCriteria = CreatePixelCriteria(text, actionType, count, pixelCriteria);
                                }
                            }
                            else
                            {
                                // Create the pixelCriteria based upon this text
                                pixelCriteria = CreatePixelCriteria(text, actionType, count);

                                // verify the pixelCriteria exists before adding
                                if (pixelCriteria != null)
                                {
                                    // Set the ComparisonText
                                    SetComparisonType(text, ref pixelCriteria);

                                    // Add this criteria
                                    criteria.Add(pixelCriteria);
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(criteria);
        }
        /// <summary>
        /// event is fired when the 'ImportFirstNamesButton' is clicked.
        /// </summary>
        private void ImportFirstNamesButton_Click(object sender, EventArgs e)
        {
            // locals
            bool   saved    = false;
            string fileName = "";

            try
            {
                // get the text of the firstNameText
                string firstNamesTextFile = FirstNamesControl.Text;

                // attempt to read all the text
                string textFileContents = File.ReadAllText(firstNamesTextFile);

                // If the textFileContents string exists
                if (TextHelper.Exists(textFileContents))
                {
                    // create the fileInfo
                    FileInfo fileInfo = new FileInfo(firstNamesTextFile);

                    // set the name of the file
                    fileName = fileInfo.Name;

                    // get the text lines (this file is one entry per row)
                    List <TextLine> lines = WordParser.GetTextLines(textFileContents);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // Setup the Graph
                        Graph.Visible = true;
                        Graph.Maximum = lines.Count;
                        Graph.Value   = 0;

                        // refresh everything
                        Refresh();

                        // Create a new instance of a 'Gateway' object.
                        Gateway gateway = new Gateway();

                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // Create a firstName instance
                            dataObjects.FirstName firstName = new dataObjects.FirstName();

                            // set the firstName
                            firstName.Name = line.Text.Trim();

                            // save this firstName
                            saved = gateway.SaveFirstName(ref firstName);

                            // if the value for saved is true
                            if (saved)
                            {
                                // increment the value for the Graph
                                Graph.Value++;
                            }
                        }

                        // Show finished
                        MessageBoxHelper.ShowMessage("The file '" + fileName + "' has been imported.", "Import Complete");
                    }
                }
                else
                {
                    // Show an error
                    MessageBoxHelper.ShowMessage("The selected import file could not be read.", "Import File Error");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("ImportFirstNameButton_Click", this.Name, error);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This method returns the Project Files
        /// </summary>
        public int ReadProjectFiles()
        {
            // initial value
            int count = 0;

            // clear the list box
            ProjectFilesListBox.Items.Clear();

            // if the value for HasProject is true
            if ((HasProject) && (Project.HasSolutions))
            {
                // iterate the solutions
                foreach (Solution solution in Project.Solutions)
                {
                    // If the value for the property solution.HasProjects is true
                    if (solution.HasProjects)
                    {
                        // iterate the solutions
                        foreach (VSProject project in solution.Projects)
                        {
                            // Create a new instance of a 'DirectoryInfo' object.
                            DirectoryInfo directory = new DirectoryInfo(project.Path);

                            // Create a new collection of 'ProjectFile' objects.
                            project.Files = new List <ProjectFile>();

                            // if the project has a path and the path exists on the disk
                            if ((project.HasPath) && (File.Exists(project.Path)))
                            {
                                // read the text of the file
                                string fileText = File.ReadAllText(project.Path);

                                // parse the textLines
                                List <TextLine> lines = WordParser.GetTextLines(fileText);

                                // If the lines collection exists and has one or more items
                                if (ListHelper.HasOneOrMoreItems(lines))
                                {
                                    // get the lines that contain include and either .jpg or .png
                                    lines = lines.Where(x => x.Text.Contains("Include=") && (x.Text.Contains(".jpg")) || (x.Text.Contains(".png"))).ToList();

                                    // iterate the collection of lines
                                    if (ListHelper.HasOneOrMoreItems(lines))
                                    {
                                        // Iterate the collection of string objects
                                        foreach (TextLine line in lines)
                                        {
                                            // create a projectFile
                                            ProjectFile projectFile = new ProjectFile();

                                            // if this line is considered content
                                            projectFile.IsContent = line.Text.Contains("Content");

                                            // get the index of Include=
                                            int index = line.Text.IndexOf("Include=");

                                            // if the index exists
                                            if (index >= 0)
                                            {
                                                // get the tempPath
                                                string tempPath = line.Text.Substring(index + 9, line.Text.Length - index - 8 - 4 - 1);

                                                // now build the FullPath
                                                projectFile.FullPath = Path.Combine(directory.Parent.FullName, tempPath);

                                                // if the file exists
                                                if (File.Exists(projectFile.FullPath))
                                                {
                                                    // Create a new instance of a 'FileInfo' object.
                                                    FileInfo fileInfo = new FileInfo(projectFile.FullPath);

                                                    // set the name
                                                    projectFile.Name = fileInfo.Name;

                                                    // set the size
                                                    projectFile.Size = fileInfo.Length;

                                                    // add this file
                                                    project.Files.Add(projectFile);

                                                    // Add this item
                                                    ProjectFilesListBox.Items.Add(projectFile.Name);

                                                    // increment count
                                                    count++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // display the count
            ProjectImagesCountControl.Text = count.ToString();

            // display the count
            this.Refresh();

            // return value
            return(count);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method returns the Links With Href
        /// </summary>
        public string ReplaceLinksWithHref(string text)
        {
            // initial value
            string formattedText = text;

            // delimiters
            char[] delimiters = { ' ', '\n', };

            // If the text string exists
            if (ContainsLink(text))
            {
                // if the NewLine is not found
                if (!text.Contains(Environment.NewLine))
                {
                    // The parsing on lines isn't working, this is a good hack till
                    // I rewrite the parser to be more robust someday
                    text = text.Replace("\n", Environment.NewLine);
                }

                // just in case, fix for the hack
                text = text.Replace("\r\r", "\r");

                // Get the text lines
                List <TextLine> lines = WordParser.GetTextLines(text);

                // If the lines collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(lines))
                {
                    // iterate the textLines
                    foreach (TextLine line in lines)
                    {
                        // Get the words - parse only on space
                        List <Word> words = WordParser.GetWords(line.Text, delimiters);

                        // If the words collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(words))
                        {
                            // iterate each word
                            foreach (Word word in words)
                            {
                                // if this is a link
                                if (StartsWithLink(word.Text, true))
                                {
                                    // set the word as a href
                                    string temp = "<a href=" + word.Text + " target=_blank>" + word.Text + "</a>";

                                    // if the word.Text ends with a known extension, but does not start with http or https
                                    if ((TextEndsWithKnownExtension(word.Text)) && (!StartsWithLink(word.Text, false)))
                                    {
                                        // send the user to https. Its 2020, and if the user is send someone to an insecure site,
                                        // they must specify http:// in the link, otherwise don't post a link to an insecure site.
                                        temp = "<a href=https://" + word.Text + " target=_blank>" + word.Text + "</a>";
                                    }

                                    // Replace out the word with the link
                                    formattedText = formattedText.Replace(word.Text, temp);
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(formattedText);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// event is fired when the 'RemoveDataSyncButton' is clicked.
        /// </summary>
        private void RemoveDataSyncButton_Click(object sender, EventArgs e)
        {
            // get the text
            string filePath = SQLFileControl.Text;

            // local
            List <SQLBlock> sqlBlocks = new List <SQLBlock>();

            // If the filePath string exists
            if (TextHelper.Exists(filePath))
            {
                // parse the text lines
                string fileText = File.ReadAllText(filePath);

                // If the fileText string exists
                if (TextHelper.Exists(fileText))
                {
                    // get the text lines
                    List <TextLine> lines = WordParser.GetTextLines(fileText);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // create the block
                        SQLBlock block = new SQLBlock();

                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // if this is a go line
                            if (line.Text.ToLower().Trim() == "go")
                            {
                                // add this block
                                sqlBlocks.Add(block);

                                // Create a new block
                                block = new SQLBlock();
                            }
                            else
                            {
                                // add this line
                                block.Lines.Add(line);
                            }
                        }

                        // Create a new instance of a 'StringBuilder' object.
                        StringBuilder sb = new StringBuilder();

                        // If the sqlBlocks collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(sqlBlocks))
                        {
                            // Iterate the collection of SQLBlock objects
                            foreach (SQLBlock tempBlock in sqlBlocks)
                            {
                                // if this block does not contain the text DataSync
                                if (!tempBlock.ContainsDataSync)
                                {
                                    // Iterate the collection of TextLine objects
                                    foreach (TextLine textLine in tempBlock.Lines)
                                    {
                                        // Add this line
                                        sb.Append(textLine.Text);

                                        // Put the new line back
                                        sb.Append(Environment.NewLine);
                                    }

                                    // Add a newline
                                    sb.Append(Environment.NewLine);

                                    // Append the word GO
                                    sb.Append("GO");

                                    // Add a newline
                                    sb.Append(Environment.NewLine);
                                }
                            }

                            // Get the new SQL
                            string sql = sb.ToString().Trim();

                            // Copy to the clipboard
                            Clipboard.SetText(sql);

                            // Show the user a message
                            MessageBoxHelper.ShowMessage("DataSync has been removed and the SQL has been copied to your clipboard.", "SQL Copied");
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// event is fired when the 'ImportButton' is clicked.
        /// </summary>
        private void CreateSQL_Click(object sender, EventArgs e)
        {
            // set the fileName
            string fileName = SourceFileControl.Text;

            // locals
            TextLine    firstRowContent = null;
            List <Word> words           = null;

            char[]        delimiters          = { ',' };
            StringBuilder sb                  = new StringBuilder();
            string        alterTableTemplate  = "Alter Table RawImport";
            string        alterTableTemplate2 = "Add [ColumnName] nvarchar(255) null";
            string        alterTable          = "";

            // if the fileName exists
            if ((TextHelper.Exists(fileName)) && (File.Exists(fileName)))
            {
                // read the text of the file
                string fileText = File.ReadAllText(fileName);

                // set the textLines
                List <TextLine> textLines = WordParser.GetTextLines(fileText);

                // If the textLines collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(textLines))
                {
                    // set the first row contents
                    firstRowContent = textLines[0];
                }

                // If the firstRowContent object exists
                if (NullHelper.Exists(firstRowContent))
                {
                    // parse the words from the first column
                    words = WordParser.GetWords(firstRowContent.Text, delimiters);
                }

                // If the words collection exists and has one or more items
                if (ListHelper.HasOneOrMoreItems(words))
                {
                    // Iterate the collection of Word objects
                    foreach (Word word in words)
                    {
                        // remove any spaces and special characters from the column names. This may have to be modified as more files are tested.
                        word.Text = word.Text.Replace(" ", "").Replace("(", "").Replace(")", "").Replace(".", "").Replace("_", "").Replace("<", "").Replace(">", "");

                        // Start on a new line
                        sb.Append(Environment.NewLine);

                        // add this one
                        sb.Append(alterTableTemplate);

                        // Start on a new line
                        sb.Append(Environment.NewLine);

                        // replace out the text of the template
                        alterTable = alterTableTemplate2.Replace("[ColumnName]", TextHelper.CapitalizeFirstChar(word.Text));

                        // add this one
                        sb.Append(alterTable);

                        // Start on a new line
                        sb.Append(Environment.NewLine);

                        // Append Go
                        sb.Append("Go");
                    }

                    // set the sqlQuery and trim off the last line
                    string sqlQuery = sb.ToString().Trim();

                    // copy to clipboard
                    Clipboard.SetText(sqlQuery);

                    // Show finished message
                    MessageBoxHelper.ShowMessage("Finished", "Done");
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// event is fired when the 'ProcessButton' is clicked.
        /// </summary>
        private void ProcessButton_Click(object sender, EventArgs e)
        {
            // we want only csharp files
            string extension = ".cs";

            // local
            bool          nameSpaceReached = false;
            StringBuilder sb = null;

            // Create a new collection of 'string' objects.
            List <string> extensions = new List <string>();

            // Add this item
            extensions.Add(extension);

            // get the files to process
            FilesToProcess = FileHelper.GetFilesRecursively(DataTierFolder, ref filesToProcess, extensions);

            // If the FilesToProcess collection exists and has one or more items
            if (ListHelper.HasOneOrMoreItems(FilesToProcess))
            {
                // Setup the Graph
                this.Graph.Minimum = 0;
                this.Graph.Maximum = FilesToProcess.Count;
                this.Graph.Value   = 0;
                this.Graph.Visible = true;

                // update everything
                Refresh();
                Application.DoEvents();

                // Iterate the collection of string objects
                foreach (string fileToProcess in FilesToProcess)
                {
                    // reset this value
                    nameSpaceReached = false;

                    // get the text of this file
                    string fileText = File.ReadAllText(fileToProcess);

                    // If the fileText string exists
                    if (TextHelper.Exists(fileText))
                    {
                        // get the textLines
                        List <TextLine> textLines = WordParser.GetTextLines(fileText);

                        // If the textLines collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(textLines))
                        {
                            // Create a new instance of a 'StringBuilder' object.
                            sb = new StringBuilder();

                            // Append two blank lines
                            sb.Append(Environment.NewLine);
                            sb.Append(Environment.NewLine);

                            // Iterate the collection of TextLine objects
                            foreach (TextLine line in textLines)
                            {
                                // if the value for nameSpaceReached is true
                                if (nameSpaceReached)
                                {
                                    // append the line text and ending newline character
                                    sb.Append(line.Text);
                                    sb.Append(Environment.NewLine);
                                }
                                else
                                {
                                    // if the lines starts with namespace
                                    if (line.Text.StartsWith("namespace"))
                                    {
                                        // set the value
                                        nameSpaceReached = true;

                                        // append the line text and ending newline character
                                        sb.Append(line.Text);
                                        sb.Append(Environment.NewLine);
                                    }
                                }
                            }
                        }

                        // delete this file
                        File.Delete(fileToProcess);

                        // Write out the file without the namespace
                        File.AppendAllText(fileToProcess, sb.ToString());

                        // Increment the value for Graph
                        Graph.Value++;

                        // update the graph every 10 records
                        if (Graph.Value % 10 == 0)
                        {
                            // update everything
                            Refresh();
                        }
                    }
                }
            }

            // Show a message box
            MessageBox.Show("The import has finished", "Done");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// event is fired when the 'GetCommitButton' is clicked.
        /// </summary>
        private void GetCommitButton_Click(object sender, EventArgs e)
        {
            // local
            string commitRawText = "";

            try
            {
                // get the client
                using (var client = new WebClient())
                {
                    // get the result
                    string webPageText = client.DownloadString(RepoUrl);

                    // If the webPageText string exists
                    if (TextHelper.Exists(webPageText))
                    {
                        // string we are looking for
                        string href = @"DataJuggler/DataTier.Net/commit/";

                        // parse the textLines
                        List <TextLine> textLines = WordParser.GetTextLines(webPageText);

                        // If the textLines collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(textLines))
                        {
                            // Iterate the collection of TextLine objects
                            foreach (TextLine textLine in textLines)
                            {
                                // is this is the line we are looking for
                                if (textLine.Text.Contains(href))
                                {
                                    // get the full text
                                    commitRawText = textLine.Text;

                                    // break out of the loop
                                    break;
                                }
                            }
                        }
                    }

                    // If the commitRawText string exists
                    if (TextHelper.Exists(commitRawText))
                    {
                        // convert to words
                        List <Word> words = WordParser.GetWords(commitRawText);

                        // If the words collection exists and has one or more items
                        if (ListHelper.HasOneOrMoreItems(words))
                        {
                            // local
                            bool nextWord = false;

                            // Iterate the collection of Word objects
                            foreach (Word word in words)
                            {
                                // if the value for nextWord is true
                                if ((nextWord) && (word.HasText) && (word.Text.Length > 7))
                                {
                                    // set the commitText
                                    string commitText = word.Text;

                                    // Set the text
                                    this.CommitTextBox.Text = commitText.Substring(0, 7);

                                    // break out of the loop
                                    break;
                                }
                                else
                                {
                                    // we must check for the word commit
                                    if (TextHelper.IsEqual("commit", word.Text))
                                    {
                                        // Set the value for the nextWord to true
                                        nextWord = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("GetCommitButton_Click", this.Name, error);
            }
        }
        /// <summary>
        /// event is fired when the 'ImportLastNamesButton' is clicked.
        /// </summary>
        private void ImportLastNamesButton_Click(object sender, EventArgs e)
        {
            // locals
            bool        saved    = false;
            string      fileName = "";
            List <Word> words    = null;

            char[] delimiters = { ' ' };
            bool   skipName   = false;

            try
            {
                // get the text of the LastNames.txt file
                string LastNamesTextFile = LastNamesControl.Text;

                // attempt to read all the text
                string textFileContents = File.ReadAllText(LastNamesTextFile);

                // If the textFileContents string exists
                if (TextHelper.Exists(textFileContents))
                {
                    // create the fileInfo
                    FileInfo fileInfo = new FileInfo(LastNamesTextFile);

                    // set the name of the file
                    fileName = fileInfo.Name;

                    // get the text lines (this file is one entry per row)
                    List <TextLine> lines = WordParser.GetTextLines(textFileContents);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // Setup Graph2
                        Graph2.Visible = true;
                        Graph2.Maximum = lines.Count;
                        Graph2.Value   = 0;

                        // refresh everything
                        Refresh();

                        // Create a new instance of a 'Gateway' object.
                        Gateway gateway = new Gateway();

                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // reset
                            skipName = false;

                            // if this name contains weird symbols
                            if (line.Text.Contains("^"))
                            {
                                // skip this name
                                skipName = true;
                            }
                            else if (line.Text.Contains(" or "))
                            {
                                // skip this name
                                skipName = true;
                            }
                            else if (line.Text.Contains("-"))
                            {
                                // skip any hyphenated names
                                skipName = true;
                            }

                            // if the value for skipName is false
                            if (!skipName)
                            {
                                // Create a LastName instance
                                dataObjects.LastName LastName = new dataObjects.LastName();

                                // get the words
                                words = WordParser.GetWords(line.Text, delimiters);

                                // if there is a space in the name
                                if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count > 1))
                                {
                                    // Create a new instance of a 'StringBuilder' object.
                                    StringBuilder sb = new StringBuilder();

                                    // Iterate the collection of Word objects
                                    foreach (Word word in words)
                                    {
                                        // Capitalize each word
                                        sb.Append(TextHelper.CapitalizeFirstChar(word.Text));
                                        sb.Append(" ");
                                    }

                                    // set the LastName
                                    LastName.Name = sb.ToString().Trim();
                                }
                                else
                                {
                                    // set the LastName
                                    LastName.Name = TextHelper.CapitalizeFirstChar(line.Text.Trim());
                                }

                                // save this LastName
                                saved = gateway.SaveLastName(ref LastName);

                                // if the value for saved is true
                                if (saved)
                                {
                                    // increment the value for Graph2
                                    Graph2.Value++;
                                }
                            }
                        }

                        // Show finished
                        MessageBoxHelper.ShowMessage("The file '" + fileName + "' has been imported.", "Import Complete");
                    }
                }
                else
                {
                    // Show an error
                    MessageBoxHelper.ShowMessage("The selected import file could not be read.", "Import File Error");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("ImportLastNameButton_Click", this.Name, error);
            }
        }