Beispiel #1
0
        private void CreateWheelsXElement(XElement element)
        {
            var childElement = new XElement("wheels");

            if (this.Wheel != null)
            {
                childElement.SetAttributeValue("type", this.Wheel.Type.ToString().ToLower());
                childElement.SetAttributeValue("width", this.Wheel.Width);
                childElement.SetAttributeValue("height", this.Wheel.Height);

                if (this.Wheel.Rows?.Any() ?? false)
                {
                    childElement.SetAttributeValue("rows", this.Wheel.Rows.ToCommaDelimitedString());
                }

                var wheelElement = new List <int>();
                for (var i = 0; i < this.Wheel.Width; i++)
                {
                    wheelElement.AddRange(this.Wheel[i]);
                }

                if (this.Wheel.ReelSets != null)
                {
                    childElement.SetAttributeValue("reelsets", this.Wheel.ReelSets.Select(reelSet => reelSet.Width).ToCommaDelimitedString());
                    CreateReelSetsXElement(childElement);
                }

                childElement.SetAttributeValue("val", this.Wheel.ToList().ToCommaDelimitedString());

                childElement.SetAttributeValue("val", wheelElement.ToCommaDelimitedString());
            }

            element.Add(childElement);
        }
Beispiel #2
0
        private void CreateBonusWheelsXElement(XElement element)
        {
            if (this.BonusWheel == null)
            {
                return;
            }

            var childElement = new XElement("bonuswheels");

            childElement.SetAttributeValue("type", this.BonusWheel.Type.ToString().ToLower());
            childElement.SetAttributeValue("width", this.BonusWheel.Width);
            childElement.SetAttributeValue("height", this.BonusWheel.Height);
            childElement.SetAttributeValue("mode", this.BonusWheel.Mode);

            var wheelElement = new List <int>();

            for (var i = 0; i < this.Wheel.Width; i++)
            {
                wheelElement.AddRange(this.BonusWheel[i]);
            }

            childElement.SetAttributeValue("val", wheelElement.ToCommaDelimitedString());

            element.Add(childElement);
        }
            protected override void Render(System.Web.UI.HtmlTextWriter output)
            {
                if (string.IsNullOrEmpty(_robots))
                {
                    _robots = "INDEX,FOLLOW,ARCHIVE";
                }

                output.Write("<meta name=\"description\" content=\"" + _description.Replace("\"", "\'").Replace("\r", "").Replace("\n", "") + "\">");
                output.Write("<meta name=\"keywords\" content=\"" + _keywords.ToCommaDelimitedString() + "\">");
                output.Write("<meta name=\"robots\" content=\"" + _robots + "\">");
            }
        public void ToCommaDelimitedString_ReturnsQuotedText_ForListWithCommas()
        {
            List <string> origList = new List <string>()
            {
                "One",
                "Two",
                "Three,Four",
                "Five",
                "Six"
            };
            string expectedString = "One,Two,\"Three,Four\",Five,Six";

            Assert.That(() => origList.ToCommaDelimitedString(), Is.EqualTo(expectedString));
        }
Beispiel #5
0
        private void CreateWheelsXElement(XElement element)
        {
            var wheel        = this.Wheel;
            var childElement = new XElement("wheels");

            childElement.SetAttributeValue("type", wheel.Type.ToString().ToLower());
            childElement.SetAttributeValue("width", wheel.Width);
            childElement.SetAttributeValue("height", wheel.Height);
            var wheelElement = new List <int>();

            for (var i = 0; i < wheel.Width; i++)
            {
                wheelElement.AddRange(wheel[i]);
            }
            childElement.SetAttributeValue("val", wheelElement.ToCommaDelimitedString());

            element.Add(childElement);
        }
        public override string Translate(SqlLockType lockType)
        {
            var items = new List <string>();

            items.Add("ROWLOCK");
            if (lockType.Supports(SqlLockType.Update))
            {
                items.Add("UPDLOCK");
            }
            else if (lockType.Supports(SqlLockType.Exclusive))
            {
                items.Add("XLOCK");
            }
            if (lockType.Supports(SqlLockType.ThrowIfLocked))
            {
                items.Add("NOWAIT");
            }
            else if (lockType.Supports(SqlLockType.SkipLocked))
            {
                items.Add("READPAST");
            }
            return(items.ToCommaDelimitedString());
        }
Beispiel #7
0
        public IList<ulong> Pages_GetParentIds(PageBE page) {

            //MaxM: This query returns 10 segments of a hierarchy without using a loop or titles and can be query cached. Please don't submit to the dailywtf. :)
            string query = @" /* Pages_GetParentIds */
select p0.page_id, p0.page_parent, p1.page_parent, p2.page_parent, p3.page_parent, p4.page_parent, p5.page_parent, p6.page_parent, p7.page_parent, p8.page_parent, p9.page_parent
from pages p0
left join pages p1 on p0.page_parent = p1.page_id
left join pages p2 on p1.page_parent = p2.page_id
left join pages p3 on p2.page_parent = p3.page_id
left join pages p4 on p3.page_parent = p4.page_id
left join pages p5 on p4.page_parent = p5.page_id
left join pages p6 on p5.page_parent = p6.page_id
left join pages p7 on p6.page_parent = p7.page_id
left join pages p8 on p7.page_parent = p8.page_id
left join pages p9 on p8.page_parent = p9.page_id
where p0.page_id = ?PAGEID;";

            ulong homepageid = Head.Pages_HomePageId;
            int counter = 0;
            ulong id = page.ID;
            bool first = true;
            Dictionary<ulong, object> dupeChecker = new Dictionary<ulong, object>();
            List<ulong> result = new List<ulong>(16);

            // loop until we've found all the parents
            while(counter++ < 20) {

                // execute query for given page
                bool done = false;
                Catalog.NewQuery(query)
                    .With("PAGEID", id)
                    .Execute(delegate(IDataReader dr) {
                    if(dr.Read()) {
                        for(int i = first ? 0 : 1; i < dr.FieldCount; i++) {
                            ulong parentPageId = DbUtils.Convert.To<ulong>(dr.GetValue(i)) ?? 0;
                            if(parentPageId == 0) {

                                // no valid parent found
                                if(page.Title.Namespace == NS.MAIN) {

                                    // add the homepage for pages in the MAIN namespace
                                    result.Add(homepageid);
                                }
                                done = true;
                                break;
                            } else {
                                if(!dupeChecker.ContainsKey(parentPageId)) {
                                    result.Add(parentPageId);
                                    dupeChecker[parentPageId] = null;
                                } else {

                                    //Cycle detected
                                    done = true;
                                }
                            }
                        }
                    } else {
                        done = true;
                    }
                });

                // check if done
                if(done) {
                    return result;
                }

                // continue with last parent id
                id = result[result.Count - 1];
                first = false;
            }
            throw new Exception(string.Format("GetParentPages failed: too many iterations. Starting id: {0} Parent chain: {1}", page.ID, result.ToCommaDelimitedString()));
        }
Beispiel #8
0
        private void DetermineConfigEditControl()
        {
            // clear out the controls collection for would be-new type of controls
            plhConfigValueEditor.Controls.Clear();

            GlobalConfig config   = this.Datasource;
            string       editorId = string.Format("ctrlConfigEditor{0}", config.ID);

            if (config.ValueType.EqualsIgnoreCase("integer"))
            {
                TextBox txt = new TextBox();
                txt.ID         = editorId;
                txt.Text       = config.ConfigValue;
                GetConfigValue = () => { return(txt.Text); };

                FilteredTextBoxExtender extFilterInt = new FilteredTextBoxExtender();
                extFilterInt.ID = "extFilterInt";
                extFilterInt.TargetControlID = editorId;
                extFilterInt.FilterType      = FilterTypes.Numbers;

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterInt);
            }
            else if (config.ValueType.EqualsIgnoreCase("decimal") || config.ValueType.EqualsIgnoreCase("double"))
            {
                TextBox txt = new TextBox();
                txt.ID         = editorId;
                txt.Text       = config.ConfigValue;
                GetConfigValue = () => { return(txt.Text); };

                FilteredTextBoxExtender extFilterNumeric = new FilteredTextBoxExtender();
                extFilterNumeric.ID = "extFilterNumeric";
                extFilterNumeric.TargetControlID = editorId;
                extFilterNumeric.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
                extFilterNumeric.ValidChars      = ".";

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterNumeric);
            }
            else if (config.ValueType.EqualsIgnoreCase("boolean"))
            {
                bool isYes = Localization.ParseBoolean(config.ConfigValue);

                RadioButtonList rbYesNo = new RadioButtonList();
                rbYesNo.ID = editorId;
                rbYesNo.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;

                ListItem optionYes = new ListItem("Yes");
                ListItem optionNo  = new ListItem("No");

                optionYes.Selected = isYes;
                optionNo.Selected  = !isYes;

                rbYesNo.Items.Add(optionYes);
                rbYesNo.Items.Add(optionNo);

                GetConfigValue = () => { return(optionYes.Selected.ToString().ToLowerInvariant()); };

                plhConfigValueEditor.Controls.Add(rbYesNo);
            }
            else if (config.ValueType.EqualsIgnoreCase("enum"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;
                foreach (string value in config.AllowableValues)
                {
                    cboValues.Items.Add(value);
                }
                cboValues.SelectedValue = config.ConfigValue;

                GetConfigValue = () => { return(cboValues.SelectedValue); };

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("invoke"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;

                bool   invocationSuccessful = false;
                string errorMessage         = string.Empty;

                try
                {
                    if (config.AllowableValues.Count == 3)
                    {
                        // format should be
                        // {FullyQualifiedName},MethodName
                        // Fully qualified name format is Namespace.TypeName,AssemblyName
                        string typeName     = config.AllowableValues[0];
                        string assemblyName = config.AllowableValues[1];
                        string methodName   = config.AllowableValues[2];

                        string     fqName = typeName + "," + assemblyName;
                        Type       t      = Type.GetType(fqName);
                        object     o      = Activator.CreateInstance(t);
                        MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                        object     result = method.Invoke(o, new object[] { });

                        if (result is IEnumerable)
                        {
                            cboValues.DataSource = result;
                            cboValues.DataBind();

                            invocationSuccessful = true;

                            // now try to find which one is matching, case-insensitive
                            foreach (ListItem item in cboValues.Items)
                            {
                                item.Selected = item.Text.EqualsIgnoreCase(config.ConfigValue);
                            }
                        }
                        else
                        {
                            errorMessage         = "Invocation method must return IEnumerable";
                            invocationSuccessful = false;
                        }
                    }
                    else
                    {
                        errorMessage         = "Invalid invocation value";
                        invocationSuccessful = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage         = ex.Message;
                    invocationSuccessful = false;
                }

                if (invocationSuccessful == false)
                {
                    cboValues.Items.Add(errorMessage);
                }

                GetConfigValue = () => { return(cboValues.SelectedValue); };

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("multiselect"))
            {
                CheckBoxList chkValues = new CheckBoxList();
                chkValues.ID = editorId;

                Func <string, bool> isIncluded = (optionValue) =>
                {
                    return(config.ConfigValue.Split(',').Any(val => val.Trim().EqualsIgnoreCase(optionValue)));
                };

                foreach (string optionValue in config.AllowableValues)
                {
                    ListItem option = new ListItem(optionValue, optionValue);
                    option.Selected = isIncluded(optionValue);
                    chkValues.Items.Add(option);
                }

                GetConfigValue = () =>
                {
                    var selectedValues = new List <string>();
                    foreach (ListItem option in chkValues.Items)
                    {
                        if (option.Selected)
                        {
                            selectedValues.Add(option.Value);
                        }
                    }

                    // format the selected values into a comma delimited string
                    return(selectedValues.ToCommaDelimitedString());
                };

                plhConfigValueEditor.Controls.Add(chkValues);
            }
            else
            {
                // determine length for proper control to use
                string configValue = config.ConfigValue;

                TextBox txt = new TextBox();
                txt.ID   = editorId;
                txt.Text = configValue;

                if (configValue.Length >= MAX_COLUMN_LENGTH)
                {
                    // use textArea
                    txt.TextMode = TextBoxMode.MultiLine;
                    txt.Rows     = 4; // make it 4 rows by default
                }

                txt.Columns = DetermineProperTextColumnLength(configValue);

                GetConfigValue = () => { return(txt.Text); };

                plhConfigValueEditor.Controls.Add(txt);
            }
        }
Beispiel #9
0
        private PlaceHolder DetermineConfigEditControl(string StoreName, int StoreId, AppConfig config)
        {
            PlaceHolder plhConfigValueEditor = new PlaceHolder();
            String      editorId;
            Boolean     isnew = (config == null);

            if (isnew)
            {
                //return AddParameterControl(StoreName, StoreId, config);
                config   = AppLogic.GetAppConfigRouted(this.Datasource.Name, StoreId);
                editorId = string.Format("ctrlNewConfig{0}_{1}", StoreId, this.Datasource.AppConfigID);
                plhConfigValueEditor.Controls.Add(new LiteralControl("<small style=\"color:gray;\">(Unassigned for <em>{0}</em>. Currently using default.)</small><br />".FormatWith(Store.GetStoreName(StoreId))));
            }
            else
            {
                editorId = string.Format("ctrlConfigEditor{0}", config.AppConfigID);
            }


            if (config.ValueType.EqualsIgnoreCase("integer"))
            {
                TextBox txt = new TextBox();
                txt.ID        = editorId;
                txt.Text      = config.ConfigValue;
                m_configvalue = txt.Text;

                CompareValidator compInt = new CompareValidator();
                compInt.Type              = ValidationDataType.Integer;
                compInt.Operator          = ValidationCompareOperator.DataTypeCheck;
                compInt.ControlToValidate = txt.ID;
                compInt.ErrorMessage      = AppLogic.GetString("admin.editquantitydiscounttable.EnterInteger", ThisCustomer.LocaleSetting);

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(compInt);
            }
            else if (config.ValueType.EqualsIgnoreCase("decimal") || config.ValueType.EqualsIgnoreCase("double"))
            {
                TextBox txt = new TextBox();
                txt.ID        = editorId;
                txt.Text      = config.ConfigValue;
                m_configvalue = txt.Text;

                FilteredTextBoxExtender extFilterNumeric = new FilteredTextBoxExtender();
                extFilterNumeric.ID = DB.GetNewGUID();
                extFilterNumeric.TargetControlID = editorId;
                extFilterNumeric.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
                extFilterNumeric.ValidChars      = ".";

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterNumeric);
            }
            else if (config.ValueType.EqualsIgnoreCase("boolean"))
            {
                bool isYes = Localization.ParseBoolean(config.ConfigValue);

                RadioButtonList rbYesNo = new RadioButtonList();
                rbYesNo.ID = editorId;
                rbYesNo.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;

                ListItem optionYes = new ListItem("Yes");
                ListItem optionNo  = new ListItem("No");

                if (StoreId == 0)
                {
                    optionYes.Attributes.Add("onclick", "$(this).parents('.modal_popup_Content').find('span.defaultTrue input').each(function (index, value) {$(value).click();});");
                    optionNo.Attributes.Add("onclick", "$(this).parents('.modal_popup_Content').find('span.defaultFalse input').each(function (index, value) {$(value).click();});");
                }
                else if (isnew)
                {
                    optionYes.Attributes.Add("class", "defaultTrue");
                    optionNo.Attributes.Add("class", "defaultFalse");
                }

                optionYes.Selected = isYes;
                optionNo.Selected  = !isYes;

                rbYesNo.Items.Add(optionYes);
                rbYesNo.Items.Add(optionNo);

                m_configvalue = optionYes.Selected.ToString().ToLowerInvariant();

                plhConfigValueEditor.Controls.Add(rbYesNo);
            }
            else if (config.ValueType.EqualsIgnoreCase("enum"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;
                foreach (string value in config.AllowableValues)
                {
                    cboValues.Items.Add(value);
                }
                cboValues.SelectedValue = config.ConfigValue;

                m_configvalue = cboValues.SelectedValue;

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("invoke"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;

                bool   invocationSuccessful = false;
                string errorMessage         = string.Empty;

                try
                {
                    if (config.AllowableValues.Count == 3)
                    {
                        // format should be
                        // {FullyQualifiedName},MethodName
                        // Fully qualified name format is Namespace.TypeName,AssemblyName
                        string typeName     = config.AllowableValues[0];
                        string assemblyName = config.AllowableValues[1];
                        string methodName   = config.AllowableValues[2];

                        string     fqName = typeName + "," + assemblyName;
                        Type       t      = Type.GetType(fqName);
                        object     o      = Activator.CreateInstance(t);
                        MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                        object     result = method.Invoke(o, new object[] { });

                        if (result is IEnumerable)
                        {
                            cboValues.DataSource = result;
                            cboValues.DataBind();

                            invocationSuccessful = true;

                            // now try to find which one is matching, case-insensitive
                            foreach (ListItem item in cboValues.Items)
                            {
                                item.Selected = item.Text.EqualsIgnoreCase(config.ConfigValue);
                            }
                        }
                        else
                        {
                            errorMessage         = "Invocation method must return IEnumerable";
                            invocationSuccessful = false;
                        }
                    }
                    else
                    {
                        errorMessage         = "Invalid invocation value";
                        invocationSuccessful = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage         = ex.Message;
                    invocationSuccessful = false;
                }

                if (invocationSuccessful == false)
                {
                    cboValues.Items.Add(errorMessage);
                }

                m_configvalue = cboValues.SelectedValue;

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("multiselect"))
            {
                CheckBoxList chkValues = new CheckBoxList();
                chkValues.ID = editorId;

                Func <string, bool> isIncluded = (optionValue) =>
                {
                    return(config.ConfigValue.Split(',').Any(val => val.Trim().EqualsIgnoreCase(optionValue)));
                };

                foreach (string optionValue in config.AllowableValues)
                {
                    ListItem option = new ListItem(optionValue, optionValue);
                    option.Selected = isIncluded(optionValue);
                    chkValues.Items.Add(option);
                }

                List <string> selectedValues = new List <string>();
                foreach (ListItem option in chkValues.Items)
                {
                    if (option.Selected)
                    {
                        selectedValues.Add(option.Value);
                    }
                }

                // format the selected values into a comma delimited string
                m_configvalue = selectedValues.ToCommaDelimitedString();

                plhConfigValueEditor.Controls.Add(chkValues);
            }
            else
            {
                // determine length for proper control to use
                string configValue = config.ConfigValue;

                TextBox txt = new TextBox();
                txt.ID   = editorId;
                txt.Text = configValue;

                if (configValue.Length >= MAX_COLUMN_LENGTH)
                {
                    // use textArea
                    txt.TextMode = TextBoxMode.MultiLine;
                    txt.Rows     = 4; // make it 4 rows by default
                }

                txt.Columns = DetermineProperTextColumnLength(configValue);

                m_configvalue = txt.Text;

                plhConfigValueEditor.Controls.Add(txt);
            }

            return(plhConfigValueEditor);
        }
Beispiel #10
0
        private String GetConfigValue(PlaceHolder plhConfigValueEditor, AppConfig thisConfig, Boolean findNew, int StoreId)
        {
            if (thisConfig == null)
            {
                throw new ArgumentException("config cannot be null.");
            }

            string configVal = thisConfig.ConfigValue;

            string editorId;

            if (findNew)
            {
                editorId = string.Format("ctrlNewConfig{0}_{1}", StoreId, this.Datasource.AppConfigID);
            }
            else
            {
                editorId = string.Format("ctrlConfigEditor{0}", thisConfig.AppConfigID);
            }

            if (m_OriginalDefaultType.EqualsIgnoreCase("integer"))
            {
                TextBox txt = plhConfigValueEditor.FindControl <TextBox>(editorId);
                configVal = txt.Text;
            }
            else if (m_OriginalDefaultType.EqualsIgnoreCase("decimal") || thisConfig.ValueType.EqualsIgnoreCase("double"))
            {
                TextBox txt = plhConfigValueEditor.FindControl <TextBox>(editorId);
                configVal = txt.Text;
            }
            else if (m_OriginalDefaultType.EqualsIgnoreCase("boolean"))
            {
                bool isYes = Localization.ParseBoolean(thisConfig.ConfigValue);

                RadioButtonList rbYesNo = plhConfigValueEditor.FindControl <RadioButtonList>(editorId);
                configVal = rbYesNo.Items[0].Selected.ToString().ToLowerInvariant();
            }
            else if (m_OriginalDefaultType.EqualsIgnoreCase("enum"))
            {
                DropDownList cboValues = plhConfigValueEditor.FindControl <DropDownList>(editorId);
                configVal = cboValues.SelectedValue;
            }
            else if (m_OriginalDefaultType.EqualsIgnoreCase("invoke"))
            {
                DropDownList cboValues = plhConfigValueEditor.FindControl <DropDownList>(editorId);

                configVal = cboValues.SelectedValue;
            }
            else if (m_OriginalDefaultType.EqualsIgnoreCase("multiselect"))
            {
                CheckBoxList chkValues = plhConfigValueEditor.FindControl <CheckBoxList>(editorId);

                List <string> selectedValues = new List <string>();
                foreach (ListItem option in chkValues.Items)
                {
                    if (option.Selected)
                    {
                        selectedValues.Add(option.Value);
                    }
                }

                // format the selected values into a comma delimited string
                configVal = selectedValues.ToCommaDelimitedString();
            }
            else
            {
                TextBox txt = plhConfigValueEditor.FindControl <TextBox>(editorId);
                configVal = txt.Text;
            }

            return(configVal);
        }
        public void ToCommaDelimitedString_ReturnsBlankString_ForEmptyList()
        {
            List <string> emptyList = new List <string>();

            Assert.That(() => emptyList.ToCommaDelimitedString(), Is.EqualTo(""));
        }
Beispiel #12
0
        public IList <ulong> Pages_GetParentIds(PageBE page)
        {
            //MaxM: This query returns 10 segments of a hierarchy without using a loop or titles and can be query cached. Please don't submit to the dailywtf. :)
            string query = @" /* Pages_GetParentIds */
select p0.page_id, p0.page_parent, p1.page_parent, p2.page_parent, p3.page_parent, p4.page_parent, p5.page_parent, p6.page_parent, p7.page_parent, p8.page_parent, p9.page_parent
from pages p0
left join pages p1 on p0.page_parent = p1.page_id
left join pages p2 on p1.page_parent = p2.page_id
left join pages p3 on p2.page_parent = p3.page_id
left join pages p4 on p3.page_parent = p4.page_id
left join pages p5 on p4.page_parent = p5.page_id
left join pages p6 on p5.page_parent = p6.page_id
left join pages p7 on p6.page_parent = p7.page_id
left join pages p8 on p7.page_parent = p8.page_id
left join pages p9 on p8.page_parent = p9.page_id
where p0.page_id = ?PAGEID;";

            ulong homepageid = Head.Pages_HomePageId;
            int   counter    = 0;
            ulong id         = page.ID;
            bool  first      = true;
            Dictionary <ulong, object> dupeChecker = new Dictionary <ulong, object>();
            List <ulong> result = new List <ulong>(16);

            // loop until we've found all the parents
            while (counter++ < 20)
            {
                // execute query for given page
                bool done = false;
                Catalog.NewQuery(query)
                .With("PAGEID", id)
                .Execute(delegate(IDataReader dr) {
                    if (dr.Read())
                    {
                        for (int i = first ? 0 : 1; i < dr.FieldCount; i++)
                        {
                            ulong parentPageId = DbUtils.Convert.To <ulong>(dr.GetValue(i)) ?? 0;
                            if (parentPageId == 0)
                            {
                                // no valid parent found
                                if (page.Title.Namespace == NS.MAIN)
                                {
                                    // add the homepage for pages in the MAIN namespace
                                    result.Add(homepageid);
                                }
                                done = true;
                                break;
                            }
                            else
                            {
                                if (!dupeChecker.ContainsKey(parentPageId))
                                {
                                    result.Add(parentPageId);
                                    dupeChecker[parentPageId] = null;
                                }
                                else
                                {
                                    //Cycle detected
                                    done = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        done = true;
                    }
                });

                // check if done
                if (done)
                {
                    return(result);
                }

                // continue with last parent id
                id    = result[result.Count - 1];
                first = false;
            }
            throw new Exception(string.Format("GetParentPages failed: too many iterations. Starting id: {0} Parent chain: {1}", page.ID, result.ToCommaDelimitedString()));
        }
Beispiel #13
0
 private void WriteLinks(int page, List<string> tags, List<string> searchTerms, string sortBy)
 {
     if (sortBy == null)
         sortBy = "DATE";
     this.CommandResult.ClearScreen = true;
     this.CommandResult.ScrollToBottom = true;
     var linksPage = _linkRepository.GetLinks(page, AppSettings.LinksPerPage, tags, searchTerms, sortBy);
     if (page > linksPage.TotalPages)
         page = linksPage.TotalPages;
     else if (page < 1)
         page = 1;
     this.CommandResult.WriteLine(DisplayMode.Inverted | DisplayMode.Bold, "Welcome to the links board!");
     this.CommandResult.WriteLine();
     this.CommandResult.WriteLine(DisplayMode.Bold, "Active Filters");
     this.CommandResult.WriteLine("Tags: {0}", tags.ToCommaDelimitedString());
     this.CommandResult.WriteLine("Search Terms: {0}", searchTerms.ToCommaDelimitedString());
     this.CommandResult.WriteLine("Sorted By: {0}", sortBy.ToUpper());
     this.CommandResult.WriteLine();
     this.CommandResult.WriteLine(DisplayMode.DontType, "Page {0}/{1}", page, linksPage.TotalPages);
     this.CommandResult.WriteLine();
     this.CommandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
     foreach (var link in linksPage.Items)
     {
         var displayMode = DisplayMode.DontType;
         var lastLinkComment = link.LinkComments.LastOrDefault();
         this.CommandResult.WriteLine(displayMode | DisplayMode.Bold, "{{[transmit=LINK]{0}[/transmit]}} {1}", link.LinkID, link.Title);
         this.CommandResult.WriteLine(displayMode, "   by [transmit=USER]{0}[/transmit] {1} | {2} comments", link.Username, link.Date.TimePassed(), link.LinkComments.Count);
         if (lastLinkComment != null)
             this.CommandResult.WriteLine(displayMode, "   last comment by [transmit=USER]{0}[/transmit] {1}", lastLinkComment.Username, lastLinkComment.Date.TimePassed());
         this.CommandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
     }
     if (linksPage.TotalItems == 0)
     {
         this.CommandResult.WriteLine("There are no links on the links board at this time.");
         this.CommandResult.WriteLine();
         this.CommandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
         this.CommandResult.WriteLine();
     }
     this.CommandResult.WriteLine();
     this.CommandResult.WriteLine(DisplayMode.DontType, "Page {0}/{1}", page, linksPage.TotalPages);
     this.CommandResult.CommandContext.CurrentPage = page;
     this.CommandResult.CommandContext.CurrentLinkTags = tags;
     this.CommandResult.CommandContext.CurrentSearchTerms = searchTerms;
     this.CommandResult.CommandContext.CurrentSortOrder = sortBy;
     this.CommandResult.CommandContext.Set(ContextStatus.Passive, this.Name, null, null);
 }