Here are the examples of the csharp api System.IO.Path.GetTempFileName() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1256 Examples
19
Source : TemplateEngin.cs
with MIT License
from 2881099
with MIT License
from 2881099
public static byte[] ReadFile(string path) {
if (File.Exists(path)) {
string destFileName = Path.GetTempFileName();
File.Copy(path, destFileName, true);
int read = 0;
byte[] data = new byte[1024];
using (MemoryStream ms = new MemoryStream()) {
using (FileStream fs = new FileStream(destFileName, FileMode.OpenOrCreate, FileAccess.Read)) {
do {
read = fs.Read(data, 0, data.Length);
if (read <= 0) break;
ms.Write(data, 0, read);
} while (true);
}
File.Delete(destFileName);
data = ms.ToArray();
}
return data;
}
return new byte[] { };
}
19
Source : DebuggingEditor.cs
with MIT License
from 71
with MIT License
from 71
protected override void Initialize(CSharpCompilation oldCompilation, CancellationToken _)
{
OptimizationLevel compilationConfiguration = oldCompilation.Options.OptimizationLevel;
DebugCometaryAttribute attribute = Attribute;
if (compilationConfiguration == OptimizationLevel.Debug && !attribute.RunInDebug)
return;
if (compilationConfiguration == OptimizationLevel.Release && !attribute.RunInRelease)
return;
string typeName = attribute.MainClreplacedName ?? DebugCometaryAttribute.DefaultMainClreplacedName;
if (replacedembly.GetEntryreplacedembly().GetType(typeName) != null)
return;
CSharpCompilation EditCompilation(CSharpCompilation compilation, CancellationToken cancellationToken)
{
CSharpCompilationOptions options = compilation.Options;
CSharpCompilationOptions newOptions = options
.WithOutputKind(OutputKind.ConsoleApplication)
.WithMainTypeName(typeName);
// - Make the compilation an application, allowing its execution.
// - Redirect the entry point to the automatically generated clreplaced.
compilation = compilation.WithOptions(newOptions);
// Create the entry point:
string errorFile = Path.GetTempFileName();
CSharpSyntaxTree generatedSyntaxTree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(GetSourceText(attribute.DisplayEndOfCompilationMessage, errorFile), cancellationToken: cancellationToken);
CompilationUnitSyntax generatedRoot = generatedSyntaxTree.GetCompilationUnitRoot(cancellationToken);
ClreplacedDeclarationSyntax clreplacedSyntax = (ClreplacedDeclarationSyntax)generatedRoot.Members.Last();
ClreplacedDeclarationSyntax originalClreplacedSyntax = clreplacedSyntax;
// Edit the generated syntax's name, if needed.
if (typeName != DebugCometaryAttribute.DefaultMainClreplacedName)
{
clreplacedSyntax = clreplacedSyntax.WithIdentifier(F.Identifier(typeName));
}
// Change the filename and arguments.
SyntaxList<MemberDeclarationSyntax> members = clreplacedSyntax.Members;
FieldDeclarationSyntax WithValue(FieldDeclarationSyntax node, string value)
{
VariableDeclaratorSyntax variableSyntax = node.Declaration.Variables[0];
LiteralExpressionSyntax valueSyntax = F.LiteralExpression(
SyntaxKind.StringLiteralExpression,
F.Literal(value)
);
return node.WithDeclaration(
node.Declaration.WithVariables(node.Declaration.Variables.Replace(
variableSyntax, variableSyntax.WithInitializer(F.EqualsValueClause(valueSyntax))
))
);
}
FieldDeclarationSyntax WithBoolean(FieldDeclarationSyntax node, bool value)
{
VariableDeclaratorSyntax variableSyntax = node.Declaration.Variables[0];
LiteralExpressionSyntax valueSyntax = F.LiteralExpression(value ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression);
return node.WithDeclaration(
node.Declaration.WithVariables(node.Declaration.Variables.Replace(
variableSyntax, variableSyntax.WithInitializer(F.EqualsValueClause(valueSyntax))
))
);
}
for (int i = 0; i < members.Count; i++)
{
FieldDeclarationSyntax field = members[i] as FieldDeclarationSyntax;
if (field == null)
continue;
string fieldName = field.Declaration.Variables[0].Identifier.Text;
switch (fieldName)
{
case "References":
field = WithValue(field, string.Join(";", compilation.References.OfType<PortableExecutableReference>().Select(x => x.FilePath)));
break;
case "Files":
field = WithValue(field, string.Join(";", compilation.SyntaxTrees.Select(x => x.FilePath)));
break;
case "replacedemblyName":
field = WithValue(field, compilation.replacedemblyName);
break;
case "ErrorFile":
field = WithValue(field, errorFile);
break;
case "Written":
field = WithBoolean(field, OutputAllTreesAttribute.Instance != null);
break;
case "BreakAtEnd":
field = WithBoolean(field, attribute.DisplayEndOfCompilationMessage);
break;
case "BreakAtStart":
field = WithBoolean(field, attribute.BreakDuringStart);
break;
default:
continue;
}
members = members.Replace(members[i], field);
}
// Return the modified compilation.
return compilation.AddSyntaxTrees(
generatedSyntaxTree
.WithCometaryOptions(this)
.WithRoot(
generatedRoot.WithMembers(generatedRoot.Members.Replace(originalClreplacedSyntax, clreplacedSyntax.WithMembers(members))
)
)
);
}
CompilationPipeline += EditCompilation;
}
19
Source : PlantumlResource.cs
with MIT License
from 8T4
with MIT License
from 8T4
public static string Load()
{
try
{
var fileName = Path.GetTempFileName();
using var resource = ResourceMethods.GetPlantumlResource();
using var file = new FileStream(fileName, FileMode.Create, FileAccess.Write);
resource.CopyTo(file);
return fileName;
}
catch (Exception e)
{
throw new PlantumlException($"{nameof(PlantumlException)}: Could not load plantuml engine.", e);
}
}
19
Source : Shapefile.cs
with Microsoft Public License
from abfo
with Microsoft Public License
from abfo
private void OpenDb()
{
// The drivers for DBF files throw an exception if the filename
// is longer than 8 characters - in this case create a temp file
// for the DB
string safeDbasePath = _shapefileDbasePath;
if (Path.GetFileNameWithoutExtension(safeDbasePath).Length > 8)
{
// create/delete temp file (we just want a safe path)
string initialTempFile = Path.GetTempFileName();
try
{
File.Delete(initialTempFile);
}
catch { }
// set the correct extension
_shapefileTempDbasePath = Path.ChangeExtension(initialTempFile, DbasePathExtension);
// copy over the DB
File.Copy(_shapefileDbasePath, _shapefileTempDbasePath, true);
safeDbasePath = _shapefileTempDbasePath;
}
string connectionString = string.Format(ConnectionStringTemplate,
Path.GetDirectoryName(safeDbasePath));
_selectString = string.Format(DbSelectStringTemplate,
Path.GetFileNameWithoutExtension(safeDbasePath));
_dbConnection = new OleDbConnection(connectionString);
_dbConnection.Open();
}
19
Source : FileContainerHttpClient.cs
with MIT License
from actions
with MIT License
from actions
public async Task<HttpResponseMessage> UploadFileAsync(
Int64 containerId,
String itemPath,
Stream fileStream,
Guid scopeIdentifier,
CancellationToken cancellationToken = default(CancellationToken),
int chunkSize = c_defaultChunkSize,
bool uploadFirstChunk = false,
Object userState = null,
Boolean compressStream = true)
{
if (containerId < 1)
{
throw new ArgumentException(WebApiResources.ContainerIdMustBeGreaterThanZero(), "containerId");
}
ArgumentUtility.CheckForNull(fileStream, "fileStream");
if (fileStream.Length == 0)
{
HttpRequestMessage requestMessage;
List<KeyValuePair<String, String>> query = AppendItemQueryString(itemPath, scopeIdentifier);
// zero byte upload
requestMessage = await CreateRequestMessageAsync(HttpMethod.Put, FileContainerResourceIds.FileContainer, routeValues: new { containerId = containerId }, version: s_currentApiVersion, queryParameters: query, userState: userState, cancellationToken: cancellationToken).ConfigureAwait(false);
return await SendAsync(requestMessage, userState, cancellationToken).ConfigureAwait(false);
}
ApiResourceVersion gzipSupportedVersion = new ApiResourceVersion(new Version(1, 0), 2);
ApiResourceVersion requestVersion = await NegotiateRequestVersionAsync(FileContainerResourceIds.FileContainer, s_currentApiVersion, userState, cancellationToken: cancellationToken).ConfigureAwait(false);
if (compressStream
&& (requestVersion.ApiVersion < gzipSupportedVersion.ApiVersion
|| (requestVersion.ApiVersion == gzipSupportedVersion.ApiVersion && requestVersion.ResourceVersion < gzipSupportedVersion.ResourceVersion)))
{
compressStream = false;
}
Stream streamToUpload = fileStream;
Boolean gzipped = false;
long filelength = fileStream.Length;
try
{
if (compressStream)
{
if (filelength > 65535) // if file greater than 64K use a file
{
String tempFile = Path.GetTempFileName();
streamToUpload = File.Create(tempFile, 32768, FileOptions.DeleteOnClose | FileOptions.Asynchronous);
}
else
{
streamToUpload = new MemoryStream((int)filelength + 8);
}
using (GZipStream zippedStream = new GZipStream(streamToUpload, CompressionMode.Compress, true))
{
await fileStream.CopyToAsync(zippedStream).ConfigureAwait(false);
}
if (streamToUpload.Length >= filelength)
{
// compression did not help
streamToUpload.Dispose();
streamToUpload = fileStream;
}
else
{
gzipped = true;
}
streamToUpload.Seek(0, SeekOrigin.Begin);
}
return await UploadFileAsync(containerId, itemPath, streamToUpload, null, filelength, gzipped, scopeIdentifier, cancellationToken, chunkSize, uploadFirstChunk: uploadFirstChunk, userState: userState);
}
finally
{
if (gzipped && streamToUpload != null)
{
streamToUpload.Dispose();
}
}
}
19
Source : HostContextL0.cs
with MIT License
from actions
with MIT License
from actions
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void SecretMaskerForProxy()
{
try
{
Environment.SetEnvironmentVariable("http_proxy", "http://user:[email protected]:8888");
// Arrange.
Setup();
// replacedert.
var logFile = Path.Combine(Path.GetDirectoryName(replacedembly.GetEntryreplacedembly().Location), $"trace_{nameof(HostContextL0)}_{nameof(SecretMaskerForProxy)}.log");
var tempFile = Path.GetTempFileName();
File.Delete(tempFile);
File.Copy(logFile, tempFile);
var content = File.ReadAllText(tempFile);
replacedert.DoesNotContain("preplacedword123", content);
replacedert.Contains("http://user:***@127.0.0.1:8888", content);
}
finally
{
Environment.SetEnvironmentVariable("http_proxy", null);
// Cleanup.
Teardown();
}
}
19
Source : PDFFormatter.cs
with BSD 3-Clause "New" or "Revised" License
from ActuarialIntelligence
with BSD 3-Clause "New" or "Revised" License
from ActuarialIntelligence
public Bitmap GetImage(int pageNumber)
{
Bitmap result;
string workFile;
if (pageNumber < 1 || pageNumber > this.PageCount)
throw new ArgumentException("Page number is out of bounds", "pageNumber");
workFile = Path.GetTempFileName();
try
{
this.ConvertPdfPageToImage(workFile, pageNumber);
using (FileStream stream = new FileStream(workFile, FileMode.Open, FileAccess.Read))
result = new Bitmap(stream);
}
finally
{
File.Delete(workFile);
}
return result;
}
19
Source : SimpleAudioRecorderImplementation.cs
with MIT License
from adrianstevens
with MIT License
from adrianstevens
string GetTempFileName()
{
return Path.Combine("/sdcard/", Path.GetTempFileName());
}
19
Source : SimpleAudioRecorderImplementation.cs
with MIT License
from adrianstevens
with MIT License
from adrianstevens
string GetTempFileName()
{
var docFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var libFolder = Path.Combine(docFolder, "..", "Library");
var tempFileName = Path.Combine(libFolder, Path.GetTempFileName());
return tempFileName;
}
19
Source : JsonDownloader.cs
with MIT License
from adrianmteo
with MIT License
from adrianmteo
public async Task<string> GetTempFile(string url, string filename)
{
string extension = Path.GetExtension(filename);
string path = Path.ChangeExtension(Path.GetTempFileName(), extension);
await Client.DownloadFileTaskAsync(url, path);
return path;
}
19
Source : Utils.cs
with Apache License 2.0
from aequabit
with Apache License 2.0
from aequabit
public static string WriteTempData(byte[] data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
string path = null;
try
{
path = Path.GetTempFileName();
}
catch (IOException)
{
path = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName());
}
try
{
File.WriteAllBytes(path, data);
}
catch
{
path = null;
}
return path;
}
19
Source : IdentityBuilderExtensions.cs
with Apache License 2.0
from Aguafrommars
with Apache License 2.0
from Aguafrommars
public static IdenreplacedyBuilder AddFirestoreStores(this IdenreplacedyBuilder builder, Action<OAuthServiceAccountKey> configure, Action<FirestoreTableNamesConfig> tableNames = null)
{
var services = builder.Services;
services.Configure(configure)
.AddScoped(provider =>
{
var authOptions = StoreAuthFile(provider, Path.GetTempFileName());
var client = FirestoreClient.Create();
return FirestoreDb.Create(authOptions.Value.project_id, client: client);
});
AddStores(services, builder.UserType, builder.RoleType, ResolveFirestoreTableNamesConfig(tableNames));
return builder;
}
19
Source : FirestoreTestFixture.cs
with Apache License 2.0
from Aguafrommars
with Apache License 2.0
from Aguafrommars
public static FirestoreDb CreateFirestoreDb(IServiceProvider provider)
{
var authOptions = provider.GetRequiredService<IOptions<OAuthServiceAccountKey>>();
var path = Path.GetTempFileName();
var json = JsonConvert.SerializeObject(authOptions.Value);
using var writer = File.CreateText(path);
writer.Write(json);
writer.Flush();
writer.Close();
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
var client = FirestoreClient.Create();
return FirestoreDb.Create(authOptions.Value.project_id, client: client);
}
19
Source : IdentityBuilderExtensionsTest.cs
with Apache License 2.0
from Aguafrommars
with Apache License 2.0
from Aguafrommars
[Fact]
public void AddFirebaseStores_with_project_id_Test()
{
var builder = new ConfigurationBuilder();
var configuration = builder
.AddEnvironmentVariables()
.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "../../../../idenreplacedyfirestore.json"))
.Build();
var authOptions = configuration.GetSection("FirestoreAuthTokenOptions").Get<OAuthServiceAccountKey>();
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")))
{
var path = Path.GetTempFileName();
var json = JsonConvert.SerializeObject(authOptions);
using var writer = File.CreateText(path);
writer.Write(json);
writer.Flush();
writer.Close();
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
}
var services = new ServiceCollection();
services
.AddIdenreplacedy<IdenreplacedyUser, IdenreplacedyRole>()
.AddFirestoreStores(authOptions.project_id);
var provider = services.BuildServiceProvider();
replacedert.NotNull(provider.GetService<IUserStore<IdenreplacedyUser>>());
replacedert.NotNull(provider.GetService<IRoleStore<IdenreplacedyRole>>());
}
19
Source : UserStoreTest.cs
with Apache License 2.0
from Aguafrommars
with Apache License 2.0
from Aguafrommars
private static void CreateAuthFile(IServiceProvider provider, out IOptions<OAuthServiceAccountKey> authOptions)
{
authOptions = provider.GetRequiredService<IOptions<OAuthServiceAccountKey>>();
var json = JsonConvert.SerializeObject(authOptions.Value);
var path = Path.GetTempFileName();
using var writer = File.CreateText(path);
writer.Write(json);
writer.Flush();
writer.Close();
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
}
19
Source : FileManagerOnDisk.cs
with MIT License
from ahmet-cetinkaya
with MIT License
from ahmet-cetinkaya
public string Add(IFormFile file, string path)
{
var sourcepath = Path.GetTempFileName();
if (file.Length > 0)
using (var stream = new FileStream(sourcepath, FileMode.Create))
{
file.CopyTo(stream);
}
File.Move(sourcepath, path);
return path;
}
19
Source : PackageDownloader.cs
with MIT License
from ai-traders
with MIT License
from ai-traders
public async Task<Stream> DownloadOrNullAsync(Uri packageUri, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
_logger.LogInformation("Attempting to download package from {PackageUri}...", packageUri);
Stream packageStream = null;
var stopwatch = Stopwatch.StartNew();
try
{
// Download the package from the network to a temporary file.
using (var response = await _httpClient.GetAsync(packageUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
{
_logger.LogInformation(
"Received response {StatusCode}: {ReasonPhrase} of type {ContentType} for request {PackageUri}",
response.StatusCode,
response.ReasonPhrase,
response.Content.Headers.ContentType,
packageUri);
if (response.StatusCode != HttpStatusCode.OK)
{
_logger.LogWarning(
$"Expected status code {HttpStatusCode.OK} for package download, actual: {{ResponseStatusCode}}",
response.StatusCode);
return null;
}
using (var networkStream = await response.Content.ReadreplacedtreamAsync())
{
packageStream = new FileStream(
Path.GetTempFileName(),
FileMode.Create,
FileAccess.ReadWrite,
FileShare.None,
BufferSize,
FileOptions.DeleteOnClose | FileOptions.Asynchronous);
await networkStream.CopyToAsync(packageStream, BufferSize, cancellationToken);
}
}
packageStream.Position = 0;
_logger.LogInformation(
"Downloaded {PackageSizeInBytes} bytes in {DownloadElapsedTime} seconds for request {PackageUri}",
packageStream.Length,
stopwatch.Elapsed.TotalSeconds,
packageUri);
return packageStream;
}
catch (Exception e)
{
_logger.LogError(
e,
"Exception thrown when trying to download package from {PackageUri}",
packageUri);
packageStream?.Dispose();
return null;
}
}
19
Source : PackageDownloadsJsonSource.cs
with MIT License
from ai-traders
with MIT License
from ai-traders
private async Task<Stream> GetDownloadsStreamAsync()
{
_logger.LogInformation("Downloading downloads.v1.json...");
var fileStream = File.Open(Path.GetTempFileName(), FileMode.Create);
var response = await _httpClient.GetAsync(PackageDownloadsV1Url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
using (var networkStream = await response.Content.ReadreplacedtreamAsync())
{
await networkStream.CopyToAsync(fileStream);
}
fileStream.Seek(0, SeekOrigin.Begin);
_logger.LogInformation("Downloaded downloads.v1.json");
return fileStream;
}
19
Source : ScanTests.cs
with Apache License 2.0
from airbus-cert
with Apache License 2.0
from airbus-cert
[Fact]
public void CheckSaveLoadRuleTest()
{
// Initialize yara context
using (YaraContext ctx = new YaraContext())
{
using (var compiler = new Compiler())
{
compiler.AddRuleString("rule foo: bar {strings: $a = \"lmn\" condition: $a}");
CompiledRules compiledRules = compiler.Compile();
replacedert.True(compiledRules.RuleCount == 1);
Encoding encoding = Encoding.ASCII;
byte[] buffer = encoding.GetBytes("abcdefgjiklmnoprstuvwxyz");
// Initialize the scanner
var scanner = new Scanner();
List<ScanResult> compiledScanResults = scanner.ScanMemory(ref buffer, compiledRules);
replacedert.True(compiledScanResults.Count == 1);
replacedert.Equal("foo", compiledScanResults[0].MatchingRule.Identifier);
//save the rule to disk
string tempfile = System.IO.Path.GetTempFileName();
bool saved = compiledRules.Save(tempfile);
replacedert.True(saved);
//load the saved rule to a new ruleset
CompiledRules loadedRules = new CompiledRules(tempfile);
List<ScanResult> loadedScanResults = scanner.ScanMemory(ref buffer, loadedRules);
replacedert.True(loadedScanResults.Count == 1);
replacedert.Equal("foo", loadedScanResults[0].MatchingRule.Identifier);
System.IO.File.Delete(tempfile);
}
}
}
19
Source : AE_AES_128_CBC_HMAC_SHA_256_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes128cbcHmacSha256.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_128_CBC_HMAC_SHA_256_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes128cbcHmacSha256.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_128_CBC_HMAC_SHA_256_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes128cbcHmacSha256.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes128cbcHmacSha256.DecryptFile(testFilePath, testFilePath, _preplacedword, false, hasEncryptionDataAppendedInInputFile: appendEncryptionData);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_128_CBC_HMAC_SHA_256_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes128cbcHmacSha256.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes128cbcHmacSha256.DecryptFile(testFilePath, testFilePath, System.Text.Encoding.UTF8.GetBytes(_preplacedword), false, hasEncryptionDataAppendedInInputFile: appendEncryptionData,
aesEncryptionResult.Tag, aesEncryptionResult.Salt, aesEncryptionResult.IV);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_192_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes192cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_192_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes192cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_192_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes192cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes192cbcHmacSha384.DecryptFile(testFilePath, testFilePath, _preplacedword, false, hasEncryptionDataAppendedInInputFile: appendEncryptionData);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_192_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes192cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes192cbcHmacSha384.DecryptFile(testFilePath, testFilePath, System.Text.Encoding.UTF8.GetBytes(_preplacedword), false, hasEncryptionDataAppendedInInputFile: appendEncryptionData,
aesEncryptionResult.Tag, aesEncryptionResult.Salt, aesEncryptionResult.IV);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes256cbcHmacSha384.DecryptFile(testFilePath, testFilePath, _preplacedword, false, hasEncryptionDataAppendedInInputFile: appendEncryptionData);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha384.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes256cbcHmacSha384.DecryptFile(testFilePath, testFilePath, System.Text.Encoding.UTF8.GetBytes(_preplacedword), false, hasEncryptionDataAppendedInInputFile: appendEncryptionData,
aesEncryptionResult.Tag, aesEncryptionResult.Salt, aesEncryptionResult.IV);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_512_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha512.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_512_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_EncryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha512.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
replacedert.IsTrue(aesEncryptionResult.Success, aesEncryptionResult.Message);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_512_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_with_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = true;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha512.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes256cbcHmacSha512.DecryptFile(testFilePath, testFilePath, _preplacedword, false, hasEncryptionDataAppendedInInputFile: appendEncryptionData);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : AE_AES_256_CBC_HMAC_SHA_512_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void Test_DecryptFile_without_append_encryption_data()
{
var testFilePath = Path.GetTempFileName();
var appendEncryptionData = false;
var aesDecryptionResult = new AesDecryptionResult();
var testFileStringContentRead = "";
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var aesEncryptionResult = _aes256cbcHmacSha512.EncryptFile(testFilePath, testFilePath, _preplacedword, false, appendEncryptionDataToOutputFile: appendEncryptionData);
if (aesEncryptionResult.Success)
{
aesDecryptionResult = _aes256cbcHmacSha512.DecryptFile(testFilePath, testFilePath, System.Text.Encoding.UTF8.GetBytes(_preplacedword), false, hasEncryptionDataAppendedInInputFile: appendEncryptionData,
aesEncryptionResult.Tag, aesEncryptionResult.Salt, aesEncryptionResult.IV);
if (aesDecryptionResult.Success)
{
testFileStringContentRead = File.ReadAllText(testFilePath);
}
else
{
errorMessage = aesDecryptionResult.Message;
}
}
else
{
errorMessage = aesEncryptionResult.Message;
}
replacedert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && testFileStringContentRead.Equals(_testString)), errorMessage);
}
19
Source : MD5_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void ComputeAndVerifyHash_File()
{
var testFilePath = Path.GetTempFileName();
var verifyResult = new GenericHashResult();
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var hashResult = _md5.ComputeFileHash(testFilePath);
if (hashResult.Success)
{
verifyResult = _md5.VerifyFileHash(hashResult.HashString, testFilePath);
if (!verifyResult.Success)
{
errorMessage = verifyResult.Message;
}
}
else
{
errorMessage = hashResult.Message;
}
replacedert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
}
19
Source : SHA1_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void ComputeAndVerifyHash_File()
{
var testFilePath = Path.GetTempFileName();
var verifyResult = new GenericHashResult();
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var hashResult = _sha1.ComputeFileHash(testFilePath);
if (hashResult.Success)
{
verifyResult = _sha1.VerifyFileHash(hashResult.HashString, testFilePath);
if (!verifyResult.Success)
{
errorMessage = verifyResult.Message;
}
}
else
{
errorMessage = hashResult.Message;
}
replacedert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
}
19
Source : SHA256_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
[TestMethod]
public void ComputeAndVerifyHash_File()
{
var testFilePath = Path.GetTempFileName();
var verifyResult = new GenericHashResult();
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var hashResult = _sha256.ComputeFileHash(testFilePath);
if (hashResult.Success)
{
verifyResult = _sha256.VerifyFileHash(hashResult.HashString, testFilePath);
if (!verifyResult.Success)
{
errorMessage = verifyResult.Message;
}
}
else
{
errorMessage = hashResult.Message;
}
replacedert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
}
19
Source : SHA384_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
public void ComputeAndVerifyHash_File()
{
var testFilePath = Path.GetTempFileName();
var verifyResult = new GenericHashResult();
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var hashResult = _sha384.ComputeFileHash(testFilePath);
if (hashResult.Success)
{
verifyResult = _sha384.VerifyFileHash(hashResult.HashString, testFilePath);
if (!verifyResult.Success)
{
errorMessage = verifyResult.Message;
}
}
else
{
errorMessage = hashResult.Message;
}
replacedert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
}
19
Source : SHA512_Tests.cs
with MIT License
from alecgn
with MIT License
from alecgn
public void ComputeAndVerifyHash_File()
{
var testFilePath = Path.GetTempFileName();
var verifyResult = new GenericHashResult();
var errorMessage = "";
File.WriteAllText(testFilePath, _testString);
var hashResult = _sha512.ComputeFileHash(testFilePath);
if (hashResult.Success)
{
verifyResult = _sha512.VerifyFileHash(hashResult.HashString, testFilePath);
if (!verifyResult.Success)
{
errorMessage = verifyResult.Message;
}
}
else
{
errorMessage = hashResult.Message;
}
replacedert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
}
19
Source : TempFileUtils.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
public static string GetTempFileName(string originalFileName)
{
var extension = Path.GetExtension(originalFileName);
var tempFileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
var tempFile = Path.Combine(Path.GetTempPath(), "GroupMeDesktopClient", tempFileName + extension);
return tempFile;
}
19
Source : FileAttachmentControlViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
private async Task ClickedAction(PointerPressedEventArgs e)
{
if (e == null || e.GetCurrentPoint(null).Properties.IsLeftButtonPressed)
{
this.IsLoading = true;
var data = await this.FileAttachment.DownloadFileAsync(this.MessageContainer.Messages.First());
var extension = System.IO.Path.GetExtension(this.FileData.FileName);
var tempFileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
var tempFile = Path.Combine(Path.GetTempPath(), "GroupMeDesktopClientAvalonia", tempFileName + extension);
File.WriteAllBytes(tempFile, data);
var psInfo = new ProcessStartInfo()
{
FileName = tempFile,
UseShellExecute = true,
};
System.Diagnostics.Process.Start(psInfo);
this.IsLoading = false;
}
}
19
Source : Ring0.cs
with MIT License
from AlexGyver
with MIT License
from AlexGyver
private static string GetTempFileName() {
// try to create one in the application folder
string location = Getreplacedembly().Location;
if (!string.IsNullOrEmpty(location)) {
try {
string fileName = Path.ChangeExtension(location, ".sys");
using (FileStream stream = File.Create(fileName)) {
return fileName;
}
} catch (Exception) { }
}
// if this failed, try to get a file in the temporary folder
try {
return Path.GetTempFileName();
} catch (IOException) {
// some I/O exception
}
catch (UnauthorizedAccessException) {
// we do not have the right to create a file in the temp folder
}
catch (NotSupportedException) {
// invalid path format of the TMP system environment variable
}
return null;
}
19
Source : CompressAndEncryptBenchmark.cs
with MIT License
from alexis-
with MIT License
from alexis-
public static long Process(
Stream data,
ArchiveType archiveType, CompressionType compType,
EncryptionProtocol encProtocol, EncryptionAlgorithm encAlgorithm)
{
string fileName = Path.GetTempFileName();
FileInfo fileInfo = new FileInfo(fileName);
long compSizeB = 0;
ProgressStreamReportDelegate progressCallback =
(_, args) => compSizeB += args.BytesMoved;
using (Stream outFileStream = fileInfo.OpenWrite())
{
Action<Stream> streamWriter =
(outStream) => CompressionHelper.Compress(
"data.bin",
data,
outStream,
archiveType,
compType,
progressCallback
);
switch (encProtocol)
{
case EncryptionProtocol.None:
streamWriter(outFileStream);
break;
case EncryptionProtocol.AES:
EncryptionHelper.EncryptStreamAES(streamWriter, outFileStream, encAlgorithm, Const.EncKey32);
break;
case EncryptionProtocol.PBE:
EncryptionHelper.EncryptStreamPBE(streamWriter, outFileStream, encAlgorithm, Const.EncKey32);
break;
case EncryptionProtocol.PGP:
using (Stream pgpPubKeyStream = new MemoryStream(Encoding.ASCII.GetBytes(Const.PGPPubKey)))
EncryptionHelper.EncryptStreamPGP(
streamWriter, outFileStream, encAlgorithm,
pgpPubKeyStream, Convert.ToInt64(Const.PGPPubKeyID, 16));
break;
}
}
fileInfo.Delete();
return compSizeB;
}
19
Source : AppInit.cs
with MIT License
from alexis-
with MIT License
from alexis-
public static void Initialize(IAppHost appHost)
{
appHost.OnPreInitialize();
try
{
string appDataFolder = Const.GetAppDataFolderPath();
Directory.CreateDirectory(appDataFolder);
Logger.Instance.Initialize();
}
catch (Exception ex)
{
string tmpFilePath = Path.GetTempFileName();
using (Stream s = File.OpenWrite(tmpFilePath))
using (StreamWriter sw = new StreamWriter(s))
sw.Write(ex.Message);
throw new Exception(
String.Format(LoggerInitErrorMsg, Logger.GetLogFilePath(), tmpFilePath, ex.Message),
ex
);
}
appHost.OnPostInitialize();
}
19
Source : Extensions.cs
with MIT License
from alkampfergit
with MIT License
from alkampfergit
private static void DownloadAndEmbedImage(WorkItem workItem, HtmlNode image)
{
var src = image.GetAttributeValue("src", "");
try
{
//need to understand if it is in base 64 or no, if the answer is no, we need to embed image
if (!String.IsNullOrEmpty(src))
{
if (src.Contains("base64")) // data:image/jpeg;base64,
{
//image already embedded
Log.Debug("found image in html content that was already in base64");
}
else
{
Log.Debug("found image in html content that point to external image {src}", src);
String downloadedAttachment = "";
String extension = "";
//is it a internal attached images?
var match = Regex.Match(src, @"FileID=(?<id>\d*)", RegexOptions.IgnoreCase);
if (match.Success)
{
var attachment = workItem.Attachments
.OfType<Attachment>()
.FirstOrDefault(_ => _.Id.ToString() == match.Groups["id"].Value);
if (attachment != null)
{
//ok we can embed in the image as base64
WorkItemServer wise = workItem.Store.TeamProjectCollection.GetService<WorkItemServer>();
downloadedAttachment = wise.DownloadFile(attachment.Id);
extension = attachment.Extension.Trim('.');
}
}
else if ((match = GetUrlMatches(src)).Success)
{
var serverCredentials = ConnectionManager.Instance.GetCredentials();
string fileName = match.Groups["fileName"].Value;
extension = Path.GetExtension(fileName).Trim('.');
downloadedAttachment = Path.GetTempFileName() + "." + extension;
if (serverCredentials != null)
{
using (var client = new WebClient())
{
client.Credentials = serverCredentials;
client.DownloadFile(src, downloadedAttachment);
}
}
else
{
//download with standard client
var fileId = match.Groups["fileId"].Value;
using (var fs = new FileStream(downloadedAttachment, FileMode.Create))
{
var downloadStream = ConnectionManager.Instance
.WorkItemTrackingHttpClient
.GetAttachmentContentAsync(new Guid(fileId), fileName, download: true).Result;
using (downloadStream)
{
downloadStream.CopyTo(fs);
}
}
}
}
else
{
Log.Error("Unable to embed image with url {src}", src);
}
if (!String.IsNullOrEmpty(downloadedAttachment))
{
byte[] byteContent = File.ReadAllBytes(downloadedAttachment);
String base64Encoded = Convert.ToBase64String(byteContent);
var newSrcValue = $"data:image/{extension};base64,{base64Encoded}";
image.SetAttributeValue("src", newSrcValue);
}
}
}
}
catch (Exception ex)
{
Log.Error("Unable to download and embed image with url {src}", src);
}
}
19
Source : Program.cs
with MIT License
from alkampfergit
with MIT License
from alkampfergit
private static void PerformStandardIterationExport(ConnectionManager connection)
{
WorkItemManger workItemManger = new WorkItemManger(connection);
workItemManger.SetTeamProject(options.TeamProject);
var workItems = workItemManger.LoadAllWorkItemForAreaAndIteration(
options.AreaPath,
options.IterationPath);
var fileName = Path.GetTempFileName() + ".docx";
var templateManager = new TemplateManager("Templates");
var template = templateManager.GetWordDefinitionTemplate(options.TemplateName);
using (WordManipulator manipulator = new WordManipulator(fileName, true))
{
AddTableContent(manipulator, workItems, template);
foreach (var workItem in workItems)
{
manipulator.InsertWorkItem(workItem, template.GetTemplateFor(workItem.Type.Name), true);
}
}
System.Diagnostics.Process.Start(fileName);
}
19
Source : ParquetReaderTest.cs
with MIT License
from aloneguid
with MIT License
from aloneguid
[Fact]
public void ParquetReader_OpenFromFile_Close_Stream()
{
// copy a file to a temp location
string tempFile = Path.GetTempFileName();
using (Stream fr = OpenTestFile("map_simple.parquet"))
using (FileStream fw = System.IO.File.OpenWrite(tempFile))
{
fr.CopyTo(fw);
}
// open the copy
using (var reader = ParquetReader.OpenFromFile(tempFile))
{
// do nothing
}
// now try to delete this temp file. If the stream is properly closed, this should succeed
System.IO.File.Delete(tempFile);
}
19
Source : StatusCacheTest.cs
with Apache License 2.0
from AmpScm
with Apache License 2.0
from AmpScm
[Test]
public void TestGetUnversionedItem()
{
StatusCache cache = new StatusCache();
string path = Path.GetTempFileName();
SvnItem item = cache[path];
replacedert.IsFalse( item.IsVersionable );
}
19
Source : SvnItemTest.cs
with Apache License 2.0
from AmpScm
with Apache License 2.0
from AmpScm
[Test]
public void TestIsVersioned()
{
// normal
SvnItem item1 = this.Gereplacedem();
replacedert.IsTrue( item1.IsVersioned );
// missing
File.Delete( item1.Path );
item1.Refresh( this.Client );
replacedert.IsFalse( item1.IsVersioned );
// revert it so we can play some more with it
this.Client.Revert( new string[]{ item1.Path }, Recurse.None );
// modified
using( StreamWriter writer = new StreamWriter(item1.Path) )
writer.WriteLine( "Foo" );
item1.Refresh( this.Client );
replacedert.IsTrue( item1.IsVersioned );
// added
string addedFilePath = Path.Combine( this.WcPath, "added.txt" );
File.CreateText(addedFilePath).Close();
this.Client.Add( addedFilePath, Recurse.Full );
Status addedFileStatus = this.Client.SingleStatus( addedFilePath );
SvnItem addedItem = new SvnItem( addedFilePath, addedFileStatus );
replacedert.IsTrue( addedItem.IsVersioned );
// conflicted
string otherWc = this.GetTempFile();
Zip.ExtractZipResource( otherWc, this.GetType(), this.WC_FILE );
try
{
using( StreamWriter w2 = new StreamWriter( Path.Combine(otherWc, "Form1.cs") ) )
w2.WriteLine( "Something else" );
this.Client.Commit( new string[]{ otherWc }, Recurse.Full );
}
finally
{
Utils.PathUtils.RecursiveDelete( otherWc );
}
this.Client.Update( this.WcPath, Revision.Head, Recurse.Full );
item1.Refresh( this.Client );
replacedert.AreEqual( StatusKind.Conflicted, item1.Status.TextStatus );
replacedert.IsTrue( item1.IsVersioned );
// deleted
this.Client.Resolved( item1.Path, Recurse.None );
this.Client.Revert( new string[]{item1.Path}, Recurse.None );
this.Client.Delete( new string[]{ item1.Path }, true );
item1.Refresh( this.Client );
replacedert.AreEqual( StatusKind.Deleted, item1.Status.TextStatus );
replacedert.IsTrue( item1.IsVersioned );
// unversioned
string unversionedFile = Path.Combine( this.WcPath, "nope.txt" );
File.CreateText(unversionedFile).Close();
SvnItem unversioned = new SvnItem(unversionedFile, this.Client.SingleStatus(unversionedFile));
replacedert.AreEqual( StatusKind.Unversioned, unversioned.Status.TextStatus );
replacedert.IsFalse( unversioned.IsVersioned );
// none
string nonePath = Path.GetTempFileName();
SvnItem none = new SvnItem(nonePath, this.Client.SingleStatus(nonePath));
replacedert.AreEqual( StatusKind.None, none.Status.TextStatus );
replacedert.IsFalse( none.IsVersioned );
}
See More Examples