/// <summary> /// The public method to create a toolbar using the datasource specified in the .DataSource property /// </summary> public void BuildToolbar() { ToolbarBuildContext context = new ToolbarBuildContext(); DataQuery query = new DataQuery(); query.TabQuery = false; query.Id = "toolbar"; query.QueryType = DataQueryType.All; query.Handler = new DataReturnedEventHandler(OnReturnToolbarData); query.Data = context; DataSource.RunQuery(query); }
/// <summary> /// This method executes the build process /// </summary> /// <param name="jewelId">The CUI ID for this Jewel</param> /// <returns>The Jewel object</returns> public bool BuildJewel(string jewelId) { if (InQuery) return false; if (IsIdTrimmed(jewelId)) return true; /* no error, so return true */ JewelBuildContext jbc = new JewelBuildContext(); jbc.JewelId = jewelId; InQuery = true; DataQuery query = new DataQuery(); query.TabQuery = false; query.Id = jbc.JewelId; query.QueryType = DataQueryType.Root; query.Handler = new DataReturnedEventHandler(OnReturnJewel); query.Data = jbc; this.DataSource.RunQuery(query); return true; }
/// <summary> /// This method executes the build process /// </summary> /// <param name="qatId">The CUI ID for this QAT</param> /// <returns>The QAT object</returns> public bool BuildQAT(string qatId) { if (InQuery) return false; if (IsIdTrimmed(qatId)) return true; /* no error, so return true */ QATBuildContext qbc = new QATBuildContext(); qbc.QATId = qatId; InQuery = true; DataQuery query = new DataQuery(); query.TabQuery = false; query.Id = qbc.QATId; query.QueryType = DataQueryType.Root; query.Handler = new DataReturnedEventHandler(OnReturnQAT); query.Data = qbc; DataSource.RunQuery(query); return true; }
public bool BuildRibbonAndInitialTab(string initialTabId) { if (string.IsNullOrEmpty(initialTabId)) throw new ArgumentNullException("Initial tab for ribbon is null or undefined"); if (InQuery) return false; RibbonBuildContext rbc = new RibbonBuildContext(); rbc.InitialTabId = initialTabId; // If this is server rendered, then we want to set and use the initial // scaling index for this first tab. if (!CUIUtility.IsNullOrUndefined(RibbonBuildOptions.AttachToDOM) && RibbonBuildOptions.AttachToDOM) { rbc.InitialScalingIndex = this.RibbonBuildOptions.InitialScalingIndex; } InQuery = true; DataQuery query = new DataQuery(); query.TabQuery = false; query.Id = rbc.InitialTabId; query.QueryType = DataQueryType.RibbonVisibleTabDeep; query.Handler = new DataReturnedEventHandler(OnReturnRibbonAndInitialTab); query.Data = rbc; DataSource.RunQuery(query); return true; }
private Component DelayInitTab(Component component, object data, object buildContext) { RibbonBuildContext rbc = (RibbonBuildContext)buildContext; Tab tab = (Tab)component; rbc.InitializedTab = (Tab)component; // If the data node does not have children, then it means that this tab // was shallowly fetched from the server. In this case we need to run // a query to get the whole node with all of its controls from the server. JSObject[] children = DataNodeWrapper.GetNodeChildren(data); if (children.Length == 0) { // TODO: implement this so that the asynchronous part works // Find out if we even need to fetch the tabs asynchronously // or if we can get away with just initializing them asynchronously DataQuery query = new DataQuery(); query.TabQuery = true; query.Id = rbc.InitializedTab.Id; query.QueryType = DataQueryType.RibbonTab; query.Handler = new DataReturnedEventHandler(this.OnReturnTab); query.Data = rbc; DataSource.RunQuery(query); return null; } FillTab(tab, data, rbc); tab.OnDelayedInitFinished(true); // TODO(josefl): this should later be an idle task registration instead of a hard call Ribbon.Refresh(); return tab; }
/* /// <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); } }