first commit
This commit is contained in:
+82
@@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Management;
|
||||||
|
using TestConsoleApp;
|
||||||
|
|
||||||
|
namespace databaseconnection
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
static string ProcessName = "AcroRd32";
|
||||||
|
static string UserID = "";
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var parser = new QueryParser();
|
||||||
|
var stopWatch = Stopwatch.StartNew();
|
||||||
|
var columns=parser.Parse();
|
||||||
|
var time = stopWatch.Elapsed.TotalMilliseconds;
|
||||||
|
Console.WriteLine(columns);
|
||||||
|
//var anInstanceofMyClass = new Program();
|
||||||
|
//anInstanceofMyClass.checkAcrobatProcess();
|
||||||
|
|
||||||
|
//Console.WriteLine("Hello World!");
|
||||||
|
//Console.WriteLine("localDate - " + localDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkAcrobatProcess()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//CatchStackOverflow1();
|
||||||
|
foreach (Process process in Process.GetProcessesByName(ProcessName))
|
||||||
|
{
|
||||||
|
if ((process.MainWindowTitle).Equals("Adobe Acrobat Reader DC (32-bit)"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("checkAcrobatProcess DEBUG: Adobe Acrobat Standard DC (32-bit) is launched");
|
||||||
|
|
||||||
|
ObjectQuery objQuery = new ObjectQuery("Select * From Win32_Process where ProcessId='" + process.Id + "'");
|
||||||
|
ManagementObjectSearcher mos = new ManagementObjectSearcher(objQuery);
|
||||||
|
|
||||||
|
foreach (ManagementObject mo in mos.Get())
|
||||||
|
{
|
||||||
|
string[] s = new string[2];
|
||||||
|
mo.InvokeMethod("GetOwner", (object[])s);
|
||||||
|
UserID = s[0].ToLower().ToString();
|
||||||
|
Console.WriteLine("checkAcrobatProcess DEBUG: " + UserID + " launched the acrobat");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Console.WriteLine("checkAcrobatProcess DEBUG: waitforexit");
|
||||||
|
process.WaitForExit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("checkAcrobatProcess DEBUG: Failed!! " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkAcrobatProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void CatchStackOverflow1()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw new StackOverflowException();
|
||||||
|
}
|
||||||
|
catch (StackOverflowException) //catch (StackOverflowException ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
namespace TestConsoleApp
|
||||||
|
{
|
||||||
|
public class QueryParser
|
||||||
|
{
|
||||||
|
|
||||||
|
public List<string> Parse()
|
||||||
|
{
|
||||||
|
var totalQuery = File.ReadAllText(@"D:\empt.txt");
|
||||||
|
return _Parse(totalQuery);
|
||||||
|
|
||||||
|
}
|
||||||
|
List<string> _Parse(string actualQuery)
|
||||||
|
{
|
||||||
|
string columnString = GetColumnString(actualQuery);
|
||||||
|
List<string> resultColumnlist = new List<string>();
|
||||||
|
var commaSeperatedArray = columnString.Split(',');
|
||||||
|
|
||||||
|
for (int i = 0; i < commaSeperatedArray.Length; i++)
|
||||||
|
{
|
||||||
|
var column = commaSeperatedArray[i];
|
||||||
|
if (IsPredefinedFunction(column))
|
||||||
|
{
|
||||||
|
if (!IsPerfectPredefinedFunction(column))
|
||||||
|
{
|
||||||
|
column = MakeItPerfect(ref i, commaSeperatedArray, commaSeperatedArray[i]);
|
||||||
|
}
|
||||||
|
resultColumnlist.Add(column);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultColumnlist.Add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultColumnlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetColumnString(string actualQuery)
|
||||||
|
{
|
||||||
|
actualQuery = actualQuery.Replace(System.Environment.NewLine, " ");
|
||||||
|
var fromidex = actualQuery.ToLower().LastIndexOf("from ");
|
||||||
|
var splitted = actualQuery.Substring(0, fromidex);
|
||||||
|
splitted = splitted.TrimStart().Remove(0, "select".Length);
|
||||||
|
return splitted;
|
||||||
|
}
|
||||||
|
bool IsPredefinedFunction(string name)
|
||||||
|
{
|
||||||
|
var _name = name.ToLower();
|
||||||
|
bool result = false;
|
||||||
|
foreach (var function in PredefinedFunctions())
|
||||||
|
{
|
||||||
|
if (_name.Contains(function.ToLower()))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
string[] PredefinedFunctions()
|
||||||
|
{
|
||||||
|
return new string[] {
|
||||||
|
"coalesce","concat","select","min","max","count"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
bool IsPerfectPredefinedFunction(string name)
|
||||||
|
{
|
||||||
|
var opencount = name.Count(c => c == '(');
|
||||||
|
var closecount = name.Count(c => c == ')');
|
||||||
|
return opencount == closecount;
|
||||||
|
}
|
||||||
|
string MakeItPerfect(ref int index, string[] colArray, string columnName)
|
||||||
|
{
|
||||||
|
index = index + 1;
|
||||||
|
var column = columnName + "," + colArray[index];
|
||||||
|
if (!IsPerfectPredefinedFunction(column))
|
||||||
|
{
|
||||||
|
column = MakeItPerfect(ref index, colArray, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace TestConsoleApp
|
||||||
|
{
|
||||||
|
class Test
|
||||||
|
{
|
||||||
|
public static void Execute()
|
||||||
|
{
|
||||||
|
var stopWatch = Stopwatch.StartNew();
|
||||||
|
for (int i = 0; i < 99999; i++)
|
||||||
|
{
|
||||||
|
var a = 0;a += i;a++;
|
||||||
|
|
||||||
|
}
|
||||||
|
Console.WriteLine("{0}", stopWatch.Elapsed.TotalMilliseconds);
|
||||||
|
var stopWatch2 = Stopwatch.StartNew();
|
||||||
|
for (int i = 0; i < 99999; i++)
|
||||||
|
{
|
||||||
|
var a = 0; a += i; a++;
|
||||||
|
|
||||||
|
}
|
||||||
|
Console.WriteLine("{0}", stopWatch2.Elapsed.TotalMilliseconds);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Management" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.31321.278
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestConsoleApp", "TestConsoleApp.csproj", "{55803876-CE84-4F74-9B21-AEA5353EAC5B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{55803876-CE84-4F74-9B21-AEA5353EAC5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{55803876-CE84-4F74-9B21-AEA5353EAC5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{55803876-CE84-4F74-9B21-AEA5353EAC5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{55803876-CE84-4F74-9B21-AEA5353EAC5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {C2ADFE16-21AF-4DC6-B341-4AE0F9B528DD}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user