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}\'")); }
IExplorerItem SaveResource(Guid resourceId, string newPath, string newResourceName) { var result = _resourceCatalog.GetResourceContents(GlobalConstants.ServerWorkspaceID, resourceId); var xElement = result.ToXElement(); var newResource = new Resource(xElement) { IsUpgraded = true }; var resource = _resourceCatalog.GetResources(GlobalConstants.ServerWorkspaceID) .FirstOrDefault(p => p.ResourceID == resourceId); var actionElement = xElement.Element("Action"); var xamlElement = actionElement?.Element("XamlDefinition"); xElement.SetAttributeValue("Name", newResourceName); var resourceID = Guid.NewGuid(); newResource.ResourceName = newResourceName; newResource.ResourceID = resourceID; xElement.SetElementValue("DisplayName", newResourceName); if (xamlElement != null) { var xamlContent = xamlElement.Value; xamlElement.Value = xamlContent.Replace("x:Class=\"" + resource?.ResourceName + "\"", "x:Class=\"" + newResourceName + "\"") .Replace("Flowchart DisplayName=\"" + resource?.ResourceName + "\"", "Flowchart DisplayName=\"" + newResourceName + "\""); } var fixedResource = xElement.ToStringBuilder(); _resourceCatalog.SaveResource(GlobalConstants.ServerWorkspaceID, newResource, fixedResource, newPath); SaveTests(resourceId, resourceID); return(ServerExplorerRepository.Instance.UpdateItem(newResource)); }
public static void SetTestResourceIds(this IDSFDataObject dataObject, IResourceCatalog catalog, WebRequestTO webRequest, string serviceName) { if (IsRunAllTestsRequest(dataObject.ReturnType, serviceName)) { var pathOfAllResources = webRequest.GetPathForAllResources(); dataObject.ResourceID = Guid.Empty; if (string.IsNullOrEmpty(pathOfAllResources)) { var resources = catalog.GetResources(GlobalConstants.ServerWorkspaceID); dataObject.TestsResourceIds = resources.Select(p => p.ResourceID).ToList(); } else { var resources = catalog.GetResources(GlobalConstants.ServerWorkspaceID); var resourcesToRunTestsFor = resources?.Where(a => a.GetResourcePath(GlobalConstants.ServerWorkspaceID) .StartsWith(pathOfAllResources, StringComparison.InvariantCultureIgnoreCase)); dataObject.TestsResourceIds = resourcesToRunTestsFor?.Select(p => p.ResourceID).ToList(); } } }
public ResourceCatalogResult DeleteResource(Guid workspaceID, string resourceName, string type, bool deleteVersions) { var @lock = Common.GetWorkspaceLock(workspaceID); lock (@lock) { if (resourceName == "*") { var noWildcardsAllowedhResult = ResourceCatalogResultBuilder.CreateNoWildcardsAllowedhResult("<Result>Delete resources does not accept wildcards.</Result>."); return(noWildcardsAllowedhResult); } if (string.IsNullOrEmpty(resourceName) || string.IsNullOrEmpty(type)) { throw new InvalidDataContractException(ErrorResource.ResourceNameAndTypeMissing); } var workspaceResources = _resourceCatalog.GetResources(workspaceID); var resources = _resourceCatalog.GetResourcesBasedOnType(type, workspaceResources, r => string.Equals(r.ResourceName, resourceName, StringComparison.InvariantCultureIgnoreCase)); var commands = new Dictionary <int, ResourceCatalogResult>() { { 0, ResourceCatalogResultBuilder.CreateNoMatchResult($"<Result>{type} '{resourceName}' was not found.</Result>") }, { 1, DeleteImpl(workspaceID, resources, workspaceResources, deleteVersions) }, }; if (commands.ContainsKey(resources.Count)) { var resourceCatalogResult = commands[resources.Count]; return(resourceCatalogResult); } return(ResourceCatalogResultBuilder.CreateDuplicateMatchResult($"<Result>Multiple matches found for {type} '{resourceName}'.</Result>")); } }
private static (AllCoverageReports AllCoverageReports, TestResults AllTestResults) RunListOfCoverage(ICoverageDataObject coverageData, ITestCoverageCatalog testCoverageCatalog, ITestCatalog testCatalog, Guid workspaceGuid, IResourceCatalog catalog) { var allTestResults = new TestResults(); var allCoverageReports = new AllCoverageReports { StartTime = DateTime.Now }; var resources = catalog.GetResources <IWarewolfWorkflow>(workspaceGuid); var selectedResources = resources.Where(resource => coverageData.CoverageReportResourceIds.Contains(resource.ResourceID)).ToArray(); var testResultsTemp = new List <WorkflowTestResults>(); var coverageReportsTemp = new List <WorkflowCoverageReports>(); foreach (var coverageResourceId in coverageData.CoverageReportResourceIds) { var res = selectedResources.FirstOrDefault(o => o.ResourceID == coverageResourceId); if (res is null) { continue; } var workflowTestResults = new WorkflowTestResults(); testCatalog.Fetch(coverageResourceId) ?.ForEach(o => workflowTestResults.Add(o)); testResultsTemp.Add(workflowTestResults); var coverageReports = new WorkflowCoverageReports(res); testCoverageCatalog.Fetch(coverageResourceId) ?.ForEach(o => coverageReports.Add(o)); coverageReportsTemp.Add(coverageReports); } testResultsTemp.ForEach(o => allTestResults.Add(o)); coverageReportsTemp.ForEach(o => allCoverageReports.Add(o)); allTestResults.EndTime = DateTime.Now; allCoverageReports.EndTime = DateTime.Now; return(allCoverageReports, allTestResults); }
void PerformSaveResult(out ResourceCatalogResult saveResult, Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath, string reason = "") { var fileManager = new TxFileManager(); using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) { try { var resources = _resourceCatalog.GetResources(workspaceID); var conflicting = resources.FirstOrDefault(r => resource.ResourceID != r.ResourceID && r.GetResourcePath(workspaceID) != null && r.GetResourcePath(workspaceID).Equals(savedPath + "\\" + resource.ResourceName, StringComparison.InvariantCultureIgnoreCase) && r.ResourceName.Equals(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase)); if (conflicting != null && !conflicting.IsNewResource || conflicting != null && !overwriteExisting) { saveResult = ResourceCatalogResultBuilder.CreateDuplicateMatchResult(string.Format(ErrorResource.TypeConflict, conflicting.ResourceType)); return; } contents = GetExistingResource(resource, contents, reason, resources); var directoryName = SetResourceFilePath(workspaceID, resource, ref savedPath); var xml = SaveToDisk(resource, contents, directoryName, fileManager); var updated = AddToCatalog(resource, resources, fileManager, xml); _resourceCatalog.AddToActivityCache(resource); Dev2Logger.Debug($"Removing Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); _resourceCatalog.RemoveFromResourceActivityCache(workspaceID, resource); Dev2Logger.Debug($"Removed Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); Dev2Logger.Debug($"Adding Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); _resourceCatalog.Parse(workspaceID, resource); Dev2Logger.Debug($"Added Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); tx.Complete(); saveResult = ResourceCatalogResultBuilder.CreateSuccessResult($"{(updated ? "Updated" : "Added")} {resource.ResourceType} '{resource.ResourceName}'"); } catch (Exception e) { Dev2Logger.Warn($"Error saving {resource.ResourceName}. " + e.Message, GlobalConstants.WarewolfWarn); Transaction.Current.Rollback(); //the process should not be terminated because of just one failure saveResult = ResourceCatalogResultBuilder.CreateFailResult(string.Format(ErrorResource.ErrorDuringSaveCallback, resource.ResourceID) + "' message " + e.Message); } } }
public List <ISearchResult> GetSearchResults(ISearch searchParameters) { var searchResults = new List <ISearchResult>(); if (searchParameters.SearchOptions.IsVariableSelected) { var allResources = _resourceCatalog.GetResources(GlobalConstants.ServerWorkspaceID).Where(res => res.ResourceType != "ReservedService"); foreach (var resource in allResources) { if (resource.DataList != null && resource.DataList.Length > 0) { GetScalarResults(searchParameters, searchResults, resource); GetRecordsetResults(searchParameters, searchResults, resource); GetObjectResults(searchParameters, searchResults, resource); } } } return(searchResults); }
public List <ISearchResult> GetSearchResults(ISearch searchParameters) { var searchResults = new List <ISearchResult>(); if (searchParameters.SearchOptions.IsWorkflowNameSelected) { var allResources = _resourceCatalog.GetResources(GlobalConstants.ServerWorkspaceID).Where(res => res.ResourceType != "ReservedService"); foreach (var resource in allResources) { if (SearchUtils.FilterText(resource.ResourceName, searchParameters)) { var searchItemType = resource.IsSource ? SearchItemType.SourceName : SearchItemType.WorkflowName; var searchResult = new SearchResult(resource.ResourceID, resource.ResourceName, resource.GetResourcePath(GlobalConstants.ServerWorkspaceID), searchItemType, resource.ResourceName); searchResults.Add(searchResult); } } } return(searchResults); }
private static AllCoverageReports RunListOfCoverage(ICoverageDataObject coverageData, ITestCoverageCatalog testCoverageCatalog, Guid workspaceGuid, IResourceCatalog catalog) { var allCoverageReports = new AllCoverageReports { StartTime = DateTime.Now }; var resources = catalog.GetResources <IWarewolfWorkflow>(workspaceGuid); var selectedResources = resources.Where(resource => coverageData.CoverageReportResourceIds.Contains(resource.ResourceID)).ToArray(); testCoverageCatalog.ReloadAllReports(); var coverageReportsTemp = new List <WorkflowCoverageReports>(); foreach (var coverageResourceId in coverageData.CoverageReportResourceIds) { var res = selectedResources.FirstOrDefault(o => o.ResourceID == coverageResourceId); if (res is null) { continue; } var coverageReports = new WorkflowCoverageReports(res); var allWorkflowReports = testCoverageCatalog.Fetch(coverageResourceId); if (allWorkflowReports?.Count > 0) { foreach (var workflowReport in allWorkflowReports) { coverageReports.Add(workflowReport); } coverageReportsTemp.Add(coverageReports); } } foreach (var item in coverageReportsTemp) { allCoverageReports.Add(item); } allCoverageReports.EndTime = DateTime.Now; return(allCoverageReports); }
void PerformCleanUp(IDirectory directory) { var resources = _catalogue.GetResources(GlobalConstants.ServerWorkspaceID).Where(p => !p.ResourceType.Equals("ReservedService")); foreach (var item in resources) { if (item?.VersionInfo == null) { continue; } var versionPath = item.GetResourcePath(GlobalConstants.ServerWorkspaceID); var path = GetVersionFolderFromResource(versionPath); var files = _directory.GetFiles(path).Where(a => a.Contains(item.VersionInfo.VersionId.ToString())); var folderName = _filePath.Combine(_envVersionFolder, item.ResourceID.ToString()); foreach (var pathForVersion in files) { directory.CreateIfNotExists(folderName); var parts = _filePath.GetFileName(pathForVersion).Split('_'); var name = string.Format("{0}_{1}_{2}", parts[1], parts[2], parts[3]); var destination = _filePath.Combine(folderName, name); if (!_file.Exists(destination)) { _file.Move(pathForVersion, destination); } } } try { const string partialName = "VersionControl"; var dirs = directory.GetDirectories(_resourcePath, "*" + partialName + "*"); foreach (var item in dirs) { directory.Delete(item, true); } } catch (Exception e) { Dev2Logger.Error(e, "Warewolf Error"); } }
private IEnumerable <IWarewolfResource> GetResources(string path) { return(_resourceCatalog.GetResources(_serverWorkspaceId) .Where(resource => resource.IsInPath(_serverWorkspaceId, path))); }
static TestResults RunListOfTests(IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog, ITestCoverageCatalog testCoverageCatalog, IServiceTestExecutorWrapper serviceTestExecutorWrapper) { var result = new TestResults(); var selectedResources = catalog.GetResources(workspaceGuid) ?.Where(resource => dataObject.TestsResourceIds.Contains(resource.ResourceID)).ToArray(); if (selectedResources != null) { var workflowTaskList = new List <Task <WorkflowTestResults> >(); foreach (var testsResourceId in dataObject.TestsResourceIds) { var workflowTask = Task <WorkflowTestResults> .Factory.StartNew(() => { var workflowTestTaskList = new List <Task <IServiceTestModelTO> >(); var res = selectedResources.FirstOrDefault(o => o.ResourceID == testsResourceId); if (res is null) { return(null); } else { var resourcePath = res.GetResourcePath(workspaceGuid).Replace("\\", "/"); var workflowTestResults = new WorkflowTestResults(res); var allTests = testCatalog.Fetch(testsResourceId); foreach (var(test, dataObjectClone) in from test in allTests let dataObjectClone = dataObject.Clone() select(test, dataObjectClone)) { dataObjectClone.Environment = new ExecutionEnvironment(); dataObjectClone.TestName = test.TestName; dataObjectClone.ServiceName = res.ResourceName; dataObjectClone.ResourceID = res.ResourceID; var lastTask = serviceTestExecutorWrapper.ExecuteTestAsync(resourcePath, userPrinciple, workspaceGuid, serializer, dataObjectClone); workflowTestTaskList.Add(lastTask); var report = testCoverageCatalog.FetchReport(res.ResourceID, test.TestName); var lastTestCoverageRun = report?.LastRunDate; if (report is null || test.LastRunDate > lastTestCoverageRun) { testCoverageCatalog.GenerateSingleTestCoverage(res.ResourceID, lastTask.Result); } } Task.WaitAll(workflowTestTaskList.Cast <Task>().ToArray()); foreach (var task in workflowTestTaskList) { workflowTestResults.Add(task.Result); } var testResults = workflowTestResults.Results; if (testResults.Count > 0) { testCoverageCatalog.GenerateAllTestsCoverage(res.ResourceName, res.ResourceID, testResults); } return(workflowTestResults); } }); if (workflowTask != null) { workflowTaskList.Add(workflowTask); } } Task.WaitAll(workflowTaskList.Cast <Task>().ToArray()); foreach (var task in workflowTaskList) { if (task.Result != null) { result.Add(task.Result); } } } result.EndTime = DateTime.Now; return(result); }
private void PerformSaveResult(out ResourceCatalogResult saveResult, Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath) { var fileManager = new TxFileManager(); using (TransactionScope tx = new TransactionScope()) { try { var resources = _resourceCatalog.GetResources(workspaceID); var conflicting = resources.FirstOrDefault(r => resource.ResourceID != r.ResourceID && r.GetResourcePath(workspaceID) != null && r.GetResourcePath(workspaceID).Equals(savedPath + "\\" + resource.ResourceName, StringComparison.InvariantCultureIgnoreCase) && r.ResourceName.Equals(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase)); if (conflicting != null && !conflicting.IsNewResource || conflicting != null && !overwriteExisting) { saveResult = ResourceCatalogResultBuilder.CreateDuplicateMatchResult(string.Format(ErrorResource.TypeConflict, conflicting.ResourceType)); return; } var res = resources.FirstOrDefault(p => p.ResourceID == resource.ResourceID); if (res != null) //Found Existing resource { if (res.ResourceName != resource.ResourceName) // Renamed while open { var resourceXml = contents.ToXElement(); resourceXml.SetAttributeValue("Name", res.ResourceName); resourceXml.SetElementValue("DisplayName", res.ResourceName); var actionElement = resourceXml.Element("Action"); var xamlElement = actionElement?.Element("XamlDefinition"); if (xamlElement != null) { var xamlContent = xamlElement.Value; xamlElement.Value = xamlContent. Replace("x:Class=\"" + resource.ResourceName + "\"", "x:Class=\"" + res.ResourceName + "\"") .Replace("Flowchart DisplayName=\"" + resource.ResourceName + "\"", "Flowchart DisplayName=\"" + res.ResourceName + "\""); } resource.ResourceName = res.ResourceName; contents = resourceXml.ToStringBuilder(); } } var directoryName = SetResourceFilePath(workspaceID, resource, ref savedPath); #region Save to disk var xml = SaveToDisk(resource, contents, directoryName, fileManager); #endregion #region Add to catalog var updated = AddToCatalog(resource, resources, fileManager, xml); #endregion Dev2Logger.Debug($"Removing Execution Plan for {resource.ResourceID} for workspace {workspaceID}"); ((ResourceCatalog)_resourceCatalog).RemoveFromResourceActivityCache(workspaceID, resource); Dev2Logger.Debug($"Removed Execution Plan for {resource.ResourceID} for workspace {workspaceID}"); Dev2Logger.Debug($"Adding Execution Plan for {resource.ResourceID} for workspace {workspaceID}"); ((ResourceCatalog)_resourceCatalog).Parse(workspaceID, resource.ResourceID); Dev2Logger.Debug($"Added Execution Plan for {resource.ResourceID} for workspace {workspaceID}"); tx.Complete(); saveResult = ResourceCatalogResultBuilder.CreateSuccessResult($"{(updated ? "Updated" : "Added")} {resource.ResourceType} '{resource.ResourceName}'"); } catch (Exception) { Transaction.Current.Rollback(); throw; } } }