/// <summary>
 /// Searches for Matches to incomming XLinks, in the local WorkingDirectory
 /// </summary>
 public void searchForMatchesThread()
 {
     for (int i = 0; i < matchingObjects.Length; i++)
     {
         IMarshaller marseller             = new JsonMarshaller();
         OOClass     currentPotentialMatch = marseller.UnmarshallObject <OOClass>(matchingObjects[i].ToString());
         Program.directoryBrowser.searchForXLinkMatches(currentPotentialMatch);
     }
 }
        /// <summary>
        /// Converts a WorkingDirectoryFile instance to a OOCLass instance and serializes it to String, with JSON
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private string convertWorkingDirectoryFileToJSON(WorkingDirectoryFile file)
        {
            OOClass ooClassOfFile = LinkingUtils.convertWorkingDirectoryFileToOpenEngSBModel(file);
            string  output        = JsonConvert.SerializeObject(ooClassOfFile);

            //HACK: remove isSpecified fields from JSON String
            output = output.Replace(",\"isStaticSpecified\":true", "");
            output = output.Replace(",\"isFinalSpecified\":true", "");
            return(output);
        }
        /// <summary>
        /// Returns an int value which indicates, how many many SQLFiels are alike between the two given statements.
        /// </summary>
        private int matchValueOfClass(WorkingDirectoryFile wdFileToCheck, OOClass potentialMatch)
        {
            int matchValue = 0;

            for (int i = 0; i < potentialMatch.attributes.Length; i++)
            {
                String attributeRepresentation = potentialMatch.attributes[i].type + " " + potentialMatch.attributes[i].name;
                if (wdFileToCheck.content.ToLower().Contains(attributeRepresentation.ToLower()))
                {
                    matchValue++;
                }
            }
            return(matchValue);
        }
 /// <summary>
 /// Returns an int value which indicates, how many many SQLFiels are alike between the two given statements.
 /// </summary>
 private int matchValueOfClass(WorkingDirectoryFile wdFileToCheck, OOClass potentialMatch)
 {
     int matchValue = 0;
     for (int i = 0; i < potentialMatch.attributes.Length; i++)
     {
         String attributeRepresentation = potentialMatch.attributes[i].type + " " + potentialMatch.attributes[i].name;
         if (wdFileToCheck.content.ToLower().Contains(attributeRepresentation.ToLower()))
         {
             matchValue++;
         }
     }
     return matchValue;
 }
        /// <summary>
        /// Searches through the Files for the most potential Match.
        /// First searches for matching filesnames.
        /// If no files where found or if more than one file was found, search for matching variables.
        /// </summary>
        public void searchForXLinkMatches(OOClass potentialMatch)
        {
            if (wdFiles.Count == 0)
            {
                outputLine("An XLink match was triggered, but the List of loaded files is empty.");
                return;
            }

            //first search for matching filesnames
            List<WorkingDirectoryFile> correspondingFiles = new List<WorkingDirectoryFile>();
            foreach (WorkingDirectoryFile wdf in wdFiles)
            {
                OOClass classModelRepresentation = LinkingUtils.convertWorkingDirectoryFileToOpenEngSBModel(wdf);
                if (classModelRepresentation.className.ToLower().Contains(potentialMatch.className.ToLower()))
                {
                    correspondingFiles.Add(wdf);
                }
            }

            WorkingDirectoryFile foundMatch = null;

            //if no files where found or if more than one file was found, compare the matching variables
            if (correspondingFiles.Count != 1)
            {
                if (correspondingFiles.Count == 0)
                {
                    correspondingFiles = wdFiles;
                }

                WorkingDirectoryFile mostPotentialLocalMatch = correspondingFiles[0];
                int maxMatchValue = matchValueOfClass(mostPotentialLocalMatch, potentialMatch);
                foreach (WorkingDirectoryFile localWDF in correspondingFiles)
                {
                    int currentMatchValue = matchValueOfClass(localWDF, potentialMatch);
                    if (currentMatchValue > maxMatchValue)
                    {
                        maxMatchValue = currentMatchValue;
                        mostPotentialLocalMatch = localWDF;
                    }
                }
                if (matchValueOfClass(mostPotentialLocalMatch, potentialMatch) != 0)
                {
                    foundMatch = mostPotentialLocalMatch;
                }
            }
            else {
                foundMatch = correspondingFiles[0];
            }

            if (foundMatch != null)
            {
                outputLine("An XLink match was triggered and a local match was found.");
                System.Diagnostics.Process.Start(foundMatch.wholePath);
            }
            else
            {
                outputLine("An XLink match was triggered, but no local match was found.");
            }
        }
 public void updateClass(OOClass args0)
 {
     logger.Info("updateClasse method call");
 }
Example #7
0
        /// <summary>
        /// Convert the interal model "WorkingDirectoryFile" to the defined OpenEngSBModel "OOClass".
        /// Returns null if resulting instance lacks classname or packagename.
        /// </summary>
        public static OOClass convertWorkingDirectoryFileToOpenEngSBModel(WorkingDirectoryFile wdf)
        {
            //Regex to fetch Data
            Regex classRegex   = new Regex(@".*class ([a-zA-Z0-9_]+).*");
            Regex packageRegex = new Regex(@".*namespace ([a-zA-Z0-9_\.]+).*");
            Regex varRegex     = new Regex(@" *(public|protected|private) (int|double|float|string|DateTime|bool|long) ([a-zA-Z0-9_]+) {.*");

            OOClass           resultingInstance = new OOClass();
            List <OOVariable> variables         = new List <OOVariable>();

            //not used in example: set this with dummy values
            resultingInstance.methods = "";

            string[] contentLines = wdf.content.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            for (int i = 0; i < contentLines.Length; i++)
            {
                if (resultingInstance.packageName == null)
                {
                    Match match = packageRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        resultingInstance.packageName = match.Groups[1].Value;
                    }
                }
                else if (resultingInstance.className == null)
                {
                    Match match = classRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        resultingInstance.className = match.Groups[1].Value;
                    }
                }
                else
                {
                    Match match = varRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        OOVariable newVar = new OOVariable();
                        newVar.type = match.Groups[2].Value;
                        newVar.name = match.Groups[3].Value;
                        //not used in example: set this with dummy values
                        newVar.isFinal           = false;
                        newVar.isFinalSpecified  = true;
                        newVar.isStatic          = false;
                        newVar.isStaticSpecified = true;
                        variables.Add(newVar);
                    }
                }
            }
            if (resultingInstance.packageName == null || resultingInstance.className == null)
            {
                //Instance not correctly set
                return(null);
            }
            resultingInstance.attributes = new OOVariable[variables.Count];
            for (int i = 0; i < variables.Count; i++)
            {
                resultingInstance.attributes[i] = variables[i];
            }
            return(resultingInstance);
        }
Example #8
0
 public void updateClass(OOClass args0)
 {
     logger.Info("updateClasse method call");
 }
 /// <summary>
 /// Domain Method of OOSourceCodeDomain, not used during example
 /// </summary>
 public void updateClass(OOClass args0)
 {
     outputLine("'updateClass' was triggered from the OpenEngSB");
     //Implement in real Program
 }
        /// <summary>
        /// Convert the interal model "WorkingDirectoryFile" to the defined OpenEngSBModel "OOClass".
        /// Returns null if resulting instance lacks classname or packagename.
        /// </summary>
        public static OOClass convertWorkingDirectoryFileToOpenEngSBModel(WorkingDirectoryFile wdf)
        {
            //Regex to fetch Data
            Regex classRegex = new Regex(@".*class ([a-zA-Z0-9_]+).*");
            Regex packageRegex = new Regex(@".*namespace ([a-zA-Z0-9_\.]+).*");
            Regex varRegex = new Regex(@" *(public|protected|private) (int|double|float|string|DateTime|bool|long) ([a-zA-Z0-9_]+) {.*");

            OOClass resultingInstance = new OOClass();
            List<OOVariable> variables = new List<OOVariable>();
            //not used in example: set this with dummy values
            resultingInstance.methods = "";

            string[] contentLines = wdf.content.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            for (int i = 0; i < contentLines.Length; i++)
            {
                if (resultingInstance.packageName == null)
                {
                    Match match = packageRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        resultingInstance.packageName = match.Groups[1].Value;
                    }
                }
                else if (resultingInstance.className == null)
                {
                    Match match = classRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        resultingInstance.className = match.Groups[1].Value;
                    }
                }
                else
                {
                    Match match = varRegex.Match(contentLines[i]);
                    if (match.Success)
                    {
                        OOVariable newVar = new OOVariable();
                        newVar.type = match.Groups[2].Value;
                        newVar.name = match.Groups[3].Value;
                        //not used in example: set this with dummy values
                        newVar.isFinal = false;
                        newVar.isFinalSpecified = true;
                        newVar.isStatic = false;
                        newVar.isStaticSpecified = true;
                        variables.Add(newVar);
                    }
                }

            }
            if (resultingInstance.packageName == null || resultingInstance.className == null)
            {
                //Instance not correctly set
                return null;
            }
            resultingInstance.attributes = new OOVariable[variables.Count];
            for (int i = 0; i < variables.Count; i++)
            {
                resultingInstance.attributes[i] = variables[i];
            }
            return resultingInstance;
        }
 /// <summary>
 /// Domain Method of OOSourceCodeDomain, not used during example
 /// </summary>
 public void updateClass(OOClass args0)
 {
     outputLine("'updateClass' was triggered from the OpenEngSB");
     //Implement in real Program
 }
        /// <summary>
        /// Searches through the Files for the most potential Match.
        /// First searches for matching filesnames.
        /// If no files where found or if more than one file was found, search for matching variables.
        /// </summary>
        public void searchForXLinkMatches(OOClass potentialMatch)
        {
            if (wdFiles.Count == 0)
            {
                outputLine("An XLink match was triggered, but the List of loaded files is empty.");
                return;
            }

            //first search for matching filesnames
            List <WorkingDirectoryFile> correspondingFiles = new List <WorkingDirectoryFile>();

            foreach (WorkingDirectoryFile wdf in wdFiles)
            {
                OOClass classModelRepresentation = LinkingUtils.convertWorkingDirectoryFileToOpenEngSBModel(wdf);
                if (classModelRepresentation.className.ToLower().Contains(potentialMatch.className.ToLower()))
                {
                    correspondingFiles.Add(wdf);
                }
            }

            WorkingDirectoryFile foundMatch = null;

            //if no files where found or if more than one file was found, compare the matching variables
            if (correspondingFiles.Count != 1)
            {
                if (correspondingFiles.Count == 0)
                {
                    correspondingFiles = wdFiles;
                }

                WorkingDirectoryFile mostPotentialLocalMatch = correspondingFiles[0];
                int maxMatchValue = matchValueOfClass(mostPotentialLocalMatch, potentialMatch);
                foreach (WorkingDirectoryFile localWDF in correspondingFiles)
                {
                    int currentMatchValue = matchValueOfClass(localWDF, potentialMatch);
                    if (currentMatchValue > maxMatchValue)
                    {
                        maxMatchValue           = currentMatchValue;
                        mostPotentialLocalMatch = localWDF;
                    }
                }
                if (matchValueOfClass(mostPotentialLocalMatch, potentialMatch) != 0)
                {
                    foundMatch = mostPotentialLocalMatch;
                }
            }
            else
            {
                foundMatch = correspondingFiles[0];
            }

            if (foundMatch != null)
            {
                outputLine("An XLink match was triggered and a local match was found.");
                System.Diagnostics.Process.Start(foundMatch.wholePath);
            }
            else
            {
                outputLine("An XLink match was triggered, but no local match was found.");
            }
        }