static DBCParserShould()
 {
     if (DBCFileTest == null)
     {
         string FilePath = FileSysHelper.GetCurrentAppLocationPath() + "\\Resources\\DBCParser.TestsResources\\dbcForTest.dbc";
         DBCFileTest = File.ReadAllText(FilePath);
     }
     if (DBCMessageBlock == null)
     {
         string FilePath = FileSysHelper.GetCurrentAppLocationPath() + "\\Resources\\DBCParser.TestsResources\\dbcMessageBlockForTest.txt";
         DBCMessageBlock = File.ReadAllText(FilePath);
     }
 }
Ejemplo n.º 2
0
        public static void ConfigureArxmlUsingDBCFiles(NodeItem DBCNode, IList <ElementBase> elementList)
        {
            string filePath = FileSysHelper.GetCurrentAppLocationPath() + "\\Resources\\ArxmlTemplateDealerResources\\Template.json";
            //Seraching to locate
            var canStackConfigureTemplateList = JObject.Parse(File.ReadAllText(filePath)).Value <JObject> ("ComStack").Value <JArray> ("Template");

            foreach (JObject template in canStackConfigureTemplateList)
            {
                IEnumerable <ElementBase> fliteredElements = ArxmlHelper.SearchingElementsByConfigure(template, elementList);
                //Configure the parameters By ParametersTemplate
                JObject canStackConfigureParametersTemplate = template.Value <JObject> ("ParametersTemplate");
                ArxmlHelper.ConfigureParametersByTemplate(fliteredElements, elementList, canStackConfigureParametersTemplate, CanStackDealerFactory(DBCNode));
            }

            //  var list = ArxmlTemplateDealer.ArxmlHelper.SearchingElementsByConfigure (canStackConfigureParametersTemplate, elementList);
        }
Ejemplo n.º 3
0
        void SetupInstance(CodeTemplate.MarkItem Node, DataTreeProperties Context)
        {
            object[] inputArgs = null;
            Assembly assemblyResolver(object?sender, ResolveEventArgs args)
            {
                string path       = Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Path];
                string fileToLoad = args.Name.Remove(args.Name.IndexOf(','));

                if (path != null)
                {
                    string resolvePath = FileSysHelper.GetCurrentAppLocationPath() + "\\" + path + "\\" + fileToLoad + ".dll";
                    if (File.Exists(resolvePath))
                    {
                        return(Assembly.LoadFile(resolvePath));
                    }
                }

                return(Assembly.Load(fileToLoad));
            }

            AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver;
            if (Node.ChildNodeList.Where(ele => ele.Type.Equals(CodeTemplate.MarkItem.NodeTypeEnum.InputArgs)).Count() != 0)
            {
                //Need to get the value
                inputArgs = Node.ChildNodeList.Where(ele => ele.Type.Equals(CodeTemplate.MarkItem.NodeTypeEnum.InputArgs)).FirstOrDefault().ChildNodeList.Where(ele => ele.Type.Equals(CodeTemplate.MarkItem.NodeTypeEnum.InputArgValue)).Select(subArg => GetValueBasic(subArg, Context)).ToArray();
            }
            else if (Node.AttributesDict.ContainsKey(CodeTemplate.MarkItem.NodeAttributeEnum.InputArgs))
            {
                inputArgs = Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.InputArgs].Split(",");
                for (int i = 0; i < inputArgs.Length; i++)
                {
                    if (inputArgs[i].Equals("null"))
                    {
                        inputArgs[i] = null;
                    }
                }
            }
            Assembly dllToLoad = null;

            if (Node.AttributesDict.ContainsKey(CodeTemplate.MarkItem.NodeAttributeEnum.Load))
            {
                dllToLoad = Assembly.Load(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Load]);
            }
            else
            {
                List <FileInfo> fileList = new List <FileInfo> ();
                string          path     = Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Path];
                if (!path.Contains(":"))
                {
                    path = FileSysHelper.GetCurrentAppLocationPath() + "\\" + path;
                }
                //searching dir or file
                if (File.Exists(path))
                {
                    fileList.Add(new FileInfo(path));
                }
                else if (Directory.Exists(path))
                {
                    fileList.AddRange(new DirectoryInfo(path).GetFiles());
                }

                foreach (var file in fileList.Where(ele => ele.Extension.ToLower().Equals(".dll")))
                {
                    Assembly dllFromPath = Assembly.LoadFile(file.FullName);

                    foreach (var dllModule in dllFromPath.GetLoadedModules())
                    {
                        foreach (var typeDefinedInModule in dllModule.GetTypes())
                        {
                            if (typeDefinedInModule.Name.Equals(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Type]))
                            {
                                dllToLoad = dllFromPath;
                                break;
                            }
                        }
                        if (dllToLoad != null)
                        {
                            break;
                        }
                    }
                    if (dllToLoad != null)
                    {
                        break;
                    }
                }
            }
            if (dllToLoad == null)
            {
                throw new Exception("not finding instances");
            }
            foreach (var typeDefinedInModule in dllToLoad.GetTypes())
            {
                if (typeDefinedInModule.Name.Equals(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Type]))
                {
                    if (typeDefinedInModule.IsClass)
                    {
                        object itemGet = null;
                        if (Node.AttributesDict.ContainsKey(CodeTemplate.MarkItem.NodeAttributeEnum.Function))
                        {
                            itemGet = typeDefinedInModule.GetMethod(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Function]).Invoke(null, inputArgs);
                        }
                        else if (Node.AttributesDict.ContainsKey(CodeTemplate.MarkItem.NodeAttributeEnum.Property))
                        {
                            itemGet = typeDefinedInModule.GetProperty(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Property]).GetValue(null);
                        }
                        else if (Node.AttributesDict.ContainsKey(CodeTemplate.MarkItem.NodeAttributeEnum.Method))
                        {
                            // if (inputArgs != null)
                            // {
                            //     var method = typeDefinedInModule.GetMethod (Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Method]);
                            // }
                            // else
                            // {
                            //     var method = typeDefinedInModule.GetMethod (Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Method]);
                            // }

                            var func = new Func <object[], object> ((object[] input) =>
                            {
                                foreach (var method in typeDefinedInModule.GetMethods())
                                {
                                    bool isCorrect = false;
                                    if (method.Name.Equals(Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Method]))
                                    {
                                        int i          = 0;
                                        isCorrect      = true;
                                        var parameters = method.GetParameters();
                                        if (parameters.Length != input.Length)
                                        {
                                            isCorrect = false;
                                        }
                                        else
                                        {
                                            foreach (var parameter in parameters)
                                            {
                                                if (input[i] != null)
                                                {
                                                    if (input[i].GetType().Equals(parameter.ParameterType))
                                                    {
                                                    }
                                                    else
                                                    {
                                                        isCorrect = false;
                                                        break;
                                                    }
                                                }
                                                else
                                                {
                                                }
                                            }
                                        }
                                    }
                                    if (isCorrect)
                                    {
                                        return(method.Invoke(null, input));
                                    }
                                }

                                throw new Exception("not finding instances");
                            });

                            itemGet = func;
                        }
                        else
                        {
                            itemGet = System.Activator
                                      .CreateInstance(typeDefinedInModule, inputArgs);
                        }

                        Context.ObjectDict[Node.AttributesDict[CodeTemplate.MarkItem.NodeAttributeEnum.Name]] = itemGet;
                        AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolver;
                        return;
                    }
                }
            }
            throw new Exception("not finding instances");
        }