string GetVersionFolderFromResource(string resourcePath)
        {
            var path = _filePath.Combine(_rootPath, GetDirectoryFromResource(resourcePath), GlobalConstants.VersionFolder);

            _directory.CreateIfNotExists(path);

            return(path);
        }
示例#2
0
 public TestCatalog()
 {
     _directoryWrapper = new DirectoryWrapper();
     _fileWrapper      = new FileWrapper();
     _directoryWrapper.CreateIfNotExists(EnvironmentVariables.TestPath);
     Tests       = new ConcurrentDictionary <Guid, List <IServiceTestModelTO> >();
     _serializer = new Dev2JsonSerializer();
 }
        public void DsfFolderRead_Execute_ExpectRecords2()
        {
            //------------Setup for test--------------------------
            dirHelper = new DirectoryWrapper();
            var id = Guid.NewGuid().ToString();

            _inputPath = EnvironmentVariables.ResourcePath + "\\" + id.Substring(0, 8);
            dirHelper.CreateIfNotExists(_inputPath);
            dirHelper.CreateIfNotExists(_inputPath + "\\1");
            dirHelper.CreateIfNotExists(_inputPath + "\\2");
            var act = new DsfFolderReadActivity {
                InputPath = _inputPath, Result = "[[RecordSet().File]]"
            };
            //------------Execute Test---------------------------
            var results = act.Execute(DataObject, 0);

            //------------Assert Results-------------------------
            Assert.IsTrue(2 <= DataObject.Environment.GetLength("RecordSet"));
        }
示例#4
0
 public TestCoverageCatalog(IResourceCatalog resourceCatalog)
 {
     _directoryWrapper = new DirectoryWrapper();
     _fileWrapper      = new FileWrapper();
     _filePathWapper   = new FilePathWrapper();
     _directoryWrapper.CreateIfNotExists(EnvironmentVariables.TestCoveragePath);
     _serializer          = new Dev2JsonSerializer();
     _streamWriterFactory = new StreamWriterFactory();
     _streamReaderFactory = new StreamReaderFactory();
     _serviceAllTestsCoverageModelToFactory = CustomContainer.Get <IServiceTestCoverageModelToFactory>() ?? new ServiceTestCoverageModelToFactory(resourceCatalog);
 }
示例#5
0
        public TriggersCatalog(IDirectory directoryWrapper, IFile fileWrapper, string queueTriggersPath, ISerializer serializer, IFileSystemWatcher watcherWrapper)
        {
            _directoryWrapper  = directoryWrapper;
            _fileWrapper       = fileWrapper;
            _queueTriggersPath = queueTriggersPath;
            _directoryWrapper.CreateIfNotExists(_queueTriggersPath);
            Queues          = new List <ITriggerQueue>();
            _serializer     = serializer;
            _watcherWrapper = watcherWrapper;

            MonitorTriggerFolder();
        }
示例#6
0
        private bool CopyMissingResources(string[] programDataIds, List <ResourceBuilderTO> programFilesBuilders, IDirectory directory, IFile fileWrapper)
        {
            var foundMissingResources = false;

            // NOTE: we have not filtered for files that are not
            programFilesBuilders.ForEach(programFileItem =>
            {
                XElement xml = null;
                try
                {
                    xml = XElement.Load(programFileItem._fileStream);
                }
                catch (Exception e)
                {
                    Dev2Logger.Error("Resource [ " + programFileItem._filePath + " ] caused " + e.Message, GlobalConstants.WarewolfError);
                }

                var id = xml?.Attribute("ID")?.Value ?? null;
                if (id != null && programDataIds.Any(programDataId => programDataId == id))
                { // resource already installed
                    return;
                }
                if (id is null) // invalid resource
                {
                    return;
                }

                // Only get here if the bite file does not exist in ProgramData directory
                foundMissingResources = true;
                programFileItem._fileStream.Close();
                var currentPath = programFileItem._filePath;

                var appResourcesPath       = Path.Combine(EnvironmentVariables.ApplicationPath, "Resources");
                var currentSubPath         = currentPath.Replace(appResourcesPath, "").Replace(".xml", ".bite");
                var MyNewInstalledFilePath = EnvironmentVariables.ResourcePath + $"{currentSubPath}";
                directory.CreateIfNotExists(fileWrapper.DirectoryName(MyNewInstalledFilePath));

                try
                {
                    fileWrapper.Copy(programFileItem._filePath, MyNewInstalledFilePath, false);
                }
                catch (Exception e)
                {
                    Dev2Logger.Warn("Failed to copy Examples resource to ProgramData, " + e.Message, GlobalConstants.WarewolfWarn);
                }
            });

            return(foundMissingResources);
        }
示例#7
0
        public void MoveVersions(Guid resourceId, string newPath)
        {
            var resource = _catalogue.GetResource(Guid.Empty, resourceId);

            if (resource == null || resource.VersionInfo == null)
            {
                return;
            }
            var path = GetVersionFolderFromResource(resource);

            // ReSharper disable ImplicitlyCapturedClosure
            var files       = _directory.GetFiles(path).Where(a => a.Contains(resource.VersionInfo.VersionId.ToString()));
            var versionPath = Path.Combine(ServerExplorerRepository.DirectoryStructureFromPath(newPath), "VersionControl");

            if (!_directory.Exists(versionPath))
            {
                _directory.CreateIfNotExists(versionPath);
            }
            // ReSharper restore ImplicitlyCapturedClosure
            IEnumerable <string> enumerable = files as IList <string> ?? files.ToList();

            // ReSharper disable once AssignNullToNotNullAttribute
            enumerable.ForEach(a => _file.Move(a, Path.Combine(versionPath, Path.GetFileName(a))));
        }
示例#8
0
        private void SaveCoverageReport(Guid resourceId, IServiceTestCoverageModelTo serviceTestCoverageModelTo)
        {
            var dirPath = GetTestCoveragePathForResourceId(resourceId);

            _directoryWrapper.CreateIfNotExists(dirPath);

            if (!string.Equals(serviceTestCoverageModelTo.OldReportName, serviceTestCoverageModelTo.ReportName, StringComparison.InvariantCultureIgnoreCase))
            {
                var oldFilePath = _filePathWapper.Combine(dirPath, $"{serviceTestCoverageModelTo.OldReportName}.coverage");
                _fileWrapper.Delete(oldFilePath);
            }
            var filePath = _filePathWapper.Combine(dirPath, $"{serviceTestCoverageModelTo.ReportName}.coverage");
            var sw       = _streamWriterFactory.New(filePath, false);

            _serializer.Serialize(sw, serviceTestCoverageModelTo);
        }
示例#9
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);
        }
示例#10
0
        public void DsfFolderRead_Execute_Expecting_No_Out_Puts_Has_1_Empty_Record()
        {
            //------------Setup for test--------------------------
            dirHelper = new DirectoryWrapper();
            var id = Guid.NewGuid().ToString();

            _inputPath = EnvironmentVariables.ResourcePath + "\\" + id.Substring(0, 8);
            dirHelper.CreateIfNotExists(_inputPath);
            var act = new DsfFolderRead {
                InputPath = _inputPath, Result = "[[RecordSet().File]]"
            };
            //------------Execute Test---------------------------
            var results = act.Execute(DataObject, 0);

            //------------Assert Results-------------------------
            Assert.IsTrue(DataObject.Environment.HasRecordSet("[[RecordSet()]]"));
            Assert.AreEqual(1, DataObject.Environment.GetLength("RecordSet"));
        }
        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");
            }
        }
示例#12
0
 /// <summary>
 /// Crea un directorio si no existe
 /// </summary>
 /// <returns></returns>
 public DirectoryInformation CreateIfNotExists()
 {
     return(_directory.CreateIfNotExists().Result);
 }
示例#13
0
 void CreateDir()
 {
     _dir.CreateIfNotExists(_debugOutputPath);
 }