Carrotware.CMS.Mvc.UI.Admin.Service.CMS.CacheWidgetUpdate C# (CSharp) Метод

CacheWidgetUpdate() приватный Метод

private CacheWidgetUpdate ( string WidgetAddition, string ThisPage ) : string
WidgetAddition string
ThisPage string
Результат string
        public string CacheWidgetUpdate(string WidgetAddition, string ThisPage)
        {
            try {
                WidgetAddition = CMSConfigHelper.DecodeBase64(WidgetAddition);
                CurrentPageGuid = new Guid(ThisPage);
                LoadGuids();

                List<Widget> cacheWidget = cmsAdminWidget;

                List<Widget> inputWid = new List<Widget>();
                Dictionary<Guid, int> dictOrder = new Dictionary<Guid, int>();
                int iW = 0;

                WidgetAddition = WidgetAddition.Replace("\r\n", "\n");
                WidgetAddition = WidgetAddition.Replace("\r", "\n");
                string[] arrWidgRows = WidgetAddition.Split('\n');

                foreach (string arrWidgCell in arrWidgRows) {
                    if (!String.IsNullOrEmpty(arrWidgCell)) {
                        bool bGoodWidget = false;
                        string[] w = arrWidgCell.Split('\t');

                        Widget rWidg = new Widget();
                        if (w[2].ToLowerInvariant().EndsWith(".cshtml") || w[2].ToLowerInvariant().EndsWith(".vbhtml")
                                || w[2].ToLowerInvariant().Contains(":") || w[2].ToLowerInvariant().Contains("|")) {
                            rWidg.ControlPath = w[2];
                            rWidg.Root_WidgetID = Guid.NewGuid();

                            DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now);
                            rWidg.GoLiveDate = dtSite;
                            rWidg.RetireDate = dtSite.AddYears(200);

                            bGoodWidget = true;
                        } else {
                            if (w[2].ToString().Length == Guid.Empty.ToString().Length) {
                                rWidg.Root_WidgetID = new Guid(w[2]);
                                bGoodWidget = true;
                            }
                        }
                        if (bGoodWidget) {
                            dictOrder.Add(rWidg.Root_WidgetID, iW);

                            rWidg.WidgetDataID = Guid.NewGuid();
                            rWidg.IsPendingChange = true;
                            rWidg.PlaceholderName = w[1].Substring(4);
                            rWidg.WidgetOrder = int.Parse(w[0]);
                            rWidg.Root_ContentID = CurrentPageGuid;
                            rWidg.IsWidgetActive = true;
                            rWidg.IsLatestVersion = true;
                            rWidg.EditDate = SiteData.CurrentSite.Now;
                            inputWid.Add(rWidg);
                        }
                        iW++;
                    }
                }

                foreach (Widget wd1 in inputWid) {
                    Widget wd2 = (from d in cacheWidget where d.Root_WidgetID == wd1.Root_WidgetID select d).FirstOrDefault();

                    if (wd2 == null) {
                        cacheWidget.Add(wd1);
                    } else {
                        wd2.EditDate = SiteData.CurrentSite.Now;
                        wd2.PlaceholderName = wd1.PlaceholderName; // if moving zones

                        int i = cacheWidget.IndexOf(wd2);
                        cacheWidget[i].WidgetOrder = wd1.WidgetOrder;

                        int? mainSort = (from entry in dictOrder
                                         where entry.Key == wd1.Root_WidgetID
                                         select entry.Value).FirstOrDefault();

                        if (mainSort != null) {
                            cacheWidget[i].WidgetOrder = Convert.ToInt32(mainSort);
                        }
                    }
                }

                cmsAdminWidget = cacheWidget;
                return "OK";
            } catch (Exception ex) {
                SiteData.WriteDebugException("webservice", ex);

                return ex.ToString();
            }
        }