Beispiel #1
0
        public string RenderForDisplay(MerchantTribeApplication app, Catalog.Category cat)
        {
            string sizeClass = "flexsize12";

            if (this._Container != null)
            {
                sizeClass  = "flexsize";
                sizeClass += ((int)_Container.Size).ToString();
                if (_Container.NoGutter && _Container.Size != ColumnSize.Size12)
                {
                    sizeClass += "w";
                }
            }
            string url = System.Web.VirtualPathUtility.ToAbsolute("~/images/system/flexedit/imagePlaceholder.png");
            string alt = "Placeholder Image";

            if (Images.Count > 0)
            {
                ImageDisplayFile img       = this.Images[0];
                long             versionId = cat.GetCurrentVersion().Id;
                url = Storage.DiskStorage.FlexPageImageUrl(app, cat.Bvin, versionId.ToString(), img.FileName, true);
                alt = img.AltText;
            }

            return("<img src=\"" + url + "\" alt=\"" + alt + "\" class=\"" + sizeClass + "\" />");
        }
Beispiel #2
0
        public string Process(MerchantTribeApplication app, Dictionary<string, ITagHandler> handlers, ParsedTag tag, string contents)
        {
            this.App = app;
            this.Url = new System.Web.Mvc.UrlHelper(app.CurrentRequestContext.RoutingContext);
            CurrentCategory = app.CurrentRequestContext.CurrentCategory;
            if (CurrentCategory == null)
            {
                CurrentCategory = new Category();
                CurrentCategory.Bvin = "0";
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"categorymenu\">");
            sb.Append("<div class=\"decoratedblock\">");

            string title = tag.GetSafeAttribute("title");
            if (title.Trim().Length > 0)
            {
                sb.Append("<h4>" + title + "</h4>");
            }

            sb.Append("<ul>");

            int maxDepth = 5;

            string mode = tag.GetSafeAttribute("mode");
            switch (mode.Trim().ToUpperInvariant())
            {
                case "ROOT":
                case "ROOTS":
                    // Root Categories Only
                    LoadRoots(sb);
                    break;
                case "ALL":
                    // All Categories
                    LoadAllCategories(sb, maxDepth);
                    break;
                case "":
                case "PEERS":
                    // Peers, Children and Parents
                    LoadPeersAndChildren(sb);
                    break;
                case "ROOTPLUS":
                    // Show root and expanded children
                    LoadRootPlusExpandedChildren(sb);
                    break;
                default:
                    // All Categories
                    LoadPeersAndChildren(sb);
                    break;
            }

            sb.Append("</ul>");

            sb.Append("</div>");
            sb.Append("</div>");

            return sb.ToString();
        }
Beispiel #3
0
        public PartJsonResult ProcessJsonRequest(System.Collections.Specialized.NameValueCollection form,
                                                 MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            PartJsonResult result = new PartJsonResult();

            string action = form["partaction"];

            switch (action.ToLowerInvariant())
            {
            case "addpart":
                string       parttype = form["parttype"];
                IContentPart part     = PartFactory.Instantiate(System.Guid.NewGuid().ToString(), parttype, this);
                if (part != null)
                {
                    this.AddPart(part);
                    app.CatalogServices.Categories.Update(containerCategory);
                    result.ResultHtml = part.RenderForEdit(app, containerCategory);
                }
                break;

            case "resort":
                string        sortedIds = form["sortedIds[]"];
                string[]      ids       = sortedIds.Split(',');
                List <string> idList    = new List <string>();
                foreach (string s in ids)
                {
                    idList.Add(s.Trim().Replace("part", ""));
                }
                result.Success = this.SortParts(idList);
                app.CatalogServices.Categories.Update(containerCategory);
                break;
            }
            return(result);
        }
Beispiel #4
0
        public string RenderForDisplay(MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            StringBuilder sb = new StringBuilder();

            foreach (IContentPart p in _Parts)
            {
                sb.Append(p.RenderForDisplay(app, containerCategory));
            }
            return(sb.ToString());
        }
Beispiel #5
0
        public string RenderForEdit(MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            StringBuilder sb = new StringBuilder();

            foreach (IContentPart p in _Parts)
            {
                sb.Append(p.RenderForEdit(app, containerCategory));
            }
            //sb.Append("<div class=\"editplaceholder\">Drag Parts Here</div>");
            return(sb.ToString());
        }
Beispiel #6
0
        public string RenderForEdit(MerchantTribeApplication app, Catalog.Category cat)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div id=\"part" + Id + "\" class=\"editable issortable\">");
            sb.Append(PartHelper.RenderEditTools(this.Id));
            sb.Append(RenderForDisplay(app, cat));
            sb.Append("</div>");

            return(sb.ToString());
        }
        public PartJsonResult ProcessJsonRequest(System.Collections.Specialized.NameValueCollection form,
                                                 MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            PartJsonResult result = new PartJsonResult();

            string action = form["partaction"];

            switch (action.ToLowerInvariant())
            {
            case "showeditor":
                result.IsFinishedEditing = false;
                result.Success           = true;
                result.ResultHtml        = BuildEditor();
                break;

            case "saveedit":

                string colsRequestedString = form["totalColumnsRequested"];
                int    columnsRequested    = this.Columns.Count;
                if (int.TryParse(colsRequestedString, out columnsRequested))
                {
                    this.SetNumberOfColumns(columnsRequested);
                }
                ParseColumnChanges(form);
                if (form["spacerabove"] == "on")
                {
                    this.SpacerAbove = true;
                }
                else
                {
                    this.SpacerAbove = false;
                }
                app.CatalogServices.Categories.Update(containerCategory);
                result.Success           = true;
                result.IsFinishedEditing = false;
                result.ResultHtml        = BuildEditor();
                break;

            case "canceledit":
                result.Success           = true;
                result.IsFinishedEditing = true;
                result.ResultHtml        = this.RenderForEdit(app, containerCategory);
                break;

            case "deletepart":
                containerCategory.GetCurrentVersion().Root.RemovePart(this.Id);
                app.CatalogServices.Categories.Update(containerCategory);
                result.Success = true;
                break;
            }
            return(result);
        }
Beispiel #8
0
 public static bool IsCategorySlugInUse(string slug, string bvin, Catalog.CategoryRepository repository)
 {
     Catalog.Category c = repository.FindBySlug(slug);
     if (c != null)
     {
         if (c.Bvin != string.Empty)
         {
             if (c.Bvin != bvin)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #9
0
        public override string FriendlyDescription(MerchantTribeApplication app)
        {
            string result = "When Product is in Category:<ul>";

            foreach (string bvin in this.CurrentCategoryIds())
            {
                Catalog.Category c = app.CatalogServices.Categories.Find(bvin);
                if (c != null)
                {
                    result += "<li>" + c.Name + "<br />";
                    result += "<em>" + c.RewriteUrl + "</em></li>";
                }
            }
            result += "</ul>";
            return(result);
        }
Beispiel #10
0
        public PartJsonResult ProcessJsonRequest(System.Collections.Specialized.NameValueCollection form,
                                                 MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            PartJsonResult result = new PartJsonResult();

            string action = form["partaction"];

            StringBuilder sb = new StringBuilder();

            switch (action.Trim().ToLowerInvariant())
            {
            case "showeditor":
                sb.Append("<textarea name=\"changedtext\" style=\"height:400px;width:675px;\">");
                sb.Append(this.RawHtml);
                sb.Append("</textarea><br />");
                sb.Append("<input type=\"hidden\" name=\"partaction\" class=\"editactionhidden\" value=\"saveedit\" />");
                sb.Append("<input type=\"submit\" name=\"canceleditbutton\" value=\"Close\">");
                sb.Append("<input type=\"submit\" name=\"savechanges\" value=\"Save Changes\">");
                result.IsFinishedEditing = false;
                result.Success           = true;
                result.ResultHtml        = sb.ToString();
                break;

            case "saveedit":
                this.RawHtml             = form["changedtext"];
                result.IsFinishedEditing = true;
                result.Success           = true;
                result.ResultHtml        = this.RenderForEdit(app, containerCategory);
                app.CatalogServices.Categories.Update(containerCategory);
                break;

            case "canceledit":
                result.Success           = true;
                result.IsFinishedEditing = true;
                result.ResultHtml        = this.RenderForEdit(app, containerCategory);
                break;

            case "deletepart":
                containerCategory.GetCurrentVersion().Root.RemovePart(this.Id);
                app.CatalogServices.Categories.Update(containerCategory);
                break;
            }

            return(result);
        }
Beispiel #11
0
        public static void LoadFromJson(Catalog.Category category)
        {
            ModConfiguration.data[(int)category] = new List <dynamic>();

            if (ModConfiguration.streamingAssetsPath == null)
            {
                return;
            }
            GetDefaultJsonSettings();
            foreach (string text2 in Directory.GetDirectories(ModConfiguration.streamingAssetsPath + "/" + "Default"))
            {
                string fileName = Path.GetFileName(text2);
                foreach (FileInfo fileInfo in new DirectoryInfo(text2 + "/").GetFiles(category.ToString() + "_*.json", SearchOption.AllDirectories))
                {
                    Debug.Log("JSON loader - Found file: " + fileInfo.Name);
                    string value = File.ReadAllText(fileInfo.FullName);
                    value = value.Replace("$type", "type");
                    var sub = Regex.Match(value, "\\\"type\\\":\\s+\\\"(\\w+\\.[\\w\\d]+, [\\w\\d-]+)\\\"", RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    string typeStr      = sub.Groups[1].Value;
                    Type   type         = Type.GetType(typeStr);
                    var    internalType = TypeHelper.GenerateMissingType(type);

                    var usedType = internalType;
                    try
                    {
                        dynamic catalogData = Activator.CreateInstance(internalType);

                        catalogData = JsonConvert.DeserializeObject(value, usedType) as CatalogData;

                        catalogData.type = typeStr;

                        if (catalogData != null)
                        {
                            ModConfiguration.data[(int)category].Add(catalogData);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
        }
Beispiel #12
0
        private string Render(MerchantTribeApplication app, bool isEditMode, Catalog.Category containerCategory)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"cols\">");
            sb.Append("<div class=\"grid_12");
            sb.Append("\" >");

            if (isEditMode)
            {
                sb.Append("<div class=\"droppable\" id=\"part" + Id.ToString() + "\">");
                sb.Append("<div class=\"edittools\" id=\"edittools" + this.Id + "\"><strong>Page Root</strong> </div>");
            }
            foreach (IContentPart p in Parts)
            {
                if (isEditMode)
                {
                    sb.Append(p.RenderForEdit(app, containerCategory));
                }
                else
                {
                    sb.Append(p.RenderForDisplay(app, containerCategory));
                }
            }

            if (isEditMode)
            {
                //sb.Append("<div class=\"editplaceholder\">Drag Parts Here</div>");
                sb.Append("</div>"); // Close out droppable div
            }

            sb.Append("</div>");
            sb.Append("<div class=\"clearcol\"></div>");
            sb.Append("</div>");
            return(sb.ToString());
        }
Beispiel #13
0
        private string BuildEditor(Catalog.Category containerCategory, string message, MerchantTribeApplication app)
        {
            MerchantTribe.Commerce.RequestContext context = app.CurrentRequestContext;

            long             versionId = containerCategory.GetCurrentVersion().Id;
            ImageDisplayFile img       = new ImageDisplayFile();

            if (this.Images.Count > 0)
            {
                img = this.Images[0];
            }

            string previewUrl = "";
            string alt        = string.Empty;

            previewUrl = System.Web.VirtualPathUtility.ToAbsolute("~/images/system/flexedit/imagePlaceholder.png");
            if (this.Images.Count > 0)
            {
                alt = this.Images[0].AltText;
                if (this.Images[0].FileName.Trim().Length > 0)
                {
                    previewUrl = Storage.DiskStorage.FlexPageImageUrl(app, containerCategory.Bvin, versionId.ToString(), img.FileName, false);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"flexeditarea\">");
            sb.Append("<div id=\"uploadimagemessage\">" + message + "</div>");
            sb.Append("<table width=\"100%\">");

            sb.Append("<tr><td class=\"formlabel\">Image:</td><td class=\"formfield\">");
            sb.Append("<img width=\"200px\" height=\"200px\" src=\"" + previewUrl + "\" id=\"uploadimagepreview\" name=\"uploadimagepreview\" /><br />");

            sb.Append("<div id=\"silverlightControlHost\">");
            sb.Append("<object data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"100\" height=\"55\">");

            string SilverLightUrl = System.Web.VirtualPathUtility.ToAbsolute("~/ClientBin/BVSoftware.SilverlightFileUpload.xap");

            sb.Append("<param name=\"source\" value=\"" + SilverLightUrl + "\"/>");

            sb.Append("<param name=\"background\" value=\"black\" />");
            sb.Append("<param name=\"onError\" value=\"onSilverlightError\" />");
            sb.Append("<param name=\"minRuntimeVersion\" value=\"4.0.50826.0\" />");
            sb.Append("<param name=\"autoUpgrade\" value=\"true\" />");

            sb.Append("<param name=\"initParams\" value=\"scriptname=ImageWasUploaded,uploadurl=");

            // We have to pull the host out because the ToAbsolute of the virutal path utility
            // will append sub folder name if the web site is not the root app in IIS
            string currentFullRoot = app.StoreUrl(false, false);
            Uri    fullUri         = new Uri(currentFullRoot);
            string host            = fullUri.DnsSafeHost;

            sb.Append("http://" + host);
            sb.Append(System.Web.VirtualPathUtility.ToAbsolute("~/fileuploadhandler/1/" + containerCategory.Bvin + "/" + versionId.ToString()));
            sb.Append("\"/>");

            sb.Append("<a href=\"http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0\" style=\"text-decoration:none\">");
            sb.Append("<img src=\"http://go.microsoft.com/fwlink/?LinkId=161376\" alt=\"Get Microsoft Silverlight\" style=\"border-style:none\"/>");
            sb.Append("</a>");
            sb.Append("</object><iframe id=\"_sl_historyFrame\" style=\"visibility:hidden;height:0px;width:0px;border:0px\"></iframe>");
            sb.Append("</div>");

            sb.Append("</td></tr>");

            sb.Append("<tr><td class=\"formlabel\">Alt. Text:</td><td class=\"formfield\">");
            sb.Append("<input type=\"text\" id=\"altfield\" name=\"altfield\" value=\"" + System.Web.HttpUtility.HtmlEncode(alt) + "\" />");
            sb.Append("</td></tr>");

            sb.Append("</table>");


            sb.Append("</div>");
            sb.Append("<div class=\"flexeditbuttonarea\">");
            sb.Append("<input type=\"hidden\" name=\"uploadedfilename\" id=\"uploadedfilename\" value=\"\" />");
            sb.Append("<input type=\"hidden\" name=\"partaction\" class=\"editactionhidden\" value=\"saveedit\" />");
            sb.Append("<input type=\"submit\" name=\"canceleditbutton\" value=\"Close\">");
            sb.Append("<input type=\"submit\" name=\"savechanges\" value=\"Save Changes\">");
            sb.Append("</div>");

            return(sb.ToString());
        }
Beispiel #14
0
        public string Process(MerchantTribeApplication app, Dictionary <string, ITagHandler> handlers, ParsedTag tag, string contents)
        {
            StringBuilder sb = new StringBuilder();

            string mode  = tag.GetSafeAttribute("mode");
            string href  = string.Empty;
            string sysid = tag.GetSafeAttribute("sysid");

            switch (mode.Trim().ToLowerInvariant())
            {
            case "home":
                href = app.CurrentStore.RootUrl();
                break;

            case "checkout":
                href = app.CurrentStore.RootUrlSecure() + "checkout";
                if (contents == string.Empty)
                {
                    contents = "<span>Checkout</span>";
                }
                break;

            case "cart":
                href = app.CurrentStore.RootUrl() + "cart";
                if (contents == string.Empty)
                {
                    string itemCount = "0";
                    string subTotal  = "$0.00";

                    if (SessionManager.CurrentUserHasCart(app.CurrentStore))
                    {
                        itemCount = SessionManager.GetCookieString(WebAppSettings.CookieNameCartItemCount(app.CurrentStore.Id), app.CurrentStore);
                        subTotal  = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(app.CurrentStore.Id), app.CurrentStore);
                        if (itemCount.Trim().Length < 1)
                        {
                            itemCount = "0";
                        }
                        if (subTotal.Trim().Length < 1)
                        {
                            subTotal = "$0.00";
                        }
                    }

                    contents = "<span>View Cart: " + itemCount + " items</span>";
                }
                break;

            case "category":
                Catalog.Category cat = app.CatalogServices.Categories.Find(sysid);
                href = app.CurrentStore.RootUrl() + cat.RewriteUrl;
                break;

            case "product":
                Catalog.Product p = app.CatalogServices.Products.Find(sysid);
                href = app.CurrentStore.RootUrl() + p.UrlSlug;
                break;

            case "":
                string temp = tag.GetSafeAttribute("href");
                if (temp.StartsWith("http://") || temp.StartsWith("https://"))
                {
                    href = temp;
                }
                else
                {
                    href = app.CurrentStore.RootUrl() + temp.TrimStart('/');
                }
                break;

            case "myaccount":
                href = app.CurrentStore.RootUrlSecure() + "account";
                if (contents == string.Empty)
                {
                    contents = "<span>My Account</span>";
                }
                break;

            case "signin":
                string currentUserId = SessionManager.GetCurrentUserId(app.CurrentStore);
                if (currentUserId == string.Empty)
                {
                    href = app.CurrentStore.RootUrlSecure() + "signin";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign In</span>";
                    }
                }
                else
                {
                    href = app.CurrentStore.RootUrlSecure() + "signout";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign Out</span>";
                    }
                }

                break;
            }

            if (href.Trim().Length > 0)
            {
                sb.Append("<a href=\"" + href + "\"");

                PassAttribute(ref sb, tag, "id");
                PassAttribute(ref sb, tag, "title");
                PassAttribute(ref sb, tag, "style");
                PassAttribute(ref sb, tag, "class");
                PassAttribute(ref sb, tag, "dir");
                PassAttribute(ref sb, tag, "lang");
                PassAttribute(ref sb, tag, "target");
                PassAttribute(ref sb, tag, "rel");
                PassAttribute(ref sb, tag, "media");
                PassAttribute(ref sb, tag, "hreflang");
                PassAttribute(ref sb, tag, "type");
                PassAttribute(ref sb, tag, "name");

                sb.Append(">" + contents + "</a>");
            }
            return(sb.ToString());
        }
Beispiel #15
0
        public ReferenceManager(FieldInfo fieldInfo, DataGridViewCellEventArgs e)
        {
            FormClosing += ReferenceManager_FormClosing;
            fieldValue   = fieldInfo.GetValue(ModConfiguration.current.instancedType).ToString();
            fieldInfo.GetValue(ModConfiguration.current.instancedType);
            string fieldTypeName = Spell.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex - 2].Value as string;

            fieldTypeName = fieldTypeName.Replace("Id", "Data");
            Catalog.Category categorylocal = Catalog.Category.Brain;
            foreach (var en in Enum.GetValues(typeof(Catalog.Category)))
            {
                var index = fieldTypeName.IndexOf(en.ToString() + "Data");
                if (index < 0)
                {
                    continue;
                }
                var split = fieldTypeName.Substring(index);
                fieldType     = ModConfiguration.generatedTypes.First(x => x.Name == split);
                category      = (int)Enum.Parse(typeof(Catalog.Category), en.ToString());
                categorylocal = (Catalog.Category)en;
                break;
            }
            if (fieldType == null)
            {
                fieldType = ModConfiguration.generatedTypes.First(x => x.Name == "ItemPhysic");
                category  = (int)Catalog.Category.Item;
            }

            foreach (var data in ModConfiguration.data[category])
            {
                //var dota = ModConfiguration.ConvertDynamic(data, ModConfiguration.generatedTypes.FirstOrDefault(x => x.Name.Contains(categorylocal.ToString())));
                autoCompSrc.Add(fieldType.GetField("id").GetValue(data));
                //allowedValues.Add(data);
                if (fieldType.GetField("id").GetValue(data) != null)
                {
                    targetSource = "Default";
                }
            }
            foreach (var data in ModConfiguration.current.modData[category])
            {
                autoCompSrc.Add(fieldType.GetField("id").GetValue(data));
                //allowedValues.Add(data);
                if (fieldType.GetField("id").GetValue(data) != null)
                {
                    targetSource = ModConfiguration.current.modName;
                }
            }
            if (string.IsNullOrEmpty(targetSource))
            {
                targetSource = "Default";
            }


            //allowedValues.ForEach(x => autoCompSrc.Add(x.id));



            InitializeComponent();
            if (targetSource != "Default")
            {
                labelDefault.Visible = false;
            }
            else
            {
                labelDefault.Visible = true;
            }
            fieldValueLabel.Text = fieldValue + " (" + fieldType.Name + ")";

            var copyField = fieldValue.Replace("Fire", ModConfiguration.current.modName);

            copyRenameText.Text = copyField;

            eventArgs = e;
            ReferenceText.AutoCompleteCustomSource = autoCompSrc;
            ReferenceText.AutoCompleteMode         = AutoCompleteMode.Suggest;
            ReferenceText.AutoCompleteSource       = AutoCompleteSource.CustomSource;

            //category = (Catalog.Category)Enum.Parse(typeof(Catalog.Category), fieldTypeName.Replace("Data", ""));
        }
Beispiel #16
0
 public string RenderForEdit(MerchantTribeApplication app, Catalog.Category containerCategory)
 {
     return(Render(app, true, containerCategory));
 }
Beispiel #17
0
        public PartJsonResult ProcessJsonRequest(System.Collections.Specialized.NameValueCollection form,
                                                 MerchantTribeApplication app, Catalog.Category containerCategory)
        {
            PartJsonResult result = new PartJsonResult();

            string action = form["partaction"];

            StringBuilder sb = new StringBuilder();

            switch (action.Trim().ToLowerInvariant())
            {
            case "showeditor":
                result.IsFinishedEditing = false;
                result.Success           = true;
                result.ResultHtml        = BuildEditor(containerCategory, string.Empty, app);
                //result.ScriptFunction = initScript;
                break;

            case "saveedit":

                // Update from Form Here
                string editMessage = string.Empty;

                if (form["uploadedfilename"] != null)
                {
                    string uploadedname = form["uploadedfilename"];

                    if (uploadedname.Length > 0)
                    {
                        if (this.Images.Count < 1)
                        {
                            this.Images.Add(new ImageDisplayFile()
                            {
                                AltText = uploadedname, FileName = uploadedname, SortOrder = 0
                            });
                        }
                        else
                        {
                            this.Images[0].FileName = uploadedname;
                        }
                    }
                }

                if (this.Images.Count > 0)
                {
                    string altText = form["altfield"];
                    this.Images[0].AltText = altText;
                    editMessage            = "Changes Saved!";
                }
                else
                {
                    editMessage = "Upload an Image before Saving Changes!";
                }

                app.CatalogServices.Categories.Update(containerCategory);
                result.Success           = true;
                result.IsFinishedEditing = false;
                result.ResultHtml        = BuildEditor(containerCategory, editMessage, app);
                //result.ScriptFunction = initScript;
                break;

            case "canceledit":
                result.Success           = true;
                result.IsFinishedEditing = true;
                result.ResultHtml        = this.RenderForEdit(app, containerCategory);
                break;

            case "deletepart":
                containerCategory.GetCurrentVersion().Root.RemovePart(this.Id);
                app.CatalogServices.Categories.Update(containerCategory);
                break;
            }

            return(result);
        }
Beispiel #18
0
 public string RenderForDisplay(MerchantTribeApplication app, Catalog.Category containerCategory)
 {
     return(RawHtml);
 }
Beispiel #19
0
        public static void LoadFromJson(string modName, Catalog.Category category)
        {
            if (String.IsNullOrEmpty(modName) || modName == "Default")
            {
                return;
            }
            var           dirList    = Directory.GetDirectories(ModConfiguration.streamingAssetsPath + "/" + ModConfiguration.current.modName + "/", "*", SearchOption.TopDirectoryOnly);
            List <string> dirStrList = new List <string>();

            dirStrList.AddRange(dirList);
            dirStrList.Add(ModConfiguration.streamingAssetsPath + "/" + ModConfiguration.current.modName);
            foreach (string text2 in dirStrList)
            {
                if (text2.Contains("Default"))
                {
                    return;
                }
                string fileName = Path.GetFileName(text2);

                foreach (FileInfo fileInfo in new DirectoryInfo(text2 + "/").GetFiles(category.ToString() + "_*.json", SearchOption.AllDirectories))
                {
                    Debug.Log("JSON loader - Found file: " + fileInfo.Name);
                    string value = File.ReadAllText(fileInfo.FullName);
                    value = value.Replace("$type", "type");
                    var sub = Regex.Match(value, "\\\"type\\\":\\s+\\\"(\\w+\\.[\\w\\d]+, [\\w\\d-]+)\\\"", RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    string typeStr = sub.Groups[1].Value;

                    Type type = Type.GetType(typeStr);

                    if (type == null)
                    {
                        Debug.Log("Type is null, loading all DLL's inside mod directory ---");
                        var asm = LoadDLL();
                        foreach (var atype in asm.GetTypes())
                        {
                            if (atype.FullName.Contains("+"))
                            {
                                continue;
                            }
                            var r = typeStr.Split('.')[1].Split(',')[0]; // F*****G YOLO
                            if (atype.Name.Contains(r))
                            {
                                type = TypeHelper.GenerateMissingType(atype);
                                Debug.Log("Type " + r + " was found in " + asm.FullName + " successful");
                                break;
                            }
                        }
                        if (type == null)
                        {
                            Debug.LogWarning("Failed to find type... type is null, skipping...");
                            continue;
                        }
                    }
                    TypeHelper.GenerateMissingType(type);

                    var usedType = ModConfiguration.generatedTypes.Find(x => x.Name == "CatalogData");
                    try
                    {
                        CatalogData catalogData = Activator.CreateInstance(ModConfiguration.generatedTypes.Find(x => x.Name == type.Name)) as CatalogData;

                        catalogData = JsonConvert.DeserializeObject(value, usedType) as CatalogData;

                        if (catalogData != null)
                        {
                            ModConfiguration.data[(int)category].Add(catalogData);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
        }
        private string Render(MerchantTribeApplication app, bool IsEditMode, Catalog.Category containerCategory)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"cols editable issortable");
            if (this.SpacerAbove)
            {
                sb.Append(" spacerabove");
            }
            sb.Append("\"");

            if (IsEditMode)
            {
                sb.Append(" id=\"part" + this.Id + "\"");
            }

            sb.Append(">");

            if (IsEditMode)
            {
                sb.Append(PartHelper.RenderEditTools(this.Id));
                sb.Append("<div class=\"colholder\"><strong>Columns</strong></div>");
            }

            for (int i = 0; i < _Columns.Count; i++)
            {
                bool isLast = (i == _Columns.Count - 1);

                sb.Append("<div class=\"grid_");
                sb.Append((int)_Columns[i].Size);
                if (isLast)
                {
                    if (_Columns[i].NoGutter)
                    {
                        if (_Parent.NoGutter)
                        {
                            sb.Append("w");
                        }
                        else
                        {
                            sb.Append("l");
                        }
                    }
                    else
                    {
                        sb.Append("l");
                    }
                }
                else
                {
                    if (_Columns[i].NoGutter)
                    {
                        sb.Append("w");
                    }
                }
                sb.Append("\" >");
                if (IsEditMode)
                {
                    sb.Append("<div class=\"droppable\" id=\"part" + _Columns[i].Id + "\">");

                    sb.Append("<div class=\"coltools\"><strong>Col");
                    if ((int)_Columns[i].Size > 1)
                    {
                        sb.Append("umn");
                    }
                    sb.Append("</strong> [" + ((int)_Columns[i].Size).ToString() + "]</div>");

                    sb.Append(_Columns[i].RenderForEdit(app, containerCategory));
                    sb.Append("</div>");
                }
                else
                {
                    sb.Append(_Columns[i].RenderForDisplay(app, containerCategory));
                }
                sb.Append("</div>");
            }
            sb.Append("<div class=\"clearcol\"></div>");
            sb.Append("</div>");
            return(sb.ToString());
        }