private void MapServiceActionDependencies(ServiceAction serviceAction, ServiceLocator serviceLocator) { serviceAction.Service = GetService(serviceAction.ServiceName, serviceAction.ServiceID, serviceLocator); if(!string.IsNullOrWhiteSpace(serviceAction.SourceName)) { serviceAction.Source = serviceLocator.FindSourceByName(serviceAction.SourceName, _workspace.ID); } }
DynamicService GetService(string serviceName, Guid resourceId, ServiceLocator sl) { try { Dev2Logger.Log.Debug(string.Format("Getting DynamicService: {0}", serviceName)); if(resourceId == Guid.Empty) { return sl.FindService(serviceName, _workspace.ID) ?? sl.FindService(serviceName, GlobalConstants.ServerWorkspaceID); //Check the workspace is it something we are working on if not use the server version } return sl.FindService(resourceId, _workspace.ID) ?? sl.FindService(resourceId, GlobalConstants.ServerWorkspaceID); //Check the workspace is it something we are working on if not use the server version }catch(Exception) { //Internal services return null; } }
/// <summary> /// Generates the invoke container. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="serviceId">The service unique identifier.</param> /// <param name="isLocalInvoke">if set to <c>true</c> [is local invoke].</param> /// <param name="masterDataListId">The master data list unique identifier.</param> /// <returns></returns> public EsbExecutionContainer GenerateInvokeContainer(IDSFDataObject dataObject, Guid serviceId, bool isLocalInvoke, Guid masterDataListId = default(Guid)) { if(isLocalInvoke) { ServiceAction sa; if(Cache.ContainsKey(dataObject.ResourceID)) { sa = Cache[dataObject.ResourceID]; return GenerateContainer(sa, dataObject, _workspace); } ServiceLocator sl = new ServiceLocator(); var theService = sl.FindService(serviceId, _workspace.ID); if(theService != null && theService.Actions.Any()) { sa = theService.Actions.FirstOrDefault(); MapServiceActionDependencies(sa, sl); Cache.TryAdd(dataObject.ResourceID, sa); return GenerateContainer(sa, dataObject, _workspace); } return null; } // we need a remote container ;) // TODO : Set Output description for shaping ;) return GenerateContainer(new ServiceAction { ActionType = Common.Interfaces.Core.DynamicServices.enActionType.RemoteService }, dataObject, null); }
/// <summary> /// Generates the invoke container. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="serviceName">Name of the service.</param> /// <param name="isLocalInvoke">if set to <c>true</c> [is local invoke].</param> /// <param name="masterDataListId">The master data list unique identifier.</param> /// <returns></returns> public EsbExecutionContainer GenerateInvokeContainer(IDSFDataObject dataObject, String serviceName, bool isLocalInvoke, Guid masterDataListId = default(Guid)) { if(isLocalInvoke) { if (Cache.ContainsKey(dataObject.ResourceID)) { ServiceAction sa = Cache[dataObject.ResourceID]; return GenerateContainer(sa, dataObject, _workspace); } // ReSharper disable RedundantIfElseBlock else // ReSharper restore RedundantIfElseBlock { ServiceLocator sl = new ServiceLocator(); var resourceId = dataObject.ResourceID; DynamicService theService = GetService(serviceName, resourceId, sl); EsbExecutionContainer executionContainer = null; if (theService != null && theService.Actions.Any()) { var sa = theService.Actions.FirstOrDefault(); MapServiceActionDependencies(sa, sl); Cache.TryAdd(dataObject.ResourceID, sa); executionContainer = GenerateContainer(sa, dataObject, _workspace); } return executionContainer; } } // we need a remote container ;) // TODO : Set Output description for shaping ;) return GenerateContainer(new ServiceAction { ActionType = Common.Interfaces.Core.DynamicServices.enActionType.RemoteService }, dataObject, null); }
/// <summary> /// Invokes the specified service as per the dataObject against theHost /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="errors">The errors.</param> /// <returns></returns> /// <exception cref="System.Exception">Can only execute workflows from web browser</exception> public Guid Invoke(IDSFDataObject dataObject, out ErrorResultTO errors) { var result = GlobalConstants.NullDataListID; var time = new Stopwatch(); time.Start(); errors = new ErrorResultTO(); int update = 0; // BUG 9706 - 2013.06.22 - TWR : added pre debug dispatch if(dataObject.Environment.HasErrors()) { errors.AddError(dataObject.Environment.FetchErrors()); DispatchDebugErrors(errors, dataObject, StateType.Before); } errors.ClearErrors(); try { var serviceId = dataObject.ResourceID; // we need to get better at getting this ;) var serviceName = dataObject.ServiceName; if(serviceId == Guid.Empty && string.IsNullOrEmpty(serviceName)) { errors.AddError(Resources.DynamicServiceError_ServiceNotSpecified); } else { try { var sl = new ServiceLocator(); Dev2Logger.Log.Debug("Finding service"); var theService = serviceId == Guid.Empty ? sl.FindService(serviceName, _workspace.ID) : sl.FindService(serviceId, _workspace.ID); if(theService == null) { errors.AddError("Service [ " + serviceName + " ] not found."); } else if(theService.Actions.Count <= 1) { #region Execute ESB container var theStart = theService.Actions.FirstOrDefault(); if(theStart != null && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.InvokeManagementDynamicService && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.Workflow && dataObject.IsFromWebServer) { throw new Exception("Can only execute workflows from web browser"); } Dev2Logger.Log.Debug("Mapping Action Dependencies"); MapServiceActionDependencies(theStart, sl); // Invoke based upon type ;) if(theStart != null) { theStart.DataListSpecification = theService.DataListSpecification; Dev2Logger.Log.Debug("Getting container"); var container = GenerateContainer(theStart, dataObject, _workspace); ErrorResultTO invokeErrors; result = container.Execute(out invokeErrors, update); errors.MergeErrors(invokeErrors); } #endregion } else { errors.AddError("Malformed Service [ " + serviceId + " ] it contains multiple actions"); } } catch(Exception e) { errors.AddError(e.Message); } finally { if (dataObject.Environment.HasErrors()) { var errorString = dataObject.Environment.FetchErrors(); var executionErrors = ErrorResultTO.MakeErrorResultFromDataListString(errorString); errors.MergeErrors(executionErrors); } dataObject.Environment.AddError(errors.MakeDataListReady()); if(errors.HasErrors()) { Dev2Logger.Log.Error(errors.MakeDisplayReady()); } } } } finally { time.Stop(); ServerStats.IncrementTotalRequests(); ServerStats.IncrementTotalTime(time.ElapsedMilliseconds); // BUG 9706 - 2013.06.22 - TWR : added DispatchDebugErrors(errors, dataObject, StateType.End); } return result; }