예제 #1
0
        private void OnReturnJewel(DataQueryResult dqr)
        {
            JewelBuildContext jbc = (JewelBuildContext)dqr.ContextData;

            // Apply any extensions to the data.
            dqr.QueryData = ApplyDataExtensions(dqr.QueryData);

            JSObject jewelNode = DataNodeWrapper.GetFirstChildNodeWithName(dqr.QueryData, DataNodeWrapper.JEWEL);

            Jewel = BuildJewelInternal(jewelNode, jbc);
            Jewel.JewelBuilder = this;
            BuildClient.OnComponentCreated(Jewel, Jewel.Id);

            if (JewelBuildOptions.AttachToDOM)
            {
                Jewel.AttachInternal(true);
            }
            else
            {
                Jewel.RefreshInternal();
                Placeholder.AppendChild(Jewel.ElementInternal);
                Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            }
            OnRootBuilt(Jewel);
            BuildClient.OnComponentBuilt(Jewel, Jewel.Id);
        }
예제 #2
0
        internal void BuildQATFromData(object dataNode, QATBuildContext qbc)
        {
            DataQueryResult dqr = new DataQueryResult();

            dqr.Success     = true;
            dqr.QueryData   = dataNode;
            dqr.ContextData = qbc;
            OnReturnQAT(dqr);
        }
예제 #3
0
        internal void BuildJewelFromData(object dataNode, JewelBuildContext jbc)
        {
            DataQueryResult dqr = new DataQueryResult();

            dqr.Success     = true;
            dqr.QueryData   = dataNode;
            dqr.ContextData = jbc;
            OnReturnJewel(dqr);
        }
예제 #4
0
        public void BuildRibbonFromData(object dataNode, string initialTabId)
        {
            RibbonBuildContext rbc = new RibbonBuildContext();

            rbc.InitialTabId = initialTabId;

            DataQueryResult res = new DataQueryResult();

            res.Success     = true;
            res.QueryData   = dataNode;
            res.ContextData = rbc;
            OnReturnRibbonAndInitialTab(res);
        }
예제 #5
0
파일: data.cs 프로젝트: tralivali1234/IL2JS
        /*
         * /// <summary>
         * /// Subclassers can hook in here if they want to run their own logic to
         * /// get the sought after cui data.
         * /// </summary>
         * /// <param name="query">The cui query that is to be run.</param>
         * public virtual void RunQuery(DataQuery query)
         * {
         *  string version = _version;
         *  if (!string.IsNullOrEmpty(query.Version))
         *      version = query.Version;
         *
         *  string lcid = _lcid;
         *  if (!string.IsNullOrEmpty(query.Lcid))
         *      lcid = query.Lcid;
         *
         *  string dataUrl = _dataUrl;
         *  if (!string.IsNullOrEmpty(query.DataUrl))
         *      dataUrl = query.DataUrl;
         *
         *  string url;
         *  string type = null;
         *
         *  // The dataUrl passed in might already have parameters
         *  if (dataUrl.IndexOf('?') == -1)
         *      url = dataUrl + "?ver=";
         *  else
         *      url = dataUrl + "&ver=";
         *
         *  url = url + version + "&id=" + query.Id + "&lcid=" + lcid + "&qt=";
         *
         *  switch (query.QueryType)
         *  {
         *      case DataQueryType.All:
         *          type = "all";
         *          break;
         *      case DataQueryType.RibbonTab:
         *          type = "ribbontab";
         *          break;
         *      case DataQueryType.RibbonShallow:
         *          type = "ribbonshallow";
         *          break;
         *      case DataQueryType.Root:
         *          type = "root";
         *          break;
         *      case DataQueryType.RibbonVisibleTabDeep:
         *          type = "ribbonvisibletabdeep";
         *          break;
         *  }
         *
         *  url += type;
         #if PERF_METRICS
         *  PMetrics.PerfMark(PMarker.perfCUIRibbonQueryDataStart);
         #endif
         *  HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
         *  req.Method = "GET";
         *  req.ContentType = "text/html";
         *
         *  QueryRecord rec = new QueryRecord();
         *  rec.id = query.Id;
         *  rec.queryType = query.QueryType;
         *  rec.data = query.Data;
         *  rec.handler = query.Handler;
         *
         *  object data= new object();
         *  RequestState state = new RequestState(req, data, rec);
         *  IAsyncResult result = req.BeginGetResponse(new AsyncCallback(OnDataReturned),state);
         *
         *  //Register the timeout callback
         *  ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
         *      new WaitOrTimerCallback(ScanTimeoutCallback), state, (30 * 1000), true);
         * }
         *
         * /// <summary>
         * /// Subsclassers could hook in here if they wanted to subprocess the
         * /// resulting JSON.
         * /// </summary>
         * /// <param name="executor">the web executor that has returned from async request</param>
         * protected virtual void OnDataReturned(IAsyncResult result)
         * {
         #if PERF_METRICS
         *  PMetrics.PerfMark(PMarker.perfCUIRibbonQueryDataEnd);
         #endif
         *  RequestState state = (RequestState)result.AsyncState;
         *  WebRequest request = (WebRequest)state.Request;
         *
         *  HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(result);
         *  Stream s = (Stream)response.GetResponseStream();
         *  StreamReader readStream = new StreamReader(s);
         *
         *  // Get the complete contents of the message
         *  string dataString = readStream.ReadToEnd();
         *  response.Close();
         *  s.Close();
         *  readStream.Close();
         *
         *  QueryRecord rec = state.Query;
         *  DataQueryResult res = new DataQueryResult();
         *  res.ContextData = rec.data;
         *  res.Id = rec.id;
         *
         *  // If the request succeeded
         *  // TODO(josefl) figure out right way to find out if it succeeded
         *  if (!string.IsNullOrEmpty(dataString))
         *  {
         *      res.Success = true;
         *      res.QueryData = dataString;
         *      rec.handler(res);
         *  }
         *  else
         *  {
         *      res.Success = false;
         *      // Return that the data retrieval failed
         *      rec.handler(res);
         *  }
         * }
         *
         * private static void ScanTimeoutCallback (object state, bool timedOut)
         * {
         *  if (timedOut)
         *  {
         *      RequestState reqState = (RequestState)state;
         *      if (reqState != null)
         *          reqState.Request.Abort();
         *  }
         * }
         */

        /// <summary>
        /// Subclassers can hook in here if they want to run their own logic to
        /// get the sought after cui data.
        /// </summary>
        /// <param name="query">The cui query that is to be run.</param>
        public virtual void RunQuery(DataQuery query)
        {
            QueryRecord rec = new QueryRecord();

            rec.id        = query.Id;
            rec.queryType = query.QueryType;
            rec.data      = query.Data;
            rec.handler   = query.Handler;

            RibbonData rData = new RibbonData();

            JSObject dataBlock;

            if (query.TabQuery)
            {
                dataBlock = rData.GetTabQueryData(query.Id);
            }
            else
            {
                dataBlock = rData.GetQueryData(query.Id);
            }

            DataQueryResult res = new DataQueryResult();

            res.ContextData = rec.data;
            res.Id          = rec.id;

            if (!CUIUtility.IsNullOrUndefined(dataBlock))
            {
                res.Success   = true;
                res.QueryData = dataBlock;
                rec.handler(res);
            }
            else
            {
                // Return that the data retrieval failed
                res.Success = false;
                rec.handler(res);
            }
        }
예제 #6
0
        /// <summary>
        /// Builds the toolbar and attaches it to the page.
        /// Called once the DataQuery completes and the toolbar data is available.
        /// </summary>
        private void OnReturnToolbarData(DataQueryResult res)
        {
            ToolbarBuildContext context = (ToolbarBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);

            Toolbar = BuildToolbarFromData(res.QueryData, context);
            Toolbar.ToolbarBuilder = this;
            BuildClient.OnComponentCreated(Toolbar, Toolbar.Id);
            Toolbar.RefreshInternal();

            Placeholder.AppendChild(Toolbar.ElementInternal);

            // If there's a jewel on the toolbar, position the left buttondock adjacent to it
            foreach (ButtonDock dock in Toolbar.Children)
            {
                if (dock.Alignment == DataNodeWrapper.LEFTALIGN)
                {
                    Div jewelContainer = (Div)Browser.Document.GetById("jewelcontainer");
                    if (!CUIUtility.IsNullOrUndefined(jewelContainer))
                    {
                        if (Toolbar.TextDirection == Direction.LTR)
                        {
                            dock.ElementInternal.Style.Left = jewelContainer.OffsetWidth + "px";
                        }
                        else
                        {
                            dock.ElementInternal.Style.Right = jewelContainer.OffsetWidth + "px";
                        }
                    }
                    break;
                }
            }

            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            BuildClient.OnComponentBuilt(Toolbar, Toolbar.Id);
        }
예제 #7
0
        /// <summary>
        /// Builds the toolbar and attaches it to the page.
        /// Called once the DataQuery completes and the toolbar data is available.
        /// </summary>
        private void OnReturnToolbarData(DataQueryResult res)
        {
            ToolbarBuildContext context = (ToolbarBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);

            Toolbar = BuildToolbarFromData(res.QueryData, context);
            Toolbar.ToolbarBuilder = this;
            BuildClient.OnComponentCreated(Toolbar, Toolbar.Id);
            Toolbar.RefreshInternal();

            Placeholder.AppendChild(Toolbar.ElementInternal);

            // If there's a jewel on the toolbar, position the left buttondock adjacent to it
            foreach (ButtonDock dock in Toolbar.Children)
            {
                if (dock.Alignment == DataNodeWrapper.LEFTALIGN)
                {
                    Div jewelContainer = (Div)Browser.Document.GetById("jewelcontainer");
                    if (!CUIUtility.IsNullOrUndefined(jewelContainer))
                    {
                        if (Toolbar.TextDirection == Direction.LTR)
                        {
                            dock.ElementInternal.Style.Left = jewelContainer.OffsetWidth + "px";
                        }
                        else
                        {
                            dock.ElementInternal.Style.Right = jewelContainer.OffsetWidth + "px";
                        }
                    }
                    break;
                }
            }

            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            BuildClient.OnComponentBuilt(Toolbar, Toolbar.Id);
        }
예제 #8
0
        private void OnReturnQAT(DataQueryResult dqr)
        {
            QATBuildContext qbc = (QATBuildContext)dqr.ContextData;

            // Apply any extensions to the data.
            dqr.QueryData = ApplyDataExtensions(dqr.QueryData);

            QAT            = BuildQATInternal(DataNodeWrapper.GetFirstChildNodeWithName(dqr.QueryData, DataNodeWrapper.QAT), qbc);
            QAT.QATBuilder = this;
            BuildClient.OnComponentCreated(QAT, QAT.Id);

            if (QATBuildOptions.AttachToDOM)
            {
                QAT.AttachInternal(true);
            }
            else
            {
                QAT.RefreshInternal();
                Placeholder.AppendChild(QAT.ElementInternal);
                Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            }
            OnRootBuilt(QAT);
            BuildClient.OnComponentBuilt(QAT, QAT.Id);
        }
예제 #9
0
        private void OnReturnJewel(DataQueryResult dqr)
        {
            JewelBuildContext jbc = (JewelBuildContext)dqr.ContextData;

            // Apply any extensions to the data.
            dqr.QueryData = ApplyDataExtensions(dqr.QueryData);

            JSObject jewelNode = DataNodeWrapper.GetFirstChildNodeWithName(dqr.QueryData, DataNodeWrapper.JEWEL);
            Jewel = BuildJewelInternal(jewelNode, jbc);
            Jewel.JewelBuilder = this;
            BuildClient.OnComponentCreated(Jewel, Jewel.Id);

            if (JewelBuildOptions.AttachToDOM)
            {
                Jewel.AttachInternal(true);
            }
            else
            {
                Jewel.RefreshInternal();
                Placeholder.AppendChild(Jewel.ElementInternal);
                Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            }
            OnRootBuilt(Jewel);
            BuildClient.OnComponentBuilt(Jewel, Jewel.Id);
        }
예제 #10
0
 internal void BuildJewelFromData(object dataNode, JewelBuildContext jbc)
 {
     DataQueryResult dqr = new DataQueryResult();
     dqr.Success = true;
     dqr.QueryData = dataNode;
     dqr.ContextData = jbc;
     OnReturnJewel(dqr);
 }
예제 #11
0
        private void OnReturnRibbonAndInitialTab(DataQueryResult res)
        {
            PMetrics.PerfMark(PMarker.perfCUIRibbonInitStart);

            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);
            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            JSObject templates = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData, DataNodeWrapper.TEMPLATES);
            if (!CUIUtility.IsNullOrUndefined(templates))
                TemplateManager.Instance.LoadTemplates(templates);

            Ribbon = BuildRibbon(res.QueryData, rbc);
            Ribbon.RibbonBuilder = this;
            BuildClient.OnComponentCreated(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.Minimized)
            {
                Ribbon.MinimizedInternal = true;
            }
            else
            {
                Ribbon.MinimizedInternal = false;
                Tab firstTab = (Tab)Ribbon.GetChild(rbc.InitialTabId);
                if (!CUIUtility.IsNullOrUndefined(firstTab))
                {
                    // We need this in order to set the "ChangedByUser" property of the first
                    // TabSwitch command that comes out of the ribbon correctly.
                    firstTab.SelectedByUser = RibbonBuildOptions.InitialTabSelectedByUser;
                    Ribbon.MakeTabSelectedInternal(firstTab);
                }
            }

            Ribbon.ClientID = RibbonBuildOptions.ClientID;

            bool shouldAttach = !RibbonBuildOptions.Minimized && RibbonBuildOptions.AttachToDOM;

            if (shouldAttach)
            {
                // Scale the ribbon to the scaling index that matches the ribbon that was
                // rendered by the server.  This sets the in memory Ribbon structure to match
                // what was rendered by the server.  This is needed so that Ribbon.AttachInternal()
                // will work properly.  
                if (!((RibbonBuildOptions)Options).Minimized)
                {
                    // We subtract one from this scaling index because internally
                    // this scaling index is an entry into an array of "<ScaleStep>" so
                    // the MaxSize for all the groups is actually index "-1" and the first 
                    // step is index 0.
                    Ribbon.ScaleIndex(rbc.InitialScalingIndex - 1);
                }

                Ribbon.AttachInternal(true);

                // Attach to the QAT and Jewel
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, true, DataSource);
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, true, DataSource);

#if DEBUG
                // Validate that the server rendered ribbon is identical to the client rendered one
                // for this tab.
                if (Options.ValidateServerRendering)
                {
                    RibbonBuilder rb2 = new RibbonBuilder(this.RibbonBuildOptions,
                                                          this.Placeholder,
                                                          null);

                    DataSource ds = new DataSource(this.DataSource.DataUrl,
                                                   this.DataSource.Version,
                                                   this.DataSource.Lcid);

                    rb2.DataSource = ds;
                    SPRibbon r2 = rb2.BuildRibbon(res.QueryData, rbc);
                    r2.Id += "-client";
                    r2.ClientID = RibbonBuildOptions.ClientID + "-client";
                    r2.RibbonBuilder = this;
                    if (!RibbonBuildOptions.Minimized)
                        r2.Minimized = false;

                    // Clone all the peripheral sections for the client-rendering version
                    Div p_qrc = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowCenter);
                    Div p_qrr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowRight);
                    Div p_trl = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowLeft);
                    Div p_trr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowRight);

                    Div hiddenClonedPeripherals = new Div();
                    hiddenClonedPeripherals.Style.Display = "none";
                    Browser.Document.Body.AppendChild(hiddenClonedPeripherals);

                    Div clone;
                    if (null != p_qrc)
                    {
                        clone = (Div)p_qrc.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_qrr)
                    {
                        clone = (Div)p_qrr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trl)
                    {
                        clone = (Div)p_trl.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trr)
                    {
                        clone = (Div)p_trr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }

                    r2.MakeTabSelectedInternal((Tab)r2.GetChild(rbc.InitialTabId));
                    r2.RefreshInternal();

                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                        r2.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, ds);
                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                        r2.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, ds);

                    r2.ScaleIndex(rbc.InitialScalingIndex - 1);
                    r2.CompleteConstruction();

                    // If this returns a message it means that it found some inconsistencies
                    // between the DOM Nodes
                    CompareNodes(Ribbon.ElementInternal, r2.ElementInternal);
                }
#endif
            }
            else
            {
                // Do the minimum amount of work necessary in order to be able to 
                // get the outer ribbon element and to be able to attach the Jewel and QAT.
                Ribbon.EnsureDOMElement();

                // Build the QAT and Jewel after the ribbon so that the placeholders
                // will have been created within the ribbon via Ribbon.RefreshInternal()
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, DataSource);
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, DataSource);

                // Remove anything else that is in the placeholder in case there is a temporary
                // animated gif or a static ribbon in there while the ribbon is loading.
                // We're doing this the slow way since partners might have a reference to this node
                Utility.RemoveChildNodesSlow(Placeholder);
                Placeholder.AppendChild(Ribbon.ElementInternal);
            }

            Ribbon.Scale();
            OnRootBuilt(Ribbon);
            BuildClient.OnComponentBuilt(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.LaunchedByKeyboard)
                Ribbon.SetFocusOnRibbon();

            PMetrics.PerfMark(PMarker.perfCUIRibbonInitPercvdEnd);
        }
예제 #12
0
        public void BuildRibbonFromData(object dataNode, string initialTabId)
        {
            RibbonBuildContext rbc = new RibbonBuildContext();
            rbc.InitialTabId = initialTabId;

            DataQueryResult res = new DataQueryResult();
            res.Success = true;
            res.QueryData = dataNode;
            res.ContextData = rbc;
            OnReturnRibbonAndInitialTab(res);
        }
예제 #13
0
        private void OnReturnQAT(DataQueryResult dqr)
        {
            QATBuildContext qbc = (QATBuildContext)dqr.ContextData;

            // Apply any extensions to the data.
            dqr.QueryData = ApplyDataExtensions(dqr.QueryData);

            QAT = BuildQATInternal(DataNodeWrapper.GetFirstChildNodeWithName(dqr.QueryData, DataNodeWrapper.QAT), qbc);
            QAT.QATBuilder = this;
            BuildClient.OnComponentCreated(QAT, QAT.Id);

            if (QATBuildOptions.AttachToDOM)
            {
                QAT.AttachInternal(true);
            }
            else
            {
                QAT.RefreshInternal();
                Placeholder.AppendChild(QAT.ElementInternal);
                Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            }
            OnRootBuilt(QAT);
            BuildClient.OnComponentBuilt(QAT, QAT.Id);
        }
예제 #14
0
 internal void BuildQATFromData(object dataNode, QATBuildContext qbc)
 {
     DataQueryResult dqr = new DataQueryResult();
     dqr.Success = true;
     dqr.QueryData = dataNode;
     dqr.ContextData = qbc;
     OnReturnQAT(dqr);
 }
예제 #15
0
        private void OnReturnRibbonAndInitialTab(DataQueryResult res)
        {
            PMetrics.PerfMark(PMarker.perfCUIRibbonInitStart);

            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            // Apply any extensions to the data.
            res.QueryData = ApplyDataExtensions(res.QueryData);
            Utility.EnsureCSSClassOnElement(Placeholder, "loaded");
            JSObject templates = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData, DataNodeWrapper.TEMPLATES);

            if (!CUIUtility.IsNullOrUndefined(templates))
            {
                TemplateManager.Instance.LoadTemplates(templates);
            }

            Ribbon = BuildRibbon(res.QueryData, rbc);
            Ribbon.RibbonBuilder = this;
            BuildClient.OnComponentCreated(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.Minimized)
            {
                Ribbon.MinimizedInternal = true;
            }
            else
            {
                Ribbon.MinimizedInternal = false;
                Tab firstTab = (Tab)Ribbon.GetChild(rbc.InitialTabId);
                if (!CUIUtility.IsNullOrUndefined(firstTab))
                {
                    // We need this in order to set the "ChangedByUser" property of the first
                    // TabSwitch command that comes out of the ribbon correctly.
                    firstTab.SelectedByUser = RibbonBuildOptions.InitialTabSelectedByUser;
                    Ribbon.MakeTabSelectedInternal(firstTab);
                }
            }

            Ribbon.ClientID = RibbonBuildOptions.ClientID;

            bool shouldAttach = !RibbonBuildOptions.Minimized && RibbonBuildOptions.AttachToDOM;

            if (shouldAttach)
            {
                // Scale the ribbon to the scaling index that matches the ribbon that was
                // rendered by the server.  This sets the in memory Ribbon structure to match
                // what was rendered by the server.  This is needed so that Ribbon.AttachInternal()
                // will work properly.
                if (!((RibbonBuildOptions)Options).Minimized)
                {
                    // We subtract one from this scaling index because internally
                    // this scaling index is an entry into an array of "<ScaleStep>" so
                    // the MaxSize for all the groups is actually index "-1" and the first
                    // step is index 0.
                    Ribbon.ScaleIndex(rbc.InitialScalingIndex - 1);
                }

                Ribbon.AttachInternal(true);

                // Attach to the QAT and Jewel
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                {
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, true, DataSource);
                }
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                {
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, true, DataSource);
                }

#if DEBUG
                // Validate that the server rendered ribbon is identical to the client rendered one
                // for this tab.
                if (Options.ValidateServerRendering)
                {
                    RibbonBuilder rb2 = new RibbonBuilder(this.RibbonBuildOptions,
                                                          this.Placeholder,
                                                          null);

                    DataSource ds = new DataSource(this.DataSource.DataUrl,
                                                   this.DataSource.Version,
                                                   this.DataSource.Lcid);

                    rb2.DataSource = ds;
                    SPRibbon r2 = rb2.BuildRibbon(res.QueryData, rbc);
                    r2.Id           += "-client";
                    r2.ClientID      = RibbonBuildOptions.ClientID + "-client";
                    r2.RibbonBuilder = this;
                    if (!RibbonBuildOptions.Minimized)
                    {
                        r2.Minimized = false;
                    }

                    // Clone all the peripheral sections for the client-rendering version
                    Div p_qrc = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowCenter);
                    Div p_qrr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.QATRowRight);
                    Div p_trl = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowLeft);
                    Div p_trr = (Div)Browser.Document.GetById(RibbonBuildOptions.ClientID + "-" + RibbonPeripheralSection.TabRowRight);

                    Div hiddenClonedPeripherals = new Div();
                    hiddenClonedPeripherals.Style.Display = "none";
                    Browser.Document.Body.AppendChild(hiddenClonedPeripherals);

                    Div clone;
                    if (null != p_qrc)
                    {
                        clone    = (Div)p_qrc.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_qrr)
                    {
                        clone    = (Div)p_qrr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trl)
                    {
                        clone    = (Div)p_trl.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }
                    if (null != p_trr)
                    {
                        clone    = (Div)p_trr.CloneNode(true);
                        clone.Id = clone.Id.Replace(RibbonBuildOptions.ClientID, r2.ClientID);
                        hiddenClonedPeripherals.AppendChild(clone);
                    }

                    r2.MakeTabSelectedInternal((Tab)r2.GetChild(rbc.InitialTabId));
                    r2.RefreshInternal();

                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                    {
                        r2.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, ds);
                    }
                    if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                    {
                        r2.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, ds);
                    }

                    r2.ScaleIndex(rbc.InitialScalingIndex - 1);
                    r2.CompleteConstruction();

                    // If this returns a message it means that it found some inconsistencies
                    // between the DOM Nodes
                    CompareNodes(Ribbon.ElementInternal, r2.ElementInternal);
                }
#endif
            }
            else
            {
                // Do the minimum amount of work necessary in order to be able to
                // get the outer ribbon element and to be able to attach the Jewel and QAT.
                Ribbon.EnsureDOMElement();

                // Build the QAT and Jewel after the ribbon so that the placeholders
                // will have been created within the ribbon via Ribbon.RefreshInternal()
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowQATId))
                {
                    Ribbon.BuildAndSetQAT(RibbonBuildOptions.ShowQATId, false, DataSource);
                }
                if (!string.IsNullOrEmpty(RibbonBuildOptions.ShowJewelId))
                {
                    Ribbon.BuildAndSetJewel(RibbonBuildOptions.ShowJewelId, false, DataSource);
                }

                // Remove anything else that is in the placeholder in case there is a temporary
                // animated gif or a static ribbon in there while the ribbon is loading.
                // We're doing this the slow way since partners might have a reference to this node
                Utility.RemoveChildNodesSlow(Placeholder);
                Placeholder.AppendChild(Ribbon.ElementInternal);
            }

            Ribbon.Scale();
            OnRootBuilt(Ribbon);
            BuildClient.OnComponentBuilt(Ribbon, Ribbon.Id);
            if (RibbonBuildOptions.LaunchedByKeyboard)
            {
                Ribbon.SetFocusOnRibbon();
            }

            PMetrics.PerfMark(PMarker.perfCUIRibbonInitPercvdEnd);
        }
예제 #16
0
        private void OnReturnTab(DataQueryResult res)
        {
            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            if (res.Success)
            {
                JSObject ribbonNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                        DataNodeWrapper.RIBBON);
                JSObject tabsNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                        DataNodeWrapper.TABS);

                JSObject[] tabs = null;
                JSObject[] children = DataNodeWrapper.GetNodeChildren(tabsNode);
                if (children.Length == 0)
                {
                    JSObject ctxtabsNode =
                        DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                            DataNodeWrapper.CONTEXTUALTABS);
                    JSObject[] contextualGroups = DataNodeWrapper.GetNodeChildren(ctxtabsNode);
                    for (int i = 0; i < contextualGroups.Length; i++)
                    {
                        JSObject contextualGroup = contextualGroups[i];
                        tabs = DataNodeWrapper.GetNodeChildren(contextualGroup);
                        if (tabs.Length > 0)
                            break;
                    }
                }
                else
                {
                    tabs = DataNodeWrapper.GetNodeChildren(tabsNode);
                }

                JSObject templatesNode = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                        DataNodeWrapper.TEMPLATES);

                // Apply any extensions to the template data.
                templatesNode = (JSObject)ApplyDataExtensions(templatesNode);

                TemplateManager.Instance.LoadTemplates(templatesNode);

                // Apply any extensions to the tab data.
                // In this case we do not want to apply the extensions to the whole hierarchy
                // including <CommandUI>, <Ribbon> etc because this query is really only for
                // a specific tab.
                object tabData = ApplyDataExtensions(tabs[0]);

                FillTab(rbc.InitializedTab, tabData, rbc);
                // This may need to be parametrized so that tabs can be inited 
                // without automatically getting selected when the initing is done.
                rbc.InitializedTab.Ribbon.MakeTabSelectedInternal(rbc.InitializedTab);
                rbc.InitializedTab.OnDelayedInitFinished(true);
            }
            // TODO: how to handle failures

#if PERF_METRICS
            PMetrics.PerfMark(PMarker.perfCUIRibbonTabSwitchWarmPercvdEnd);
#endif
        }
예제 #17
0
        private void OnReturnTab(DataQueryResult res)
        {
            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            if (res.Success)
            {
                JSObject ribbonNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                                                              DataNodeWrapper.RIBBON);
                JSObject tabsNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                                                              DataNodeWrapper.TABS);

                JSObject[] tabs     = null;
                JSObject[] children = DataNodeWrapper.GetNodeChildren(tabsNode);
                if (children.Length == 0)
                {
                    JSObject ctxtabsNode =
                        DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                                                                  DataNodeWrapper.CONTEXTUALTABS);
                    JSObject[] contextualGroups = DataNodeWrapper.GetNodeChildren(ctxtabsNode);
                    for (int i = 0; i < contextualGroups.Length; i++)
                    {
                        JSObject contextualGroup = contextualGroups[i];
                        tabs = DataNodeWrapper.GetNodeChildren(contextualGroup);
                        if (tabs.Length > 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    tabs = DataNodeWrapper.GetNodeChildren(tabsNode);
                }

                JSObject templatesNode = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                                                                                   DataNodeWrapper.TEMPLATES);

                // Apply any extensions to the template data.
                templatesNode = (JSObject)ApplyDataExtensions(templatesNode);

                TemplateManager.Instance.LoadTemplates(templatesNode);

                // Apply any extensions to the tab data.
                // In this case we do not want to apply the extensions to the whole hierarchy
                // including <CommandUI>, <Ribbon> etc because this query is really only for
                // a specific tab.
                object tabData = ApplyDataExtensions(tabs[0]);

                FillTab(rbc.InitializedTab, tabData, rbc);
                // This may need to be parametrized so that tabs can be inited
                // without automatically getting selected when the initing is done.
                rbc.InitializedTab.Ribbon.MakeTabSelectedInternal(rbc.InitializedTab);
                rbc.InitializedTab.OnDelayedInitFinished(true);
            }
            // TODO: how to handle failures

#if PERF_METRICS
            PMetrics.PerfMark(PMarker.perfCUIRibbonTabSwitchWarmPercvdEnd);
#endif
        }
예제 #18
0
파일: data.cs 프로젝트: modulexcite/IL2JS
        /*
        /// <summary>
        /// Subclassers can hook in here if they want to run their own logic to 
        /// get the sought after cui data.
        /// </summary>
        /// <param name="query">The cui query that is to be run.</param>
        public virtual void RunQuery(DataQuery query)
        {
            string version = _version;
            if (!string.IsNullOrEmpty(query.Version))
                version = query.Version;

            string lcid = _lcid;
            if (!string.IsNullOrEmpty(query.Lcid))
                lcid = query.Lcid;

            string dataUrl = _dataUrl;
            if (!string.IsNullOrEmpty(query.DataUrl))
                dataUrl = query.DataUrl;

            string url;
            string type = null;

            // The dataUrl passed in might already have parameters
            if (dataUrl.IndexOf('?') == -1)
                url = dataUrl + "?ver=";
            else
                url = dataUrl + "&ver=";

            url = url + version + "&id=" + query.Id + "&lcid=" + lcid + "&qt=";

            switch (query.QueryType)
            {
                case DataQueryType.All:
                    type = "all";
                    break;
                case DataQueryType.RibbonTab:
                    type = "ribbontab";
                    break;
                case DataQueryType.RibbonShallow:
                    type = "ribbonshallow";
                    break;
                case DataQueryType.Root:
                    type = "root";
                    break;
                case DataQueryType.RibbonVisibleTabDeep:
                    type = "ribbonvisibletabdeep";
                    break;
            }

            url += type;
#if PERF_METRICS
            PMetrics.PerfMark(PMarker.perfCUIRibbonQueryDataStart);
#endif
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "GET";
            req.ContentType = "text/html";

            QueryRecord rec = new QueryRecord();
            rec.id = query.Id;
            rec.queryType = query.QueryType;
            rec.data = query.Data;
            rec.handler = query.Handler;

            object data= new object();
            RequestState state = new RequestState(req, data, rec);
            IAsyncResult result = req.BeginGetResponse(new AsyncCallback(OnDataReturned),state);

            //Register the timeout callback
            ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, 
                new WaitOrTimerCallback(ScanTimeoutCallback), state, (30 * 1000), true);
        }

        /// <summary>
        /// Subsclassers could hook in here if they wanted to subprocess the
        /// resulting JSON.
        /// </summary>
        /// <param name="executor">the web executor that has returned from async request</param>
        protected virtual void OnDataReturned(IAsyncResult result)
        {
#if PERF_METRICS
            PMetrics.PerfMark(PMarker.perfCUIRibbonQueryDataEnd);
#endif
            RequestState state = (RequestState)result.AsyncState;
            WebRequest request = (WebRequest)state.Request;

            HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(result);
            Stream s = (Stream)response.GetResponseStream();
            StreamReader readStream = new StreamReader(s);

            // Get the complete contents of the message
            string dataString = readStream.ReadToEnd();
            response.Close();
            s.Close();
            readStream.Close();

            QueryRecord rec = state.Query;
            DataQueryResult res = new DataQueryResult();
            res.ContextData = rec.data;
            res.Id = rec.id;

            // If the request succeeded
            // TODO(josefl) figure out right way to find out if it succeeded
            if (!string.IsNullOrEmpty(dataString))
            {
                res.Success = true;
                res.QueryData = dataString;
                rec.handler(res);
            }
            else
            {
                res.Success = false;
                // Return that the data retrieval failed
                rec.handler(res);
            }
        }

        private static void ScanTimeoutCallback (object state, bool timedOut) 
        {
            if (timedOut) 
            {
                RequestState reqState = (RequestState)state;
                if (reqState != null) 
                    reqState.Request.Abort();
            }
        }
        */

        /// <summary>
        /// Subclassers can hook in here if they want to run their own logic to 
        /// get the sought after cui data.
        /// </summary>
        /// <param name="query">The cui query that is to be run.</param>
        public virtual void RunQuery(DataQuery query)
        {
            QueryRecord rec = new QueryRecord();
            rec.id = query.Id;
            rec.queryType = query.QueryType;
            rec.data = query.Data;
            rec.handler = query.Handler;

            RibbonData rData = new RibbonData();

            JSObject dataBlock;
            if (query.TabQuery)
                dataBlock = rData.GetTabQueryData(query.Id);
            else
                dataBlock = rData.GetQueryData(query.Id);

            DataQueryResult res = new DataQueryResult();
            res.ContextData = rec.data;
            res.Id = rec.id;

            if (!CUIUtility.IsNullOrUndefined(dataBlock))
            {
                res.Success = true;
                res.QueryData = dataBlock;
                rec.handler(res);
            }
            else
            {
                // Return that the data retrieval failed
                res.Success = false;
                rec.handler(res);
            }
        }