ashish.thakur

Customizing or custom PI treeview webpart

Discussion created by ashish.thakur on Nov 14, 2014
Latest reply on Nov 17, 2014 by David Hearn

Hi,

 

We are deploying on SharePoint 2013 (claims and kerberos delegation no host to host trust) typical realtime Pi treeview and Pi graphic webpart where the framework structure is stored in the Pi AF.

 

But would like to change the style and javascript functions of treeview plugin.

 

I am currently investigating two viable options

 

1) applying CSS and javascript after the its loaded on the page

 

2) creating custom pi treeview webpart.

 

I am investigating the second option .. and unable to delegate the current sharepoint logged in user to access PI AF. I get the following error :

 

'Message "Cannot connect to server 'xxxxx'. It may be that the impersonated client user account cannot be delegated to the remote AF Server." string'

 

8780.2014_2D00_11_2D00_14_5F00_1426.png

 

When I am using the following code:

 

 

 

 

 
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebPartPages.Communication;
using System.Web.UI.HtmlControls;
using OSIsoft.AF;
using OSIsoft.AF.Asset;
using System.Security.Principal;

namespace CustomTreeviewWebpart.RTCustomTreeview
{
    [ToolboxItemAttribute(false)]
    public class RTCustomTreeview : WebPart, IParametersOutProvider
    {

        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/CustomTreeviewWebpart/RTCustomTreeview/RTCustomTreeviewUserControl.ascx";
        

        public event NoParametersOutEventHandler NoParametersOut;
        public event ParametersOutProviderInitEventHandler ParametersOutProviderInit;
        public event ParametersOutReadyEventHandler ParametersOutReady;

        string textData = "Sinusoid\r\nSinusoidU";

        string _afDbName = "xxxxx";
        string _afServerName = "xxxxx";
        AFDatabase _myAfdb;

       

        protected override void CreateChildControls()
        {
            //using (SPSecurityContext.GetWindowsIdentity().Impersonate())
            //{
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                // Get Windows Token for current claim

                WindowsIdentity windowsIdentity = null;
                  try
                {

                    windowsIdentity = SPSecurityContext.GetWindowsIdentity(); // This will fail if C2WTS isn't configured correctly

                }

                catch (Exception ex)
                {

                                        return; // Exit method

                }

                // Impersonate using Windows token

                using (WindowsImpersonationContext ctx = windowsIdentity.Impersonate())
                {
                    base.CreateChildControls();
                    try
                    {
                        PISystems _myPISystems = new PISystems();
                        _myAfdb = _myPISystems[_afServerName].Databases[_afDbName];

                    }
                    catch (Exception e)
                    {

                    }
                    HtmlTable htmlTable = new HtmlTable();
                    HtmlTableRow tr = new HtmlTableRow();

                    HtmlTableCell tc = new HtmlTableCell();

                    foreach (AFElement childElem in _myAfdb.Elements)
                    {
                        htmlTable.Rows.Add(tr);
                        tr.Cells.Add(tc);
                        tc.InnerText = childElem.Name;
                    }

                    Controls.Add(htmlTable); 

                }

            });
                
            

        }

        [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;
        private bool paramsOutRunAtServer = false;
        [Obsolete]
        public override void PartCommunicationConnect(string interfaceName, Microsoft.SharePoint.WebPartPages.WebPart connectedPart, string connectedInterfaceName, ConnectionRunAt runAt)
        {
            paramsOutConnected = true;
            paramsOutRunAtServer = (runAt == ConnectionRunAt.Server);
        }

        [Obsolete]
        public override void PartCommunicationInit()
        {
            ParametersOutProviderInitEventArgs args = new ParametersOutProviderInitEventArgs();
            args.ParameterOutProperties = new ParameterOutProperty[1];
            args.ParameterOutProperties[0] = new ParameterOutProperty();
            args.ParameterOutProperties[0].ParameterName = "TagName";
            args.ParameterOutProperties[0].ParameterDisplayName = "Selected Tag";
            args.ParameterOutProperties[0].Description = "The selected tag name";
            ParametersOutProviderInit(this, args);
        }

        private DropDownList dropDownList;
        [Obsolete]
        public override void PartCommunicationMain()
        {
            EnsureChildControls();
            ParametersOutReadyEventArgs args = new ParametersOutReadyEventArgs();
            args.ParameterValues = new string[1];
            args.ParameterValues[0] = dropDownList.SelectedValue;
            ParametersOutReady(this, args);
        }

        protected override void RenderWebPart(HtmlTextWriter output)
        {
            EnsureChildControls();
            if (paramsOutConnected && paramsOutRunAtServer)
            {
                dropDownList.Attributes["onchange"] = "javascript:__doPostBack('" + this.UniqueID + "', '');";
            }
            base.RenderWebPart(output);
        }



    }
}

 

 

 

 

 

Outcomes