public static void SetResourceNameAndId(this IDSFDataObject dataObject, IResourceCatalog catalog, string serviceName, out IResource resource) { IResource localResource = null; Guid resourceID; if (Guid.TryParse(serviceName, out resourceID)) { localResource = catalog.GetResource(dataObject.WorkspaceID, resourceID); if (localResource != null) { dataObject.ServiceName = localResource.ResourceName; dataObject.ResourceID = localResource.ResourceID; dataObject.SourceResourceID = localResource.ResourceID; } } else { if (!string.IsNullOrEmpty(dataObject.ServiceName)) { localResource = catalog.GetResource(dataObject.WorkspaceID, dataObject.ServiceName); if (localResource != null) { dataObject.ResourceID = localResource.ResourceID; dataObject.SourceResourceID = localResource.ResourceID; } } } resource = localResource; }
// POST: Service/Services/Save public string Save(string args, Guid workspaceId, Guid dataListId) { try { var service = DeserializeService(args); var dbService = service as DbService; if (dbService != null) { var source = _resourceCatalog.GetResource <DbSource>(workspaceId, dbService.Source.ResourceID); if (source.ServerType == enSourceType.MySqlDatabase) { var broker = new MySqlDatabaseBroker(); broker.UpdateServiceOutParameters(dbService, source); } } _resourceCatalog.SaveResource(workspaceId, service); if (workspaceId != GlobalConstants.ServerWorkspaceID) { _resourceCatalog.SaveResource(GlobalConstants.ServerWorkspaceID, service); } return(service.ToString()); } catch (Exception ex) { RaiseError(ex); return(new ValidationResult { IsValid = false, ErrorMessage = ex.Message }.ToString()); } }
public ResourceCatalogResult RenameResource(Guid workspaceID, Guid?resourceID, string newName, string resourcePath) { GlobalConstants.HandleEmptyParameters(resourceID, "resourceID"); GlobalConstants.HandleEmptyParameters(newName, "newName"); var resourcesToUpdate = _resourceCatalog.GetResources(workspaceID).Where(resource => resource.ResourceID == resourceID).ToArray(); try { if (!resourcesToUpdate.Any()) { return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToFindResource} '{resourceID}' to '{newName}'")); } _versionRepository.StoreVersion(_resourceCatalog.GetResource(Guid.Empty, resourceID.Value), "unknown", "Rename", workspaceID, resourcePath); //rename and save to workspace var renameResult = UpdateResourceName(workspaceID, resourcesToUpdate[0], newName, resourcePath); if (renameResult.Status != ExecStatus.Success) { return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToRenameResource} '{resourceID}' to '{newName}'")); } } catch (Exception err) { Dev2Logger.Error(err, GlobalConstants.WarewolfError); return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToRenameResource} '{resourceID}' to '{newName}'")); } return(ResourceCatalogResultBuilder.CreateSuccessResult($"Renamed Resource \'{resourceID}\' to \'{newName}\'")); }
void GetSource(IResourceCatalog catalog) { Source = catalog.GetResource <TSource>(GlobalConstants.ServerWorkspaceID, Service.Source.ResourceID) ?? catalog.GetResource <TSource>(GlobalConstants.ServerWorkspaceID, Service.Source.ResourceName); if (Source == null) { _errorResult.AddError(string.Format(ErrorResource.ErrorRetrievingDBSourceForResource, Service.Source.ResourceID, Service.Source.ResourceName)); } }
bool GetService(IResourceCatalog catalog) { Service = catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ResourceID) ?? catalog.GetResource <TService>(GlobalConstants.ServerWorkspaceID, DataObj.ServiceName); if (Service == null) { _errorResult.AddError(string.Format(ErrorResource.ErrorLoadingResource, DataObj.ResourceID)); return(false); } return(true); }
protected void DispatchDebugStateAndUpdateRemoteServer(IDSFDataObject dataObject, StateType before) { if (_debugState != null) { Guid remoteID; Guid.TryParse(dataObject.RemoteInvokerID, out remoteID); var res = _resourceCatalog.GetResource(GlobalConstants.ServerWorkspaceID, remoteID); string name = remoteID != Guid.Empty ? res != null ? res.ResourceName : "localhost" : "localhost"; _debugState.Server = name; } DispatchDebugState(dataObject, before, 0); }
void UpdateDependantResourceWithCompileMessages(Guid workspaceID, IResource resource, IList <ICompileMessageTO> messages) { var resourceId = resource.ResourceID; var dependants = _resourceCatalog.GetDependentsAsResourceForTrees(workspaceID, resourceId); var dependsMessageList = new List <ICompileMessageTO>(); foreach (var dependant in dependants) { var affectedResource = _resourceCatalog.GetResource(workspaceID, dependant.ResourceID); foreach (var compileMessageTO in messages) { compileMessageTO.WorkspaceID = workspaceID; compileMessageTO.UniqueID = dependant.UniqueID; if (affectedResource != null) { compileMessageTO.ServiceName = affectedResource.ResourceName; compileMessageTO.ServiceID = affectedResource.ResourceID; } dependsMessageList.Add(compileMessageTO.Clone()); } if (affectedResource != null) { Common.UpdateResourceXml(_resourceCatalog, workspaceID, affectedResource, messages); } } CompileMessageRepo.Instance.AddMessage(workspaceID, dependsMessageList); }
static List <IServiceTestModelTO> RunListOfTests(IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog) { var testResults = new List <IServiceTestModelTO>(); var taskList = new List <Task>(); foreach (var testsResourceId in dataObject.TestsResourceIds) { var allTests = testCatalog.Fetch(testsResourceId); foreach (var test in allTests) { var dataObjectClone = dataObject.Clone(); dataObjectClone.Environment = new ExecutionEnvironment(); dataObjectClone.TestName = test.TestName; var res = catalog.GetResource(GlobalConstants.ServerWorkspaceID, testsResourceId); dataObjectClone.ServiceName = res.ResourceName; dataObjectClone.ResourceID = res.ResourceID; var resourcePath = res.GetResourcePath(GlobalConstants.ServerWorkspaceID).Replace("\\", "/"); var lastTask = ServiceTestExecutor.GetTaskForTestExecution(resourcePath, userPrinciple, workspaceGuid, serializer, testResults, dataObjectClone); taskList.Add(lastTask); } } Task.WaitAll(taskList.ToArray()); return(testResults); }
public static DataListFormat RunMultipleTestBatches(this IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, DataListFormat formatter, IResourceCatalog catalog, ITestCatalog testCatalog, ref string executePayload) { foreach (var testsResourceId in dataObject.TestsResourceIds) { var allTests = testCatalog.Fetch(testsResourceId); var taskList = new List <Task>(); var testResults = new List <IServiceTestModelTO>(); foreach (var test in allTests) { dataObject.ResourceID = testsResourceId; var dataObjectClone = dataObject.Clone(); dataObjectClone.Environment = new ExecutionEnvironment(); dataObjectClone.TestName = test.TestName; var res = catalog.GetResource(GlobalConstants.ServerWorkspaceID, testsResourceId); var resourcePath = res.GetResourcePath(GlobalConstants.ServerWorkspaceID).Replace("\\", "/"); var lastTask = ServiceTestExecutor.GetTaskForTestExecution(resourcePath, userPrinciple, workspaceGuid, serializer, testResults, dataObjectClone); taskList.Add(lastTask); } Task.WaitAll(taskList.ToArray()); formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); var objArray = (from testRunResult in testResults where testRunResult != null select testRunResult.BuildTestResultForWebRequest() ).ToList(); executePayload = executePayload + Environment.NewLine + serializer.Serialize(objArray); } return(formatter); }
public static void SetResourceNameAndId(this IDSFDataObject dataObject, IResourceCatalog catalog, string serviceName, out IWarewolfResource resource) { IWarewolfResource localResource = null; if (Guid.TryParse(serviceName, out var resourceId)) { localResource = catalog.GetResource(dataObject.WorkspaceID, resourceId); if (localResource != null) { MapServiceToDataObjects(dataObject, localResource); } } else { if (!string.IsNullOrEmpty(dataObject.ServiceName)) { localResource = catalog.GetResource(dataObject.WorkspaceID, dataObject.ServiceName); if (localResource != null) { dataObject.ResourceID = localResource.ResourceID; dataObject.SourceResourceID = localResource.ResourceID; } } } if (localResource == null) { var stringDynaResourceId = serviceName.Replace(".xml", "").Replace(".bite", "").Replace(".json", ""); if (Guid.TryParse(stringDynaResourceId, out resourceId)) { localResource = catalog.GetResource(dataObject.WorkspaceID, resourceId); if (localResource != null) { MapServiceToDataObjects(dataObject, localResource); } } if (localResource == null) { dataObject.Environment.AddError($"Service {serviceName} not found."); } } resource = localResource; dataObject.Resource = resource; }
private bool ProcessDsfDataObject(EsbExecuteRequest request, Guid workspaceId, Guid dataListId, string connectionId, EsbServicesEndpoint channel) { var(xmlData, queryString) = FormatXmlData(request); DsfDataObject = new DsfDataObject(xmlData, dataListId); if (!DsfDataObject.ExecutionID.HasValue) { DsfDataObject.ExecutionID = Guid.NewGuid(); } DsfDataObject.QueryString = queryString; if (IsDebugRequest(request)) { DsfDataObject.IsDebug = true; } DsfDataObject.StartTime = DateTime.Now; DsfDataObject.EsbChannel = channel; DsfDataObject.ServiceName = request.ServiceName; DsfDataObject.Settings = new Dev2WorkflowSettingsTO { ExecutionLogLevel = Config.Server.ExecutionLogLevel, EnableDetailedLogging = Config.Server.EnableDetailedLogging, LoggerType = LoggerType.JSON, KeepLogsForDays = 2, CompressOldLogFiles = true }; var resource = request.ResourceID != Guid.Empty ? _catalog.GetResource(workspaceId, request.ResourceID) : _catalog.GetResource(workspaceId, request.ServiceName); var isManagementResource = false; if (!string.IsNullOrEmpty(request.TestName)) { DsfDataObject.TestName = request.TestName; DsfDataObject.IsServiceTestExecution = true; } if (resource != null) { DsfDataObject.ResourceID = resource.ResourceID; DsfDataObject.SourceResourceID = resource.ResourceID; isManagementResource = _catalog.ManagementServices.ContainsKey(resource.ResourceID); } else { if (request.ResourceID != Guid.Empty) { DsfDataObject.ResourceID = request.ResourceID; } } DsfDataObject.ClientID = Guid.Parse(connectionId); Common.Utilities.OrginalExecutingUser = ExecutingUser; DsfDataObject.ExecutingUser = ExecutingUser; return(isManagementResource); }
private void PerformSearchOnActivity(ISearch searchParameters, List <ISearchResult> searchResults, KeyValuePair <Guid, IDev2Activity> resourceActivity, IDev2Activity activity) { if (activity != null) { var foundMatch = SearchUtils.FilterText(activity.GetDisplayName(), searchParameters); if (foundMatch) { var resource = _resourceCatalog.GetResource(GlobalConstants.ServerWorkspaceID, resourceActivity.Key); var searchResult = new SearchResult(resource.ResourceID, resource.ResourceName, resource.GetResourcePath(GlobalConstants.ServerWorkspaceID), SearchItemType.ToolTitle, activity.GetDisplayName()); searchResults.Add(searchResult); } } }
public static void UpdateResourceXml(IResourceCatalog resourceCatalog, Guid workspaceID, IResource effectedResource, IList <ICompileMessageTO> compileMessagesTO) { var resourceContents = resourceCatalog.GetResourceContents(workspaceID, effectedResource.ResourceID); UpdateXmlToDisk(effectedResource, compileMessagesTO, resourceContents); var serverResource = resourceCatalog.GetResource(Guid.Empty, effectedResource.ResourceName); if (serverResource != null) { resourceContents = resourceCatalog.GetResourceContents(Guid.Empty, serverResource.ResourceID); UpdateXmlToDisk(serverResource, compileMessagesTO, resourceContents); } }
// POST: Service/Services/DbMethods public ServiceMethodList DbMethods(string args, Guid workspaceId, Guid dataListId) { var result = new ServiceMethodList(); if (!string.IsNullOrEmpty(args)) { try { Dev2JsonSerializer serialiser = new Dev2JsonSerializer(); var source = serialiser.Deserialize <DbSource>(args); var actualSource = _resourceCatalog.GetResource <DbSource>(workspaceId, source.ResourceID); actualSource.ReloadActions = source.ReloadActions; var serviceMethods = FetchMethods(actualSource); result.AddRange(serviceMethods); } catch (Exception ex) { RaiseError(ex); result.Add(new ServiceMethod(ex.Message, ex.StackTrace)); } } return(result); }
/// <summary> /// Finds the service shape. /// </summary> /// <param name="workspaceId">The workspace ID.</param> /// <param name="resourceId">The ID of the resource</param> /// <returns></returns> private string FindServiceShape(Guid workspaceId, Guid resourceId) { const string EmptyDataList = "<DataList></DataList>"; var resource = _lazyCat.GetResource(workspaceId, resourceId); if (resource == null) { return(EmptyDataList); } var serviceShape = resource.DataList.Replace(GlobalConstants.SerializableResourceQuote, "\"").ToString(); serviceShape = serviceShape.Replace(GlobalConstants.SerializableResourceSingleQuote, "\'"); return(string.IsNullOrEmpty(serviceShape) ? EmptyDataList : serviceShape); }
public IList <IExplorerItem> GetVersions(Guid resourceId) { var resource = _catalogue.GetResource(Guid.Empty, resourceId); if (resource == null || resource.VersionInfo == null) { return(new List <IExplorerItem>()); } var path = GetVersionFolderFromResource(resource); // ReSharper disable ImplicitlyCapturedClosure var files = _directory.GetFiles(path).Where(a => a.Contains(resource.VersionInfo.VersionId.ToString())); // ReSharper restore ImplicitlyCapturedClosure return(files.Select(a => CreateVersionFromFilePath(a, resource)).OrderByDescending(a => a.VersionInfo.DateTimeStamp).Take(GlobalConstants.VersionCount).ToList()); }
public List <ISearchResult> GetSearchResults(ISearch searchParameters) { var foundItems = new List <ISearchResult>(); if (searchParameters.SearchOptions.IsTestNameSelected) { var tests = _testCatalog.FetchAllTests(); foreach (var test in tests) { var found = SearchUtils.FilterText(test.TestName, searchParameters); if (found) { var resource = _resourceCatalog.GetResource(GlobalConstants.ServerWorkspaceID, test.ResourceId); var searchResult = new SearchResult(resource.ResourceID, resource.ResourceName, resource.GetResourcePath(GlobalConstants.ServerWorkspaceID), SearchItemType.TestName, test.TestName); foundItems.Add(searchResult); } } } return(foundItems); }
public IList <IExplorerItem> GetVersions(Guid resourceId) { var resource = _catalogue.GetResource(Guid.Empty, resourceId); if (resource?.VersionInfo == null) { return(new List <IExplorerItem>()); } var versionFolder = _filePath.Combine(_envVersionFolder, resourceId.ToString()); var files = _directory.GetFiles(versionFolder); return(files.Select(a => CreateVersionFromFilePath(a, resource, _envVersionFolder)) .OrderByDescending(a => a.VersionInfo.DateTimeStamp) .Take(GlobalConstants.VersionCount) .ToList()); }
/// <summary> /// Finds the service by name /// </summary> /// <param name="serviceName">Name of the service.</param> /// <param name="workspaceID">The workspace ID.</param> /// <exception cref="System.IO.InvalidDataException">Empty or null service passed in</exception> /// <exception cref="System.Runtime.Serialization.InvalidDataContractException">Null workspace</exception> public DynamicService FindService(string serviceName, Guid workspaceID) { if (string.IsNullOrEmpty(serviceName)) { throw new InvalidDataException(ErrorResource.ServiceIsNull); } var res = _resourceCatalog.GetResource(workspaceID, serviceName); DynamicService ret = null; if (res != null) { ret = ServiceActionRepo.Instance.ReadCache(res.ResourceID); } if (ret == null) { ret = _resourceCatalog.GetDynamicObjects <DynamicService>(workspaceID, serviceName).FirstOrDefault(); if (ret == null) { _perfCounter.Increment(); } } return(ret); }
#pragma warning disable S2360 // Optional parameters should not be used, unless they are only used in the same assembly internal DebugState GetDebugState(IDSFDataObject dataObject, StateType stateType, ErrorResultTO errors, bool interrogateInputs = false, bool interrogateOutputs = false, bool durationVisible = false) #pragma warning restore S2360 // Optional parameters should not be used { var errorMessage = string.Empty; if (dataObject.Environment.HasErrors()) { errorMessage = dataObject.Environment.FetchErrors(); } var server = "localhost"; var hasRemote = Guid.TryParse(dataObject.RemoteInvokerID, out var remoteID); if (hasRemote) { var res = _lazyCat.GetResource(GlobalConstants.ServerWorkspaceID, remoteID); if (res != null) { server = remoteID != Guid.Empty ? _lazyCat.GetResource(GlobalConstants.ServerWorkspaceID, remoteID).ResourceName : "localhost"; } } Guid.TryParse(dataObject.ParentInstanceID, out var parentInstanceId); var debugState = new DebugState { ID = dataObject.OriginalInstanceID, ParentID = parentInstanceId, WorkspaceID = dataObject.WorkspaceID, StateType = stateType, StartTime = dataObject.StartTime, EndTime = DateTime.Now, ActivityType = ActivityType.Workflow, DisplayName = dataObject.ServiceName, IsSimulation = dataObject.IsOnDemandSimulation, ServerID = dataObject.ServerID, OriginatingResourceID = dataObject.ResourceID, OriginalInstanceID = dataObject.OriginalInstanceID, Server = server, Version = string.Empty, SessionID = dataObject.DebugSessionID, EnvironmentID = dataObject.DebugEnvironmentId, ClientID = dataObject.ClientID, SourceResourceID = dataObject.SourceResourceID, Name = stateType.ToString(), HasError = dataObject.Environment.HasErrors(), ErrorMessage = errorMessage, IsDurationVisible = durationVisible }; if (stateType == StateType.End) { debugState.NumberOfSteps = dataObject.NumberOfSteps; } if (stateType == StateType.Start) { debugState.ExecutionOrigin = dataObject.ExecutionOrigin; debugState.ExecutionOriginDescription = dataObject.ExecutionOriginDescription; } if (interrogateInputs) { var defs = DataListUtil.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Input); var inputs = GetDebugValues(defs, dataObject, out var invokeErrors); errors.MergeErrors(invokeErrors); debugState.Inputs.AddRange(inputs); } if (interrogateOutputs) { var defs = DataListUtil.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Output); var outputs = GetDebugValues(defs, dataObject, out var invokeErrors); errors.MergeErrors(invokeErrors); debugState.Outputs.AddRange(outputs); } return(debugState); }
public StringBuilder ProcessRequest(EsbExecuteRequest request, Guid workspaceId, Guid dataListId, string connectionId) { var channel = new EsbServicesEndpoint(); var xmlData = string.Empty; var queryString = ""; if (request.Args != null && request.Args.ContainsKey("DebugPayload")) { xmlData = request.Args["DebugPayload"].ToString(); queryString = BuildStudioUrl(xmlData); xmlData = xmlData.Replace("<DataList>", "<XmlData>").Replace("</DataList>", "</XmlData>"); } if (string.IsNullOrEmpty(xmlData)) { xmlData = "<DataList></DataList>"; } var isDebug = false; if (request.Args != null && request.Args.ContainsKey("IsDebug")) { var debugString = request.Args["IsDebug"].ToString(); if (!bool.TryParse(debugString, out isDebug)) { isDebug = false; } } var serializer = new Dev2JsonSerializer(); IDSFDataObject dataObject = new DsfDataObject(xmlData, dataListId); if (!dataObject.ExecutionID.HasValue) { dataObject.ExecutionID = Guid.NewGuid(); } dataObject.QueryString = queryString; if (isDebug) { dataObject.IsDebug = true; } dataObject.StartTime = DateTime.Now; dataObject.EsbChannel = channel; dataObject.ServiceName = request.ServiceName; var resource = request.ResourceID != Guid.Empty ? _catalog.GetResource(workspaceId, request.ResourceID) : _catalog.GetResource(workspaceId, request.ServiceName); var isManagementResource = false; if (!string.IsNullOrEmpty(request.TestName)) { dataObject.TestName = request.TestName; dataObject.IsServiceTestExecution = true; } if (resource != null) { dataObject.ResourceID = resource.ResourceID; dataObject.SourceResourceID = resource.ResourceID; isManagementResource = _catalog.ManagementServices.ContainsKey(resource.ResourceID); } else { if (request.ResourceID != Guid.Empty) { dataObject.ResourceID = request.ResourceID; } } dataObject.ClientID = Guid.Parse(connectionId); Common.Utilities.OrginalExecutingUser = ExecutingUser; dataObject.ExecutingUser = ExecutingUser; if (!dataObject.Environment.HasErrors()) { return(ProcessRequest(request, workspaceId, channel, dataObject, isManagementResource)); } var msg = new ExecuteMessage { HasError = true }; msg.SetMessage(string.Join(Environment.NewLine, dataObject.Environment.Errors)); return(serializer.SerializeToBuilder(msg)); }
public StringBuilder ProcessRequest(EsbExecuteRequest request, Guid workspaceID, Guid dataListID, string connectionId) { var channel = new EsbServicesEndpoint(); var xmlData = string.Empty; if (request.Args != null && request.Args.ContainsKey("DebugPayload")) { xmlData = request.Args["DebugPayload"].ToString(); xmlData = xmlData.Replace("<DataList>", "<XmlData>").Replace("</DataList>", "</XmlData>"); } if (string.IsNullOrEmpty(xmlData)) { xmlData = "<DataList></DataList>"; } var isDebug = false; if (request.Args != null && request.Args.ContainsKey("IsDebug")) { var debugString = request.Args["IsDebug"].ToString(); if (!bool.TryParse(debugString, out isDebug)) { isDebug = false; } } var serializer = new Dev2JsonSerializer(); IDSFDataObject dataObject = new DsfDataObject(xmlData, dataListID); if (isDebug) { dataObject.IsDebug = true; } dataObject.StartTime = DateTime.Now; dataObject.EsbChannel = channel; dataObject.ServiceName = request.ServiceName; var resource = request.ResourceID != Guid.Empty ? _catalog.GetResource(workspaceID, request.ResourceID) : _catalog.GetResource(workspaceID, request.ServiceName); var isManagementResource = false; if (!string.IsNullOrEmpty(request.TestName)) { dataObject.TestName = request.TestName; dataObject.IsServiceTestExecution = true; } if (resource != null) { dataObject.ResourceID = resource.ResourceID; dataObject.SourceResourceID = resource.ResourceID; isManagementResource = _catalog.ManagementServices.ContainsKey(resource.ResourceID); } else { if (request.ResourceID != Guid.Empty) { dataObject.ResourceID = request.ResourceID; } } dataObject.ClientID = Guid.Parse(connectionId); Common.Utilities.OrginalExecutingUser = ExecutingUser; dataObject.ExecutingUser = ExecutingUser; if (!dataObject.Environment.HasErrors()) { ErrorResultTO errors; if (ExecutingUser == null) { throw new Exception(ErrorResource.NullExecutingUser); } try { // Execute in its own thread to give proper context ;) var t = new Thread(() => { Thread.CurrentPrincipal = ExecutingUser; if (isManagementResource) { Thread.CurrentPrincipal = Common.Utilities.ServerUser; ExecutingUser = Common.Utilities.ServerUser; dataObject.ExecutingUser = Common.Utilities.ServerUser; } else if (dataObject.IsServiceTestExecution) { if (_authorizationService != null) { var authorizationService = _authorizationService; var hasContribute = authorizationService.IsAuthorized(AuthorizationContext.Contribute, Guid.Empty.ToString()); if (!hasContribute) { throw new UnauthorizedAccessException( "The user does not have permission to execute tests."); } } } channel.ExecuteRequest(dataObject, request, workspaceID, out errors); }); t.Start(); t.Join(); } catch (Exception e) { Dev2Logger.Error(e.Message, e); } if (request.ExecuteResult.Length > 0) { return(request.ExecuteResult); } return(new StringBuilder()); } var msg = new ExecuteMessage { HasError = true }; msg.SetMessage(string.Join(Environment.NewLine, dataObject.Environment.Errors)); return(serializer.SerializeToBuilder(msg)); }
public StringBuilder ProcessRequest(EsbExecuteRequest request, Guid workspaceId, Guid dataListId, string connectionId) { var channel = new EsbServicesEndpoint(); var xmlData = string.Empty; var queryString = ""; if (request.Args != null && request.Args.ContainsKey("DebugPayload")) { xmlData = request.Args["DebugPayload"].ToString(); queryString = BuildStudioUrl(xmlData); xmlData = xmlData.Replace("<DataList>", "<XmlData>").Replace("</DataList>", "</XmlData>"); } if (string.IsNullOrEmpty(xmlData)) { xmlData = "<DataList></DataList>"; } var isDebug = false; if (request.Args != null && request.Args.ContainsKey("IsDebug")) { var debugString = request.Args["IsDebug"].ToString(); if (!bool.TryParse(debugString, out isDebug)) { isDebug = false; } } var serializer = new Dev2JsonSerializer(); IDSFDataObject dataObject = new DsfDataObject(xmlData, dataListId); if (!dataObject.ExecutionID.HasValue) { dataObject.ExecutionID = Guid.NewGuid(); } dataObject.QueryString = queryString; if (isDebug) { dataObject.IsDebug = true; } dataObject.StartTime = DateTime.Now; dataObject.EsbChannel = channel; dataObject.ServiceName = request.ServiceName; var resource = request.ResourceID != Guid.Empty ? _catalog.GetResource(workspaceId, request.ResourceID) : _catalog.GetResource(workspaceId, request.ServiceName); var isManagementResource = false; if (!string.IsNullOrEmpty(request.TestName)) { dataObject.TestName = request.TestName; dataObject.IsServiceTestExecution = true; } if (resource != null) { dataObject.ResourceID = resource.ResourceID; dataObject.SourceResourceID = resource.ResourceID; isManagementResource = _catalog.ManagementServices.ContainsKey(resource.ResourceID); } else { if (request.ResourceID != Guid.Empty) { dataObject.ResourceID = request.ResourceID; } } dataObject.ClientID = Guid.Parse(connectionId); Common.Utilities.OrginalExecutingUser = ExecutingUser; dataObject.ExecutingUser = ExecutingUser; if (!dataObject.Environment.HasErrors()) { if (ExecutingUser == null) { throw new Exception(ErrorResource.NullExecutingUser); } try { var t = new Thread(() => { Thread.CurrentPrincipal = ExecutingUser; if (isManagementResource) { Thread.CurrentPrincipal = Common.Utilities.ServerUser; ExecutingUser = Common.Utilities.ServerUser; dataObject.ExecutingUser = Common.Utilities.ServerUser; } else { IsAuthorizedForServiceTestRun(dataObject); } channel.ExecuteRequest(dataObject, request, workspaceId, out ErrorResultTO errors); }); t.Start(); t.Join(); } catch (Exception e) { Dev2Logger.Error(e.Message, e, GlobalConstants.WarewolfError); } if (request.ExecuteResult.Length > 0) { return(request.ExecuteResult); } return(new StringBuilder()); } var msg = new ExecuteMessage { HasError = true }; msg.SetMessage(string.Join(Environment.NewLine, dataObject.Environment.Errors)); return(serializer.SerializeToBuilder(msg)); }
public bool CopyResource(Guid resourceID, Guid sourceWorkspaceID, Guid targetWorkspaceID, string userRoles = null) { var resource = _resourceCatalog.GetResource(sourceWorkspaceID, resourceID); return(CopyResource(resource, targetWorkspaceID, userRoles)); }