Internal Modelclass to hold Content and Metadata of loaded Class Files
コード例 #1
0
 /// <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>
        /// Creates a XLink to the given WorkingDirectoryFile and copies it to the clipboard. 
        /// Aborts the creation if no connection to the OpenEngSB is established.
        /// </summary>
        /// <param name="file"></param>
        public string createXLink(WorkingDirectoryFile file)
        {
            if (!connected)
            {
                outputLine("Error while creating XLink. No connection to OpenEngSB.");
                return null;
            }
            ModelDescription modelInformation = blueprint.viewToModels.ConvertMap<String, ModelDescription>()[Program.viewId];

            /*Note that only the target class SQLCreate is allowed */
            if (!modelInformation.modelClassName.Equals(classNameOfOpenEngSBModel))
            {
                outputLine("Error: Defined ModelClass '"+ classNameOfOpenEngSBModel + "' for view, from OpenEngSB, is not supported by this software program.");
                return null;
            }

            String completeUrl = blueprint.baseUrl;
            completeUrl += "&" + blueprint.keyNames.modelClassKeyName + "=" + HttpUtility.UrlEncode(modelInformation.modelClassName);
            completeUrl += "&" + blueprint.keyNames.modelVersionKeyName + "=" + HttpUtility.UrlEncode(modelInformation.versionString);
            completeUrl += "&" + blueprint.keyNames.contextIdKeyName + "=" + HttpUtility.UrlEncode(openengsbContext);

            string objectString = convertWorkingDirectoryFileToJSON(file);
            completeUrl += "&" + blueprint.keyNames.identifierKeyName + "=" + HttpUtility.UrlEncode(objectString);

            return completeUrl;
        }
 /// <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;
 }
コード例 #4
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;
        }