/// <summary> /// Sets the web service URL for a CacheRefresher from an XmlNode. /// </summary> /// <param name="cr">The CacheRefresher.</param> /// <param name="n">The XmlNode.</param> private static void SetWebServiceUrlFromNode(CacheRefresher cr, XmlNode n) { string protocol = GlobalSettings.UseSSL ? "https" : "http"; if (n.Attributes.GetNamedItem("forceProtocol") != null && !String.IsNullOrEmpty(n.Attributes.GetNamedItem("forceProtocol").Value)) { protocol = n.Attributes.GetNamedItem("forceProtocol").Value; } string domain = xmlHelper.GetNodeValue(n); if (n.Attributes.GetNamedItem("forcePortnumber") != null && !String.IsNullOrEmpty(n.Attributes.GetNamedItem("forcePortnumber").Value)) { domain += string.Format(":{0}", n.Attributes.GetNamedItem("forcePortnumber").Value); } cr.Url = string.Format("{0}://{1}{2}/cacheRefresher.asmx", protocol, domain, _webServicesUrl); }
/// <summary> /// Invokes the relevant dispatch method. /// </summary> /// <param name="dispatchType">Type of the dispatch.</param> /// <param name="factoryGuid">The factory GUID.</param> /// <param name="numericId">The numeric id.</param> /// <param name="guidId">The GUID id.</param> private static void InvokeDispatchMethod(DispatchType dispatchType, Guid factoryGuid, int numericId, Guid guidId) { string name = GetFactoryObjectName(factoryGuid); try { using (var cacheRefresher = new CacheRefresher()) { var asyncResultsList = new List<IAsyncResult>(); LogStartDispatch(); // Go through each configured node submitting a request asynchronously foreach (XmlNode n in GetDistributedNodes()) { SetWebServiceUrlFromNode(cacheRefresher, n); // Add the returned WaitHandle to the list for later checking switch (dispatchType) { case DispatchType.RefreshAll: asyncResultsList.Add(cacheRefresher.BeginRefreshAll(factoryGuid, _login, _password, null, null)); break; case DispatchType.RefreshByGuid: asyncResultsList.Add(cacheRefresher.BeginRefreshByGuid(factoryGuid, guidId, _login, _password, null, null)); break; case DispatchType.RefreshByNumericId: asyncResultsList.Add(cacheRefresher.BeginRefreshById(factoryGuid, numericId, _login, _password, null, null)); break; case DispatchType.RemoveById: asyncResultsList.Add(cacheRefresher.BeginRemoveById(factoryGuid, numericId, _login, _password, null, null)); break; } } List<WaitHandle> waitHandlesList; IAsyncResult[] asyncResults = GetAsyncResults(asyncResultsList, out waitHandlesList); int errorCount = 0; // Once for each WaitHandle that we have, wait for a response and log it // We're previously submitted all these requests effectively in parallel and will now retrieve responses on a FIFO basis for (int waitCalls = 0; waitCalls < asyncResults.Length; waitCalls++) { int handleIndex = WaitHandle.WaitAny(waitHandlesList.ToArray(), TimeSpan.FromSeconds(15)); try { // Find out if the call succeeded switch (dispatchType) { case DispatchType.RefreshAll: cacheRefresher.EndRefreshAll(asyncResults[waitCalls]); break; case DispatchType.RefreshByGuid: cacheRefresher.EndRefreshByGuid(asyncResults[waitCalls]); break; case DispatchType.RefreshByNumericId: cacheRefresher.EndRefreshById(asyncResults[waitCalls]); break; case DispatchType.RemoveById: cacheRefresher.EndRemoveById(asyncResults[waitCalls]); break; } } catch (WebException ex) { LogDispatchNodeError(ex); errorCount++; } catch (Exception ex) { LogDispatchNodeError(ex); errorCount++; } } LogDispatchBatchResult(errorCount); } } catch (Exception ee) { LogDispatchBatchError(ee); } }
/// <summary> /// Sets the web service URL for a CacheRefresher from an XmlNode. /// </summary> /// <param name="cr">The CacheRefresher.</param> /// <param name="n">The XmlNode.</param> private static void SetWebServiceUrlFromNode(CacheRefresher cr, XmlNode n) { string protocol = GlobalSettings.UseSSL ? "https" : "http"; if (n.Attributes.GetNamedItem("forceProtocol") != null && !String.IsNullOrEmpty(n.Attributes.GetNamedItem("forceProtocol").Value)) protocol = n.Attributes.GetNamedItem("forceProtocol").Value; string domain = xmlHelper.GetNodeValue(n); if (n.Attributes.GetNamedItem("forcePortnumber") != null && !String.IsNullOrEmpty(n.Attributes.GetNamedItem("forcePortnumber").Value)) domain += string.Format(":{0}", n.Attributes.GetNamedItem("forcePortnumber").Value); cr.Url = string.Format("{0}://{1}{2}/cacheRefresher.asmx", protocol, domain, _webServicesUrl); }
/// <summary> /// Invokes the relevant dispatch method. /// </summary> /// <param name="dispatchType">Type of the dispatch.</param> /// <param name="factoryGuid">The factory GUID.</param> /// <param name="numericId">The numeric id.</param> /// <param name="guidId">The GUID id.</param> private static void InvokeDispatchMethod(DispatchType dispatchType, Guid factoryGuid, int numericId, Guid guidId) { string name = GetFactoryObjectName(factoryGuid); try { using (var cacheRefresher = new CacheRefresher()) { var asyncResultsList = new List <IAsyncResult>(); LogStartDispatch(); // Go through each configured node submitting a request asynchronously foreach (XmlNode n in GetDistributedNodes()) { SetWebServiceUrlFromNode(cacheRefresher, n); // Add the returned WaitHandle to the list for later checking switch (dispatchType) { case DispatchType.RefreshAll: asyncResultsList.Add(cacheRefresher.BeginRefreshAll(factoryGuid, _login, _password, null, null)); break; case DispatchType.RefreshByGuid: asyncResultsList.Add(cacheRefresher.BeginRefreshByGuid(factoryGuid, guidId, _login, _password, null, null)); break; case DispatchType.RefreshByNumericId: asyncResultsList.Add(cacheRefresher.BeginRefreshById(factoryGuid, numericId, _login, _password, null, null)); break; case DispatchType.RemoveById: asyncResultsList.Add(cacheRefresher.BeginRemoveById(factoryGuid, numericId, _login, _password, null, null)); break; } } List <WaitHandle> waitHandlesList; IAsyncResult[] asyncResults = GetAsyncResults(asyncResultsList, out waitHandlesList); int errorCount = 0; // Once for each WaitHandle that we have, wait for a response and log it // We're previously submitted all these requests effectively in parallel and will now retrieve responses on a FIFO basis for (int waitCalls = 0; waitCalls < asyncResults.Length; waitCalls++) { int handleIndex = WaitHandle.WaitAny(waitHandlesList.ToArray(), TimeSpan.FromSeconds(15)); try { // Find out if the call succeeded switch (dispatchType) { case DispatchType.RefreshAll: cacheRefresher.EndRefreshAll(asyncResults[waitCalls]); break; case DispatchType.RefreshByGuid: cacheRefresher.EndRefreshByGuid(asyncResults[waitCalls]); break; case DispatchType.RefreshByNumericId: cacheRefresher.EndRefreshById(asyncResults[waitCalls]); break; case DispatchType.RemoveById: cacheRefresher.EndRemoveById(asyncResults[waitCalls]); break; } } catch (WebException ex) { LogDispatchNodeError(ex); errorCount++; } catch (Exception ex) { LogDispatchNodeError(ex); errorCount++; } } LogDispatchBatchResult(errorCount); } } catch (Exception ee) { LogDispatchBatchError(ee); } }
/// <summary> /// Sets the web service URL for a CacheRefresher from an XmlNode. /// </summary> /// <param name="cr">The CacheRefresher.</param> /// <param name="n">The XmlNode.</param> private static void SetWebServiceUrlFromNode(CacheRefresher cr, XmlNode n) { cr.Url = "http://" + xmlHelper.GetNodeValue(n) + _webServicesUrl + "/cacheRefresher.asmx"; }