13 Replies Latest reply on Oct 31, 2012 3:19 PM by Asle Frantzen

    PI Custom TreeView

    priyanka.tayade

      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)

       

              {

       

              }

       

          }

       

      }

       

       

       

       

        • Re: PI Custom TreeView
          Asle Frantzen

          Hi Priyanka

           

          The first thing I'd do is take a look at the Sharepoint logs, and exactly what went wrong. They should be located in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\LOGS" if you haven't specified otherwise.

            • Re: PI Custom TreeView
              priyanka.tayade

              Thanks for reply Asle.

               

              I found these error messages in LoG. Any suggestions?

               

              - Failed to create the sandboxed process

               

              -  - Error starting worker process. - Inner Exception: System.ComponentModel.Win32Exception: CreateSandBoxedProcess failed     at Microsoft.SharePoint.Security.SandBoxInterop.StartProcess(SandBoxedProcessArguments sbpArgs, Boolean fSuspended, ProcessInformation* psandBoxProcessInfo)     at Microsoft.SharePoint.Security.SandBoxedProcess.StartProcessSuspended(SandBoxedProcessArguments sbpArgs)     at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcess.CreateSandBoxWindowsProcess(String processExeName)

               

              -  - Error starting worker process. - Starting worker process threw - Inner Exception: System.ComponentModel.Win32Exception: CreateSandBoxedProcess failed     at Microsoft.SharePoint.Security.SandBoxInterop.StartProcess(SandBoxedProcessArguments sbpArgs, Boolean fSuspended, ProcessInformation* psandBoxProcessInfo)     at Microsoft.SharePoint.Security.SandBoxedProcess.StartProcessSuspended(SandBoxedProcessArguments sbpArgs)     at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcess.CreateSandBoxWindowsProcess(String processExeName)

                • Re: PI Custom TreeView
                  Asle Frantzen

                  Ok, I think the problem is that you're running this as a sandboxed solution.

                   

                  I've only barely touched into that myself, but I distinctly remember when Sharepoint 2010 (and sandboxed solutions) were launched, I said to a colleague of mine that this was a cool feature but we cannot use it against PI or any other external systems.

                   

                  You should read more about the restrictions of sandboxed solutions. Especially in the table column "Implications and remarks" under "Low-Privileged Security Token for the Sandboxed Worker Process" here: msdn.microsoft.com/.../gg615454.aspx

                   

                  It specifically states that Visual web parts cannot be run in sandboxed solutions.

                   

                  So that's a start, I guess. You'll have to do some digging to find out if you *can* do what you want somehow, by sticking to the sandboxed solution. Or if you in fact are better off just creating a normal web part project and not use the sandbox feature.