public override int GetExpansionFunction(IXMLDOMNode xmlFunctionNode, string bstrFieldName, out IVsExpansionFunction pFunc)
        {
            string snippetFunctionName, param;
            if (!TryGetSnippetFunctionInfo(xmlFunctionNode, out snippetFunctionName, out param))
            {
                pFunc = null;
                return VSConstants.E_INVALIDARG;
            }

            switch (snippetFunctionName)
            {
                case "SimpleTypeName":
                    pFunc = new SnippetFunctionSimpleTypeName(this, TextView, SubjectBuffer, bstrFieldName, param);
                    return VSConstants.S_OK;
                case "ClassName":
                    pFunc = new SnippetFunctionClassName(this, TextView, SubjectBuffer, bstrFieldName);
                    return VSConstants.S_OK;
                case "GenerateSwitchCases":
                    pFunc = new SnippetFunctionGenerateSwitchCases(this, TextView, SubjectBuffer, bstrFieldName, param);
                    return VSConstants.S_OK;
                default:
                    pFunc = null;
                    return VSConstants.E_INVALIDARG;
            }
        }
        protected static bool TryGetSnippetFunctionInfo(IXMLDOMNode xmlFunctionNode, out string snippetFunctionName, out string param)
        {
            if (xmlFunctionNode.text.IndexOf('(') == -1 ||
                xmlFunctionNode.text.IndexOf(')') == -1 ||
                xmlFunctionNode.text.IndexOf(')') < xmlFunctionNode.text.IndexOf('('))
            {
                snippetFunctionName = null;
                param = null;
                return false;
            }

            snippetFunctionName = xmlFunctionNode.text.Substring(0, xmlFunctionNode.text.IndexOf('('));

            var paramStart = xmlFunctionNode.text.IndexOf('(') + 1;
            var paramLength = xmlFunctionNode.text.LastIndexOf(')') - xmlFunctionNode.text.IndexOf('(') - 1;
            param = xmlFunctionNode.text.Substring(paramStart, paramLength);
            return true;
        }
 public abstract int GetExpansionFunction(IXMLDOMNode xmlFunctionNode, string bstrFieldName, out IVsExpansionFunction pFunc);
 /// <summary>
 /// Sets the node value.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="value">The value.</param>
 /// <param name="removeNilAttribute">if set to <c>true</c> remove nil attribute.</param>
 private void SetNodeValue(IXMLDOMNode node, string value, bool removeNilAttribute)
 {
     if (removeNilAttribute && node.attributes.getNamedItem("xsi:nil") != null)
     {
         node.attributes.removeNamedItem("xsi:nil");
     }
     node.text = value;
 }
Beispiel #5
0
 public int InsertSpecificExpansion(IXMLDOMNode pSnippet, TextSpan tsInsertPos, IVsExpansionClient pExpansionClient, Guid guidLang, string pszRelativePath, out IVsExpansionSession pSession) {
     TextBuffer.Insert(0, "specific-expansion");
     pSession = new VsExpansionSessionMock();
     return VSConstants.S_OK;
 }
Beispiel #6
0
 public int GetExpansionFunction(IXMLDOMNode xmlFunctionNode, string bstrFieldName, out IVsExpansionFunction pFunc) {
     pFunc = null;
     return VSConstants.S_OK;
 }
Beispiel #7
0
        public virtual string GetXML(string sNodeName)
        {
            try
            {
                if (sNodeName == null)
                {
                    sNodeName = GetType().Name;
                }
                this.XMLParser = new XMLParser(sNodeName);

                this.XMLParser.AddAttribute("AssemblyName", this.GetType().Assembly.ManifestModule.Name, (IXMLDOMElement)this.XMLParser.documentElement);
                this.XMLParser.AddAttribute("ObjectType", this.GetType().Name, (IXMLDOMElement)this.XMLParser.documentElement);

                List <PropertyInfo> pInfos = Methods.GetBrowsableAttributes(this.GetType());

                foreach (PropertyInfo pInfo in pInfos)
                {
                    //Type tObj = typeof(ISbnObject);

                    object val = pInfo.GetValue(this, null);

                    if (!object.ReferenceEquals(val, null))
                    {
                        IXMLDOMNode node = null;

                        Type type = val.GetType();

                        if (type == typeof(string))
                        {
                            node = this.XMLParser.AddChildFromString(pInfo.Name, (string)val, this.XMLParser.documentElement);
                        }
                        else if (type == typeof(System.Byte[]))
                        {
                            if (!_bSaveMode)
                            {
                                node = this.XMLParser.AddChildFromString(pInfo.Name, "", this.XMLParser.documentElement);
                                node.set_dataType("bin.base64");
                                string attach = Convert.ToBase64String((byte[])val);
                                node.nodeTypedValue = attach;
                            }
                            else
                            {
                                node = this.XMLParser.AddChildFromString(pInfo.Name, _PhysicalPath + "\\" + pInfo.Name + ".dat", this.XMLParser.documentElement);

                                if (!System.IO.Directory.Exists(_PhysicalPath))
                                {
                                    System.IO.Directory.CreateDirectory(_PhysicalPath);
                                }

                                System.IO.StreamWriter sw = new System.IO.StreamWriter(_PhysicalPath + "\\" + pInfo.Name + ".dat");

                                sw.BaseStream.Write((byte[])val, 0, (int)((byte[])val).Length);

                                sw.Close();
                            }
                        }
                        else if (type == typeof(System.Guid))
                        {
                            node = this.XMLParser.AddChildFromString(pInfo.Name, ((Guid)val).ToString(), this.XMLParser.documentElement);
                        }
                        else if (type == typeof(System.Int64) || type == typeof(System.Int32))
                        {
                            node = this.XMLParser.AddChildFromString(pInfo.Name, val.ToString(), this.XMLParser.documentElement);
                        }
                        else if (type.BaseType == typeof(SbnBinary))
                        {
                            if (!_bSaveMode)
                            {
                                try
                                {
                                    ((SbnObject)val).GetXML(pInfo.Name);

                                    if (((SbnObject)val).XMLParser != null && ((SbnObject)val).XMLParser.documentElement != null)
                                    {
                                        node = this.XMLParser.AddChildFromNode(((SbnObject)val).XMLParser.documentElement, this.XMLParser.documentElement);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string sError = ex.Message;
                                    node = this.XMLParser.AddChildFromString(pInfo.Name, sError, this.XMLParser.documentElement);
                                }
                            }
                        }
                        else if (type.BaseType == typeof(SbnObject))
                        {
                            if (!_bSaveMode)
                            {
                                try
                                {
                                    ((SbnObject)val).GetXML(pInfo.Name);

                                    if (((SbnObject)val).XMLParser != null && ((SbnObject)val).XMLParser.documentElement != null)
                                    {
                                        node = this.XMLParser.AddChildFromNode(((SbnObject)val).XMLParser.documentElement, this.XMLParser.documentElement);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string sError = ex.Message;
                                    node = this.XMLParser.AddChildFromString(pInfo.Name, sError, this.XMLParser.documentElement);
                                }
                            }
                        }
                        else if (type.BaseType.Name.Contains("SbnListObject"))
                        {
                            if (!_bSaveMode)
                            {
                                try
                                {
                                    node = this.XMLParser.AddChildFromString(pInfo.Name, "", this.XMLParser.documentElement);
                                    Type   valType    = val.GetType();
                                    object countItems = valType.InvokeMember("Count", BindingFlags.GetProperty, null, val, null);
                                    for (int i = 0; i < (int)countItems; i++)
                                    {
                                        object[] objChildItem = new object[1];
                                        objChildItem[0] = i;

                                        object objItem = valType.InvokeMember("GetItem", BindingFlags.InvokeMethod, null, val, objChildItem);

                                        SbnObject OutObj = (SbnObject)objItem;
                                        OutObj.GetXML(null);

                                        this.XMLParser.AddChildFromNode(OutObj.XMLParser.documentElement, node);
                                    }

                                    /* commented by ghmhm 930512
                                     * if (((SbnObject)val).XMLParser != null && ((SbnObject)val).XMLParser.documentElement != null)
                                     *  node = this.XMLParser.AddChildFromNode(((SbnObject)val).XMLParser.documentElement, this.XMLParser.documentElement);
                                     */
                                }
                                catch (Exception ex)
                                {
                                    string sError = ex.Message;
                                    node = this.XMLParser.AddChildFromString(pInfo.Name, sError, this.XMLParser.documentElement);
                                }
                            }
                        }
                        else if (type.BaseType == typeof(Enum))
                        {
                            node = this.XMLParser.AddChildFromString(pInfo.Name, val.ToString(), this.XMLParser.documentElement);
                        }
                        if (node != null)
                        {
                            this.XMLParser.AddAttribute("SystemDataType", type.ToString(), (IXMLDOMElement)node);
                        }
                        else
                        {
                            if (pInfo.PropertyType.Name == "ISbnObject")
                            {
                                node = this.XMLParser.AddChildFromString(pInfo.Name, "", this.XMLParser.documentElement);
                                this.XMLParser.AddAttribute("AssemblyName", type.Assembly.ManifestModule.Name, (IXMLDOMElement)node);
                                this.XMLParser.AddAttribute("SystemDataType", type.ToString(), (IXMLDOMElement)node);
                            }
                        }
                    }
                }

                //this.XMLParser.AddChildFromString("UID", this._Uid.ToString(), this.XMLParser.documentElement);
                //this.XMLParser.AddChildFromString("ID", this._ID.ToString(), this.XMLParser.documentElement);
                //if (this._Description != null) this.XMLParser.AddChildFromString("Description", this._Description.ToString(), this.XMLParser.documentElement);
                //this.XMLParser.AddChildFromString("RowIDInList", this._RowIDInList.ToString(), this.XMLParser.documentElement);

                return(this.XMLParser.xml);
            }
            catch
            {
                throw;
            }
            return(null);
        }