Exemplo n.º 1
0
        public static List <EngineClass> BuildAsList(List <EngineClass> classes)
        {
            Dictionary <IEngineObject, List <EngineClass> > subclassDictionary =
                new Dictionary <IEngineObject, List <EngineClass> >();
            Dictionary <string, EngineClass> classNameDictionary = new Dictionary <string, EngineClass>();

            // Create a mapping from classname to class objects
            classes.ForEach(x => classNameDictionary[x.Name] = x);

            classes.ForEach(x => {
                // First, filter out non-simclasses
                if (x.SuperType == null)
                {
                    return;
                }
                // Insert the current simclass as a subclass to the parent
                if (!subclassDictionary.ContainsKey(x.SuperType))
                {
                    subclassDictionary[x.SuperType] = new List <EngineClass>();
                }

                subclassDictionary[x.SuperType].Add(x);
            });

            List <EngineClass> simClasses = new List <EngineClass>();

            // Locate the top-level class
            EngineClass simObjectClass = classes.Find(x => x.Name == "SimObject");

            // Insert all sim classes into the simClasses list
            AddClassAndSubclasses(subclassDictionary, simClasses, simObjectClass);
            return(simClasses);
        }
Exemplo n.º 2
0
        public EngineClass GetMultipleClass()
        {
            try
            {
                var className = $"{Name}Response";
                var result    = new EngineClass()
                {
                    Name = className,
                    Type = "object",
                };
                foreach (var response in Responses)
                {
                    var engineProprty = new EngineProperty()
                    {
                        Name        = response.Name,
                        Description = response.Description,
                        Type        = QlikApiUtils.GetDotNetType(response.GetRealType()),
                        Required    = response.Required,
                        Format      = response.Format,
                    };

                    var serviceType = response.GetServiceType();
                    if (serviceType != null)
                    {
                        engineProprty.Type = serviceType;
                    }
                    result.Properties.Add(engineProprty);
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("The method \"GetMultipleClass\" was failed.", ex);
            }
        }
        public void Execute()
        {
            SelectCarType();
            Brand brand = SelectBrand();

            SelectColour();
            IColourDecoration colourDecoration = SelectColourDeco();
            EngineClass       engine           = SelectEngine();

            SelectWheel();
            IWheelDeco  wheelDeco   = SelectWheelDeco();
            Numberplate numberplate = AssignNumberplate();


            IWheel wheel = (IWheel)Activator.CreateInstance(wheelList[listOfIndex.Last()], wheelDeco);

            listOfIndex.RemoveAt(listOfIndex.Count - 1);
            ICarColour carColour = (ICarColour)Activator.CreateInstance(carColourList[listOfIndex.Last()], colourDecoration);

            listOfIndex.RemoveAt(listOfIndex.Count - 1);

            Vehicle vehicle = (Vehicle)Activator.CreateInstance(types[listOfIndex.Last()], new object[] { carColour, wheel, brand, numberplate, engine });

            Console.WriteLine("Congratulation you successfully added a new vehicle");

            carDealer.AddVehicleToList(vehicle);
            command = new PrintVehicleCommand()
            {
                List = carDealer.Vehicles
            };
            command.Execute();
            listOfIndex.Clear();
        }
 public void GenerateHierarchy()
 {
     for (int index = Classes.Count - 1; index >= 0; index--)
     {
         EngineClass engineClass = Classes[index];
         foreach (string parentClassName in engineClass.ParentClassNames)
         {
             foreach (EngineClass innerT6Class in Classes)
             {
                 if (innerT6Class.ClassName.Equals(parentClassName))
                 {
                     engineClass.ParentClasses[parentClassName] = innerT6Class;
                 }
             }
         }
         if (engineClass.ParentClasses.Count <= 0 && engineClass.ClassName != "SimObject")
         {
             Classes.Remove(engineClass);
         }
     }
     foreach (EngineClass t6Class in Classes)
     {
         if (t6Class.DerivesFromSimObject)
         {
             continue;
         }
         t6Class.DerivesFromSimObject = t6Class.ParentsDerivesFromSimObject();
     }
 }
Exemplo n.º 5
0
        public ParseState Parse(XmlElement element, ParseState parseState)
        {
            string name           = element.Attributes["name"].InnerText;
            string docs           = element.Attributes["docs"].InnerText;
            string superType      = element.Attributes["superType"]?.InnerText;
            bool   isAbstract     = GenericMarshal.StringToBool(element.Attributes["isAbstract"].InnerText);
            bool   isInstantiable = GenericMarshal.StringToBool(element.Attributes["isInstantiable"].InnerText);
            bool   isDisposable   = GenericMarshal.StringToBool(element.Attributes["isDisposable"].InnerText);
            bool   isSingleton    = GenericMarshal.StringToBool(element.Attributes["isSingleton"].InnerText);

            EngineClass engineClass = new EngineClass(name)
            {
                Docs           = docs,
                SuperTypeName  = superType,
                Scope          = parseState.Scope,
                IsAbstract     = isAbstract,
                IsInstantiable = isInstantiable,
                IsDisposable   = isDisposable,
                IsSingleton    = isSingleton
            };

            ParseState functionParseState = new ParseState()
                                            .EnterScope(name);

            foreach (XmlElement childNode in element.ChildNodes)
            {
                if (childNode.Name.Equals("properties"))
                {
                    List <EngineClass.Property> properties = ParseProperties(childNode, null);
                    foreach (EngineClass.Property property in properties)
                    {
                        engineClass.Add(property);
                    }
                }
                else if (childNode.Name.Equals("exports"))
                {
                    foreach (XmlElement funElement in childNode.ChildNodes)
                    {
                        if (funElement.Name.Equals("RegisterObject"))
                        {
                            Debugger.Break();
                        }
                        new FunctionParser().Parse(funElement, functionParseState);
                    }
                }
                else
                {
                }
            }

            foreach (EngineFunction engineFunction in functionParseState.Functions)
            {
                engineClass.Add(engineFunction);
            }

            parseState.Classes.Add(engineClass);

            return(parseState);
        }
Exemplo n.º 6
0
 public void WagFile(string filenamewithpath)
 {
     using (STFReader stf = new STFReader(filenamewithpath, false))
         stf.ParseBlock(new STFReader.TokenProcessor[] {
             new STFReader.TokenProcessor("engine", () => { Engine = new EngineClass(stf); }),
             new STFReader.TokenProcessor("_openrails", () => { OpenRails = new OpenRailsData(stf); }),
         });
 }
Exemplo n.º 7
0
        protected Vehicle(ICarColour carColour, IWheel wheel, Brand brand, Numberplate numberplate, EngineClass engine)
        {
            this.brand       = brand;
            this.carColour   = carColour;
            this.numberplate = numberplate;
            this.wheel       = wheel;
            this.engine      = engine;

            id    = ++counter;
            price = wheel.Price() + carColour.CalculatePrice() + brand.GetPrice() + engine.GetPrice();
        }
Exemplo n.º 8
0
        private static void AddClassAndSubclasses(Dictionary <IEngineObject, List <EngineClass> > subclassDictionary,
                                                  List <EngineClass> simClasses, EngineClass simObjectClass, bool isDatablock = false)
        {
            simObjectClass.IsDatablock = isDatablock;
            simObjectClass.IsSimObject = true;

            // Add this class to the simClasses
            simClasses.Add(simObjectClass);
            // If this class has no subclasses, return
            if (!subclassDictionary.ContainsKey(simObjectClass))
            {
                return;
            }
            // Add the class and all subclasses
            subclassDictionary[simObjectClass].ForEach(x =>
                                                       AddClassAndSubclasses(subclassDictionary, simClasses, x, isDatablock || x.Name == "SimDataBlock"));
        }
Exemplo n.º 9
0
        public IEnumerable <CarClass> GetList()
        {
            string          query  = "SELECT * FROM cars";
            MySqlDataReader reader = GetReader(query);

            while (reader.Read())
            {
                int           carId       = int.Parse(reader[0].ToString());
                BodyworkClass bodywork    = SQLBodyworks.GetInstance().Search(reader[1].ToString());
                EngineClass   engine      = SQLEngines.GetInstance().Search(reader[2].ToString());
                ClientClass   client      = ClientService.SearchClientById(int.Parse(reader[3].ToString()));
                int           kilometrage = int.Parse(reader[4].ToString());
                int           cost        = int.Parse(reader[5].ToString());
                int           carStatus   = int.Parse(reader[6].ToString());
                yield return(new CarClass(carId, bodywork, engine, client, kilometrage, cost, carStatus));
            }
            reader.Close();
        }
Exemplo n.º 10
0
        public static string Render(EngineClass @class, string scope)
        {
            Template template;

            using (StreamReader reader = new StreamReader("Resources/Templates/SimClass.scriban")) {
                template = Template.Parse(reader.ReadToEnd(), "Resources/Templates/SimClass.scriban");
            }

            var scriptObject = new ScriptObject {
                { "class", @class },
                { "scope", scope }
            };

            scriptObject.Import(BaseTemplate.GetScriptObject());

            var context = BaseTemplate.GetTemplateContext();

            context.PushGlobal(scriptObject);

            return(template.Render(context));
        }
Exemplo n.º 11
0
        public CarClass Search(string carId)
        {
            string          query  = "SELECT * FROM cars WHERE carId='" + carId + "'";
            CarClass        car    = null;
            MySqlDataReader reader = GetReader(query);

            try
            {
                reader.Read();
                BodyworkClass bodywork    = SQLBodyworks.GetInstance().Search(reader[1].ToString());
                EngineClass   engine      = SQLEngines.GetInstance().Search(reader[2].ToString());
                ClientClass   client      = ClientService.SearchClientById(int.Parse(reader[3].ToString()));
                int           kilometrage = int.Parse(reader[4].ToString());
                int           cost        = int.Parse(reader[5].ToString());
                int           carStatus   = int.Parse(reader[6].ToString());
                car = new CarClass(int.Parse(carId), bodywork, engine, client, kilometrage, cost, carStatus);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { reader.Close(); }
            return(car);
        }
Exemplo n.º 12
0
        private static void GenerateFor(string outputDir, EngineApi engineApi, EngineClass @class)
        {
            string scope = (string.IsNullOrEmpty(@class.Scope) ? "Global" : @class.Scope);

            var scriptObject = new ScriptObject();

            scriptObject.Add("class", @class);
            scriptObject.Add("scope", scope);

            string output = ClassTemplate.Render(@class, scope);

            string dir = $"{outputDir}/Classes/{scope.Replace('.', '/')}";

            Console.WriteLine($"{dir}/{@class.Name}.cs");

            Directory.CreateDirectory(dir);

            using (StreamWriter SW = new StreamWriter($"{dir}/{@class.Name}.cs")
                   ) {
                SW.Write(output);
            }
        }
        private static List <EngineClass> ParseClassesFromHeaderFile(string pHeaderFile, List <CFunction> pFunctions)
        {
            List <EngineClass> classes = new List <EngineClass>();
            StreamReader       SR      = new StreamReader(pHeaderFile);

            while (!SR.EndOfStream)
            {
                string line = SR.ReadLine().Trim();
                if (line.StartsWith("class") && line.Contains(":") && !line.Contains("##"))
                {
                    MatchCollection parentMatches =
                        Regex.Matches(line,
                                      ":?\\s*,?\\s*public\\s+(?:virtual\\s+)?([a-zA-Z0-9:<>]+)");
                    MatchCollection classMatches =
                        Regex.Matches(line,
                                      "class (?:(?:[a-zA-Z 0-9_]|::)* )?([a-zA-Z0-9]+)\\s*");
                    if (classMatches.Count <= 0)
                    {
                        continue;
                    }

                    EngineClass engineClass = new EngineClass(classMatches[0].Groups[1].Value);
                    foreach (Match match in parentMatches)
                    {
                        engineClass.ParentClassNames.Add(match.Groups[1].Value);
                    }

                    foreach (CFunction cFunction in pFunctions)
                    {
                        if (cFunction.FunctionName.StartsWith(engineClass.ClassName) &&
                            cFunction.FunctionParams.Count > 0 &&
                            cFunction.FunctionParams[0].ParamTypeInfo.DataName != null &&
                            cFunction.FunctionParams[0].ParamTypeInfo.DataName.Equals(engineClass.ClassName) ||
                            cFunction.FunctionName == engineClass.ClassName + "CreateInstance")
                        {
                            cFunction.OwnerClass = engineClass;
                        }
                    }

                    classes.Add(engineClass);

                    StringBuilder bodyBuilder = new StringBuilder();
                    int           indentation = 0;
                    while ((line = SR.ReadLine()) != null)
                    {
                        if (line.Contains("}"))
                        {
                            indentation--;
                        }
                        if (indentation != 0)
                        {
                            bodyBuilder.AppendLine(line);
                        }
                        if (line.Contains("{"))
                        {
                            indentation++;
                        }
                        if (indentation == 0)
                        {
                            break;
                        }
                    }
                }
            }
            SR.Close();
            return(classes);
        }
        private static List <T6Field> ParseFieldsFromCCFile(string pCcFile, List <EngineClass> pClasses,
                                                            List <CFunction> pFunctions)
        {
            List <T6Field> fields    = new List <T6Field>();
            StreamReader   SR        = new StreamReader(pCcFile);
            bool           inComment = false;

            while (!SR.EndOfStream)
            {
                string line = SR.ReadLine().Trim();
                if (inComment)
                {
                    line = "/*" + line; //hack
                }
                if (line.IndexOf("//", StringComparison.Ordinal) >= 0)
                {
                    line = line.Remove(line.IndexOf("//", StringComparison.Ordinal));
                }
                while (line.IndexOf("/*", StringComparison.Ordinal) >= 0)
                {
                    int commentStartIdx = line.IndexOf("/*", StringComparison.Ordinal);
                    if (line.IndexOf("*/", StringComparison.Ordinal) >= 0)
                    {
                        int commentEndIdx = line.IndexOf("*/", StringComparison.Ordinal);
                        line      = line.Remove(commentStartIdx, commentEndIdx - commentStartIdx + 2);
                        inComment = false;
                    }
                    else
                    {
                        line      = line.Remove(commentStartIdx);
                        inComment = true;
                        continue;
                    }
                }
                if (line.Contains("::initPersistFields()") &&
                    !line.Contains("Parent::initPersistFields()"))
                {
                    Match match =
                        Regex.Matches(line,
                                      "void\\s+([a-zA-Z 0-9:_]+)::initPersistFields()")
                        [0];
                    string      className   = match.Groups[1].Value;
                    EngineClass engineClass = pClasses.Find(c => c.ClassName.Equals(className));

                    int indentation = 0;
                    while ((line = SR.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.StartsWith("//"))
                        {
                            continue;
                        }
                        if (line.Contains("}"))
                        {
                            indentation--;
                        }
                        if (indentation != 0)
                        {
                            MatchCollection matches =
                                Regex.Matches(line,
                                              "Field\\(\\s*\"?([a-zA-Z0-9:_]+)\"?[\\s,]+([a-zA-Z0-9:_]+)[\\s,]+(?:Offset\\([^\\)]*\\)|0)[\\s,]*([0-9]+)?");
                            if (matches.Count <= 0)
                            {
                                continue;
                            }
                            match = matches[0];
                            string  fieldName = match.Groups[1].Value.Trim();
                            T6Field t6Field   = new T6Field
                            {
                                FieldName     = fieldName[0].ToString().ToUpper() + fieldName.Substring(1),
                                FieldTypeInfo = T6Field.TypeFromString(match.Groups[2].Value.Trim())
                            };
                            t6Field.FieldCount = match.Groups[3].Success ? int.Parse(match.Groups[3].Value.Trim()) : -1;
                            engineClass.Fields.Add(t6Field);

                            foreach (CFunction cFunction in pFunctions)
                            {
                                if (cFunction.OwnerClass != engineClass)
                                {
                                    continue;
                                }
                                if (
                                    cFunction.FunctionName.ToLower()
                                    .Equals(engineClass.ClassName.ToLower() + "get" + t6Field.FieldName.ToLower()))
                                {
                                    t6Field.GetterFunction     = cFunction;
                                    cFunction.PropertyFunction = true;
                                }
                                else if (
                                    cFunction.FunctionName.ToLower()
                                    .Equals(engineClass.ClassName.ToLower() + "set" + t6Field.FieldName.ToLower()))
                                {
                                    t6Field.SetterFunction     = cFunction;
                                    cFunction.PropertyFunction = true;
                                }
                            }

                            fields.Add(t6Field);
                        }
                        if (line.Contains("{"))
                        {
                            indentation++;
                        }
                        if (indentation == 0)
                        {
                            break;
                        }
                    }
                }
            }
            SR.Close();
            return(fields);
        }
Exemplo n.º 15
0
        private void AddDefinitions(JObject mergeObject)
        {
            try
            {
                var definitions = mergeObject["definitions"] as JObject;
                foreach (var child in definitions.Children())
                {
                    var jProperty = child as JProperty;
                    foreach (var subChild in child.Children())
                    {
                        logger.Debug($"Object name: {jProperty.Name}");
                        dynamic jObject = subChild as JObject;
                        var     export  = jObject?.export?.ToObject <bool>() ?? true;
                        if (!export)
                        {
                            continue;
                        }
                        var         objectType  = jObject?.type?.ToString() ?? null;
                        EngineClass engineClass = null;
                        switch (objectType)
                        {
                        case "object":
                            engineClass      = jObject.ToObject <EngineClass>();
                            engineClass.Name = jProperty.Name;

                            //special case for .NET JObject - JsonObject is ignored
                            if (engineClass.Name == "JsonObject")
                            {
                                logger.Info("The class \"JsonObject\" is ignored because \"JObject\" already exists in the namespace Newtonsoft.");
                                continue;
                            }

                            engineClass.SeeAlso = GetValueFromProperty <List <string> >(jObject, "x-qlik-see-also");
                            var properties = ReadProperties(jObject, "properties", engineClass.Name);
                            if (properties.Count == 0)
                            {
                                logger.Info($"The Class \"{engineClass.Name}\" has no properties.");
                            }
                            engineClass.Properties.AddRange(properties);
                            EngineObjects.Add(engineClass);

                            //Special for ObjectInterface => Add IObjectInterface
                            if (engineClass.Name == Config.BaseObjectInterfaceClassName)
                            {
                                var baseInterface = new EngineInterface()
                                {
                                    Name        = Config.BaseObjectInterfaceName,
                                    Description = "Generated Interface",
                                };
                                baseInterface.Properties.AddRange(engineClass.Properties);
                                EngineObjects.Add(baseInterface);
                            }
                            break;

                        case "array":
                            engineClass         = jObject.ToObject <EngineClass>();
                            engineClass.Name    = jProperty.Name;
                            engineClass.SeeAlso = GetValueFromProperty <List <string> >(jObject, "x-qlik-see-also");
                            var arrays = ReadProperties(jObject, "items", engineClass.Name);
                            engineClass.Properties.AddRange(arrays);
                            EngineObjects.Add(engineClass);
                            break;

                        case "enum":
                            EngineEnum engineEnum = jObject.ToObject <EngineEnum>();
                            engineEnum.Name = jProperty.Name;
                            var enums = GetEnumValues(jObject);
                            engineEnum.Values = enums;
                            if (EnumExists(engineEnum) == null)
                            {
                                EngineObjects.Add(engineEnum);
                            }
                            break;

                        default:
                            logger.Error($"Unknown object type {objectType}");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "The definitions could not be added.");
            }
        }
Exemplo n.º 16
0
 public Player(String PlayerName, EngineClass engine) : base(PlayerName, engine)
 {
 }
Exemplo n.º 17
0
        public Vehicle CreateVWVehicle(string name, CarColour carColour, IWheel wheel, Numberplate numberplate, EngineClass engine)
        {
            this.brand = new VW(name);

            return(new Car(carColour, wheel, brand, numberplate, engine));
        }
Exemplo n.º 18
0
 public Truck(ICarColour carColour, IWheel wheel, Brand brand, Numberplate numberplate, EngineClass engine)
     :
     base(carColour, wheel, brand, numberplate, engine)
 {
 }
Exemplo n.º 19
0
 public Vehicle CreateVehicle(CarColour carColour, IWheel wheel, Brand brand, Numberplate numberplate, EngineClass engine)
 {
     return(new Car(carColour, wheel, brand, numberplate, engine));
 }