/// <summary> /// Registers all online marketing methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("LastActivityOfType", LastActivityOfType, typeof(ActivityInfo), "Returns contact's last activity of specified activity type.", GetMethodFormat("LastActivityOfType"), 2, new object[, ] { { "Contact", typeof(object), "Contact info object." }, { "activityType", typeof(string), "Name of the activity type, optional." } }, null, new List <Type>() { typeof(ContactInfo) }); MacroMethods.RegisterMethod("FirstActivityOfType", FirstActivityOfType, typeof(ActivityInfo), "Returns contact's first activity of specified activity type.", GetMethodFormat("FirstActivityOfType"), 2, new object[, ] { { "Contact", typeof(object), "Contact info object." }, { "activityType", typeof(string), "Name of the activity type, optional." } }, null, new List <Type>() { typeof(ContactInfo) }); MacroMethods.RegisterMethod("IsInContactGroup", IsInContactGroup, typeof(bool), "Returns true if contact is in contact group.", GetMethodFormat("IsInContactGroup"), 2, new object[, ] { { "Contact", typeof(object), "Contact info object." }, { "groupName", typeof(string), "Name of the contact group to test whether contact is in." } }, null, new List <Type>() { typeof(ContactInfo) }); MacroMethods.RegisterMethod("GetScore", GetScore, typeof(int), "Returns contact's points in specified score on current site.", GetMethodFormat("GetScore"), 2, new object[, ] { { "Contact", typeof(object), "Contact info object." }, { "scoreName", typeof(string), "Name of the score to get contact's points of." } }, null, new List <Type>() { typeof(ContactInfo) }); MacroMethods.RegisterMethod("GetEmailDomain", GetEmailDomain, typeof(string), "Returns e-mail domain name.", GetMethodFormat("GetEmailDomain"), 1, new object[, ] { { "email", typeof(string), "E-mail address." } }, null, null); }
/// <summary> /// Registers all media library methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("GetMediaFileUrl", GetMediaFileUrl, typeof(string), "Returns direct URL to the media file, user permissions are not checked.", GetMethodFormat("GetMediaFileUrl"), 5, new object[, ] { { "libraryId", typeof(object), "Media library ID." }, { "filePath", typeof(object), "File path." }, { "fileGuid", typeof(object), "File GUID." }, { "fileName", typeof(object), "File name." }, { "useSecureLinks", typeof(object), "Determines whether to generate secure link." }, { "downloadlink", typeof(object), "Determines whether disposition parametr should be added to permanent link." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetMediaFileUrlWithCheck", GetMediaFileUrlWithCheck, typeof(string), "Returns URL to media file which is rewritten to calling GetMediaFile.aspx page where user permissions are checked.", GetMethodFormat("GetMediaFileUrlWithCheck"), 2, new object[, ] { { "fileGuid", typeof(object), "File GUID." }, { "fileName", typeof(object), "File name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetMediaFileDirectUrl", GetMediaFileDirectUrl, typeof(string), "Returns direct URL to the media file, user permissions are not checked.", GetMethodFormat("GetMediaFileDirectUrl"), 2, new object[, ] { { "libraryId", typeof(object), "Media library ID." }, { "filePath", typeof(object), "File path." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetMediaFileDetailUrl", GetMediaFileDetailUrl, typeof(string), "Returns URL to detail of media file.", GetMethodFormat("GetMediaFileDetailUrl"), 1, new object[, ] { { "fileId", typeof(object), "File ID." }, { "parameter", typeof(string), "Query parameter name (\"fileId\" by default)." } }, null, new List <Type>() { typeof(TransformationNamespace) }); }
/// <summary> /// Registers all blog methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("GetUserName", GetUserName, typeof(string), "Returns user name.", GetMethodFormat("GetUserName"), 1, new object[, ] { { "userId", typeof(object), "User ID." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetUserFullName", GetUserFullName, typeof(string), "Returns user full name.", GetMethodFormat("GetUserFullName"), 1, new object[, ] { { "userId", typeof(object), "User ID." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetBlogCommentsCount", GetBlogCommentsCount, typeof(int), "Returns number of comments of given blog.", GetMethodFormat("GetBlogCommentsCount"), 2, new object[, ] { { "postId", typeof(object), "Post document ID." }, { "postAliasPath", typeof(object), "Post alias path." }, { "includingTrackbacks", typeof(bool), "Indicates if trackback comments should be included (true by default)." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetDocumentTags", GetDocumentTags, typeof(string), "Gets a list of links of tags assigned for the specific document pointing to the page with URL specified.", GetMethodFormat("GetDocumentTags"), 3, new object[, ] { { "documentGroupId", typeof(object), "ID of the group document tags belong to." }, { "documentTags", typeof(object), "String containing all the tags related to the document." }, { "documentListPageUrl", typeof(string), "URL of the page displaying other documents of the specified tag." } }, null, new List <Type>() { typeof(TransformationNamespace) }); }
/// <summary> /// Registers all translation services methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get user name MacroMethod isTranslationReady = new MacroMethod("IsTranslationReady", IsTranslationReady) { Comment = "Returns true if there is at least one translation submission item with target XLIFF ready to import.", Type = typeof(bool), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(CMS.DocumentEngine.TreeNode), typeof(DocumentInfo) } }; isTranslationReady.AddParameter("document", typeof(CMS.DocumentEngine.TreeNode), "Document to check."); MacroMethods.RegisterMethod(isTranslationReady); MacroMethod getTranslationPriority = new MacroMethod("GetTranslationPriority", GetTranslationPriority) { Comment = "Returns priority name from priority integer constant.", Type = typeof(string), MinimumParameters = 1, }; getTranslationPriority.AddParameter("priorty", typeof(int), "Priority integer constant."); MacroMethods.RegisterMethod(getTranslationPriority); }
/// <summary> /// Registers all workflow methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethod passedThroughActions = new MacroMethod("PassedThroughActions", PassedThroughActions) { Comment = "Returns true if document passed through specified actions.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; passedThroughActions.AddParameter("document", typeof(TreeNode), "Document to check."); passedThroughActions.AddParameter("actions", typeof(string), "Action names separated with a semicolon"); passedThroughActions.AddParameter("allActions", typeof(string), "If true, document must have passed through all specified actions. One of them is sufficient otherwise."); MacroMethods.RegisterMethod(passedThroughActions); MacroMethod passedThroughSteps = new MacroMethod("PassedThroughSteps", PassedThroughSteps) { Comment = "Returns true if document passed through specified tags.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; passedThroughSteps.AddParameter("document", typeof(TreeNode), "Document to check."); passedThroughSteps.AddParameter("steps", typeof(string), "Step names separated with a semicolon"); passedThroughSteps.AddParameter("allSteps", typeof(bool), "If true, document must have passed through all specified steps. One of them is sufficient otherwise."); MacroMethods.RegisterMethod(passedThroughSteps); }
/// <summary> /// Registers all forum methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("GetPostURL", GetPostURL, typeof(string), "Returns link to selected post.", GetMethodFormat("GetPostURL"), 2, new object[, ] { { "postIdPath", typeof(object), "Post ID path." }, { "forumId", typeof(object), "Forum ID." }, { "aliasPath", typeof(object), "Alias path." } }, null, new List <Type>() { typeof(TransformationNamespace) }); }
/// <summary> /// Initializes the system. /// </summary> public static void Init() { // Init CMS environment CMSContext.Init(mAsyncInit); // Register the events RegisterEvents(); // Register module methods and transformation methods to macro resolver CMSModuleLoader loader = new CMSModuleLoader(); loader.RegisterTransformationMethods(); MacroMethods.RegisterMethods(); CMSMacroMethods.RegisterMethods(); }
/// <summary> /// Initializes the system. /// </summary> public static void Init() { // Init CMS environment CMSContext.Init(mAsyncInit); // Register the events RegisterEvents(); // Register module methods and transformation methods to macro resolver CMSModuleLoader.InitializeModules(); MacroMethods.RegisterMethods(); CMSMacroMethods.RegisterMethods(); TransformationMacroMethods.RegisterMethods(); Functions.RegisterUniGridTransformations(); }
/// <summary> /// Registers all forum methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get post URL MacroMethod getPostURL = new MacroMethod("GetPostURL", GetPostURL) { Comment = "Returns link to selected post.", Type = typeof(string), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getPostURL.AddParameter("postIdPath", typeof(object), "Post ID path."); getPostURL.AddParameter("forumId", typeof(object), "Forum ID."); getPostURL.AddParameter("aliasPath", typeof(object), "Alias path."); MacroMethods.RegisterMethod(getPostURL); }
/// <summary> /// Registers all blog methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get user name MacroMethod getBoardMessagesCount = new MacroMethod("GetBoardMessagesCount", GetBoardMessagesCount) { Comment = "Returns count of messages in messageboard.", Type = typeof(int), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getBoardMessagesCount.AddParameter("documentId", typeof(int), "ID of the document."); getBoardMessagesCount.AddParameter("boardWebpartName", typeof(object), "Name of the webpart used for creating messageboard."); getBoardMessagesCount.AddParameter("type", typeof(object), "String constant representing the type of board 'user', 'group' or 'document' (default) are accepted."); MacroMethods.RegisterMethod(getBoardMessagesCount); }
/// <summary> /// Registers all blog methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("MyMethod", MyMethod, typeof(string), "Returns concatenation of two strings.", null, 1, new object[, ] { { "param1", typeof(string), "First string to concatenate." }, { "param2", typeof(string), "Second string to concatenate." } }, null); MacroMethods.RegisterMethod("MyMethodSnippet", MyMethod, typeof(string), "Calls MyMethod on lower case current user name.", null, 0, null, null, new List <Type>() { typeof(string) }, "MyMethod(ToLower(CurrentDocument.DocumentName), |);", false); // Call MacroMethods.RegisterMethod for your own custom methods here with following parameters: // 1. parameter: Method name // 2. parameter: Method delegate (wrapper method) // 3. parameter: Return type of the method // 4. parameter: Comment for the method // 5. parameter: Formatting string for "human readable" translation of the method call (optional, you do not have to specify this) // 6. parameter: Minimal number of parameters needed to call the method (mimimal overload) // 7. parameter: Parameter definition in format {{name, type, comment}, {name, type, comment}} // 8. parameter: A list of special parameters needed to be supplied by resolver (these parameters are automatically passed by MacroResolver as the first parameters to the wrapper method) // 9. parameter: List of types for which the method is applicable (set to null for all types to be allowed) // 10. parameter: Code snippet which is used in AutoCompletion when TAB is pressed (for determining the cursor position use pipe) }
/// <summary> /// Registers all web analytics methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethod isReturningVisitor = new MacroMethod("IsReturningVisitor", IsReturningVisitor) { Comment = "Returns true if current visitor is returning.", Type = typeof(bool), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; MacroMethods.RegisterMethod(isReturningVisitor); MacroMethod isFirstTimeVisitor = new MacroMethod("IsFirstTimeVisitor", IsFirstTimeVisitor) { Comment = "Returns true if current visitor comes to the website for the first time.", Type = typeof(bool), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; MacroMethods.RegisterMethod(isFirstTimeVisitor); MacroMethod getSearchEngineKeyword = new MacroMethod("GetSearchEngineKeyword", GetSearchEngineKeyword) { Comment = "Returns search keywords from search engine visitor came from.", Type = typeof(string), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; MacroMethods.RegisterMethod(getSearchEngineKeyword); MacroMethod getSearchEngine = new MacroMethod("GetSearchEngine", GetSearchEngine) { Comment = "Returns search engine visitor came from.", Type = typeof(string), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; MacroMethods.RegisterMethod(getSearchEngine); MacroMethod getUrlReferrer = new MacroMethod("GetUrlReferrer", GetUrlReferrer) { Comment = "Returns absolute URI of the URLRefferer from current HTTP context.", Type = typeof(string), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; MacroMethods.RegisterMethod(getUrlReferrer); MacroMethod getUrlReferrerParameter = new MacroMethod("GetUrlReferrerParameter", GetUrlReferrerParameter) { Comment = "Returns value of specified URLReferrer query string parameter.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; getUrlReferrerParameter.AddParameter("parameterName", typeof(string), "Query string parameter name."); MacroMethods.RegisterMethod(getUrlReferrerParameter); MacroMethod getCurrentDistance = new MacroMethod("GetCurrentDistance", GetCurrentDistance) { Comment = "Returns current distance (in kilometers) from specified location (based on Geo IP).", Type = typeof(double), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(VisitorNamespace) } }; getCurrentDistance.AddParameter("latitude", typeof(double), "Latitude of the place."); getCurrentDistance.AddParameter("longitude", typeof(double), "Longitude of the place."); MacroMethods.RegisterMethod(getCurrentDistance); }
/// <summary> /// Registers all ecommerce methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get add to shopping cart link MacroMethod getAddToShoppingCartLink = new MacroMethod("GetAddToShoppingCartLink", GetAddToShoppingCartLink) { Comment = "Returns link to \"add to shoppingcart\".", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getAddToShoppingCartLink.AddParameter("productId", typeof(object), "Product ID."); getAddToShoppingCartLink.AddParameter("enabled", typeof(object), "Indicates whether product is enabled or not."); MacroMethods.RegisterMethod(getAddToShoppingCartLink); // Get add to wishlist link MacroMethod getAddToWishListLink = new MacroMethod("GetAddToWishListLink", GetAddToWishListLink) { Comment = "Returns link to add specified product to the user's wishlist.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getAddToWishListLink.AddParameter("productId", typeof(object), "Product ID."); MacroMethods.RegisterMethod(getAddToWishListLink); // Get remove from wishlist link MacroMethod getRemoveFromWishListLink = new MacroMethod("GetRemoveFromWishListLink", GetRemoveFromWishListLink) { Comment = "Returns link to remove specified product from the user's wishlist.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getRemoveFromWishListLink.AddParameter("productId", typeof(object), "Product ID."); MacroMethods.RegisterMethod(getRemoveFromWishListLink); // Get public status name MacroMethod gtPublicStatusName = new MacroMethod("GetPublicStatusName", GetPublicStatusName) { Comment = "Returns the public SKU status display name.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; gtPublicStatusName.AddParameter("statusId", typeof(object), "Status ID"); MacroMethods.RegisterMethod(gtPublicStatusName); // Get shopping cart URL MacroMethod shoppingCartURL = new MacroMethod("ShoppingCartURL", ShoppingCartURL) { Comment = "Returns URL to the shopping cart.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; shoppingCartURL.AddParameter("siteName", typeof(string), "Site name."); MacroMethods.RegisterMethod(shoppingCartURL); // Get wishlist URL MacroMethod wishlistURL = new MacroMethod("WishlistURL", WishlistURL) { Comment = "Returns URL to the wish list.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; wishlistURL.AddParameter("siteName", typeof(string), "Site name"); MacroMethods.RegisterMethod(wishlistURL); // Get product URL MacroMethod getProductUrl = new MacroMethod("GetProductUrl", GetProductUrl) { Comment = "Returns product URL.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getProductUrl.AddParameter("skuId", typeof(object), "SKU ID."); MacroMethods.RegisterMethod(getProductUrl); // Get product URL by GUID MacroMethod getProductUrlByGUID = new MacroMethod("GetProductUrlByGUID", GetProductUrlByGUID) { Comment = "Returns user friendly URL of the specified SKU.", Type = typeof(string), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getProductUrlByGUID.AddParameter("skuGuid", typeof(object), "SKU GUID."); getProductUrlByGUID.AddParameter("skuName", typeof(object), "SKU name."); getProductUrlByGUID.AddParameter("siteName", typeof(object), "Site name."); MacroMethods.RegisterMethod(getProductUrlByGUID); // Get manufacturer MacroMethod getManufacturer = new MacroMethod("GetManufacturer", GetManufacturer) { Comment = "Gets object from the specified column of the manufacturer with specific ID.", Type = typeof(object), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getManufacturer.AddParameter("id", typeof(int), "Manufacturer ID."); getManufacturer.AddParameter("column", typeof(string), "Column name."); MacroMethods.RegisterMethod(getManufacturer); // Get department MacroMethod getDepartment = new MacroMethod("GetDepartment", GetDepartment) { Comment = "Gets object from the specified column of the department with specific ID.", Type = typeof(object), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getDepartment.AddParameter("id", typeof(int), "Department ID."); getDepartment.AddParameter("column", typeof(string), "Column name."); MacroMethods.RegisterMethod(getDepartment); // Get supplier MacroMethod getSupplier = new MacroMethod("GetSupplier", GetSupplier) { Comment = "Gets object from the specified column of the supplier with specific ID.", Type = typeof(object), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getSupplier.AddParameter("id", typeof(int), "Supplier ID."); getSupplier.AddParameter("column", typeof(string), "Column name."); MacroMethods.RegisterMethod(getSupplier); // Get internal status MacroMethod getInternalStatus = new MacroMethod("GetInternalStatus", GetInternalStatus) { Comment = "Gets object from the specified column of the internal status with specific ID.", Type = typeof(object), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getInternalStatus.AddParameter("id", typeof(int), "Internal status ID."); getInternalStatus.AddParameter("column", typeof(string), "Column name."); MacroMethods.RegisterMethod(getInternalStatus); // Get public status MacroMethod getPublicStatus = new MacroMethod("GetPublicStatus", GetPublicStatus) { Comment = "Gets object from the specified column of the public status with specific ID.", Type = typeof(object), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getPublicStatus.AddParameter("id", typeof(int), "Public status ID."); getPublicStatus.AddParameter("column", typeof(string), "Column name."); MacroMethods.RegisterMethod(getPublicStatus); // Get product image MacroMethod getProductImage = new MacroMethod("GetProductImage", GetProductImage) { Comment = "Returns complete HTML code of the specified resized product image, if not such image exists, default image is returned.", Type = typeof(string), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getProductImage.AddParameter("imageUrl", typeof(object), "Product image url."); getProductImage.AddParameter("alt", typeof(object), "Image alternate text."); getProductImage.AddParameter("maxSideSize", typeof(object), "Max side size of the image."); getProductImage.AddParameter("width", typeof(object), "Width of the image."); getProductImage.AddParameter("height", typeof(object), "Height of the image."); MacroMethods.RegisterMethod(getProductImage); // Format price MacroMethod formatPrice = new MacroMethod("FormatPrice", FormatPrice) { Comment = "Returns price rounded and formatted according to the current currency properties.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; formatPrice.AddParameter("price", typeof(double), "Price to be formatted"); formatPrice.AddParameter("round", typeof(bool), "True - price is rounded according to the current currency settings before formatting"); MacroMethods.RegisterMethod(formatPrice); // Cart items count MacroMethod getShoppingCartItemsCount = new MacroMethod("GetShoppingCartItemsCount", GetShoppingCartItemsCount) { Comment = "Returns number of products in current shopping cart.", Type = typeof(int), MinimumParameters = 0, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; MacroMethods.RegisterMethod(getShoppingCartItemsCount); }
/// <summary> /// Returns list of possible hints. /// </summary> /// <param name="tokens">Lexems from lexical analysis</param> /// <param name="currentElement">Current lexem</param> /// <param name="currentElementIndex">Index of the current lexem</param> /// <param name="previousLines">Previous lines to get previous variable declarations</param> private string GetHints(List <MacroElement> tokens, MacroElement currentElement, int currentElementIndex, string previousLines, List <string> inlineVariables) { // Get lists with methods and properties List <string> members = new List <string>(); string dataMemeberContext = ""; object obj = null; List <string> dataProperties = new List <string>(); if (currentElement == null) { GetPropertiesFromContext(members, null, ""); } else { // Properties autocomplete bool showAllProperties = false; if ((currentElement.Type == ElementType.LeftBracket) || (currentElement.Type == ElementType.LeftIndexer) || (currentElement.Type == ElementType.BlockStart) || (currentElement.Type == ElementType.BlockEnd) || (currentElement.Type == ElementType.Comma)) { showAllProperties = true; } if (!showAllProperties) { // We need to find current datamember context int brackets = 0; for (int i = currentElementIndex - 1; i >= 0; i--) { ElementType type = tokens[i].Type; if (brackets == 0) { // We need to take context to the left side of current lexem // It needs to preserve the structure (deepnes withing the brackets) if ((type == ElementType.Comma) || (type == ElementType.Operator) || (type == ElementType.LeftBracket) || (type == ElementType.LeftIndexer)) { break; } } // Append this part dataMemeberContext = tokens[i].Expression + dataMemeberContext; // Ensure correct deepnes within the brackets if ((type == ElementType.RightBracket) || (type == ElementType.RightIndexer)) { brackets++; } else if ((type == ElementType.LeftBracket) || (type == ElementType.LeftIndexer)) { brackets--; } } dataMemeberContext = dataMemeberContext.TrimEnd('.'); } // Analyze code before current line to find variable declarations (makes sense only for root hints - i.e. datamember context is empty) if (string.IsNullOrEmpty(dataMemeberContext)) { List <MacroElement> vartokens = MacroElement.ParseExpression(previousLines, true); List <string> variables = new List <string>(); for (int i = 0; i < vartokens.Count; i++) { MacroElement el = vartokens[i]; if ((el.Type == ElementType.Operator) && (el.Expression == "=") && (i > 0)) { // Add variable declaration to special fields MacroElement elPrev = vartokens[i - 1]; if (elPrev.Type == ElementType.Identifier) { variables.Add(elPrev.Expression); } } } // Add variables members.AddRange(variables); members.AddRange(inlineVariables); } obj = GetPropertiesFromContext(members, dataProperties, dataMemeberContext); } // Add proper methods if (string.IsNullOrEmpty(dataMemeberContext)) { // Add commands only for empty contexts members.AddRange(CommandsList); // Add namespaces objects members.Add("Math"); members.Add("Transformation"); members.Add("Countries"); // List of methods for any type FillFromMethodList(members, MacroMethods.GetMethodsForObject(null)); } else { if (obj == null) { // If the object is null we will offer string methods because these are the most common methods obj = ""; } // Get the list of suitable methods for resulting type FillFromMethodList(members, MacroMethods.GetMethodsForObject(obj)); } // Add methods which belongs to permanently registered namespaces members.AddRange(UsingList); // Sort everything members.Sort(); // Add data properties at the end if (dataProperties.Count > 0) { members.Add("----"); members.AddRange(dataProperties); } // Remove duplicities List <string> finalList = new List <string>(); foreach (string member in members) { if (!finalList.Contains(member)) { finalList.Add(member); } } StringBuilder sb = new StringBuilder(); foreach (string member in finalList) { sb.Append("$" + member); } return(sb.ToString().TrimStart('$')); }
/// <summary> /// Registers all ecommerce methods to macro resolver. /// </summary> public static void RegisterMethods() { MacroMethods.RegisterMethod("GetAddToShoppingCartLink", GetAddToShoppingCartLink, typeof(string), "Returns link to \"add to shoppingcart\".", GetMethodFormat("GetAddToShoppingCartLink"), 1, new object[, ] { { "productId", typeof(object), "Product ID." }, { "enabled", typeof(object), "Indicates whether product is enabled or not." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetAddToWishListLink", GetAddToWishListLink, typeof(string), "Returns link to add specified product to the user's wishlist.", GetMethodFormat("GetAddToWishListLink"), 1, new object[, ] { { "productId", typeof(object), "Product ID." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetRemoveFromWishListLink", GetRemoveFromWishListLink, typeof(string), "Returns link to remove specified product from the user's wishlist.", GetMethodFormat("GetRemoveFromWishListLink"), 1, new object[, ] { { "productId", typeof(object), "Product ID." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetPublicStatusName", GetPublicStatusName, typeof(string), "Returns the public SKU status display name.", GetMethodFormat("GetPublicStatusName"), 1, new object[, ] { { "statusId", typeof(object), "Status ID" } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("ShoppingCartURL", ShoppingCartURL, typeof(string), "Returns URL to the shopping cart.", GetMethodFormat("ShoppingCartURL"), 1, new object[, ] { { "siteName", typeof(string), "Site name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("WishlistURL", WishlistURL, typeof(string), "Returns URL to the wish list.", GetMethodFormat("WishlistURL"), 1, new object[, ] { { "siteName", typeof(string), "Site name" } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetProductUrl", GetProductUrl, typeof(string), "Returns product URL.", GetMethodFormat("GetProductUrl"), 1, new object[, ] { { "skuId", typeof(object), "SKU ID." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetProductUrlByGUID", GetProductUrlByGUID, typeof(string), "Returns user friendly URL of the specified SKU.", GetMethodFormat("GetProductUrlByGUID"), 2, new object[, ] { { "skuGuid", typeof(object), "SKU GUID." }, { "skuName", typeof(object), "SKU name." }, { "siteName", typeof(object), "Site name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetManufacturer", GetManufacturer, typeof(object), "Gets object from the specified column of the manufacturer with specific ID.", GetMethodFormat("GetManufacturer"), 2, new object[, ] { { "Id", typeof(object), "Manufacturer ID." }, { "column", typeof(string), "Column name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetDepartment", GetDepartment, typeof(object), "Gets object from the specified column of the department with specific ID.", GetMethodFormat("GetDepartment"), 2, new object[, ] { { "Id", typeof(object), "Department ID." }, { "column", typeof(string), "Column name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetSupplier", GetSupplier, typeof(object), "Gets object from the specified column of the supplier with specific ID.", GetMethodFormat("GetSupplier"), 2, new object[, ] { { "Id", typeof(object), "Supplier ID." }, { "column", typeof(string), "Column name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetInternalStatus", GetInternalStatus, typeof(object), "Gets object from the specified column of the internal status with specific ID.", GetMethodFormat("GetInternalStatus"), 2, new object[, ] { { "Id", typeof(object), "Internal status ID." }, { "column", typeof(string), "Column name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetPublicStatus", GetPublicStatus, typeof(object), "Gets object from the specified column of the public status with specific ID.", GetMethodFormat("GetPublicStatus"), 2, new object[, ] { { "Id", typeof(object), "Public status ID." }, { "column", typeof(string), "Column name." } }, null, new List <Type>() { typeof(TransformationNamespace) }); MacroMethods.RegisterMethod("GetProductImage", GetProductImage, typeof(string), "Returns complete HTML code of the specified resized product image, if not such image exists, default image is returned.", GetMethodFormat("GetProductImage"), 2, new object[, ] { { "imageUrl", typeof(object), "Product image url." }, { "alt", typeof(object), "Image alternate text." }, { "maxSideSize", typeof(object), "Max side size of the image." }, { "width", typeof(object), "Width of the image." }, { "height", typeof(object), "Height of the image." } }, null, new List <Type>() { typeof(TransformationNamespace) }); }
/// <summary> /// Registers all media library methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get media file URL MacroMethod getMediaFileUrl = new MacroMethod("GetMediaFileUrl", GetMediaFileUrl) { Comment = "Returns direct URL to the media file, user permissions are not checked.", Type = typeof(string), MinimumParameters = 5, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getMediaFileUrl.AddParameter("libraryId", typeof(object), "Media library ID."); getMediaFileUrl.AddParameter("filePath", typeof(object), "File path."); getMediaFileUrl.AddParameter("fileGuid", typeof(object), "File GUID."); getMediaFileUrl.AddParameter("fileName", typeof(object), "File name."); getMediaFileUrl.AddParameter("useSecureLinks", typeof(object), "Determines whether to generate secure link."); getMediaFileUrl.AddParameter("downloadlink", typeof(object), "Determines whether disposition parametr should be added to permanent link."); MacroMethods.RegisterMethod(getMediaFileUrl); // Get media file URL with check MacroMethod getMediaFileUrlWithCheck = new MacroMethod("GetMediaFileUrlWithCheck", GetMediaFileUrlWithCheck) { Comment = "Returns URL to media file which is rewritten to calling GetMediaFile.aspx page where user permissions are checked.", Type = typeof(string), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getMediaFileUrlWithCheck.AddParameter("fileGuid", typeof(object), "File GUID."); getMediaFileUrlWithCheck.AddParameter("fileName", typeof(object), "File name."); MacroMethods.RegisterMethod(getMediaFileUrlWithCheck); // Get media file direct URL MacroMethod getMediaFileDirectUrl = new MacroMethod("GetMediaFileDirectUrl", GetMediaFileDirectUrl) { Comment = "Returns direct URL to the media file, user permissions are not checked.", Type = typeof(string), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getMediaFileDirectUrl.AddParameter("libraryId", typeof(object), "Media library ID."); getMediaFileDirectUrl.AddParameter("filePath", typeof(object), "File path."); MacroMethods.RegisterMethod(getMediaFileDirectUrl); // Get media file detail URL MacroMethod getMediaFileDetailUrl = new MacroMethod("GetMediaFileDetailUrl", GetMediaFileDetailUrl) { Comment = "Returns URL to detail of media file.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getMediaFileDetailUrl.AddParameter("fileId", typeof(object), "File ID."); getMediaFileDetailUrl.AddParameter("parameter", typeof(string), "Query parameter name (\"fileId\" by default)."); MacroMethods.RegisterMethod(getMediaFileDetailUrl); }
/// <summary> /// Registers all online marketing methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get e-mail domain method MacroMethod getEmailDomain = new MacroMethod("GetEmailDomain", GetEmailDomain) { Comment = "Returns e-mail domain name.", Type = typeof(string), MinimumParameters = 1 }; getEmailDomain.AddParameter("email", typeof(string), "E-mail address."); MacroMethods.RegisterMethod(getEmailDomain); // Get score method MacroMethod getScore = new MacroMethod("GetScore", GetScore) { Comment = "Returns contact's points in specified score on current site.", Type = typeof(int), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; getScore.AddParameter("contact", typeof(object), "Contact info object."); getScore.AddParameter("scoreName", typeof(string), "Name of the score to get contact's points of."); MacroMethods.RegisterMethod(getScore); // Is in contact group method MacroMethod isInContactGroup = new MacroMethod("IsInContactGroup", IsInContactGroup) { Comment = "Returns true if contact is in contact group.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; isInContactGroup.AddParameter("contact", typeof(object), "Contact info object."); isInContactGroup.AddParameter("groupNames", typeof(string), "Name of the contact group(s) separated by semicolon to test whether contact is in."); isInContactGroup.AddParameter("allGroups", typeof(bool), "If true contact has to be in all specified groups, if false, it is sufficient if the contact is in any of the specified groups."); MacroMethods.RegisterMethod(isInContactGroup); // First activity of type method MacroMethod firstActivityOfType = new MacroMethod("FirstActivityOfType", FirstActivityOfType) { Comment = "Returns contact's first activity of specified activity type.", Type = typeof(ActivityInfo), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; firstActivityOfType.AddParameter("contact", typeof(object), "Contact info object."); firstActivityOfType.AddParameter("activityType", typeof(string), "Name of the activity type, optional."); MacroMethods.RegisterMethod(firstActivityOfType); // Last activity of type method MacroMethod lastActivityOfType = new MacroMethod("LastActivityOfType", LastActivityOfType) { Comment = "Returns contact's last activity of specified activity type.", Type = typeof(ActivityInfo), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; lastActivityOfType.AddParameter("contact", typeof(object), "Contact info object."); lastActivityOfType.AddParameter("activityType", typeof(string), "Name of the activity type, optional."); MacroMethods.RegisterMethod(lastActivityOfType); MacroMethod belongsToAccount = new MacroMethod("BelongsToAccount", BelongsToAccount) { Comment = "Returns true if the contact belongs to the specified account.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; belongsToAccount.AddParameter("contact", typeof(object), "Contact info object."); belongsToAccount.AddParameter("accountID", typeof(int), "ID of the account."); MacroMethods.RegisterMethod(belongsToAccount); MacroMethod cameToLandingPage = new MacroMethod("CameToLandingPage", CameToLandingPage) { Comment = "Returns true if the contact came to specified landing page.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; cameToLandingPage.AddParameter("contact", typeof(object), "Contact info object."); cameToLandingPage.AddParameter("page", typeof(string), "Node ID or node alias path of the landing page."); MacroMethods.RegisterMethod(cameToLandingPage); MacroMethod didActivity = new MacroMethod("DidActivity", DidActivity) { Comment = "Returns true if the contact did a specified activity.", Type = typeof(bool), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; didActivity.AddParameter("contact", typeof(object), "Contact info object."); didActivity.AddParameter("activityType", typeof(string), "Name of the activity to check."); didActivity.AddParameter("cancelActivityType", typeof(string), "Name of the activity which cancels the original activity (for example UnsubscribeNewsletter is a cancelling event for SubscribeNewsletter etc.)."); didActivity.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); didActivity.AddParameter("whereCondition", typeof(string), "Additional WHERE condition."); MacroMethods.RegisterMethod(didActivity); MacroMethod didActivities = new MacroMethod("DidActivities", DidActivities) { Comment = "Returns true if the contact did any/all of the specified activities.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; didActivities.AddParameter("contact", typeof(object), "Contact info object."); didActivities.AddParameter("activityTypes", typeof(string), "Name of the activity(ies) to check separated with semicolon."); didActivities.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); didActivities.AddParameter("allActivities", typeof(string), "If true, all specified types has to be found for the method to return true. If false, at least one of any specified types is sufficient to retrun true for the method."); MacroMethods.RegisterMethod(didActivities); MacroMethod isFromCountry = new MacroMethod("IsFromCountry", IsFromCountry) { Comment = "Returns true if the contact's country matches one of the specified countries.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; isFromCountry.AddParameter("contact", typeof(object), "Contact info object."); isFromCountry.AddParameter("countryList", typeof(string), "List of country names separated with semicolon."); MacroMethods.RegisterMethod(isFromCountry); MacroMethod isFromState = new MacroMethod("IsFromState", IsFromState) { Comment = "Returns true if the contact's state matches one of the specified state.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; isFromState.AddParameter("contact", typeof(object), "Contact info object."); isFromState.AddParameter("stateList", typeof(string), "List of state names separated with semicolon."); MacroMethods.RegisterMethod(isFromState); MacroMethod searchedForKeywords = new MacroMethod("SearchedForKeywords", SearchedForKeywords) { Comment = "Returns true if the contact did search for specified keywords in last X days.", Type = typeof(bool), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; searchedForKeywords.AddParameter("contact", typeof(object), "Contact info object."); searchedForKeywords.AddParameter("keywords", typeof(string), "Keywords separated with comma or semicolon (if null or empty, than method returns true iff contact did any search in last X days)."); searchedForKeywords.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); searchedForKeywords.AddParameter("op", typeof(string), "Operator to be used in WHERE condition (use AND for all keywords match, use OR for any keword match)."); MacroMethods.RegisterMethod(searchedForKeywords); MacroMethod spentMoney = new MacroMethod("SpentMoney", SpentMoney) { Comment = "Returns true if the contact spent specified amount of money (counted by order total price in main currency) in last X days.", Type = typeof(bool), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; spentMoney.AddParameter("contact", typeof(object), "Contact info object."); spentMoney.AddParameter("lowerBound", typeof(double), "Inclusive lower bound of the amount of money (in main currency) spent by contact."); spentMoney.AddParameter("upperBound", typeof(double), "Inclusive upper bound of the amount of money (in main currency) spent by contact."); spentMoney.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(spentMoney); MacroMethod purchasedNumberOfProducts = new MacroMethod("PurchasedNumberOfProducts", PurchasedNumberOfProducts) { Comment = "Returns true if the contact purchased specified number of products in last X days.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; purchasedNumberOfProducts.AddParameter("contact", typeof(object), "Contact info object."); purchasedNumberOfProducts.AddParameter("lowerBound", typeof(int), "Inclusive lower bound of the number of products bought."); purchasedNumberOfProducts.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(purchasedNumberOfProducts); MacroMethod isInRoles = new MacroMethod("IsInRoles", IsInRoles) { Comment = "Returns true if the contact is in any/all of the specified roles (i.e. if any of the user assigned to the contact is in any/all specified roles).", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; isInRoles.AddParameter("contact", typeof(object), "Contact info object."); isInRoles.AddParameter("roleNames", typeof(string), "Name of the roles separated with semicolon."); isInRoles.AddParameter("allRoles", typeof(bool), "If true, contact has to in all specified roles. If false, it is sufficient if the contact is at least in one of the roles."); MacroMethods.RegisterMethod(isInRoles); MacroMethod isInCommunityGroup = new MacroMethod("IsInCommunityGroup", IsInCommunityGroup) { Comment = "Returns true if the contact is in any/all of the specified community groups (i.e. if any of the user assigned to the contact is in any/all specified community groups).", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; isInCommunityGroup.AddParameter("contact", typeof(object), "Contact info object."); isInCommunityGroup.AddParameter("groupNames", typeof(string), "Name of the groups separated with semicolon."); isInCommunityGroup.AddParameter("allGroups", typeof(bool), "If true, contact has to in all specified groups. If false, it is sufficient if the contact is at least in one of the groups."); MacroMethods.RegisterMethod(isInCommunityGroup); MacroMethod visitedPage = new MacroMethod("VisitedPage", VisitedPage) { Comment = "Returns true if the contact visited specified page.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; visitedPage.AddParameter("contact", typeof(object), "Contact info object."); visitedPage.AddParameter("nodeAliasPath", typeof(string), "Page node alias path."); visitedPage.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(visitedPage); MacroMethod submittedForm = new MacroMethod("SubmittedForm", SubmittedForm) { Comment = "Returns true if the contact submitted specified form.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; submittedForm.AddParameter("contact", typeof(object), "Contact info object."); submittedForm.AddParameter("formName", typeof(string), "Name of the on-line form."); submittedForm.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(submittedForm); MacroMethod openedNewsletter = new MacroMethod("OpenedNewsletter", OpenedNewsletter) { Comment = "Returns true if the contact opened specified newsletter.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; openedNewsletter.AddParameter("contact", typeof(object), "Contact info object."); openedNewsletter.AddParameter("newsletterName", typeof(string), "Newsletter name"); openedNewsletter.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(openedNewsletter); MacroMethod openedNewsletterIssue = new MacroMethod("OpenedNewsletterIssue", OpenedNewsletterIssue) { Comment = "Returns true if the contact opened specified newsletter issue.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; openedNewsletterIssue.AddParameter("contact", typeof(object), "Contact info object."); openedNewsletterIssue.AddParameter("issueGuid", typeof(Guid), "Newsletter issue GUID."); openedNewsletterIssue.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(openedNewsletterIssue); MacroMethod votedInPoll = new MacroMethod("VotedInPoll", VotedInPoll) { Comment = "Returns true if the contact voted in the poll.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; votedInPoll.AddParameter("contact", typeof(object), "Contact info object."); votedInPoll.AddParameter("pollName", typeof(string), "Poll name."); votedInPoll.AddParameter("pollAnswer", typeof(string), "Poll answer text."); votedInPoll.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(votedInPoll); MacroMethod loggedIn = new MacroMethod("LoggedIn", LoggedIn) { Comment = "Returns true if the contact logged in.", Type = typeof(bool), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; loggedIn.AddParameter("contact", typeof(object), "Contact info object."); loggedIn.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(loggedIn); MacroMethod subscribedToNewsletter = new MacroMethod("SubscribedToNewsletter", SubscribedToNewsletter) { Comment = "Returns true if the contact subscribed for specific newsletter.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; subscribedToNewsletter.AddParameter("contact", typeof(object), "Contact info object."); subscribedToNewsletter.AddParameter("newsletterName", typeof(string), "Newsletter name."); subscribedToNewsletter.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(subscribedToNewsletter); MacroMethod registeredForEvent = new MacroMethod("RegisteredForEvent", RegisteredForEvent) { Comment = "Returns true if the contact registered for specific event.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; registeredForEvent.AddParameter("contact", typeof(object), "Contact info object."); visitedPage.AddParameter("nodeAliasPath", typeof(string), "Page node alias path."); registeredForEvent.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(registeredForEvent); MacroMethod clickedLinkInNewsletter = new MacroMethod("ClickedLinkInNewsletter", ClickedLinkInNewsletter) { Comment = "Returns true if the contact clicked link in specified newsletter.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; clickedLinkInNewsletter.AddParameter("contact", typeof(object), "Contact info object."); clickedLinkInNewsletter.AddParameter("newsletterName", typeof(string), "Name of the newsletter."); clickedLinkInNewsletter.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(clickedLinkInNewsletter); MacroMethod clickedLinkInNewsletterIssue = new MacroMethod("ClickedLinkInNewsletterIssue", ClickedLinkInNewsletterIssue) { Comment = "Returns true if the contact clicked link in specified newsletter issue.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; clickedLinkInNewsletterIssue.AddParameter("contact", typeof(object), "Contact info object."); clickedLinkInNewsletterIssue.AddParameter("issueGuid", typeof(Guid), "Newsletter issue GUID."); clickedLinkInNewsletterIssue.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(clickedLinkInNewsletterIssue); MacroMethod purchasedProduct = new MacroMethod("PurchasedProduct", PurchasedProduct) { Comment = "Returns true if the contact purchased specified product.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(ContactInfo) } }; purchasedProduct.AddParameter("contact", typeof(object), "Contact info object."); purchasedProduct.AddParameter("productName", typeof(string), "Name of the product."); purchasedProduct.AddParameter("lastXDays", typeof(int), "Constraint for last X days (if zero or negative value is given, no constraint is applied)."); MacroMethods.RegisterMethod(purchasedProduct); MacroMethod getLastNewsletterIssue = new MacroMethod("GetLastNewsletterIssue", GetLastNewsletterIssue) { Comment = "Returns last newsletter issue that was sent to the contact of the state.", Type = typeof(IssueInfo), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(AutomationStateInfo) } }; getLastNewsletterIssue.AddParameter("state", typeof(AutomationStateInfo), "Process instance to get last newsletter issue from."); MacroMethods.RegisterMethod(getLastNewsletterIssue); MacroMethod linkedToObject = new MacroMethod("LinkedToObject", ActivityLinkedToObject) { Comment = "Returns if activity is linked to given object by GUID or codename.", Type = typeof(bool), MinimumParameters = 3, AllowedTypes = new List <Type>() { typeof(ActivityInfo) } }; linkedToObject.AddParameter("activity", typeof(ActivityInfo), "Activity info object."); linkedToObject.AddParameter("objectType", typeof(string), "Object type."); linkedToObject.AddParameter("objectIdentifier", typeof(string), "Object code name or GUID."); MacroMethods.RegisterMethod(linkedToObject); }
/// <summary> /// Registers all blog methods to macro resolver. /// </summary> public static void RegisterMethods() { // Get user name MacroMethod getUserName = new MacroMethod("GetUserName", GetUserName) { Comment = "Returns user name.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getUserName.AddParameter("userId", typeof(object), "User ID."); MacroMethods.RegisterMethod(getUserName); // Get user full name MacroMethod getUserFullName = new MacroMethod("GetUserFullName", GetUserFullName) { Comment = "Returns user full name.", Type = typeof(string), MinimumParameters = 1, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getUserFullName.AddParameter("userId", typeof(object), "User ID."); MacroMethods.RegisterMethod(getUserFullName); // Get blog comment count MacroMethod getBlogCommentsCount = new MacroMethod("GetBlogCommentsCount", GetBlogCommentsCount) { Comment = "Returns number of comments of given blog.", Type = typeof(int), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getBlogCommentsCount.AddParameter("postId", typeof(object), "Post document ID."); getBlogCommentsCount.AddParameter("postAliasPath", typeof(object), "Post alias path."); getBlogCommentsCount.AddParameter("includingTrackbacks", typeof(bool), "Indicates if trackback comments should be included (true by default)."); MacroMethods.RegisterMethod(getBlogCommentsCount); // Get document tags MacroMethod getDocumentTags = new MacroMethod("GetDocumentTags", GetDocumentTags) { Comment = "Gets a list of links of tags assigned for the specific document pointing to the page with URL specified.", Type = typeof(string), MinimumParameters = 3, AllowedTypes = new List <Type>() { typeof(TransformationNamespace) } }; getDocumentTags.AddParameter("documentGroupId", typeof(object), "ID of the group document tags belong to."); getDocumentTags.AddParameter("documentTags", typeof(object), "String containing all the tags related to the document."); getDocumentTags.AddParameter("documentListPageUrl", typeof(string), "URL of the page displaying other documents of the specified tag."); MacroMethods.RegisterMethod(getDocumentTags); }
/// <summary> /// Returns context help (current method parameters). /// </summary> /// <param name="tokens">Lexems from lexical analysis</param> /// <param name="currentElement">Current lexem</param> /// <param name="currentElementIndex">Index of the current lexem</param> private string GetContext(List <MacroElement> tokens, MacroElement currentElement, int currentElementIndex) { string methodName = ""; int paramNumber = 0; int brackets = 0; bool withoutFirstParam = false; for (int i = currentElementIndex; i >= 0; i--) { ElementType type = tokens[i].Type; if (brackets == 0) { // Count number of commas before current element (it's the current number of parameter) if (type == ElementType.Comma) { paramNumber++; } // We need to take context to the left side of current lexem // It needs to preserve the structure (deepnes withing the brackets) if (type == ElementType.LeftBracket) { if ((i > 0) && (tokens[i - 1].Type == ElementType.Identifier)) { methodName = tokens[i - 1].Expression; if (i > 2) { bool isNamespaceCall = false; if (tokens[i - 3].Type == ElementType.Identifier) { string exprToCheck = tokens[i - 3].Expression; foreach (string item in NamespacesInUse) { if (item.ToLower() == exprToCheck.ToLower()) { isNamespaceCall = true; break; } } } withoutFirstParam = (tokens[i - 2].Type == ElementType.Dot) && !isNamespaceCall; } } break; } else if (type == ElementType.LeftIndexer) { return("Indexer: Type number or name of the element."); } } // Ensure correct deepnes within the brackets if ((type == ElementType.RightBracket) || (type == ElementType.RightIndexer)) { brackets++; } else if ((type == ElementType.LeftBracket) || (type == ElementType.LeftIndexer)) { brackets--; } } MacroMethod method = MacroMethods.GetMethod(methodName); if (method != null) { return(GetMethodString(method, paramNumber, withoutFirstParam)); } // Method not known or there is syntax error in the expression return(""); }
/// <summary> /// Register all content macro methods to re /// </summary> public static void RegisterMethods() { MacroMethod isInCategories = new MacroMethod("IsInCategories", IsInCategories) { Comment = "Returns true if document is in selected categories.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; isInCategories.AddParameter("document", typeof(TreeNode), "Document to check."); isInCategories.AddParameter("categories", typeof(string), "Category names separated with a semicolon."); isInCategories.AddParameter("allCategories", typeof(bool), "If true, document must be in all of the specified categories."); MacroMethods.RegisterMethod(isInCategories); MacroMethod hasTags = new MacroMethod("HasTags", HasTags) { Comment = "Returns true if document has specified tags.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; hasTags.AddParameter("document", typeof(TreeNode), "Document to check."); hasTags.AddParameter("tags", typeof(string), "List of tags separated with a semicolon."); hasTags.AddParameter("allTags", typeof(bool), "If true, document must have all specified tags. If false, one of specified tags is sufficient."); MacroMethods.RegisterMethod(hasTags); MacroMethod isInRelationship = new MacroMethod("IsInRelationship", IsInRelationship) { Comment = "Returns true if document has left or right relationship with specified document.", Type = typeof(bool), MinimumParameters = 4, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; isInRelationship.AddParameter("document", typeof(TreeNode), "Document to check."); isInRelationship.AddParameter("side", typeof(string), "Side of checked document in the relationship."); isInRelationship.AddParameter("relationship", typeof(string), "Relationship name."); isInRelationship.AddParameter("relatedDocument", typeof(string), "Related document."); isInRelationship.AddParameter("relatedDocumentSite", typeof(string), "Related document site name."); MacroMethods.RegisterMethod(isInRelationship); MacroMethod isTranslatedTo = new MacroMethod("IsTranslatedTo", IsTranslatedTo) { Comment = "Returns true if document is translated to one of selected cultures.", Type = typeof(bool), MinimumParameters = 2, AllowedTypes = new List <Type>() { typeof(TreeNode) } }; isTranslatedTo.AddParameter("document", typeof(TreeNode), "Document to check."); isTranslatedTo.AddParameter("cultures", typeof(string), "Culture codes separated with a semicolon."); isTranslatedTo.AddParameter("publishedOnly", typeof(bool), "Indicates whether only published translations should be considered."); MacroMethods.RegisterMethod(isTranslatedTo); }
/// <summary> /// Returns list of possible hints. /// </summary> /// <param name="tokens">Lexems from lexical analysis</param> /// <param name="currentElement">Current lexem</param> /// <param name="currentElementIndex">Index of the current lexem</param> /// <param name="previousLines">Previous lines to get previous variable declarations</param> private string GetHints(List <MacroElement> tokens, MacroElement currentElement, int currentElementIndex, string previousLines, IEnumerable <string> inlineVariables) { // Get lists with methods and properties List <string> members = new List <string>(); string dataMemeberContext = ""; object obj = null; List <string> dataProperties = new List <string>(); if (currentElement == null) { GetPropertiesFromContext(members, null, ""); } else { // Properties autocomplete bool showAllProperties = (currentElement.Type == ElementType.LeftBracket) || (currentElement.Type == ElementType.LeftIndexer) || (currentElement.Type == ElementType.BlockStart) || (currentElement.Type == ElementType.BlockEnd) || (currentElement.Type == ElementType.Comma) || MacroElement.IsValidOperator(currentElement.Expression); if (!showAllProperties) { // We need to find current datamember context int brackets = 0; for (int i = currentElementIndex - 1; i >= 0; i--) { ElementType type = tokens[i].Type; if (brackets == 0) { // We need to take context to the left side of current lexem // It needs to preserve the structure (deepnes withing the brackets) if ((type == ElementType.Comma) || (type == ElementType.Operator) || (type == ElementType.LeftBracket) || (type == ElementType.LeftIndexer)) { break; } } // Append this part dataMemeberContext = tokens[i].Expression + dataMemeberContext; // Ensure correct deepnes within the brackets if ((type == ElementType.RightBracket) || (type == ElementType.RightIndexer)) { brackets++; } else if ((type == ElementType.LeftBracket) || (type == ElementType.LeftIndexer)) { brackets--; } } dataMemeberContext = dataMemeberContext.TrimEnd('.'); } // Analyze code before current line to find variable declarations (makes sense only for root hints - i.e. datamember context is empty) if (string.IsNullOrEmpty(dataMemeberContext)) { List <MacroElement> vartokens = MacroElement.ParseExpression(previousLines, true); List <string> variables = new List <string>(); for (int i = 0; i < vartokens.Count; i++) { MacroElement el = vartokens[i]; if ((el.Type == ElementType.Operator) && (el.Expression == "=") && (i > 0)) { // Add variable declaration to special fields MacroElement elPrev = vartokens[i - 1]; if (elPrev.Type == ElementType.Identifier) { variables.Add(elPrev.Expression); } } } // Add variables members.AddRange(variables); members.AddRange(inlineVariables); } obj = GetPropertiesFromContext(members, dataProperties, dataMemeberContext); } // Do not process further if only prioritized properties should be handled if (string.IsNullOrEmpty(dataMemeberContext) && Resolver.ShowOnlyPrioritized) { members.AddRange(Resolver.NamedSourceDataPriority); members.Sort(); return(MakeFinalList(members)); } // Add proper methods if (string.IsNullOrEmpty(dataMemeberContext)) { // Add commands only for empty contexts members.AddRange(CommandsList); members.Add("Math"); // Add namespaces objects if (!ShowOnlyInnerSources) { members.Add("Transformation"); members.Add("Countries"); members.Add("Visitor"); } // List of methods for any type FillFromMethodList(members, MacroMethods.GetMethodsForObject(null)); } else { if (obj == null) { // If the object is null we will offer string methods because these are the most common methods obj = ""; } // Get the list of suitable methods for resulting type FillFromMethodList(members, MacroMethods.GetMethodsForObject(obj)); } // Add methods which belongs to permanently registered namespaces members.AddRange(UsingList); // Remove items which should not be displayed if (Resolver.Context.DisablePageContextMacros) { if (members.Contains("CurrentDocument")) { members.Remove("CurrentDocument"); } if (members.Contains("CurrentPageInfo")) { members.Remove("CurrentPageInfo"); } } // Remove context objects if not needed if (Resolver.Context.DisableContextObjectMacros) { for (int i = members.Count - 1; i >= 0; i--) { if (members[i].EndsWithCSafe("context", true)) { members.RemoveAt(i); } } } // Sort everything members.Sort(); // Insert prioritized items at the beginning if (string.IsNullOrEmpty(dataMemeberContext) && (Resolver.NamedSourceDataPriority.Count > 0)) { List <string> priorities = Resolver.NamedSourceDataPriority; priorities.Sort(); members.Insert(0, "----"); members.InsertRange(0, priorities); } // Add data properties at the end if (dataProperties.Count > 0) { members.Add("----"); members.AddRange(dataProperties); } // Remove duplicities return(MakeFinalList(members)); }