[Test] public void NoMimeTypeSet() { RepositoryFile file = new RepositoryFile(repository, NO_MIME_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); Assert.AreEqual("text/plain", file.MimeType, "RepositoryFile.MimeType does not return \"text/plain\" when svn:mime-type is not set"); Assert.IsTrue(file.IsText, "RepositoryFile.IsText does not return true when svn:mime-type is not set"); }
// The GraphQL Api does not support the recursive reading of files so using the V3 API public async Task <List <RepositoryFile> > ReadFilesAsync(string owner, string name, string gitRef) { var repoFiles = new List <RepositoryFile>(); TreeResponse treeResponse = null; try { treeResponse = await treesClient.GetRecursive(owner, name, gitRef).ConfigureAwait(false); } catch (Octokit.ApiException ex) when(ex.Message == "Git Repository is empty.") { return(repoFiles); } var treeItems = treeResponse.Tree; if (treeItems != null && treeItems.Any()) { var fileTreeItems = treeItems.Where(treeItem => treeItem.Type == TreeType.Blob); foreach (var fileTreeItem in fileTreeItems) { var codeRepoFile = new RepositoryFile(); codeRepoFile.FullPath = fileTreeItem.Path; codeRepoFile.Name = Path.GetFileName(codeRepoFile.FullPath); repoFiles.Add(codeRepoFile); } } return(repoFiles); }
[Test] public void BinaryMimeSet() { RepositoryFile file = new RepositoryFile(repository, BINARY_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); Assert.AreEqual("application/octet-stream", file.MimeType, "RepositoryFile.MimeType does not return the svn:mime-type"); Assert.IsFalse(file.IsText, "RepositoryFile.IsText does not return false when svn:mime-type does NOT start with \"text/\""); }
[Test] public void CSharpMimeSet() { RepositoryFile file = new RepositoryFile(repository, CSHARP_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); Assert.AreEqual("text/cs", file.MimeType, "RepositoryFile.MimeType does not return the svn:mime-type"); Assert.IsTrue(file.IsText, "RepositoryFile.IsText does not return true when svn:mime-type starts with \"text/\""); }
protected void Page_Load(object sender, EventArgs e) { Table dt = new Table(); RepositoryFile rf = new RepositoryFile(); List <ProductsInformation> li = new List <ProductsInformation>(); li = rf.GetDetails(); foreach (ProductsInformation pi in li) { TableRow tr = new TableRow(); TableCell tc = new TableCell(); Image img = new Image(); img.ImageUrl = "~//" + pi.ImageUrl.ToString(); img.Height = 100; img.Width = 100; HyperLink hl = new HyperLink(); hl.NavigateUrl = "ProductsDescription.aspx?id=" + pi.Id; hl.Text = pi.Name.ToString(); tc.Controls.Add(img); tc.Controls.Add(hl); tr.Cells.Add(tc); dt.Rows.Add(tr); PlaceHolder1.Controls.Add(dt); } }
[Test] public void NoProps() { RepositoryFile file = new RepositoryFile(repository, NO_PROPS_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); Assert.IsNull(file.GetProperty("svn:mime-type")); }
[Test] public void ContentsAddedPropertiesUpdated() { RepositoryFile file = new RepositoryFile(repository, "file", RepositoryStatus.Added, RepositoryStatus.Updated); Assert.AreEqual(RepositoryStatus.Added, file.ContentsStatus); Assert.AreEqual(RepositoryStatus.Updated, file.PropertiesStatus); }
[Test] public void ContentsDeleted() { RepositoryFile file = new RepositoryFile(repository, "file", RepositoryStatus.Deleted, RepositoryStatus.Unchanged); Assert.AreEqual(RepositoryStatus.Deleted, file.ContentsStatus); Assert.AreEqual(RepositoryStatus.Unchanged, file.PropertiesStatus); }
[Test] public void ContentsUnchanged() { RepositoryFile file = new RepositoryFile(repository, "file", RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); Assert.AreEqual(RepositoryStatus.Unchanged, file.ContentsStatus); Assert.AreEqual(RepositoryStatus.Unchanged, file.PropertiesStatus); }
/// <summary> /// Tests if image dimension is larger than allowed. /// If yes, the file is marked for skipping /// </summary> private void TestImageDimension(RepositoryFile file, Image bitmap, FileInfo sourceFile) { file.SkipOCR = IsImageTooLarge(bitmap, sourceFile.FullName); if (file.SkipOCR) { Log.Information("Detected oversized image file. Skipping OCR recognition for file: {FullName}", sourceFile.FullName); } }
[Test] public void EolStyleProps() { RepositoryFile file = new RepositoryFile(repository, EOL_STYLE_PROP_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); String[] props = file.GetProperty("svn:eol-style"); Assert.AreEqual(1, props.Length); Assert.AreEqual("native", props[0]); }
private void AssertNoErrors(String eolStyle, String fileName) { using (RepositoryFile file = MockRepository.GetFile(eolStyle, fileName)) { Error[] errors = hook.PreCommit(file); Assert.AreEqual(0, errors.Length); } }
private static void AddError(IList errors, RepositoryFile file, String description) { Error error = new Error(file, description); if (!errors.Contains(error)) { errors.Add(error); } }
[Test] public void Deleted() { using (RepositoryFile file = new RepositoryFile(new MockRepository(null), "File.cs", RepositoryStatus.Deleted, RepositoryStatus.Unchanged)) { Error[] errors = hook.PreCommit(file); Assert.AreEqual(0, errors.Length); } }
[Test] public void LogRegexProps() { RepositoryFile file = new RepositoryFile(repository, LOGREGEGX_PROP_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); String[] props = file.GetProperty("bugtraq:logregex"); Assert.AreEqual(2, props.Length); Assert.AreEqual(@"^.*$", props[0]); Assert.AreEqual(@"\d+", props[1]); }
[Test] public void MimeProps() { RepositoryFile file = new RepositoryFile(repository, MIME_PROP_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); String[] props = file.GetProperty("svn:mime-type"); Assert.AreEqual(1, props.Length); Assert.AreEqual("text/source", props[0]); Assert.AreEqual("text/source", file.MimeType); }
protected void btndelete_Click(object sender, EventArgs e) { RepositoryFile rf = new RepositoryFile(); int id = Convert.ToInt32(txtid.Text); rf.DeleteDetails(id); lbldelete.Text = "Product Deleted Successfully"; }
public List <RepositoryFile> GetFiles(string folderId, List <string> filePatternsToIgnore, out List <RepositoryFile> ignoredFiles) { Log.Information("Getting files for folder {folderId}", folderId); var retVal = new List <RepositoryFile>(); ignoredFiles = new List <RepositoryFile>(); var session = connectionFactory.ConnectToFirstRepository(); var folder = session.GetObject(folderId) as IFolder; if (folder != null) { var items = folder.GetChildren(); foreach (var item in items) { var document = item as IDocument; if (document?.IsLatestVersion != null && document.IsLatestVersion.Value) { var serializedProperties = JsonConvert.SerializeObject(document.Properties); Log.Verbose("Cmis Document {Id} contains the following properties {serializedProperties}", document.Id, serializedProperties); var extensions = document.GetExtensions(ExtensionLevel.Object); var repositoryFile = new RepositoryFile { Id = document.Id, LogicalName = document.Name, SizeInBytes = document.ContentStreamLength ?? 0, MimeType = document.ContentStreamMimeType, Hash = metadataAccess.GetExtendedPropertyValue(extensions, "Fixity Value"), HashAlgorithm = metadataAccess.GetExtendedPropertyValue(extensions, "Fixity Algorithm Ref"), SipOriginalName = metadataAccess.GetExtendedPropertyValue(extensions, "ARELDA:datei/datei/originalName"), SipId = metadataAccess.GetExtendedPropertyValue(extensions, "ARELDA:datei/datei@id") }; // Check if file should be ignored if (!filePatternsToIgnore.Any(fp => Regex.IsMatch(document.Name, fp, RegexOptions.IgnoreCase))) { retVal.Add(repositoryFile); } else { ignoredFiles.Add(repositoryFile); } } else if (document != null) { Log.Warning("Found an older version of a document (id: {Id}). Skipping document!", document.Id); } } } return(retVal); }
//public NewProduct() //{ // con = new SqlConnection("Data Source = ACUPC-0906; Initial Catalog = Assignment22sep; Integrated Security = True"); //} protected void btnadd_Click(object sender, EventArgs e) { RepositoryFile rf = new RepositoryFile(); string name = txtname.Text; string img = txtimg.Text; double price = Convert.ToDouble(txtprice.Text); string desc = txtdesc.Text; int brandid = ddlid.SelectedIndex; rf.InsertDetails(name, img, price, desc, brandid); lbltxt.Text = "inserted successfully"; }
public static void AddFile(string destinationFile) { var fileInfo = new FileInfo(destinationFile); var file = new Model.File(); file.Name = fileInfo.Name; file.Path = destinationFile; var fileId = RepositoryFile.SaveFileInDb(file, GetFileExtensionId(fileInfo)); MetadataService.AddMetadata(fileInfo, fileId); }
//public Productupdate() //{ // con = new SqlConnection("Data Source = ACUPC-0906; Initial Catalog = Assignment22sep; Integrated Security = True"); //} protected void btnupdate_Click(object sender, EventArgs e) { RepositoryFile rf = new RepositoryFile(); int id = Convert.ToInt32(txtid.Text); string name = txtname.Text; string img = txtimage.Text; double price = Convert.ToDouble(txtprice.Text); string desc = txtdesc.Text; int brandid = DropDownList1.SelectedIndex; rf.UpdateDetails(id, name, img, price, desc, brandid); lblupdate.Text = "updated successfully"; }
//SqlConnection con = null; //SqlCommand cmd = null; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RepositoryFile rf = new RepositoryFile(); int pid = Convert.ToInt32(Request.QueryString["Id"]); ProductsInformation pi = rf.GetDetail(pid); txtid.Text = pi.Id.ToString(); txtname.Text = pi.Name.ToString(); txtimage.Text = pi.ImageUrl.ToString(); txtprice.Text = pi.Price.ToString(); txtdesc.Text = pi.Description.ToString(); } }
private void AssertErrors(String eolStyle, int count, params String[] messages) { using (RepositoryFile file = MockRepository.GetFile(eolStyle, "trunk/File.cs")) { Error[] errors = hook.PreCommit(file); Assert.AreEqual(count, errors.Length); for (int i = 0; i < count; i++) { Assert.AreEqual(messages[i], errors[i].Description); Assert.AreEqual(file, errors[i].File); } } }
[Test] public void Contents() { RepositoryFile file = new RepositoryFile(repository, CONTENTS_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); using (Stream stream = file.GetContents()) using (TextReader reader = new StreamReader(stream)) { Assert.AreEqual("This is the first line", reader.ReadLine()); Assert.AreEqual("Second Line...", reader.ReadLine()); Assert.AreEqual("And the third", reader.ReadLine()); Assert.AreEqual("", reader.ReadLine()); Assert.AreEqual("Final line!", reader.ReadLine()); Assert.AreEqual(null, reader.ReadLine()); } }
private void fsWatcher_Changed(object sender, FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Changed && e.Name != ".git") { lock (_changedFiles) { var repoWatcher = (RepositoryFileWatcher)sender; var repoFile = new RepositoryFile(e.FullPath, repoWatcher.Repository, repoWatcher.Project); if (!_changedFiles.Contains(repoFile)) { _changedFiles.Add(repoFile); } } } }
/// <summary> /// Loads the include text. /// </summary> /// <param name="requestFileName">Name of the request file.</param> /// <param name="content">The content.</param> /// <param name="location">The location.</param> /// <returns></returns> public bool LoadIncludeText(string requestFileName, out string content, out string location) { //if the argument is the fully qualified path of an existing file, //then we are done //---------------------------------------------------------------- RepositoryFile rfi = new RepositoryFile(requestFileName); content = rfi.ReadContent(); location = String.Empty; if (content != String.Empty) { location = rfi.LocalPhysicalPath; return(true); } return(false); }
public async Task AddFileAsync(Guid repositoryId, Guid fileId) { var rep = await Context.Repositories.FindAsync(repositoryId); var file = await Context.FileModels.FindAsync(fileId); if (rep != null && file != null) { var repFile = new RepositoryFile { FileId = fileId, RepositoryId = repositoryId }; Context.RepositoryFiles.Add(repFile); await Context.SaveChangesAsync(); } }
private void CreateTestFiles(List <RepositoryFile> files) { for (var i = 0; i < NumberOfFilesPerLevel; i++) { var fileParts = fileTestData[fileIndexCounter].Split(';'); var newFile = new RepositoryFile { Id = fileParts[0], LogicalName = fileParts[1] }; files.Add(newFile); fileIndexCounter++; if (fileIndexCounter == fileTestData.Length) { fileIndexCounter = 0; } } }
/// <summary> /// Creates the custom configuration file. /// </summary> /// <param name="name">The name.</param> /// <param name="configFolderPath">The config folder path.</param> /// <param name="folder">The folder.</param> /// <returns></returns> private string CreateCustomConfigurationFile(string name, string configFolderPath, ProjectItem folder) { IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>(); // Calcule le nom du fichier personnalisable string customFileName = String.Concat(name, ".config"); string customFilePath = Path.Combine(configFolderPath, customFileName); XmlDocument xdoc = new XmlDocument(); // Ajout si n'existe pas if (!File.Exists(customFilePath)) { // On regarde si il n'existe pas un template bool fileCreated = false; string templateFileName = String.Format(_templateFormatName, name); RepositoryFile rf = new RepositoryFile(RepositoryCategory.T4Templates, Path.Combine("ConfigFiles", templateFileName)); try { if (rf.Exists()) { xdoc.Load(rf.LocalPhysicalPath); fileCreated = true; } } catch { } // Si on est pas arrivé à en créer un à partir d'un template, on en crée un vide. if (!fileCreated) { xdoc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8"" ?><configuration/>"); } xdoc.Save(customFilePath); shell.AddFileToFolder(folder, customFilePath); } else { xdoc.Load(customFilePath); } return(customFilePath); }
protected void Page_Load(object sender, EventArgs e) { RepositoryFile rf = new RepositoryFile(); List <ProductsInformation> li = new List <ProductsInformation>(); li = rf.GetDetails(); int pid = Convert.ToInt32(Request.QueryString["id"]); foreach (ProductsInformation obj in li) { if (pid == obj.Id) { ProductName.Text = obj.Name.ToString(); ProductPrice.Text = obj.Price.ToString(); ProductImage.ImageUrl = obj.ImageUrl.ToString(); ProductsDescription.Text = obj.Description.ToString(); } } }
public static void AddFile(string destinationFile) { Util.Log(String.Format("FileTypes Created:14 ")); var fileInfo = new FileInfo(destinationFile); var file = new Model.File(); file.Name = fileInfo.Name; file.Path = destinationFile; //added file.CreateDate = fileInfo.CreationTime; //end Util.Log(String.Format("FileTypes Created:15 ")); var fileId = RepositoryFile.SaveFileInDb(file, GetFileExtensionId(fileInfo)); Util.Log(String.Format("FileTypes Created:16 ")); //MetadataService.AddMetadata(fileInfo, fileId); Util.Log(String.Format("FileTypes Created:17 ")); }
public Error[] PreCommit(RepositoryFile file) { // Check files that have the proper extension // but skip the files that are deleted if (file.ContentsStatus == RepositoryStatus.Deleted || Array.IndexOf(extensions, file.Extension) == -1) { return(Error.NoErrors); } ArrayList errors = new ArrayList(); String[] props = file.GetProperty("svn:eol-style"); if (props == null || props.Length == 0 || props[0].ToLower() != "native") { return(new Error[] { new Error(file, "This file must have svn:eol-style set to native") }); } return(Error.NoErrors); }
[Test] public void GetPropertyWithNullName() { RepositoryFile file = new RepositoryFile(repository, NO_PROPS_PATH, RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); file.GetProperty(null); }
[Test] public void PropertiesDeleted() { RepositoryFile file = new RepositoryFile(repository, "file", RepositoryStatus.Unchanged, RepositoryStatus.Added); }
[Test] public void ContentsDeletedPropertiesUpdated() { RepositoryFile file = new RepositoryFile(repository, "file", RepositoryStatus.Deleted, RepositoryStatus.Updated); Assert.AreEqual(RepositoryStatus.Deleted, file.ContentsStatus); Assert.AreEqual(RepositoryStatus.Updated, file.PropertiesStatus); }
[TestFixtureSetUp] public void FixtureSetUp() { File1 = new RepositoryFile(this, "nowhere", RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); File2 = new RepositoryFile(this, "here", RepositoryStatus.Unchanged, RepositoryStatus.Unchanged); }