using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Xunit.Abstractions;
namespace CustomerService.Tests;
public sealed class VariableTracker
{
private readonly ITestOutputHelper _testOutputHelper;
public VariableTracker(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
[Fact]
public void ScanFile()
{
string filePath =
@"C:\Users\ozkan\projects\dotnet-examples\tc-guide-getting-started-with-testcontainers-for-dotnet\TestcontainersDemo\CustomerService\CustomerService.cs";
string code = File.ReadAllText(filePath);
SyntaxTree tree = CSharpSyntaxTree.ParseText(code);
var root = (CompilationUnitSyntax)tree.GetRoot();
var variableCollector = new VariableCollector();
variableCollector.Visit(root);
_testOutputHelper.WriteLine("\nVariable Assignments:");
foreach (var assignment in variableCollector.Assignments)
{
if (assignment.Key.ToLower().Contains("command"))
_testOutputHelper.WriteLine($"Variable: {assignment.Key}, Assigned Value: {assignment.Value}");
}
}
private class VariableCollector : CSharpSyntaxWalker
{
public Dictionary<string, string> Assignments { get; } = new();
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
{
var left = node.Left.ToString();
var right = node.Right.ToString();
Assignments[left] = right;
base.VisitAssignmentExpression(node);
}
}
}
Sunday, June 16, 2024
C# scan cs file and find variables values and names
Saturday, June 15, 2024
C# run testcontainers and run some commands on them
using DotNet.Testcontainers.Builders;
using Xunit.Abstractions;
using IContainer = DotNet.Testcontainers.Containers.IContainer;
namespace TestingWithContainers;
public class CustomContainerTest(ITestOutputHelper testOutputHelper) : IAsyncLifetime
{
private IContainer[] _container;
public async Task InitializeAsync()
{
_container =
[
ContainerBuildForTest("mcr.microsoft.com/mssql/rhel/server:2019-latest"), // redhat
ContainerBuildForTest("mcr.microsoft.com/mssql/rhel/server:latest"),
ContainerBuildForTest("mcr.microsoft.com/mssql/server:2019-latest"), // ubuntu
ContainerBuildForTest("mcr.microsoft.com/mssql/server:latest"),
];
foreach (var container in _container)
{
try
{
testOutputHelper.WriteLine($"Starting container with image: {container.Image.FullName}");
await container.StartAsync();
testOutputHelper.WriteLine($"Started container with ID: {container.Id}");
}
catch (Exception ex)
{
testOutputHelper.WriteLine($"Failed to start container with image {container.Image}: {ex.Message}");
testOutputHelper.WriteLine($"Stack Trace: {ex.StackTrace}");
}
}
}
private static IContainer ContainerBuildForTest(string imageName)
{
return new ContainerBuilder()
.WithImage(imageName)
// .WithWaitStrategy(Wait.ForUnixContainer().UntilCommandIsCompleted("uname"))
.Build();
}
public async Task DisposeAsync()
{
foreach (var container in _container)
{
await container.DisposeAsync();
}
}
[Fact]
public void Run_Command()
{
Parallel.For(0, _container.Length, index =>
{
var cmd = "cat /etc/issue";
var execAsync = _container[index].ExecAsync(cmd.Split(" "), default).Result.Stdout;
testOutputHelper.WriteLine(execAsync);
// Assert.Contains("Linux", execAsync);
});
}
}
Sunday, May 12, 2024
install qscintilla in windows
In order to install qscintilla we have to compile the code and install. Find the make install output from my windows below
ozkan@HP-ENVY-2021-I7 C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src
$ make install
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Makefile.Release install
make[1]: Entering directory 'C:/Users/ozkan/tmp/QScintilla_src-2.14.1/src'
copy /y release\libqscintilla2_qt5.a C:\Qt\5.15.2\mingw81_64\lib\libqscintilla2_qt5.a
1 file(s) copied.
copy /y release\qscintilla2_qt5.dll C:\Qt\5.15.2\mingw81_64\lib\qscintilla2_qt5.dll
1 file(s) copied.
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\Qsci C:\Qt\5.15.2\mingw81_64\include\Qsci
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\qscintilla_cs.qm C:\Qt\5.15.2\mingw81_64\translations\qscintilla_cs.qm
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\qscintilla_de.qm C:\Qt\5.15.2\mingw81_64\translations\qscintilla_de.qm
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\qscintilla_es.qm C:\Qt\5.15.2\mingw81_64\translations\qscintilla_es.qm
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\qscintilla_fr.qm C:\Qt\5.15.2\mingw81_64\translations\qscintilla_fr.qm
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\qscintilla_pt_br.qm C:\Qt\5.15.2\mingw81_64\translations\qscintilla_pt_br.qm
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\qsci C:\Qt\5.15.2\mingw81_64\qsci
C:\Qt\5.15.2\mingw81_64\bin\qmake.exe -install qinstall C:\Users\ozkan\tmp\QScintilla_src-2.14.1\src\features\qscintilla2.prf C:\Qt\5.15.2\mingw81_64\mkspecs\features\qscintilla2.prf
make[1]: Leaving directory 'C:/Users/ozkan/tmp/QScintilla_src-2.14.1/src'
took like 10 minutes to compile in my machine. Downloaded from https://riverbankcomputing.com/software/qscintilla/download I am surprised in year of 2024 CPP does not have maven repo like structure. compiling the code is soo old now :)
Saturday, May 11, 2024
download windows 11 ISOs legally from microsoft
Strangely it is always hard to find these links
Windows 11 Enterprise | Microsoft Evaluation Center
https://www.microsoft.com/en-gb/evalcenter/download-windows-11-enterprise
Tuesday, May 07, 2024
how to show a dialog box in wix
Sometime we may want to show a dialog box to user from installation package, below is an example
<CustomAction Id="ConfirmAndCleanUpOldFolder"
Script="vbscript"
Execute="immediate"><![CDATA[On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
strProgramData = WshShell.ExpandEnvironmentStrings("% ProgramData%")
strFolderPath = strProgramData & "\sompath\"
Set fso = CreateObject("Scripting.FileSystemObject")
If Session.Property("UILevel") = 4 And fso.FolderExists(strFolderPath) Then
result = MsgBox("An older version of the data folder exists, which is no longer necessary for the application's operation. Would you like to remove it now ? " & strFolderPath, vbYesNo + vbSystemModal, "Clean up redundant files")
If result = vbYes Then
fso.DeleteFolder strFolderPath, True
If Err.Number <> 0 Then
MsgBox "Failed to delete folder: " & Err.Description
Else
Session.Property("OLD_FOLDER_CLEANED") = "yes"
End If
End If
End If
On Error GoTo 0
]]>
</CustomAction>
and put
<InstallExecuteSequence>
<Custom Action="ConfirmAndCleanUpOldFolder" After="InstallInitialize" />
Subscribe to:
Posts (Atom)
C# scan cs file and find variables values and names
using Microsoft . CodeAnalysis ; using Microsoft . CodeAnalysis . CSharp ; using Microsoft . CodeAnalysis . CSharp . Syntax ; using Xunit . ...
-
Yeni nesil hacker'lar: Edwin Pena | Olympos Security koptum okuyunca yazılımcılar ve pazarlamacılar bu kadar kısa ve özlü bir hikayeyle ...
-
if you have wl11 ejb server and in that environment generated ejb client and deploy to wl12 it will give you this exception java.lang.NoSu...
-
https://leetcode.com/problems/odd-string-difference/ Beats 19.92% of users with Java class Solution { public String oddString ( S...