priyanka.tayade

PI Custom TreeView

Discussion created by priyanka.tayade on Oct 15, 2012
Latest reply on Oct 31, 2012 by Asle Frantzen

Hi,

 

I am trying to create a custom treeview using AF SDK. I build a webpart (code is below) and deployed it. It works fine on Sharepoint server but doesn't work client side. I get this error on client side. Any suggestions?

 

3681.Client-Sode-Error-Message.jpg

 

 

 

using System;

 

using System.ComponentModel;

 

using System.Runtime.InteropServices;

 

using Microsoft.SharePoint.WebPartPages.Communication;

 

using System.Web.UI.HtmlControls;

 

using System.Web.UI.WebControls;

 

using System.Web.UI;

 

using OSIsoft.AF;

 

using OSIsoft.AF.Asset;

 

 

 

namespace IndEv_TreeView1.VisualWebPart1

 

{

 

   [Guid("aafe696f-b9c6-4204-94c4-d4feb5e6a5be")]

 

        public partial class VisualWebPart1 : Microsoft.SharePoint.WebPartPages.WebPart, IParametersOutProvider

 

    {

 

        String _afDbName = "AF Database Name";

 

        String _afServerName = "AF Server Name";

 

        AFDatabase _myAfdb;

 

 

 

 

 

        public event NoParametersOutEventHandler NoParametersOut;

 

        public event ParametersOutProviderInitEventHandler ParametersOutProviderInit;

 

        public event ParametersOutReadyEventHandler ParametersOutReady;

 

 

 

        public VisualWebPart1()

 

        {

 

        }

 

 

 

        protected override void OnInit(EventArgs e)

 

        {

 

            base.OnInit(e);

 

            InitializeControl();

 

        }

 

 

 

        [Obsolete]

 

        public override void EnsureInterfaces()

 

        {

 

            RegisterInterface("TagListProvider_WPQ_", InterfaceTypes.IParametersOutProvider,

 

            UnlimitedConnections, CanRunAt(), this, "TagListProvider_WPQ_",

 

            "Provide a list item to", "Provides a list item to a connected web part");

 

        }

 

 

 

        [Obsolete]

 

        public override ConnectionRunAt CanRunAt()

 

        {

 

            return ConnectionRunAt.Server;

 

        }

 

 

 

        private bool paramsOutConnected = false;

 

        [Obsolete]

 

        public override void PartCommunicationConnect(

 

        string interfaceName, Microsoft.SharePoint.WebPartPages.WebPart connectedPart,

 

        string connectedInterfaceName, ConnectionRunAt runAt)

 

        {

 

            paramsOutConnected = true;

 

        }

 

 

 

        [Obsolete]

 

        public override void PartCommunicationInit()

 

        {

 

            ParametersOutProviderInitEventArgs parametersOutProviderInitEventArgs =

 

            new ParametersOutProviderInitEventArgs();

 

            parametersOutProviderInitEventArgs.ParameterOutProperties =

 

            new ParameterOutProperty[1];

 

            parametersOutProviderInitEventArgs.ParameterOutProperties[0] =

 

            new ParameterOutProperty();

 

            parametersOutProviderInitEventArgs.ParameterOutProperties[0].ParameterName =

 

            "Context";

 

            parametersOutProviderInitEventArgs.ParameterOutProperties[0].ParameterDisplayName =

 

            "SelectedContext";

 

            parametersOutProviderInitEventArgs.ParameterOutProperties[0].Description =

 

            "The selected Context Path";

 

            ParametersOutProviderInit(this, parametersOutProviderInitEventArgs);

 

        }

 

 

 

        private TreeView trview;

 

        [Obsolete]

 

        public override void PartCommunicationMain()

 

        {

 

            EnsureChildControls();

 

            ParametersOutReadyEventArgs parametersOutReadyEventArgs =

 

            new ParametersOutReadyEventArgs();

 

            parametersOutReadyEventArgs.ParameterValues = new string[1];

 

            parametersOutReadyEventArgs.ParameterValues[0] = trview.SelectedValue;

 

            ParametersOutReady(this, parametersOutReadyEventArgs);

 

        }

 

 

 

        protected override void RenderWebPart(HtmlTextWriter output)

 

        {

 

            EnsureChildControls();

 

            if (paramsOutConnected)

 

            {

 

                trview.Attributes["AfterSelect"] =

 

                "BLOCKED SCRIPT__doPostBack('" + this.UniqueID + "', '');";

 

            }

 

            base.RenderWebPart(output);

 

        }

 

 

 

        private void ConnectToServer()

 

        {

 

            PISystems _myPISystems =

 

                new PISystems();

 

            _myAfdb = _myPISystems[_afServerName].Databases[_afDbName];

 

        }

 

 

 

        protected override void CreateChildControls()

 

        {

 

            base.CreateChildControls();

 

            HtmlTable htmlTable = new HtmlTable();

 

            HtmlTableRow tr = new HtmlTableRow();

 

            htmlTable.Rows.Add(tr);

 

            HtmlTableCell tc = new HtmlTableCell();

 

            tr.Cells.Add(tc);

 

 

 

            trview = new TreeView();

 

            ConnectToServer();

 

            TreeNode root = new TreeNode("Elements") { Value = "Elements" };

 

            trview.Nodes.Add(root);

 

 

 

            foreach (AFElement childElem in _myAfdb.Elements)

 

            {

 

                TreeNode child1 = new TreeNode(childElem.Name) { Value = childElem.GetPath().ToString() };

 

                root.ChildNodes.Add(child1);

 

                if (childElem.HasChildren)

 

                    addNodes(childElem, child1);

 

            }

 

            trview.ShowLines = true;

 

            tc.Controls.Add(trview);

 

            Controls.Add(htmlTable);

 

        }

 

 

 

        private void addNodes(AFElement elem, TreeNode root)

 

        {

 

            foreach (AFElement childElem in elem.Elements)

 

            {

 

                TreeNode child1 = new TreeNode(childElem.Name) { Value = childElem.GetPath().ToString() };

 

                root.ChildNodes.Add(child1);

 

                if (childElem.HasChildren)

 

                    addNodes(childElem, child1);

 

            }

 

        }

 

 

 

        protected void Page_Load(object sender, EventArgs e)

 

        {

 

        }

 

    }

 

}

 

 

 

 

Outcomes