Exemplo n.º 1
0
 private void DeleteIfExists(string url)
 {
     if (FileWrapper.Exists(url))
     {
         FileWrapper.Delete(url);
     }
 }
Exemplo n.º 2
0
        void SaveTestToDisk(Guid resourceId, IServiceTestModelTO serviceTestModelTo)
        {
            var dirPath = GetTestPathForResourceId(resourceId);

            _directoryWrapper.CreateIfNotExists(dirPath);
            if (!string.Equals(serviceTestModelTo.OldTestName, serviceTestModelTo.TestName, StringComparison.InvariantCultureIgnoreCase))
            {
                var oldFilePath = Path.Combine(dirPath, $"{serviceTestModelTo.OldTestName}.test");
                _fileWrapper.Delete(oldFilePath);
            }
            var filePath = Path.Combine(dirPath, $"{serviceTestModelTo.TestName}.test");

            serviceTestModelTo.Password = DpapiWrapper.EncryptIfDecrypted(serviceTestModelTo.Password);
            var sw = new StreamWriter(filePath, false);

            _serializer.Serialize(sw, serviceTestModelTo);
        }
Exemplo n.º 3
0
        public void DeleteCoverageReport(Guid resourceID, string reportName)
        {
            var dirPath      = GetTestCoveragePathForResourceId(resourceID);
            var testFilePath = Path.Combine(dirPath, $"{reportName}.coverage");

            if (_fileWrapper.Exists(testFilePath))
            {
                _fileWrapper.Delete(testFilePath);
                if (TestCoverageReports.TryGetValue(resourceID, out List <IServiceTestCoverageModelTo> coverageReports))
                {
                    var foundReportToDelete = coverageReports.FirstOrDefault(to => to.ReportName.Equals(reportName, StringComparison.InvariantCultureIgnoreCase));
                    if (foundReportToDelete != null)
                    {
                        Dev2Logger.Debug("Removing Report: " + reportName + Environment.NewLine + Environment.StackTrace, GlobalConstants.WarewolfDebug);
                        coverageReports.Remove(foundReportToDelete);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private ResourceCatalogResult DeleteImpl(Guid workspaceID, IEnumerable <IResource> resources, List <IResource> workspaceResources, bool deleteVersions = true)
        {
            IResource resource = resources.FirstOrDefault();

            if (workspaceID == Guid.Empty && deleteVersions)
            {
                if (resource != null)
                {
                    var explorerItems = _serverVersionRepository.GetVersions(resource.ResourceID);
                    explorerItems?.ForEach(a => _serverVersionRepository.DeleteVersion(resource.ResourceID, a.VersionInfo.VersionNumber, resource.GetResourcePath(workspaceID)));
                }
            }

            workspaceResources.Remove(resource);
            if (resource != null && _dev2FileWrapper.Exists(resource.FilePath))
            {
                _dev2FileWrapper.Delete(resource.FilePath);
            }
            if (resource != null)
            {
                var messages = new List <ICompileMessageTO>
                {
                    new CompileMessageTO
                    {
                        ErrorType      = ErrorType.Critical,
                        MessageID      = Guid.NewGuid(),
                        MessagePayload = "The resource has been deleted",
                        MessageType    = CompileMessageType.ResourceDeleted,
                        ServiceID      = resource.ResourceID
                    }
                };
                UpdateDependantResourceWithCompileMessages(workspaceID, resource, messages);
            }
            if (workspaceID == GlobalConstants.ServerWorkspaceID)
            {
                if (resource != null)
                {
                    ServiceActionRepo.Instance.RemoveFromCache(resource.ResourceID);
                    ServerAuthorizationService.Instance.Remove(resource.ResourceID);
                }
            }

            ((ResourceCatalog)_resourceCatalog).RemoveFromResourceActivityCache(workspaceID, resource);
            return(ResourceCatalogResultBuilder.CreateSuccessResult("Success"));
        }
Exemplo n.º 5
0
        ResourceCatalogResult UpdateResourceName(Guid workspaceID, IResource resource, string newName, string resourcePath)
        {
            //rename where used
            RenameWhereUsed(_resourceCatalog.GetDependentsAsResourceForTrees(workspaceID, resource.ResourceID), workspaceID, resourcePath, newName);

            //rename resource
            var resourceContents = _resourceCatalog.GetResourceContents(workspaceID, resource.ResourceID);

            var resourceElement = resourceContents.ToXElement();
            //xml name attibute
            var    nameAttrib = resourceElement.Attribute("Name");
            string oldName    = null;

            if (nameAttrib == null)
            {
                resourceElement.Add(new XAttribute("Name", newName));
            }
            else
            {
                oldName = nameAttrib.Value;
                nameAttrib.SetValue(newName);
            }
            //xaml
            var actionElement = resourceElement.Element("Action");
            var xaml          = actionElement?.Element("XamlDefinition");

            xaml?.SetValue(xaml.Value
                           .Replace("x:Class=\"" + oldName, "x:Class=\"" + newName)
                           .Replace("ToolboxFriendlyName=\"" + oldName, "ToolboxFriendlyName=\"" + newName)
                           .Replace("DisplayName=\"" + oldName, "DisplayName=\"" + newName));
            //xml display name element
            var displayNameElement = resourceElement.Element("DisplayName");

            displayNameElement?.SetValue(newName);

            //delete old resource in local workspace without updating dependants with compile messages
            lock (Common.GetFileLock(resource.FilePath))
            {
                if (_dev2FileWrapper.Exists(resource.FilePath))
                {
                    lock (Common.GetFileLock(resource.FilePath))
                    {
                        _dev2FileWrapper.Delete(resource.FilePath);
                    }
                }
            }

            var resPath = resource.GetResourcePath(workspaceID);

            var savePath          = resPath;
            var resourceNameIndex = resPath.LastIndexOf(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase);

            if (resourceNameIndex >= 0)
            {
                savePath = resPath.Substring(0, resourceNameIndex);
            }
            resource.ResourceName = newName;
            var contents = resourceElement.ToStringBuilder();

            return(((ResourceCatalog)_resourceCatalog).SaveImpl(workspaceID, resource, contents, savePath));
        }