Exemple #1
0
 private string DelegateToString(CodeDelegate codeDelegate)
 {
     try
     {
         string s = "";
         s = s + codeDelegate.Type.AsString + " (";
         for (int i = 1; i <= codeDelegate.Parameters.Count; i++)
         {
             CodeElement codeElement = codeDelegate.Parameters.Item(i);
             if (codeElement.Kind == vsCMElement.vsCMElementParameter)
             {
                 CodeParameter codeParameter = (CodeParameter)codeElement;
                 s = s + codeParameter.Type.AsString + " " + codeParameter.Name;
                 if (i != codeDelegate.Parameters.Count)
                 {
                     s = s + ", ";
                 }
             }
         }
         s = s + ")";
         return(s);
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e.Message, "AS VS Expert: DelegateToString");
         return("");
     }
 }
        private int CalculateAge()
        {
            Int32 age = 0;
            var   currentAppPackage = Windows.ApplicationModel.Package.Current;

            foreach (var package in currentAppPackage.Dependencies)
            {
                if (package.IsOptional && package.Id.FamilyName.Contains("FabrikamAgeAnalysis"))
                {
                    try
                    {
                        IntPtr handle = LoadPackagedLibrary(OPT_PKG_LIB_FILE);
                        if (handle == IntPtr.Zero)
                        {
                            PopupUI("Failed to load dll");
                        }
                        else
                        {
                            IntPtr FuncPTR = GetProcAddress(handle, OPT_PKG_LIB_GETAGE_EXPORT);
                            if (FuncPTR != IntPtr.Zero)
                            {
                                CodeDelegate ageFunction = Marshal.GetDelegateForFunctionPointer <CodeDelegate>(FuncPTR);
                                age = ageFunction();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        PopupUI("Exception thrown while loading code {" + ex.InnerException + "}");
                    }
                }
            }
            return(age);
        }
Exemple #3
0
        public async void LoadCode(Package package, Controls.OptionalPackageControl control)
        {
            try
            {
                IntPtr handle = LoadPackagedLibrary(OPT_PKG_LIB_FILE);

                if (handle == IntPtr.Zero)
                {
                    await new MessageDialog("Unable to load code file from Optional Package - Restart Main Package").ShowAsync();
                }
                else
                {
                    IntPtr factorialFuncPTR = GetProcAddress(handle, OPT_PKG_LIB_FACTORIAL_EXPORT);
                    if (factorialFuncPTR != IntPtr.Zero)
                    {
                        CodeDelegate function       = Marshal.GetDelegateForFunctionPointer <CodeDelegate>(factorialFuncPTR);
                        UInt32       inputValue     = control.CodeInputValue;
                        UInt32       functionReturn = function(inputValue);
                        control.CodeOutputValue = functionReturn;
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog("Unable to load code from Optional Package. {" + err(ex) + "}").ShowAsync();
            }
        }
Exemple #4
0
 void CreateDelegate(string code)
 {
     AddCodeFile("delegate.cs", code);
     codeDelegate = new CodeDelegate(
         codeModelContext,
         assemblyModel.TopLevelTypeDefinitions.First().Resolve());
 }
Exemple #5
0
        public static CodeVector makeCodeVector(int controlPointCount,
                                                DynamicMethod dm)
        {
            CodeDelegate d =
                (CodeDelegate)dm.CreateDelegate(typeof(CodeDelegate));

            return(new DelegateCodeVector(controlPointCount, d));
        }
 public DelegateNode(CodeDelegate cd, CodeModelEditorForm context)
     : base(CodeModelEditor.BrowseKind.Delegate, context)
 {
     base.Tag              = cd;
     base.ImageKey         = "Delegate";
     base.SelectedImageKey = "Delegate";
     SetText(cd.Name);
 }
        public CodeAnimator(CodeDelegate del) : base(new Rectangle())
        {
            _delegate = del;
            _elem     = new Rectangle();

            _duration = new Duration(GetTimeSpan(1, OrSo.Ticks));

            _reverse = false;
        }
        public CodeAnimator(CodeDelegate del)
            : base(new Rectangle())
        {
            _delegate = del;
            _elem = new Rectangle();

            _duration = new Duration(GetTimeSpan(1, OrSo.Tick));

            _reverse = false;
        }
Exemple #9
0
        /// <summary>
        /// Gets the declaration of the specified code delegate as a string.
        /// </summary>
        /// <param name="codeDelegate">The code delegate.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetDelegateDeclaration(CodeDelegate codeDelegate)
        {
            // Get the start point at the end of the attributes if there are any (vsCMPartHeader is
            // not available for delegates).
            var startPoint = codeDelegate.Attributes.Count > 0
                ? codeDelegate.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter)
                : codeDelegate.StartPoint;

            return(TextDocumentHelper.GetTextToFirstMatch(startPoint, @";"));
        }
Exemple #10
0
        public CodeDelegate AddDelegate(string Name, object Type, object Position, vsCMAccess Access)
        {
            Initialize();

            InitTopNamespace();

            CodeDelegate cd = vsTopNamespace.AddDelegate(Name, Type, Position, Access);

            CommitChanges();

            return(cd);
        }
Exemple #11
0
        private void GenerateDelegateCode(CodeDelegate delegateDecl)
        {
            foreach (CodeComment commentDecl in delegateDecl.Comments)
            {
                GenerateCommentCode(commentDecl);
            }

            WriteCustomAttributes(delegateDecl.CustomAttributes);
            WriteAttributes(delegateDecl.Attributes);
            Output.Write("delegate ");
            Output.Write(GetClrTypeName(delegateDecl.ReturnTypeName));
            Output.Write(" ");
            Output.Write(delegateDecl.Name);
            Output.Write("(");
            Output.Write(string.Join(", ", delegateDecl.Parameters.Select(arg => GetClrTypeName(arg.Type) + " " + arg.Name)));
            Output.WriteLine(");");
        }
Exemple #12
0
 private string DelegateToString(CodeDelegate codeDelegate)
 {
     try
     {
         string s = "";
         s = s + codeDelegate.Type.AsString + " (";
         for(int i = 1; i <= codeDelegate.Parameters.Count; i++)
         {
             CodeElement codeElement = codeDelegate.Parameters.Item(i);
             if (codeElement.Kind == vsCMElement.vsCMElementParameter)
             {
                 CodeParameter codeParameter = (CodeParameter) codeElement;
                 s = s + codeParameter.Type.AsString + " " + codeParameter.Name;
                 if (i != codeDelegate.Parameters.Count)
                     s = s + ", ";
             }
         }
         s = s + ")";
         return s;
     }
     catch(Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e.Message, "AS VS Expert: DelegateToString");
         return "";
     }
 }
        /// <summary>
        /// Gets the declaration of the specified code delegate as a string.
        /// </summary>
        /// <param name="codeDelegate">The code delegate.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetDelegateDeclaration(CodeDelegate codeDelegate)
        {
            // Get the start point at the end of the attributes if there are any (vsCMPartHeader is
            // not available for delegates).
            var startPoint = codeDelegate.Attributes.Count > 0
                ? codeDelegate.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter)
                : codeDelegate.StartPoint;

            return TextDocumentHelper.GetTextToFirstMatch(startPoint, @";");
        }
Exemple #14
0
 protected virtual void VisitDelegate(CodeDelegate codeDelegate)
 {
 }
        private void BeforeExpand(TreeNode parentNode, CodeDelegate codeDelegate)
        {
            DelegateNode dn = new DelegateNode(codeDelegate, this);

            parentNode.Nodes.Add(dn);
        }
Exemple #16
0
 public DelegateCodeVector( int controlPointCount, 
                            CodeDelegate d ) 
   : base( controlPointCount ) {
   mycode = d;
 }
Exemple #17
0
 void CreateDelegate()
 {
     codeDelegate = new CodeDelegate(helper.ProjectContent, fakeDelegate);
 }
Exemple #18
0
        /// <summary>
        /// Returns a CodeElement's documentation comment if it has
        /// one, otherwise returns relevant information from the prototype.
        /// </summary>
        /// <param name="element">A CodeElement object.</param>
        /// <returns>A string representing the element's definition.</returns>
        public static string GetPrototypeFromCMElement(CodeElement element)
        {
            System.Xml.XmlDocument docComment = new System.Xml.XmlDocument();

            try
            {
                if (element == null)
                {
                    throw new ArgumentNullException("element");
                }

                switch (element.Kind)
                {
                case vsCMElement.vsCMElementFunction:
                    CodeFunction codeFunction = ((CodeFunction)element);
                    if (!string.IsNullOrEmpty(codeFunction.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeFunction.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeFunction.get_Prototype(
                                                     (int)vsCMPrototype.vsCMPrototypeType | (int)vsCMPrototype.vsCMPrototypeParamNames | (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeFunction.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementProperty:
                    CodeProperty codeProperty = ((CodeProperty)element);
                    if (!string.IsNullOrEmpty(codeProperty.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeProperty.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeProperty.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementVariable:
                    CodeVariable codeVariable = ((CodeVariable)element);
                    return(codeVariable.get_Prototype((int)vsCMPrototype.vsCMPrototypeType));

                case vsCMElement.vsCMElementEvent:
                    CodeEvent codeEvent = ((CodeEvent)element);
                    if (!string.IsNullOrEmpty(codeEvent.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeEvent.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                         (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                         (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeEvent.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                       (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                       (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementDelegate:
                    CodeDelegate codeDelegate = ((CodeDelegate)element);
                    if (!string.IsNullOrEmpty(codeDelegate.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeDelegate.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(String.Format("{0}\n{1}", node.InnerText.Trim(),
                                                 codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                                            (int)vsCMPrototype.vsCMPrototypeParamTypes)));
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(codeDelegate.get_Prototype((int)vsCMPrototype.vsCMPrototypeType |
                                                          (int)vsCMPrototype.vsCMPrototypeParamNames |
                                                          (int)vsCMPrototype.vsCMPrototypeParamTypes));
                    }

                case vsCMElement.vsCMElementClass:
                    CodeClass codeClass = ((CodeClass)element);
                    if (!string.IsNullOrEmpty(codeClass.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeClass.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                //nemerle variant type and variant options
                case vsCMElement.vsCMElementUnion:
                    CodeClass codeVariant = ((CodeClass)element);
                    if (!string.IsNullOrEmpty(codeVariant.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeVariant.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }


                case vsCMElement.vsCMElementStruct:
                    CodeStruct codeStruct = ((CodeStruct)element);
                    if (!string.IsNullOrEmpty(codeStruct.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeStruct.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                case vsCMElement.vsCMElementInterface:
                    CodeInterface codeInterface = ((CodeInterface)element);
                    if (!string.IsNullOrEmpty(codeInterface.DocComment))
                    {
                        docComment.LoadXml(String.Format("<docComment>{0}</docComment>", codeInterface.DocComment));
                        System.Xml.XmlNode node = docComment.SelectSingleNode("/docComment/summary");
                        if (node != null)
                        {
                            return(node.InnerText.Trim());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }

                default:
                    return(string.Empty);
                }
            }
            catch
            {
                return(string.Empty);
            }
        }
Exemple #19
0
 /// <summary>
 /// Runs arbitrary code.
 /// Use this method to run code after an animation completes.
 /// </summary>
 /// <param name="del"></param>
 /// <returns></returns>
 public static CodeAnimator Run(CodeDelegate del)
 {
     return new CodeAnimator(del);
 }
Exemple #20
0
 protected virtual void VisitDelegate(CodeDelegate codeDelegate)
 {
 }
Exemple #21
0
 public DelegateCodeVector(int controlPointCount,
                           CodeDelegate d)
     : base(controlPointCount)
 {
     mycode = d;
 }
Exemple #22
0
 /// <summary>
 /// Runs arbitrary code.
 /// Use this method to run code after an animation completes.
 /// </summary>
 /// <param name="del"></param>
 /// <returns></returns>
 public static CodeAnimator Run(CodeDelegate del)
 {
     return(new CodeAnimator(del));
 }
Exemple #23
0
        private void SortFunctionsWithinClass(CodeElement codeElement)
        {
            EditPoint fieldInsertionPoint;
            EditPoint constructorInsertionPoint;
            EditPoint finalizerInsertionPoint;
            EditPoint delegateInsertionPoint;
            EditPoint eventInsertionPoint;
            EditPoint enumInsertionPoint;
            EditPoint interfaceInsertionPoint;
            EditPoint propertyInsertionPoint;
            EditPoint methodInsertionPoint;
            EditPoint structInsertionPoint;
            EditPoint classInsertionPoint;

            EditPoint  origin     = codeElement.StartPoint.CreateEditPoint();
            EditPoint  classPoint = codeElement.StartPoint.CreateEditPoint();
            TextRanges trs        = null;

            if (origin.FindPattern("{", (int)vsFindOptions.vsFindOptionsMatchCase, ref classPoint, ref trs))
            {
                classPoint.Insert("\r\n");
                origin = classPoint.CreateEditPoint();
                fieldInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                constructorInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                finalizerInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                delegateInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                eventInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                enumInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                interfaceInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                propertyInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                methodInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                structInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");
                classInsertionPoint = classPoint.CreateEditPoint();
                classPoint.Insert("\r\n\r\n");

                Array accessLevels = Enum.GetValues(typeof(vsCMAccess));

                foreach (vsCMAccess accessLevel in accessLevels)
                {
                    for (int i = 1; i <= codeElement.Children.Count; i++)
                    {
                        CodeElement element           = codeElement.Children.Item(i);
                        EditPoint   elementStartPoint = element.StartPoint.CreateEditPoint();
                        switch (element.Kind)
                        {
                        case vsCMElement.vsCMElementVariable:
                            CodeVariable variable = element as CodeVariable;
                            if (variable != null)
                            {
                                if (variable.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, fieldInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeVariable " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementFunction:
                            // method, constructor, or finalizer
                            CodeFunction function = element as CodeFunction;
                            if (function != null)
                            {
                                if (function.Access == accessLevel)
                                {
                                    if (function.FunctionKind == vsCMFunction.vsCMFunctionConstructor)
                                    {
                                        MoveCodeBlock(codeElement, element, constructorInsertionPoint);
                                    }
                                    else if (function.FunctionKind == vsCMFunction.vsCMFunctionDestructor)
                                    {
                                        MoveCodeBlock(codeElement, element, finalizerInsertionPoint);
                                    }
                                    else
                                    {
                                        MoveCodeBlock(codeElement, element, methodInsertionPoint);
                                    }
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeFunction " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementDelegate:
                            CodeDelegate delegateElement = element as CodeDelegate;
                            if (delegateElement != null)
                            {
                                if (delegateElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, delegateInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeDelegate " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementEvent:
                            MoveCodeBlock(codeElement, element, eventInsertionPoint);
                            break;

                        case vsCMElement.vsCMElementEnum:
                            CodeEnum enumElement = element as CodeEnum;
                            if (enumElement != null)
                            {
                                if (enumElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, enumInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeEnum " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementInterface:
                            CodeInterface interfaceElement = element as CodeInterface;
                            if (interfaceElement != null)
                            {
                                if (interfaceElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, interfaceInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeInterface " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementProperty:
                            CodeProperty propertyElement = element as CodeProperty;
                            if (propertyElement != null)
                            {
                                if (propertyElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, propertyInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeProperty " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementStruct:
                            CodeStruct structElement = element as CodeStruct;
                            if (structElement != null)
                            {
                                if (structElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, structInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeStruct " + element.Name + " null");
                            }
                            break;

                        case vsCMElement.vsCMElementClass:
                            CodeClass classElement = element as CodeClass;
                            if (classElement != null)
                            {
                                if (classElement.Access == accessLevel)
                                {
                                    MoveCodeBlock(codeElement, element, classInsertionPoint);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("CodeStruct " + element.Name + " null");
                            }
                            break;

                        default:
                            Debug.WriteLine("unknown element: " + element.Name + " - " + element.Kind);
                            break;
                        }
                    }

                    for (int i = 1; i <= codeElement.Children.Count; i++)
                    {
                        CodeElement element = codeElement.Children.Item(i);
                        if (element.Kind == vsCMElement.vsCMElementClass || element.Kind == vsCMElement.vsCMElementInterface || element.Kind == vsCMElement.vsCMElementStruct)
                        {
                            SortFunctionsWithinClass(element);
                        }
                    }
                }

                origin.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);
                classInsertionPoint.CreateEditPoint().DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);
            }
        }