コード例 #1
0
        /*
                /// <summary>
                /// Display default dates or ones from session.
                /// </summary>
                /// <remarks></remarks>
                public static bool SetDefaultDates() {

                    try {
                        //check if start date in session is nothing, if so set it to 3 months ago (or first date if no data 3 months ago)
                        if (HttpContext.Current.Session(SessionConstants.START_DATE) == null) {
                            System.DateTime startDate = new System.DateTime();
                            System.DateTime endDate = new System.DateTime();

                            //Dim threeMonthsAgo = Date.Now.AddMonths(-3)
                            //Dim first = TimeStamp_Shared.GetFirstTimeStamp
                            //If threeMonthsAgo < first Then
                            //    startDate = first
                            //Else
                            //    startDate = threeMonthsAgo
                            //End If
                            //endDate = Date.Now

                            endDate = Inputs.GetLatestInputTimeStamp;
                            startDate = endDate.AddMonths(-3);

                            if (startDate < TimeStamp_Shared.GetFirstTimeStamp) {
                                startDate = TimeStamp_Shared.GetFirstTimeStamp;
                            }


                            HttpContext.Current.Session(SessionConstants.START_DATE) = startDate;
                            HttpContext.Current.Session(SessionConstants.END_DATE) = endDate;
                            return true;
                        }
                        else {
                            //start date in session is NOT nothing therefore show what was picked before
                            return false;
                        }

                    }
                    catch (Exception ex) {
                        UtilsShared.LogException(ex, HttpContext.Current.User.Identity.Name);
                    }
                }

                /// <summary>
                /// Return true if user is a developer or DebugOn is set to true.
                /// </summary>
                /// <returns></returns>
                /// <remarks></remarks>
                public static bool DisplayDebug() {
                    try {
                        //R               Dim userLoggedIn As String = UCase(HttpContext.Current.Session("UserName"))
                        //If UtilsShared.settings.DebugOn = True OrElse _
                        //       userLoggedIn = "RICHARDW" OrElse userLoggedIn = "RACHELA" OrElse userLoggedIn = "ANGUSC" Then
                        //    Return True
                        //Else
                        //    Return False
                        //End If
                    }
                    catch (Exception ex) {
                        UtilsShared.LogException(ex, HttpContext.Current.User.Identity.Name);
                        return false;
                    }
                }


                /// <summary>
                /// Display text on label. Display '-' if not a number etc.
                /// </summary>
                /// <param name="t"></param>
                /// <param name="value"></param>
                /// <param name="dp"></param>
                /// <remarks></remarks>
                public static void SetLabel(ref Label t, double value, int dp) {
                    //If Double.IsInfinity(value) OrElse Double.IsNaN(value) OrElse Double.IsNegativeInfinity(value) OrElse Double.IsPositiveInfinity(value) OrElse value = XMLConstants.ERROR_247 Then
                    //t.Text = "-"
                    //Else
                    t.Text = Strings.FormatNumber(value, dp);
                    //End If
                }

                /// <summary>
                /// check webconfig for path (path of settings.xml e.g. C:\Settings\Emissions Compiler\settings.xml)
                /// </summary>
                /// <returns></returns>
                /// <remarks></remarks>
                public static string GetECSettingsPath() {
                    return ConfigurationManager.AppSettings(XMLConstantsShared.SettingsXML);

                }

                /// <summary>
                /// Get Emissions Compiler settings from settings.xml file
                /// </summary>
                /// <returns></returns>
                /// <remarks></remarks>
                public static EmissionCompilerSettings GetECSettings() {
                    try {
                        //load settings if it isn't already loaded
                        if (EmissionCompilerSettings.settings == null) {
                            EmissionCompilerSettings.settings = EmissionCompilerSettings.LoadEmissionCompilerSettingsFromFile(GetECSettingsPath());
                        }

                        //return settings
                        return EmissionCompilerSettings.settings;

                    }
                    catch (Exception ex) {
                        UtilsShared.LogException(ex, HttpContext.Current.User.Identity.Name);
                        return null;
                    }
                }

               */

        /// <summary>
        /// Taken from MSDN but example calling to find GT control on page didn't work!
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Controls"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static T FindControl<T>(System.Web.UI.ControlCollection Controls) where T : class {
            try {
                T found = null;

                if (Controls != null && Controls.Count > 0) {
                    for (int i = 0; i <= Controls.Count - 1; i++) {
                        //System.Diagnostics.Debug.Print(Controls(i).UniqueID)
                        if (Controls[i] is T) {
                            found = Controls[i] as T;
                            break; // TODO: might not be correct. Was : Exit For
                        }
                        else {
                            found = FindControl<T>(Controls[i].Controls);
                        }
                    }
                }

                return found;

            }
            catch (Exception ex) {
                System.Diagnostics.Debug.Print("<h2>WebUtils Class, FindControl Method</h2>\n" + ex.ToString() + "\n" + ex.InnerException + "\n" + ex.Message);
                // Log the exception and notify system operators
                ExceptionUtility.LogException(ex, "WebUtils Class, FindControl Method");
                ExceptionUtility.NotifySystemOps(ex);
                return null;
            }
        }
コード例 #2
0
        public void AddControl(System.Web.UI.ControlCollection ControlliWeb, ParentType _myParent)
        {
            foreach (System.Web.UI.Control _Controllo in ControlliWeb)
            {
                clMyControl _myColl = new clMyControl(_myParent);

                if (_Controllo is System.Web.UI.WebControls.TextBox)
                {
                    _myColl.Valore        = ((System.Web.UI.WebControls.TextBox)_Controllo).Text;
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.TextBox)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.HtmlControls.HtmlInputHidden)
                {
                    _myColl.Valore        = ((System.Web.UI.HtmlControls.HtmlInputHidden)_Controllo).Value;
                    _myColl.NomeControllo = ((System.Web.UI.HtmlControls.HtmlInputHidden)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.WebControls.Label)
                {
                    _myColl.Valore        = ((System.Web.UI.WebControls.Label)_Controllo).Text;
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.Label)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.WebControls.CheckBox)
                {
                    _myColl.Valore        = Convert.ToString(((System.Web.UI.WebControls.CheckBox)_Controllo).Checked);
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.CheckBox)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.WebControls.ListBox)
                {
                    _myColl.Valore        = ((System.Web.UI.WebControls.ListBox)_Controllo).SelectedValue;
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.ListBox)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.WebControls.DropDownList)
                {
                    _myColl.Valore        = ((System.Web.UI.WebControls.DropDownList)_Controllo).SelectedValue;
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.DropDownList)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }
                if (_Controllo is System.Web.UI.WebControls.RadioButton)
                {
                    _myColl.Valore        = Convert.ToString(((System.Web.UI.WebControls.RadioButton)_Controllo).Checked);
                    _myColl.NomeControllo = ((System.Web.UI.WebControls.RadioButton)_Controllo).ClientID;
                    _myArray.Add(_myColl);
                }


                if (_Controllo.Controls.Count > 0)
                {
                    AddControl(_Controllo.Controls, _myParent);
                }
            }
        }
コード例 #3
0
ファイル: BBianLiControls.cs プロジェクト: zeje/zeje
 /// <summary>
 /// 遍历WebForm中的控件
 /// </summary>
 /// <param name="Controls"></param>
 public void BianLi(System.Web.UI.ControlCollection Controls)
 {
     foreach (System.Web.UI.Control item in Controls)
     {
         if (item is System.Web.UI.WebControls.TextBox)
         {
             ((System.Web.UI.WebControls.TextBox)item).Text = string.Empty;
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Outputs some navigation links to the page.
        /// </summary>
        /// <param name="controlCollection">the pages' contols</param>
        /// <param name="path">The path of the current image directory being browsed</param>
        /// <param name="url">The URL to use in the links</param>
        public static void RendenderLinkPath(System.Web.UI.ControlCollection controlCollection, string path, string url)
        {
            HyperLink h = new HyperLink();

            h.NavigateUrl = "/";
            h.Text        = "Home";
            h.Attributes.Add("class", "topNav");
            controlCollection.Add(h);

            Literal l = new Literal();

            l.Text = " &raquo; \n";
            controlCollection.Add(l);

            if (path != null && path.Length > 0)
            {
                path = path.Replace(@"\", "/");
            }
            else
            {
                Literal label = new Literal();
                label.Text = "My Pictures";
                controlCollection.Add(label);
                return;
            }

            string[] paths = path.Split('/');

            paths[0] = "My Pictures";

            for (int i = 1; i <= paths.Length; i++)
            {
                if (i < paths.Length)
                {
                    h             = new HyperLink();
                    h.NavigateUrl = url + string.Join("/", paths, 0, i).Replace("My Pictures", "/pics");
                    h.Text        = paths[i - 1];
                    h.Attributes.Add("class", "topNav");
                    controlCollection.Add(h);

                    l      = new Literal();
                    l.Text = " &raquo; \n";
                    controlCollection.Add(l);
                }
                else
                {
                    Literal label = new Literal();
                    label.Text = paths[i - 1];
                    controlCollection.Add(label);
                }
            }
        }
コード例 #5
0
 protected void setLabels(System.Web.UI.ControlCollection controls)
 {
     System.String label;
     foreach (System.Web.UI.Control childcontrol in controls)
     {
         if (childcontrol.HasControls())
         {
             this.setLabels(childcontrol.Controls);
         }
         if (childcontrol.ID == null)
         {
             continue;
         }
         label = null;
         label = this.resources.GetString(childcontrol.ID);
         if (label == null)
         {
             continue;
         }
         if (childcontrol is System.Web.UI.WebControls.Button)
         {
             ((System.Web.UI.WebControls.Button)childcontrol).Text = label;
         }
         else if (childcontrol is System.Web.UI.WebControls.HyperLink)
         {
             ((System.Web.UI.WebControls.HyperLink)childcontrol).ToolTip = label;
             ((System.Web.UI.WebControls.HyperLink)childcontrol).Text    = label;
         }
         else if (childcontrol is System.Web.UI.HtmlControls.HtmlAnchor)
         {
             ((System.Web.UI.HtmlControls.HtmlAnchor)childcontrol).Title     = label;
             ((System.Web.UI.HtmlControls.HtmlAnchor)childcontrol).InnerHtml = label;
         }
         else if (childcontrol is System.Web.UI.WebControls.ImageButton)
         {
             ((System.Web.UI.WebControls.ImageButton)childcontrol).ToolTip = label;
         }
         else if (childcontrol is System.Web.UI.WebControls.Label)
         {
             ((System.Web.UI.WebControls.Label)childcontrol).Text = label;
         }
         else if (childcontrol is System.Web.UI.WebControls.Literal)
         {
             ((System.Web.UI.WebControls.Literal)childcontrol).Text = label;
         }
         else if (childcontrol is System.Web.UI.WebControls.LinkButton)
         {
             ((System.Web.UI.WebControls.LinkButton)childcontrol).Text = label;
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Gets all controls of Type recursively.
        /// http://stackoverflow.com/questions/7362482/c-sharp-get-all-web-controls-on-page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="controlCollection">The control collection.</param>
        /// <param name="resultCollection">The result collection.</param>
        private static void GetControlListRecursive <T>(this System.Web.UI.ControlCollection controlCollection, List <T> resultCollection) where T : System.Web.UI.Control
        {
            foreach (System.Web.UI.Control control in controlCollection)
            {
                if (control is T)
                {
                    resultCollection.Add((T)control);
                }

                if (control.HasControls())
                {
                    GetControlListRecursive(control.Controls, resultCollection);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Outputs some navigation links to the page.
        /// </summary>
        /// <param name="controlCollection">the pages' contols</param>
        /// <param name="path">The path of the current image directory being browsed</param>
        /// <param name="url">The URL to use in the links</param>
        public static void RendenderLinkPath(System.Web.UI.ControlCollection controlCollection, string path, System.Web.UI.Control ctrl, ImageBrowserConfig cfg)
        {
            HyperLink h = null;
            Literal   l = null;

            if (path != null && path.Length > 0)
            {
                path = path.Replace(@"\", "/");
            }
            else
            {
                h             = new HyperLink();
                h.NavigateUrl = "";
                h.Text        = cfg.RootName;
                h.Attributes.Add("class", "LinkButton");
                controlCollection.Add(h);
                return;
            }

            string[] paths = path.Split('/');

            paths[0] = cfg.RootName;

            for (int i = 1; i <= paths.Length; i++)
            {
                if (i < paths.Length)
                {
                    h             = new HyperLink();
                    h.NavigateUrl = ctrl.Page.GetPostBackClientHyperlink(ctrl, "directory;" + string.Join("/", paths, 0, i).Replace(cfg.RootName, ""));
                    h.Text        = paths[i - 1];
                    h.Attributes.Add("class", "LinkButton");
                    controlCollection.Add(h);

                    l      = new Literal();
                    l.Text = " &raquo; \n";
                    controlCollection.Add(l);
                }
                else
                {
                    h             = new HyperLink();
                    h.NavigateUrl = "";
                    h.Text        = paths[i - 1];
                    h.Attributes.Add("class", "LinkButton");
                    controlCollection.Add(h);
                }
            }
        }
コード例 #8
0
        public void SetValues(System.Web.UI.ControlCollection Controlli)
        {
            foreach (System.Web.UI.Control _Controllo in Controlli)
            {
                foreach (clMyControl _myColl in _myArray)
                {
                    if (_myColl.NomeControllo == _Controllo.ClientID)
                    {
                        if (_Controllo is System.Web.UI.WebControls.TextBox)
                        {
                            ((System.Web.UI.WebControls.TextBox)_Controllo).Text = _myColl.Valore;
                        }
                        if (_Controllo is System.Web.UI.HtmlControls.HtmlInputHidden)
                        {
                            ((System.Web.UI.HtmlControls.HtmlInputHidden)_Controllo).Value = _myColl.Valore;
                        }
                        if (_Controllo is System.Web.UI.WebControls.Label)
                        {
                            ((System.Web.UI.WebControls.Label)_Controllo).Text = _myColl.Valore;
                        }
                        if (_Controllo is System.Web.UI.WebControls.CheckBox)
                        {
                            ((System.Web.UI.WebControls.CheckBox)_Controllo).Checked = Convert.ToBoolean(_myColl.Valore);
                        }
                        if (_Controllo is System.Web.UI.WebControls.ListBox)
                        {
                            ((System.Web.UI.WebControls.ListBox)_Controllo).SelectedValue = _myColl.Valore;
                        }
                        if (_Controllo is System.Web.UI.WebControls.DropDownList)
                        {
                            ((System.Web.UI.WebControls.DropDownList)_Controllo).SelectedValue = _myColl.Valore;
                        }
                        if (_Controllo is System.Web.UI.WebControls.RadioButton)
                        {
                            ((System.Web.UI.WebControls.RadioButton)_Controllo).Checked = Convert.ToBoolean(_myColl.Valore);
                        }
                    }
                }

                if (_Controllo.Controls.Count > 0)
                {
                    SetValues(_Controllo.Controls);
                }
            }
        }
コード例 #9
0
 static public void GetPageAllControl(ref ArrayList ret, System.Web.UI.ControlCollection cc)
 {
     foreach (System.Web.UI.Control ctl in cc)
     {
         if (ctl.Controls != null && ctl.Controls.Count > 0)
         {
             GetPageAllControl(ref ret, ctl.Controls);
         }
         else if (ctl.GetType().ToString().StartsWith("System.Web.UI.WebControls"))
         {
             ret.Add(ctl);
         }
         else if (ctl.GetType().ToString().StartsWith("System.Web.UI.HtmlControls"))
         {
             ret.Add(ctl);
         }
     }
 }
コード例 #10
0
 /// <summary>
 /// کنترلها و کنترهای داخلی را بصورت بازگشتی استخراج میکند
 /// </summary>
 /// <param name="result"></param>
 /// <param name="control"></param>
 private void GetControls(List <ResourceControl> result, System.Web.UI.ControlCollection controls)
 {
     for (int i = 0; i < controls.Count; i++)
     {
         System.Web.UI.Control control = controls[i];
         if (control.Controls != null && control.Controls.Count > 0)
         {
             GetControls(result, control.Controls);
         }
         if (control is CpontArt.NavBar)
         {
             CpontArt.NavBar navabar = (NavBar)control;
             NavBarControles.Add(navabar);
         }
         else if (control is CpontArt.ToolBar)
         {
             CpontArt.ToolBar toolabar = (ToolBar)control;
             toolbarControles.Add(toolabar);
         }
     }
 }
コード例 #11
0
ファイル: Foundry.cs プロジェクト: temaperacl/florine
        public System.Web.UI.Control RenderPage(GameState GameStatus, IPage Source, bool debugInfo)
        {
            System.Web.UI.Control Body;

            if (debugInfo)
            {
                return(RenderDebugInfo(GameStatus, Source));
            }

            System.Web.UI.HtmlControls.HtmlForm director = new System.Web.UI.HtmlControls.HtmlForm()
            {
                Action = "."
            };
            director.EnableViewState = false;
            director.ViewStateMode   = System.Web.UI.ViewStateMode.Disabled;
            director.Style["border"] = "1px solid black";
            Body = director;

            if (Source.Background != null)
            {
                Body.Controls.Add(ImageFromObject(Source.Background, "", false));
            }
            else
            {
                if (null != GameStatus &&
                    null != GameStatus.Player &&
                    null != GameStatus.Player.Avatar &&
                    null != GameStatus.Player.Avatar.Picture)
                {
                    System.Web.UI.HtmlControls.HtmlTable DisplayTable =
                        new System.Web.UI.HtmlControls.HtmlTable();
                    DisplayTable.Rows.Add(new System.Web.UI.HtmlControls.HtmlTableRow()
                    {
                        Cells =
                        {
                            new System.Web.UI.HtmlControls.HtmlTableCell()
                            {
                                Controls =
                                {
                                    ImageFromObject(
                                        GameStatus.Player.Avatar.Picture,
                                        "Player_Avatar_Picture",
                                        false
                                        )
                                }
                            },
                            new System.Web.UI.HtmlControls.HtmlTableCell()
                            {
                                Controls =
                                {
                                    RenderNutrientBlock(GameStatus.Player.Nutrients,
                                                        "Status", false
                                                        )
                                }
                            },
                            new System.Web.UI.HtmlControls.HtmlTableCell()
                            {
                                Controls =
                                {
                                    RenderNutrientBlock(GameStatus.CurrentDelta,
                                                        "Current", false
                                                        )
                                }
                            },
                            new System.Web.UI.HtmlControls.HtmlTableCell()
                            {
                                Controls =
                                {
                                    RenderNutrientBlock(GameStatus.DailyDelta,
                                                        "Change Today", true
                                                        )
                                }
                            }
                        }
                    });
                    DisplayTable.Rows.Add(new System.Web.UI.HtmlControls.HtmlTableRow()
                    {
                        Cells =
                        {
                            new System.Web.UI.HtmlControls.HtmlTableCell()
                            {
                                Controls =
                                {
                                    new System.Web.UI.WebControls.Label()
                                    {
                                        Text = "<br/>Energy: "
                                               + GameStatus.Player.Energy.ToString()
                                    },
                                    new System.Web.UI.WebControls.Label()
                                    {
                                        Text = "<br/>Focus: "
                                               + GameStatus.Player.Focus.ToString()
                                    },
                                    new System.Web.UI.WebControls.Label()
                                    {
                                        Text = "<br/>Hunger: "
                                               + GameStatus.Player.Hunger.ToString()
                                    },
                                    new System.Web.UI.WebControls.Label()
                                    {
                                        Text = "<br/>kCal/target: "
                                               + GameStatus.Player.Calories.ToString()
                                               + " / "
                                               + GameStatus.Player.TargetCalories.ToString()
                                    },
                                }
                            }
                        }
                    });
                    Body.Controls.Add(DisplayTable);
                }
            }
            if (Source.Title != null)
            {
                Body.Controls.Add(new System.Web.UI.HtmlControls.HtmlGenericControl("h3")
                {
                    InnerHtml = Source.Title
                });
            }
            if (Source.Message != null)
            {
                System.Web.UI.WebControls.Panel MessagePanel = new System.Web.UI.WebControls.Panel();
                MessagePanel.Controls.Add(new System.Web.UI.WebControls.Label()
                {
                    Text = Source.Message
                });
                Body.Controls.Add(MessagePanel);
            }

            System.Web.UI.ControlCollection form = Body.Controls;

            ControlLookup["CurrentPage"] = new System.Web.UI.HtmlControls.HtmlInputHidden()
            {
                ID            = "stg_curpage",
                Value         = Source.MainType.ToString(),
                ViewStateMode = System.Web.UI.ViewStateMode.Disabled
            };
            form.Add(ControlLookup["CurrentPage"]);

            /* Special Handling for Character Creation */
            if (Source.MainType == GameState.PageType.Char_Creation)
            {
                form.Add(CharCreateControls(Source));
            }

            if (null != Source.PrimaryOptions)
            {
                form.Add(RenderOptions(Source.PrimaryOptions, true));
            }
            if (null != Source.AppliedOptions)
            {
                form.Add(RenderOptions(Source.AppliedOptions, false));
            }

            return(Body);
        }
コード例 #12
0
        private System.Windows.Forms.TreeNode AddNodeTreeWindows(System.Web.UI.ControlCollection parentCollection, TreeNode Parent)
        {
            System.Windows.Forms.TreeNode ret = null;

            foreach (object control in parentCollection)
            {
                ActiveUp.WebControls.TreeNode child = control as ActiveUp.WebControls.TreeNode;
                if (child != null)

                {
                    System.Windows.Forms.TreeNode newNode = new System.Windows.Forms.TreeNode(child.Text);
                    if (child.Expanded == true)
                    {
                        newNode.Expand();
                    }

                    NodeDesign nodeList = null;

                    if (Parent == null)
                    {
                        _tvTree.Nodes.Add(newNode);

                        nodeList = new NodeDesign(child.Key, "0", child.Text, child.Link);
                    }

                    else
                    {
                        System.Windows.Forms.TreeNode parentNode = GetNode(Parent.Key, _tvTree.Nodes, TypeSearch.searchID);
                        if (parentNode != null)
                        {
                            parentNode.Nodes.Add(newNode);
                        }

                        nodeList = new NodeDesign(child.Key, Parent.Key, child.Text, child.Link);
                    }

                    nodeList.Target    = child.Target;
                    nodeList.Expanded  = child.Expanded;
                    nodeList.Selected  = child.Selected;
                    nodeList.Icon      = child.Icon;
                    nodeList.NodeStyle = child.NodeStyle;

                    if (child.Selected == true)
                    {
                        newNode.Checked = true;
                    }

                    newNode.Tag = nodeList;

                    if (child.Nodes.Count > 0)
                    {
                        ret = AddNodeTreeWindows(child.Nodes, child);
                    }

                    if (ret != null)
                    {
                        break;
                    }
                }
            }

            return(ret);
        }
コード例 #13
0
 public void PageRequest(System.Web.UI.ControlCollection Controls)
 {
     _foundry.UpdatePage(_controller.GetCurrentPage());
     _foundry.FinalizePage(_controller.CurrentState);
 }
コード例 #14
0
        public override void PushData(IList <PublishingSystemEventInfo> items)
        {
            var node     = new Uri("http://elastic-test:9200");
            var settings = new ConnectionSettings(node);

            settings.DefaultIndex("website");
            var client = new ElasticClient(settings);

            var    searchIndexName  = this.PipeSettings.PublishingPoint.Name.ToLower();
            string document_content = string.Empty;

            foreach (PublishingSystemEventInfo item in items)
            {
                document_content = string.Empty;

                if (item.ItemType != typeof(PageData).FullName && item.ItemType != typeof(PageNode).FullName)
                {
                    continue;
                }

                string itemAction = item.ItemAction;
                string str        = itemAction;

                if (itemAction == null)
                {
                    continue;
                }
                if (str == "SystemObjectDeleted")
                {
                    client.Delete <DahuIndexablePage>(this.GetPageNode(item).Id.ToString());
                }
                else if (str == "SystemObjectAdded" || str == "SystemObjectModified")
                {
                    var pageNode = this.GetPageNode(item);

                    if (!this.ShouldProcessNode(pageNode, item))
                    {
                        continue;
                    }
                    var culture = CultureInfo.GetCultureInfo("en");
                    var url     = String.Empty;
                    // Get the URL of the pageNode
                    url = pageNode.GetUrl(culture);
                    url = UrlPath.ResolveUrl(url, true, true);

                    if (url.Contains("not-in-use-currently"))
                    {
                        continue;
                    }

                    if (pageNode.Title.ToLower().Equals("article-item"))
                    {
                        continue;
                    }

                    if (pageNode.Title.ToLower().Equals("ai-articles"))
                    {
                        continue;
                    }

                    try
                    {
                        PageManager    pManager       = PageManager.GetManager();
                        ContentManager contentmanager = ContentManager.GetManager();
                        string         pagetitle      = string.Empty;

                        foreach (PageControl ctrl in pageNode.GetPageData().Controls)
                        {
                            try
                            {
                                var mycontrol = ctrl;
                                var control   = pManager.LoadControl(ctrl);


                                if (control is ContentBlock)
                                {
                                    var mycontrol1 = ctrl;

                                    ContentBlock content = control as ContentBlock;
                                    document_content = document_content + " " + content.Html;
                                }
                                else if (control.GetType().ToString().EndsWith("TitleWidget"))  // "AboutWidget"   - need Title and Subtitle
                                {
                                    System.Web.UI.Control titleWidgetControl = control as System.Web.UI.Control;
                                    foreach (System.Web.UI.Control values in titleWidgetControl.Controls)
                                    {
                                        System.Web.UI.ControlCollection messageLabel = values.Controls;
                                        foreach (Object o in messageLabel)
                                        {
                                            if (o is System.Web.UI.Control)
                                            {
                                                System.Web.UI.Control messageLabelControl = o as System.Web.UI.UserControl;
                                                foreach (Object o1 in messageLabelControl.Controls)
                                                {
                                                    if (o1 is System.Web.UI.WebControls.Label)
                                                    {
                                                        document_content = document_content + " " + ((System.Web.UI.WebControls.Label)o1).Text;
                                                        if (pageNode.Title == "Home" && !((System.Web.UI.WebControls.Label)o1).Text.IsNullOrEmpty())
                                                        {
                                                            pagetitle = ((System.Web.UI.WebControls.Label)o1).Text;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

/*
 *                              else if (control.GetType().ToString().EndsWith("AboutWidget"))
 *                              {
 *
 *                                  Telerik.Sitefinity.Web.UI.SimpleView aboutWidgetSimpleView = control as Telerik.Sitefinity.Web.UI.SimpleView;
 *                                  foreach (var aboutWidgetControl in aboutWidgetSimpleView.Controls)
 *                                  {
 *                                      if (aboutWidgetControl is Telerik.Sitefinity.Web.UI.GenericContainer)
 *                                      {
 *                                          Telerik.Sitefinity.Web.UI.GenericContainer aboutWidgetContainer = aboutWidgetControl as Telerik.Sitefinity.Web.UI.GenericContainer;
 *
 *                                          foreach (var aboutWidgetControlValues in ((Telerik.Sitefinity.Web.UI.GenericContainer)aboutWidgetControl).Controls)
 *                                          {
 *                                              var allFields = aboutWidgetControlValues.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(pi => pi.Name).ToList();
 *                                              foreach (FieldInfo myField in allFields)
 *                                              {
 *                                                  var myValue = myField.GetValue(aboutWidgetControlValues);
 *                                                  if (myValue is System.Web.UI.WebControls.Label)
 *                                                  {
 *                                                      document_content = document_content + " " + ((System.Web.UI.WebControls.Label)myValue).Text;
 *                                                  }
 *                                              }
 *                                          }
 *                                      }
 *                                  }
 *                              }
 */
                            } catch (Exception e1) {
                                // Exception in loading a control - its someone else's control so its their problem to fix! Cannot index any content on the control so ignore the exception.
                                message = "PageInboundPipe : PushData : Exception : " + e1.ToString();
                                Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Write(message);
                            }
                        }

                        document_content = Regex.Replace(document_content, "<.*?>", String.Empty);
                        document_content = Regex.Replace(document_content, "&nbsp;", String.Empty);
                        document_content = Regex.Replace(document_content, "&rsquo;", "'");
                        document_content = Regex.Replace(document_content, "&amp;", "&");

                        if (pagetitle == string.Empty)
                        {
                            pagetitle = pageNode.Title;
                        }

                        var pageToIndex = new DahuIndexablePage
                        {
                            id                         = pageNode.Id.ToString(),
                            title                      = pagetitle,
                            originalItemId             = pageNode.Id.ToString(),
                            contentType                = "Telerik.Sitefinity.Pages.Model.PageNode",
                            summary                    = pagetitle,
                            content                    = document_content,
                            siteSection                = "Website",
                            language                   = "",
                            elaticsearchIdPropertyName = pageNode.Id.ToString(),
                            pipeId                     = ""
                        };

                        if (str == "SystemObjectModified")
                        {
                            client.Delete <DahuIndexablePage>(pageNode.Id.ToString());
                        }

                        client.Index(pageToIndex);
                    } catch (Exception e) {
                        message = "PageInboundPipe : PushData : Loop :: Exception " + e.ToString();
                        Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Write(message);
                    }
                }
            }
        }
コード例 #15
0
        static public void SetPageControl(object page, string szName, string szValue)
        {
            System.Web.UI.ControlCollection cc = null;
            ArrayList ret = new ArrayList();

            if (page is System.Web.UI.Page)
            {
                cc = (page as System.Web.UI.Page).Controls;
            }
            else if (page is System.Web.UI.UserControl)
            {
                cc = (page as System.Web.UI.UserControl).Controls;
            }
            else
            {
                return;
            }
            GetPageAllControl(ref ret, cc);
            foreach (object ctrInObj in ret)
            {
                System.Web.UI.Control ctr = (System.Web.UI.Control)ctrInObj;
                Type controlType          = ctr.GetType();
                switch (controlType.ToString())
                {
                case "System.Web.UI.WebControls.TextBox":
                    System.Web.UI.WebControls.TextBox controlTextBoxObj = (System.Web.UI.WebControls.TextBox)ctr;
                    if (controlTextBoxObj.ID == szName)
                    {
                        controlTextBoxObj.Text = szValue;
                    }
                    break;

                case "System.Web.UI.WebControls.Label":
                    System.Web.UI.WebControls.Label controlLabelObj = (System.Web.UI.WebControls.Label)ctr;
                    if (controlLabelObj.ID == szName)
                    {
                        controlLabelObj.Text = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlInputText":
                    System.Web.UI.HtmlControls.HtmlInputText controlInputObj = (System.Web.UI.HtmlControls.HtmlInputText)ctr;
                    if (controlInputObj.Name == szName || controlInputObj.Name.EndsWith("$" + szName))
                    {
                        controlInputObj.Value = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlSelect":
                    System.Web.UI.HtmlControls.HtmlSelect controlSelectObj = (System.Web.UI.HtmlControls.HtmlSelect)ctr;
                    if (controlSelectObj.Name == szName || controlSelectObj.Name.EndsWith("$" + szName))
                    {
                        controlSelectObj.Value = szValue;
                    }
                    break;

                case "System.Web.UI.HtmlControls.HtmlInputRadioButton":
                    System.Web.UI.HtmlControls.HtmlInputRadioButton controlRadioButtonObj = (System.Web.UI.HtmlControls.HtmlInputRadioButton)ctr;
                    if (controlRadioButtonObj.Name == szName || controlRadioButtonObj.Name.EndsWith("$" + szName))
                    {
                        if (controlRadioButtonObj.Value == szValue)
                        {
                            controlRadioButtonObj.Checked = true;
                        }
                        else
                        {
                            controlRadioButtonObj.Checked = false;
                        }
                    }
                    break;

                default:
                    //TODO:其它控件
                    break;
                }
            }
        }