예제 #1
0
파일: Parser.cs 프로젝트: lulzzz/BrandStore
        /// <summary>
        /// Takes command string and parameters and returns the result string of the command.
        /// </summary>
        protected string DispatchCommand(string command, Hashtable parameters)
        {
            string result = "(!" + command + "!)";

            command = command.ToLowerInvariant().Replace("username", "user_name");
            XSLTExtensions ExtObj = new XSLTExtensions(m_ThisCustomer, m_SkinID);

            switch (command)
            {
            case "obfuscatedemail":
            {
                String EMail = CommonLogic.HashtableParam(parameters, "email");
                //No longer supported.  Just return the email address.
                result = EMail;
                break;
            }

            case "remoteurl":     // (!RemoteUrl URL=""!)
            {
                String URL = CommonLogic.HashtableParam(parameters, "url");
                if (URL.Length != 0)
                {
                    result = ExtObj.RemoteUrl(URL);
                }
                break;
            }

            case "pagingcontrol":
            {
                // (!PagingControl BaseURL="" PageNum="N" NumPages="M"!)
                String BaseURL  = CommonLogic.HashtableParam(parameters, "baseurl");        // optional, will use existing QUERY_STRING if not provided
                int    PageNum  = CommonLogic.HashtableParamUSInt(parameters, "pagenum");   // optional, can get from QUERY_STRING if not provided
                int    NumPages = CommonLogic.HashtableParamUSInt(parameters, "numpages");  // required
                result = ExtObj.PagingControl(BaseURL, PageNum.ToString(), NumPages.ToString());
                break;
            }

            case "skinid":
            {
                // (!SKINID!)
                result = SkinID.ToString();
                break;
            }

            case "customerid":
            {
                // (!CUSTOMERID!)
                if (ThisCustomer != null)
                {
                    result = ThisCustomer.CustomerID.ToString();
                }
                else
                {
                    result = String.Empty;
                }
                break;
            }

            case "user_name":
            {
                result = ExtObj.User_Name();
                break;
            }

            case "user_menu_name":
            {
                result = ExtObj.User_Menu_Name();
                break;
            }

            case "store_version":
            {
                // (!STORE_VERSION!)
                result = String.Empty;
                break;
            }

            case "manufacturerlink":
            {
                // (!ManufacturerLink ManufacturerID="N" SEName="xxx" IncludeATag="true/false" InnerText="Some Text"!)
                int    ManufacturerID = CommonLogic.HashtableParamUSInt(parameters, "manufacturerid");
                String SEName         = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag    = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ManufacturerLink(ManufacturerID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "categorylink":
            {
                // (!CategoryLink CategoryID="N" SEName="xxx" IncludeATag="true/false"!)
                int    CategoryID  = CommonLogic.HashtableParamUSInt(parameters, "categoryid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.CategoryLink(CategoryID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "sectionlink":
            {
                // (!SectionLink SectionID="N" SEName="xxx" IncludeATag="true/false"!)
                int    SectionID   = CommonLogic.HashtableParamUSInt(parameters, "sectionid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.SectionLink(SectionID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "librarylink":
            {
                // (!LibraryLink LibraryID="N" SEName="xxx" IncludeATag="true/false"!)
                int    LibraryID   = CommonLogic.HashtableParamUSInt(parameters, "libraryid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.LibraryLink(LibraryID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "productlink":
            {
                // (!ProductLink ProductID="N" SEName="xxx" IncludeATag="true/false"!)
                int    ProductID   = CommonLogic.HashtableParamUSInt(parameters, "productid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ProductLink(ProductID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "upsellproducts":
            {
                // (!UpsellProducts ProductID="N"!)
                int ProductID = CommonLogic.HashtableParamUSInt(parameters, "productid");
                result = ExtObj.ShowUpsellProducts(ProductID.ToString());
                break;
            }

            case "relatedproducts":
            {
                // (!RelatedProducts ProductID="N"!)
                int ProductID = CommonLogic.HashtableParamUSInt(parameters, "productid");
                result = ExtObj.RelatedProducts(ProductID.ToString());
                break;
            }

            case "documentlink":
            {
                // (!DocumentLink DocumentID="N" SEName="xxx" IncludeATag="true/false"!)
                int    DocumentID  = CommonLogic.HashtableParamUSInt(parameters, "documentid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.DocumentLink(DocumentID.ToString(), SEName, IncludeATag.ToString());
                break;
            }

            case "productandcategorylink":
            {
                // (!ProductAndCategoryLink ProductID="N" CategoryID="M" SEName="xxx" IncludeATag="true/false"!)
                int    ProductID   = CommonLogic.HashtableParamUSInt(parameters, "productid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                int    CategoryID  = CommonLogic.HashtableParamUSInt(parameters, "categoryid");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ProductandCategoryLink(ProductID.ToString(), SEName, CategoryID.ToString(), IncludeATag.ToString());
                break;
            }

            case "productandsectionlink":
            {
                // (!ProductAndSectionLink ProductID="N" SectionID="M" SEName="xxx" IncludeATag="true/false"!)
                int    ProductID   = CommonLogic.HashtableParamUSInt(parameters, "productid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                int    SectionID   = CommonLogic.HashtableParamUSInt(parameters, "sectionid");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ProductandSectionLink(ProductID.ToString(), SEName, SectionID.ToString(), IncludeATag.ToString());
                break;
            }

            case "productandmanufacturerlink":
            {
                // (!ProductAndManufacturerLink ProductID="N" ManufacturerID="M" SEName="xxx" IncludeATag="true/false"!)
                int    ProductID      = CommonLogic.HashtableParamUSInt(parameters, "productid");
                String SEName         = CommonLogic.HashtableParam(parameters, "sename");
                int    ManufacturerID = CommonLogic.HashtableParamUSInt(parameters, "manufacturerid");
                bool   IncludeATag    = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ProductandManufacturerLink(ProductID.ToString(), SEName, ManufacturerID.ToString(), IncludeATag.ToString());
                break;
            }

            case "productpropername":
            {
                // (!ProductProperName ProductID="N" VariantID="M"!)
                int ProductID = CommonLogic.HashtableParamUSInt(parameters, "productid");
                int VariantID = CommonLogic.HashtableParamUSInt(parameters, "variantid");
                result = ExtObj.ProductProperName(ProductID.ToString(), VariantID.ToString());
                break;
            }

            case "documentandlibrarylink":
            {
                // (!DocumentAndLibraryLink DocumentID="N" LibraryID="M" SEName="xxx" IncludeATag="true/false"!)
                int    DocumentID  = CommonLogic.HashtableParamUSInt(parameters, "documentid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                int    LibraryID   = CommonLogic.HashtableParamUSInt(parameters, "libraryid");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.DocumentandLibraryLink(DocumentID.ToString(), SEName, LibraryID.ToString(), IncludeATag.ToString());
                break;
            }

            case "entitylink":
            {
                // (!EntityLink EntityID="N" EntityName="xxx" SEName="xxx" IncludeATag="true/false"!)
                int    EntityID    = CommonLogic.HashtableParamUSInt(parameters, "entityid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                String EntityName  = CommonLogic.HashtableParam(parameters, "entityname");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.EntityLink(EntityID.ToString(), SEName, EntityName, IncludeATag.ToString());
                break;
            }

            case "objectlink":
            {
                // (!ObjectLink ObjectID="N" ObjectName="xxx" SEName="xxx" IncludeATag="true/false"!)
                int    ObjectID    = CommonLogic.HashtableParamUSInt(parameters, "objectid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                String ObjectName  = CommonLogic.HashtableParam(parameters, "objectname");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.ObjectLink(ObjectID.ToString(), SEName, ObjectName, IncludeATag.ToString());
                break;
            }

            case "productandentitylink":
            {
                // (!ProductAndEntityLink ProductID="N" EntityID="M" EntityName="xxx" SEName="xxx" IncludeATag="true/false"!)
                int    ProductID   = CommonLogic.HashtableParamUSInt(parameters, "productid");
                String SEName      = CommonLogic.HashtableParam(parameters, "sename");
                int    EntityID    = CommonLogic.HashtableParamUSInt(parameters, "entityid");
                String EntityName  = CommonLogic.HashtableParam(parameters, "entityname");
                bool   IncludeATag = CommonLogic.HashtableParamBool(parameters, "includeatag");
                String InnerText   = CommonLogic.HashtableParam(parameters, "innertext");
                result = ExtObj.ProductandEntityLink(ProductID.ToString(), SEName, EntityID.ToString(), EntityName, IncludeATag.ToString());
                break;
            }

            case "topic":
            {
                // (!Topic TopicID="M"!) or (!Topic ID="M"!) or (!Topic Name="xxx"!)
                int TopicID = CommonLogic.HashtableParamUSInt(parameters, "id");
                if (TopicID == 0)
                {
                    TopicID = CommonLogic.HashtableParamUSInt(parameters, "topicid");
                }
                String LS = Localization.GetDefaultLocale();
                if (ThisCustomer != null)
                {
                    LS = ThisCustomer.LocaleSetting;
                }
                if (TopicID != 0)
                {
                    Topic t = new Topic(TopicID, LS, SkinID, null);
                    result = t.Contents;
                }
                else
                {
                    String TopicName = CommonLogic.HashtableParam(parameters, "name");
                    if (TopicName.Length != 0)
                    {
                        Topic t = new Topic(TopicName, LS, SkinID, null);
                        result = t.Contents;
                    }
                }
                break;
            }

            case "appconfig":
            {
                // (!AppConfig Name="xxx"!)
                String AppConfigName = CommonLogic.HashtableParam(parameters, "name");
                result = ExtObj.AppConfig(AppConfigName);
                break;
            }

            case "stringresource":
            {
                // (!StringResource Name="xxx"!)
                String StringResourceName = CommonLogic.HashtableParam(parameters, "name");
                result = ExtObj.StringResource(StringResourceName);
                break;
            }

            case "getstring":
            {
                // (!GetString Name="xxx"!)
                String StringResourceName = CommonLogic.HashtableParam(parameters, "name");
                result = ExtObj.StringResource(StringResourceName);
                break;
            }

            case "loginoutprompt":
            {
                // (!LoginOutPrompt!)
                result = AppLogic.GetLoginBox(SkinID);
                break;
            }

            case "searchbox":
            {
                // (!SearchBox!)
                result = ExtObj.SearchBox();
                break;
            }

            case "helpbox":
            {
                // (!HelpBox!)
                result = ExtObj.HelpBox();
                break;
            }

            case "addtocartform":
            {
                int  ProductID = CommonLogic.HashtableParamUSInt(parameters, "productid");
                int  VariantID = CommonLogic.HashtableParamUSInt(parameters, "variantid");
                bool ColorChangeProductImage = CommonLogic.HashtableParamBool(parameters, "colorchangeproductimage");
                result = ExtObj.AddtoCartForm(ProductID.ToString(), VariantID.ToString(), ColorChangeProductImage.ToString());
                break;
            }

            case "lookupimage":
            {
                int    ID = CommonLogic.HashtableParamUSInt(parameters, "id");
                String EntityOrObjectName = CommonLogic.HashtableParam(parameters, "type");
                String DesiredSize        = CommonLogic.HashtableParam(parameters, "size");
                bool   IncludeATag        = CommonLogic.HashtableParamBool(parameters, "includeatag");
                result = ExtObj.LookupImage(ID.ToString(), EntityOrObjectName, DesiredSize, IncludeATag.ToString());
                break;
            }

            case "productnavlinks":
            {
                int  ProductID   = CommonLogic.HashtableParamUSInt(parameters, "productid");
                int  CategoryID  = CommonLogic.QueryStringUSInt("CategoryID");     // should really get them from parameters, NOT from the querystring, but whatever...
                int  SectionID   = CommonLogic.QueryStringUSInt("SectionID");      // should really get them from parameters, NOT from the querystring, but whatever...
                bool UseGraphics = CommonLogic.HashtableParamBool(parameters, "usegraphics");
                result = ExtObj.ProductNavLinks(ProductID.ToString(), CategoryID.ToString(), SectionID.ToString(), UseGraphics.ToString());
                break;
            }

            case "emailproducttofriend":
            {
                int ProductID  = CommonLogic.HashtableParamUSInt(parameters, "productid");
                int CategoryID = CommonLogic.HashtableParamUSInt(parameters, "categoryid");
                result = ExtObj.EmailProductToFriend(ProductID.ToString(), CategoryID.ToString());
                break;
            }

            case "productdescriptionfile":
            {
                int  ProductID       = CommonLogic.HashtableParamUSInt(parameters, "productid");
                bool IncludeBRBefore = CommonLogic.HashtableParamBool(parameters, "includebrbefore");
                result = ExtObj.ProductDescriptionFile(ProductID.ToString(), IncludeBRBefore.ToString());
                break;
            }

            case "productspecs":
            {
                int  ProductID       = CommonLogic.HashtableParamUSInt(parameters, "productid");
                bool IncludeBRBefore = CommonLogic.HashtableParamBool(parameters, "includebrbefore");
                result = ExtObj.ProductSpecs(ProductID.ToString(), IncludeBRBefore.ToString());
                break;
            }

            case "productratings":
            {
                int  ProductID       = CommonLogic.HashtableParamUSInt(parameters, "productid");
                int  CategoryID      = CommonLogic.QueryStringUSInt("CategoryID");     // should really get them from parameters, NOT from the querystring, but whatever...
                int  SectionID       = CommonLogic.QueryStringUSInt("SectionID");      // should really get them from parameters, NOT from the querystring, but whatever...
                int  ManufacturerID  = CommonLogic.QueryStringUSInt("ManufacturerID"); // should really get them from parameters, NOT from the querystring, but whatever...
                bool IncludeBRBefore = CommonLogic.HashtableParamBool(parameters, "includebrbefore");
                result = ExtObj.ProductRatings(ProductID.ToString(), CategoryID.ToString(), SectionID.ToString(), ManufacturerID.ToString(), IncludeBRBefore.ToString());
                break;
            }

            case "formatcurrency":
            {
                decimal CurrencyValue = CommonLogic.HashtableParamNativeDecimal(parameters, "value");
                String  LocaleSetting = CommonLogic.HashtableParam(parameters, "localesetting");
                result = ExtObj.FormatCurrency(CurrencyValue.ToString());
                break;
            }

            case "getspecialsboxexpandedrandom":
            {
                int    CategoryID   = CommonLogic.HashtableParamUSInt(parameters, "categoryid");
                bool   ShowPics     = CommonLogic.HashtableParamBool(parameters, "showpics");
                bool   IncludeFrame = CommonLogic.HashtableParamBool(parameters, "includeframe");
                String Teaser       = CommonLogic.HashtableParam(parameters, "teaser");
                result = ExtObj.GetSpecialsBoxExpandedRandom(CategoryID.ToString(), ShowPics.ToString(), IncludeFrame.ToString(), Teaser);
                break;
            }

            case "getspecialsboxexpanded":
            {
                int    CategoryID   = CommonLogic.HashtableParamUSInt(parameters, "categoryid");
                int    ShowNum      = CommonLogic.HashtableParamUSInt(parameters, "shownum");
                bool   ShowPics     = CommonLogic.HashtableParamBool(parameters, "showpics");
                bool   IncludeFrame = CommonLogic.HashtableParamBool(parameters, "includeframe");
                String Teaser       = CommonLogic.HashtableParam(parameters, "teaser");
                result = ExtObj.GetSpecialsBoxExpanded(CategoryID.ToString(), ShowNum.ToString(), ShowPics.ToString(), IncludeFrame.ToString(), Teaser);
                break;
            }

            case "getnewsboxexpanded":
            {
                bool   ShowCopy     = CommonLogic.HashtableParamBool(parameters, "showcopy");
                int    ShowNum      = CommonLogic.HashtableParamUSInt(parameters, "shownum");
                bool   IncludeFrame = CommonLogic.HashtableParamBool(parameters, "includeframe");
                String Teaser       = CommonLogic.HashtableParam(parameters, "teaser");
                result = ExtObj.GetNewsBoxExpanded(ShowCopy.ToString(), ShowNum.ToString(), IncludeFrame.ToString(), Teaser);
                break;
            }

            case "xmlpackage":
            {
                // (!XmlPackage Name="xxx" version="N"!)
                // version can only be 2 at this time, or blank
                String    PackageName       = CommonLogic.HashtableParam(parameters, "name");
                String    VersionID         = CommonLogic.HashtableParam(parameters, "version"); // optional
                Hashtable userruntimeparams = parameters;
                userruntimeparams.Remove("name");
                userruntimeparams.Remove("version");
                string runtimeparams = String.Empty;
                foreach (DictionaryEntry de in userruntimeparams)
                {
                    runtimeparams += de.Key.ToString() + "=" + de.Value.ToString() + "&";
                }
                if (runtimeparams.Length > 0)
                {
                    runtimeparams = runtimeparams.Substring(0, runtimeparams.Length - 1);
                }

                if (PackageName.Length != 0)
                {
                    if (PackageName.EndsWith(".xslt", StringComparison.InvariantCultureIgnoreCase) && VersionID != "2")
                    {
                        throw new ArgumentException("Version 1 XmlPackages are no longer supported!");
                    }
                    else
                    {
                        // WARNING YOU COULD CAUSE ENDLESS RECURSION HERE! if your XmlPackage refers to itself in some direct, or INDIRECT! way!!
                        result = AppLogic.RunXmlPackage(PackageName, this, ThisCustomer, SkinID, String.Empty, runtimeparams, true, true);
                    }
                }
                break;
            }
            }
            return(result);
        }