Esempio n. 1
0
        public object ExecuteNewAssembly(byte[] rawAssm, object param)
        {
            Assembly      asm         = Assembly.Load(rawAssm);
            CodeInterface assemblyObj = null;

            foreach (Type t in asm.GetTypes())
            {
                if (t.GetInterface("CodeInterface") != null)
                {
                    assemblyObj = (CodeInterface)Activator.CreateInstance(t);
                }
            }

            object output = string.Empty;

            try
            {
                output = assemblyObj.DoWork(param);
            }
            catch (Exception ex)
            {
                output = ex.Message;
            }
            return(output);
        }
        public override bool CanExecute(IDictionary<string, object> parameter)
        {
            _document = _dte.ActiveDocument;
            if (_document == null || _document.ProjectItem == null || _document.ProjectItem.FileCodeModel == null)
            {
                MessageBox(ErrMessage);
                return false;
            }

            _serviceClass = GetClass(_document.ProjectItem.FileCodeModel.CodeElements);
            if (_serviceClass == null)
            {
                MessageBox(ErrMessage);
                return false;
            }

            _serviceInterface = GetServiceInterface(_serviceClass as CodeElement);
            if (_serviceInterface == null)
            {
                MessageBox(ErrMessage);
                return false;
            }

            _serviceName = _serviceClass.Name.Replace("AppService", "");
            return true;
        }
Esempio n. 3
0
 /// <summary>
 /// Finds the function interface element.
 /// </summary>
 /// <param name="cc">The cc.</param>
 /// <param name="functionName">Name of the function.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns></returns>
 internal static CodeFunction2 FindFunctionInterfaceElement(CodeInterface cc, string functionName,
                                                            List <Argument> arguments)
 {
     foreach (CodeElement ce in cc.Members)
     {
         if (ce is CodeFunction2 && functionName == ce.Name)
         {
             CodeFunction2 cf = ce as CodeFunction2;
             if (cf.Parameters.Count == arguments.Count)
             {
                 // On regarde si les paramètres correspondent
                 for (int i = 0; i < arguments.Count; i++)
                 {
                     CodeParameter param = (CodeParameter)cf.Parameters.Item(i + 1);
                     if (param.Name != arguments[i].Name)
                     {
                         return(null);
                     }
                 }
                 return(cf);
             }
         }
     }
     return(null);
 }
Esempio n. 4
0
        public bool AddInterface(string intName, string intNotes, string intType, ref CodeInterface intObj)
        {
            Project prjObj = null;

            if (!prjCreate(intType, ref prjObj))
            {
                return(false);
            }
            prjObj.ProjectItems.AddFromTemplate("C:\\Program Files\\Microsoft Visual Studio .NET\\VC#\\CSharpProjectItems\\NewCSharpFile.cs", intName + ".cs");
            ProjectItem pi = prjObj.ProjectItems.Item(intName + ".cs");

            CodeNamespace cn = pi.FileCodeModel.AddNamespace(intType, 0);
            TextPoint     tp = cn.GetStartPoint(EnvDTE.vsCMPart.vsCMPartHeader);
            EditPoint     ep = tp.CreateEditPoint();

            ep.StartOfDocument();
            ep.Insert("using System;\n");



            CodeInterface ci = cn.AddInterface(intName, 0, null, EnvDTE.vsCMAccess.vsCMAccessPublic);

            ci.Comment = intNotes;
            appOb.Solution.SolutionBuild.Build(false);


            intObj = ci;
            return(true);
        }
 void CreateInterface(string code, string fileName = @"c:\projects\MyProject\interface.cs")
 {
     CreateCodeModel();
     AddCodeFile(fileName, code);
     interfaceTypeDefinition = assemblyModel.TopLevelTypeDefinitions.First().Resolve();
     codeInterface           = new CodeInterface(codeModelContext, interfaceTypeDefinition);
 }
Esempio n. 6
0
        /// <summary>
        /// Finds the interface element for given <see cref="CodeElements"/> instance
        /// </summary>
        /// <param name="elements"></param>
        /// <returns></returns>
        public static CodeInterface FindInterface(this CodeElements elements)
        {
            // Loop
            foreach (CodeElement element in elements)
            {
                // Get element as interface
                CodeInterface myInterface = element as CodeInterface;

                // if it is interface then return
                if (myInterface != null)
                {
                    return(myInterface);
                }

                // Or recurse the clidren
                myInterface = FindInterface(element.Children);

                // if found return
                if (myInterface != null)
                {
                    return(myInterface);
                }
            }

            // Oppss. We didnt find it
            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the interface.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The interface.</returns>
        public static CodeInterface CreateInterface(this ProjectItem instance)
        {
            string interfaceName = string.Format("I{0}", instance.Name);
            string path          = instance.FileNames[1].Replace(instance.Name, interfaceName);

            CodeNamespace codeNamespace = instance.GetNameSpace();

            string nameSpace = codeNamespace.FullName;

            object[] bases = { };

            CodeNamespace interfaceNameSpace = instance.ProjectItems.ContainingProject.CodeModel.AddNamespace(
                nameSpace, path);

            CodeInterface codeInterface = interfaceNameSpace.AddInterface(
                interfaceName, -1, bases, vsCMAccess.vsCMAccessPublic);

            CodeClass codeClass = instance.GetFirstClass();

            if (codeClass != null)
            {
                object interfaceClass = interfaceName;
                codeClass.AddImplementedInterface(interfaceClass, 0);
            }

            return(codeInterface);
        }
Esempio n. 8
0
        void CreateInterface(string code)
        {
            AddCodeFile("interface.cs", code);
            ITypeDefinition typeDefinition = assemblyModel.TopLevelTypeDefinitions.First().Resolve();

            codeInterface = new CodeInterface(codeModelContext, typeDefinition);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the declaration of the specified code interface as a string.
        /// </summary>
        /// <param name="codeInterface">The code interface.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetInterfaceDeclaration(CodeInterface codeInterface)
        {
            // Get the start point after the attributes.
            var startPoint = codeInterface.GetStartPoint(vsCMPart.vsCMPartHeader);

            return(TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{"));
        }
Esempio n. 10
0
        public TypeScriptInterface Build(
            CodeInterface codeInterface,
            TypeContext typeContext)
        {
            TypeScriptInterface result = null;

            string moduleName = this.settings.GetModuleNameFromNamespace(codeInterface.Namespace);

            bool interfaceCreated;

            result = typeContext.GetOrCreateInterface(
                moduleName,
                TypeName.ParseDte(codeInterface.FullName),
                codeInterface.Name,
                out interfaceCreated);
            result.IsClass = this.settings.CreateClasses;

            this.PopulateBases(
                codeInterface.Bases,
                result,
                typeContext);

            this.PopulateMembers(
                codeInterface.Members,
                result,
                typeContext);

            return(result);
        }
        private void Interfaces(CodeElement codeElement)
        {
            CodeElements ces = null;

            if (codeElement is CodeClass)
            {
                ces = (codeElement as CodeClass).ImplementedInterfaces;
            }
            else if (codeElement is CodeInterface)
            {
                ces = (codeElement as CodeInterface).Bases;
            }
            else
            {
                return;
            }

            foreach (CodeElement ce in ces)
            {
                CodeInterface codeInterface = ce as CodeInterface;
                if (codeInterface.Name != null)
                {
                    string i = string.Format(interfaceInheritanceExpression, codeInterface.Name, codeElement.Name);
                    AppendExpression(i);
                }
            }
        }
Esempio n. 12
0
        private static string getInterfaceName(CodeInterface @interface)
        {
            var parents = GetParents(@interface);
            var nspace  = GetNameSpaceName(@interface.Namespace);

            return(nspace + "." + parents);
        }
        protected string ObjectToClassName(object baseCls)
        {
            string strBase = baseCls as string;

            if (strBase != null)
            {
                return(strBase);
            }

            CodeClass cs = baseCls as CodeClass;

            if (cs != null)
            {
                return(cs.FullName);
            }

            CodeInterface ci = baseCls as CodeInterface;

            if (ci != null)
            {
                return(ci.FullName);
            }

            return(ObjectToTypeRef(baseCls).AsFullName);
        }
        private void AddMethodToInterface(CodeInterface serviceInterface, string name, bool async)
        {
            string parameter  = string.Format("{0}Input", name);
            var    returnName = string.Format(async ? "Task<{0}Output>" : "{0}Output", name);
            var    function   = serviceInterface.AddFunction(name, vsCMFunction.vsCMFunctionFunction, returnName, -1);

            function.AddParameter("input", parameter);
        }
Esempio n. 15
0
        /// <summary>
        /// 生成方法定义到接口
        /// </summary>
        /// <param name="serviceInterface"></param>
        /// <param name="name"></param>
        /// <param name="async"></param>
        private void AddMethodToInterface(CodeInterface serviceInterface, string methodName, string doccoment, bool async)
        {
            var returnName = string.Format(async ? "Task<{0}>" : "{0}", GetDtoClassName(methodName, DtoType.Output));
            var function   = serviceInterface.AddFunction(methodName, vsCMFunction.vsCMFunctionFunction, returnName, -1);

            function.AddParameter("input", GetDtoClassName(methodName, DtoType.Input));
            function.Comment = doccoment;
        }
Esempio n. 16
0
 public InterfaceNode(CodeInterface ci, CodeModelEditorForm context)
     : base(CodeModelEditor.BrowseKind.Interface, context)
 {
     base.Tag              = ci;
     base.ImageKey         = "Interface";
     base.SelectedImageKey = "Interface";
     SetText(ci.Name);
 }
        private void AddMethodToInterface(CodeInterface serviceInterface, string name, bool async)
        {
            _statusBar.Progress(true, $"Generating service interface: {name}...", _steps++, _totalSteps);
            string parameter  = $"{name}Input";
            var    returnName = string.Format(async ? "Task<{0}Output>" : "{0}Output", name);
            var    function   = serviceInterface.AddFunction(name, vsCMFunction.vsCMFunctionFunction, returnName, -1);

            function.AddParameter("input", parameter);
        }
Esempio n. 18
0
        public void Item_OneInterfaceCompletionEntryAndItemSelectedByName_ReturnsOneCodeInterface()
        {
            helper.AddInterfaceToProjectContentAndCompletionEntries("Test", "Test.IClass");
            CreateCodeElements("Test");

            CodeInterface codeInterface = codeElements.Item("IClass") as CodeInterface;

            Assert.AreEqual("Test.IClass", codeInterface.FullName);
        }
Esempio n. 19
0
        public bool ImpInterface(string intType, Project intPrj, CodeInterface intObj, ref CodeClass intCla)
        {
            Project prjObj = null;

            if (!prjCreate(intType, ref prjObj))
            {
                return(false);
            }
            // add the necessary references
            VSProject vsPrj = (VSProject)prjObj.Object;
            Reference vsref = vsPrj.References.AddProject(intPrj);



            string claName;

            claName = intObj.Name;
            CodeInterface[] Ints = new CodeInterface[1];
            Ints[0] = intObj;

            prjObj.ProjectItems.AddFromTemplate("C:\\Program Files\\Microsoft Visual Studio .NET\\VC#\\CSharpProjectItems\\NewCSharpFile.cs", claName + ".cs");


            ProjectItem   pi = prjObj.ProjectItems.Item(claName + ".cs");
            CodeNamespace cn = pi.FileCodeModel.AddNamespace(intType, 0);
            TextPoint     tp = cn.GetStartPoint(EnvDTE.vsCMPart.vsCMPartHeader);
            EditPoint     ep = tp.CreateEditPoint();

            ep.StartOfDocument();
            ep.Insert("using " + intObj.Namespace.FullName + ";\n");
            CodeClass cc = cn.AddClass(intObj.Name, 0, null, null, EnvDTE.vsCMAccess.vsCMAccessPublic);

            tp = cc.GetStartPoint(EnvDTE.vsCMPart.vsCMPartName);
            ep = tp.CreateEditPoint();
            ep.EndOfLine();
            ep.Insert(" : " + intObj.FullName);
            cc.Comment = intObj.Comment;
            foreach (CodeElement ce in intObj.Members)
            {
                if (ce.Kind == EnvDTE.vsCMElement.vsCMElementFunction)
                {
                    CodeFunction  cf   = (CodeFunction)ce;
                    CodeFunction  cf1  = cc.AddFunction(cf.Name, cf.FunctionKind, cf.Type, 0, cf.Access, 0);
                    CodeParameter cep1 = null;
                    foreach (CodeElement cep in cf.Parameters)
                    {
                        CodeParameter cp = (CodeParameter)cep;
                        cep1 = cf1.AddParameter(cp.Name, cp.Type, -1);
                    }
                }
            }


            intCla = cc;
            return(true);
        }
        private static string GetNamespace(CodeInterface cc)
        {
            if (!Options.UseNamespace)
            {
                return(Options.DefaultModuleName);
            }

            return(cc == null
                ? Options.DefaultModuleName
                : cc.Namespace.FullName);
        }
Esempio n. 21
0
        public CodeInterface AddInterface(string Name, object Position, object Bases, vsCMAccess Access)
        {
            Initialize();

            InitTopNamespace();

            CodeInterface ci = vsTopNamespace.AddInterface(Name, Position, Bases, Access);

            CommitChanges();

            return(ci);
        }
Esempio n. 22
0
 public static void AddIfNotExists(this List <CodeInterface> lst, CodeInterface codeInterface)
 {
     if (codeInterface == null || codeInterface.Name == null || lst == null)
     {
         return;
     }
     if (lst.Any(x => x.FullName == codeInterface.FullName))
     {
         return;
     }
     lst.Add(codeInterface);
 }
Esempio n. 23
0
        public void ImplementedInterfaces_ClassImplementsGenericICollectionOfString_ReturnsCodeInterfaceForICollection()
        {
            CreateProjectContent();
            CreatePublicClass("MyClass");
            AddInterfaceToClassBaseTypes("System.Collections.Generic.ICollection", "System.Collections.Generic.ICollection{System.String}");

            CodeElements  codeElements  = codeClass.ImplementedInterfaces;
            CodeInterface codeInterface = codeElements.FirstCodeInterfaceOrDefault();

            Assert.AreEqual(1, codeElements.Count);
            Assert.AreEqual("System.Collections.Generic.ICollection<System.String>", codeInterface.FullName);
        }
Esempio n. 24
0
 public CodeInterfaceDeclarationWriterTests()
 {
     codeElementWriter = new CodeInterfaceDeclarationWriter(new GoConventionService());
     writer            = LanguageWriter.GetLanguageWriter(GenerationLanguage.Go, DefaultPath, DefaultName);
     tw = new StringWriter();
     writer.SetTextWriter(tw);
     root            = CodeNamespace.InitRootNamespace();
     parentInterface = new () {
         Name = "parentClass"
     };
     root.AddInterface(parentInterface);
 }
Esempio n. 25
0
        private void BeforeExpand(TreeNode parentNode, CodeInterface codeInterface)
        {
            InterfaceNode cn = new InterfaceNode(codeInterface, this);

            if (codeInterface.Members.Count > 0)
            {
                AddNodeWithChilds(parentNode.Nodes, cn);
            }
            else
            {
                parentNode.Nodes.Add(cn);
            }
        }
Esempio n. 26
0
        public void ImplementedInterfaces_ClassImplementsIDisposable_ReturnsCodeInterfaceForIDisposable()
        {
            CreateClass(
                "using System;\r\n" +
                "class MyClass : IDisposable {}");

            global::EnvDTE.CodeElements codeElements = codeClass.ImplementedInterfaces;

            CodeInterface codeInterface = codeElements.FirstCodeInterfaceOrDefault();

            Assert.AreEqual(1, codeElements.Count);
            Assert.AreEqual("System.IDisposable", codeInterface.FullName);
        }
Esempio n. 27
0
        public void ImplementedInterfaces_ClassImplementsGenericICollectionOfString_ReturnsCodeInterfaceForICollection()
        {
            CreateClass(
                "using System;\r\n" +
                "using System.Collections.Generic;\r\n" +
                "class MyClass : ICollection<string> {}");

            global::EnvDTE.CodeElements codeElements = codeClass.ImplementedInterfaces;

            CodeInterface codeInterface = codeElements.FirstCodeInterfaceOrDefault();

            Assert.AreEqual(1, codeElements.Count);
            Assert.AreEqual("System.Collections.Generic.ICollection<System.String>", codeInterface.FullName);
        }
Esempio n. 28
0
        private bool IsFoundInInterface(CodeFunction function, CodeInterface codeInterface)
        {
            foreach (CodeElement destFunc in codeInterface.Children)
            {
                if (destFunc.Kind == vsCMElement.vsCMElementFunction)
                {
                    if (function.Name == destFunc.Name && ContainSameParameters(function, (CodeFunction)destFunc))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 29
0
        private void FillAllBaseInterfaces(List <CodeInterface> list, CodeInterface codeInterface)
        {
            if (IsPartOfTheSolution((CodeElement)codeInterface))
            {
                list.Add(codeInterface);
            }

            foreach (CodeElement item in codeInterface.Bases)
            {
                if (item.Kind == vsCMElement.vsCMElementInterface)
                {
                    FillAllBaseInterfaces(list, (CodeInterface)item);
                }
            }
        }
		private static IEnumerable<CodeInterface> GetImplementedInterfacesRecursivly(CodeInterface currentInterface)
		{
			if (currentInterface != null)
			{
				var interfaces = new List<CodeInterface> { currentInterface };
				foreach (var baseElement in currentInterface.Bases)
				{
					if (baseElement is CodeInterface)
					{
						interfaces.AddRange(GetImplementedInterfacesRecursivly(baseElement as CodeInterface));
					}
				}
				return interfaces;
			}
			return Enumerable.Empty<CodeInterface>();
		}
Esempio n. 31
0
        /// <summary>
        /// Determines whether the specified element has attribute.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <returns>
        ///     <c>true</c> if the specified element has attribute; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasAttribute(CodeInterface element, string attributeName)
        {
            if (element.Attributes.Count > 0)
            {
                foreach (CodeElement att in element.Attributes)
                {
                    CodeAttribute codeAttribute = (CodeAttribute)att;

                    if (att.Name.Equals(attributeName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 32
0
        private void mnuAddDInterface_Click(object sender, System.EventArgs e)
        {
            frmAddInterface frmAI = new frmAddInterface();

            if (frmAI.ShowDialog() == DialogResult.OK)
            {
                string intName, intNotes;
                intName  = frmAI.tbxIntName.Text.Trim().Replace(" ", "_");
                intNotes = frmAI.txbNotes.Text.Trim();
                CodeInterface ci = null;
                sc.AddInterface(intName, intNotes, "Data_Interfaces", ref ci);
                TreeNode addTemp = new TreeNode("", 4, 4);
                addTemp.Text = intName;
                addTemp.Tag  = ci;
                tv.SelectedNode.Nodes.Add(addTemp);
                tv.SelectedNode.ExpandAll();
            }
        }
 private void AddMethodToInterface(CodeInterface serviceInterface, string name, bool async)
 {
     string parameter = string.Format("{0}Input", _serviceName + name);
     var returnName = string.Format(async ? "Task<{0}Output>" : "{0}Output", _serviceName + name);
     var function = serviceInterface.AddFunction(name, vsCMFunction.vsCMFunctionFunction, returnName, -1);
     function.AddParameter("input", parameter);
 }
		private static void AddDocCommentToInterface(CodeInterface codeInterface)
		{
			codeInterface.DocComment = string.Format("The {0}.", codeInterface.Name.CamelCaseSplit()).ToDocComment();
		}
Esempio n. 35
0
        /// <summary>
        /// Gets the declaration of the specified code interface as a string.
        /// </summary>
        /// <param name="codeInterface">The code interface.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetInterfaceDeclaration(CodeInterface codeInterface)
        {
            // Get the start point after the attributes.
            var startPoint = codeInterface.GetStartPoint(vsCMPart.vsCMPartHeader);

            return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{");
        }
Esempio n. 36
0
 protected virtual void VisitInterface(CodeInterface codeInterface)
 {
 }
        /// <summary>
        /// Determines whether the specified element has attribute.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <returns>
        /// 	<c>true</c> if the specified element has attribute; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasAttribute(CodeInterface element, string attributeName)
        {
            if(element.Attributes.Count > 0)
            {
                foreach(CodeElement att in element.Attributes)
                {
                    CodeAttribute codeAttribute = (CodeAttribute)att;

                    if(att.Name.Equals(attributeName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
 private static string getInterfaceName(CodeInterface @interface)
 {
     var parents = GetParents(@interface);
     var nspace = GetNameSpaceName(@interface.Namespace);
     return nspace + "." + parents;
 }
 public static string GetParents(CodeInterface c)
 {
     var parent = c.Parent as CodeClass2;
     return GetParents((CodeElement2)c, parent);
 }