If you get “Unable to automatically debug ‘XXX.Service’. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server. See help for more information.” message while debugging WCF Service remove “Configure” static function from service.

public static void Configure(ServiceConfiguration config)
{
}

 

VisualStudio-Unable-to-automatically-debug

Original file: C# to C++ / Qt T4 generator

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".h" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ assembly name="PATH_TO_REFERENCE_DLL.dll" #>

<# bool useQTTypes = true; List ccs = new List()
{
typeof(namespace.CLASS1),
typeof(namespace.CLASS2),
typeof(namespace.CLASS3)
};
GetPropertiesAll(ccs, useQTTypes);
#>
<#+ private void GetPropertiesAll(List ccs, bool useQTTypes)
{
foreach(Type cc in ccs)
{
GetProperties(ccs, cc,useQTTypes);
}
}
private void GetProperties(List ccs, Type t, bool useQTTypes)
{
string objectName = t.Name;
WriteLine(“//”);
WriteLine(“// Copyright © ” + DateTime.Now.ToString(“yyyy”) +”, Cihan T. (Generate Date: [” + DateTime.Now.ToString(“yyyy-MM-dd HH:mm:00″) +”])”);
WriteLine(“//”);
WriteLine(“#ifndef ” + objectName.ToUpper() + “_H”);
WriteLine(“#define ” + objectName.ToUpper() + “_H”);
WriteLine(“#include “);

if(useQTTypes)
{
WriteLine(“#include “);
}
if(t.IsClass || t.IsInterface)
GenerateClass(ccs, t, objectName, useQTTypes);
else if(t.IsEnum)
GenerateFromEnum(t, objectName, useQTTypes);

WriteLine(“#endif // ” + objectName.ToUpper() + “_H\r\n”);

SaveOutput(objectName + “.h”);
}
private void GenerateClass(List ccs,Type t, string objectName, bool useQTTypes)
{
GenerateIncludes(ccs, t, objectName, useQTTypes);
var properties = t.GetProperties().ToList();
WriteLine(“class ” + objectName);
WriteLine(“{“);
WriteLine(“public:”);
WriteLine(“\t” + objectName + “();”);

foreach(var p in properties){
WriteLine(“\tproperty<" + getAsQtProperty(p, useQTTypes) + "> ” + p.Name + “;”);
}
WriteLine(“};”);
}

private void GenerateIncludes(List ccs,Type t, string objectName, bool useQTTypes)
{
var properties = t.GetProperties().ToList();

foreach(var p in properties){
bool contains = ccs.Any(cc => cc.Name == p.PropertyType.Name);
if(contains)
WriteLine(“#include <" + p.PropertyType.Name + ".h>“);
}
}
private void GenerateFromEnum(Type t, string objectName, bool useQTTypes)
{
FieldInfo[] memberInfos = t.GetFields(BindingFlags.Public | BindingFlags.Static);

WriteLine(“enum class ” + objectName + “”);
WriteLine(“{“);

for(int i = 0; i < memberInfos.Length; i++){ Write("\t" + memberInfos[i].Name + " = " + memberInfos[i].GetRawConstantValue().ToString()); if(i < memberInfos.Length - 1) Write(","); Write("\r\n"); } WriteLine("};"); } private string getAsQtProperty(PropertyInfo p, bool useQTTypes) { switch(p.PropertyType.Name){ case "String": return useQTTypes?"QString":"string"; case "Int32": return "int"; case "Decimal": return "float"; case "Double": return "float"; case "Char": return "char"; case "Byte": return "char"; case "DateTime": return useQTTypes?"QDateTime":"DateTime"; case "Boolean": return useQTTypes?"bool":"BOOL"; case "List`1": return useQTTypes?"QList<" + getListTypes(p, useQTTypes) +">“:”vector<>“;
case “Dictionary`2”:
return useQTTypes?”QMap<" + getDictionaryTypes(p, useQTTypes) + ">“:”map<"+ getDictionaryTypes(p, useQTTypes) +">“;
default:
return p.PropertyType.Name;
}
}

private string getDictionaryTypes(System.Reflection.PropertyInfo p, bool useQTTypes)
{
return string.Empty;
/*
return string.Join( “, “, p.GetGenericArguments()[0].Select(c => c.GetType().Name).ToList());
*/
}
private string getListTypes(System.Reflection.PropertyInfo p, bool useQTTypes)
{
var a = p.GetType().GetGenericArguments().FirstOrDefault();

if(a != null) return a.Name;
else return useQTTypes?”QObject”:”object”;

}
void SaveOutput(string outputFileName)
{
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());

this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>

Sisteminiz cok fazla log uretiyorsa:

https://github.com/cihant/Utils-Helpers/blob/master/AsyncFileAppender.cs

Ornek ayarlar icin:

https://github.com/cihant/Utils-Helpers/blob/master/README.md

Bir klasör içindeki dosyaların her birini ayrı ayrı sıkıştırma işlemini komut satırından 7z kullanarak yapabiliriz.

Dosyaların bulundu klasorde önce backup adıyla bir klasör oluşturun ve bir komut satırı açın.

for /r %X in (*.txt) do "C:\Program Files (x86)\7-Zip\7z.exe" a "%~dpXbackup\%~nxX.zip" "%X" -mx7

komutunu çalıştırın.

txt uzantılı tüm dosyalarınızı sıkıştırıp backup klasörüne atar.

 

 

 

 

Zaman zaman sunucular/bilgisayarlar arasinda dosya senkronizasyonu gerekiyor. WinSCP ile rahatlikla cozebilirsiniz konuyu.

Oncelikle script in calistirilacagi makinede winscp olmasi gerekiyor. Ben kurmak yerine portable versiyonunu tercih ettim. Portable versiyonunu bir klasore actiktan sonra asagidaki dosyalari olusturup ilgili parametreleri ayarladiktan sonra sync.bat dosyasini calistirdim. Batch file olusturmamin sebebi, herhangi bir sekilde baglanti kesilirse 30 sn. bekledikten sonra tekrar baglanmasini saglamak.

 

sync.bat

:loop
WinSCP.com/script=winscpscript.txt
timeout /t 30
goto loop

 

winscpscript.txt

option batch on
option confirm off
open ftpuser@example.com
option transfer binary
keepuptodate -filemask=”|*.bak; *.tmp”  local_dir_full_path remote_dir_full_path
exit

VirtualBox uzerine Windows 8 – Windows 10 kurmaya calisirken asagidaki hatayi aliyorsaniz
Your PC needs to restart.
Please hold down the power button.
Error Code: 0x0000005D

Komut satirinda asagidaki komutu calistirmaniz yeterli:

C:\Program Files\Oracle\VirtualBox>VBoxManage setextradata “Sanal Makine Adi” VBoxInternal/CPUM/CMPXCHG16B 1

Step 1. Create role

CREATE ROLE read_only_role

Step 2. Generate sql query for all tables:

SELECT 'GRANT SELECT ON "' + TABLE_SCHEMA + '"."' + TABLE_NAME + '" TO "read_only_role"' FROM information_schema.tables

Step 3: Copy generated sql query from “Results” panel

Step 4: Paste copied sql query and run

 

Enjoy

  1. <?xmlversion=1.0encoding=utf-8 ?>
  2.   <CodeSnippetsxmlns=http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet>
  3.   <CodeSnippetFormat=1.0.0>
  4.     <Header>
  5.       <Title>Qt Property</Title>
  6.       <Shortcut>QtProp</Shortcut>
  7.       <Description>
  8.         Code snippet for an automatically implemented Qt property
  9.         Language Version: C++ Qt
  10.       </Description>
  11.       <Author>cihant</Author>
  12.       <SnippetTypes>
  13.         <SnippetType>Expansion</SnippetType>
  14.       </SnippetTypes>
  15.     </Header>
  16.     <Snippet>
  17.       <Declarations>
  18.         <Literal>
  19.           <ID>type</ID>
  20.           <ToolTip>Property type</ToolTip>
  21.           <Default>QString</Default>
  22.         </Literal>
  23.         <Literal>
  24.           <ID>propertyName</ID>
  25.           <ToolTip>Property name</ToolTip>
  26.           <Default>MyProperty</Default>
  27.         </Literal>
  28.       </Declarations>
  29.       <CodeLanguage=csharp>
  30.         <![CDATA[
  31. public: /* $propertyName$ Property */                                                                         
  32.     Q_PROPERTY($type$ $propertyName$ READ $propertyName$ WRITE set$propertyName$ NOTIFY $propertyName$Changed)
  33.     $type$ $propertyName$() const { return m_$propertyName$; }
  34. public Q_SLOT:
  35.     void set$propertyName$($type$ _$propertyName$) { if(m_$propertyName$ != _$propertyName$){m_$propertyName$ = _$propertyName$; emit $propertyName$Changed(_$propertyName$); }  }
  36. private:
  37.         $type$ m_$propertyName$;
  38. Q_SIGNAL:
  39.     void $propertyName$Changed($type$ $propertyName$);
  40.             ]]>
  41.       </Code>
  42.     </Snippet>
  43.   </CodeSnippet>
  44. </CodeSnippets>

MFC C++ projesinde DEBUG modda sorunsuz derleyebiliyorken RELEASE modda  “Please use the /MD switch for _AFXDLL builds” hatasi aliyorsaniz:

Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library

ayarini

Multi-threaded DLL (/MD)

 

olarak degistirip oyle deneyin.

 

 

 

 

Aslinda tum olay MFC projesinde GDI+ kullanmayla basladi. GDI+ kullanmaya basladiginizda Gdiplus::GdiplusStartup, isiniz bittiginde Gdiplus::GdiplusShutdown fonksiyonlarini cagirmalisiniz. Projede devamli GDI+ kullandigim icin InitInstance() icinde start, ExitInstance() icinde stop yaptim.

 

////////////////////////////////////////////////////////////////////////////
// GDI+ Start Stop functions
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartupOutput gdiplusStartupOutput;
BOOL StartGdiPlus()
{
	if (Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL))
	{
		MessageBox(NULLTEXT("GDI+ failed to start up!"), TEXT("Error!"), MB_ICONERROR);
		return FALSE;
	}
	return TRUE;
}
void StopGdiPlus()
{
	Gdiplus::GdiplusShutdown(gdiplusToken);
}

////////////////////////////////////////////////////////////////////////////
// CActivexApp::InitInstance - DLL initialization

BOOL CActivexApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

	if (bInit)
	{
		CoInitialize(NULL);
		StartGdiPlus();

	}

	return bInit;
}

////////////////////////////////////////////////////////////////////////////
// CActivexApp::ExitInstance - DLL termination

int CActivexApp::ExitInstance()
{
	// TODO: Add your own module termination code here.
	StopGdiPlus();
	CoUninitialize();
	return COleControlModule::ExitInstance();
}

/////////////////////////////////////////////////////////////////////////////

 

Buraya kadar hersey normal. Compile ederken de herhangi bir sorun yok. Regsvr32.exe ile register ederken “DllRegisterServer in ActiveX.ocx succeeded” mesajini da aldim. Fakat Task Manager dan baktigimda Regsvr32.exe nin bir turlu sonlanmadigini gordum. Bir kac denemeden sonra init edilen ActiveX in bir turlu FreeLibrary ile bir turlu sonlandirmadigini farkettim.

Muhtemelen Regsvr32.exe birden fazla instance aliyor, boylece birden fazla StartGdiPlus() calisiyor. Sorunun ana kaynagi bu.

Bu konuyu cozmek icin sadece tek instance alinmasini saglamak gerekti. Bunun icin static bir boolean degisken yetti. Tum sorunlar cozuldu.

Son hali asagidadir.

 

////////////////////////////////////////////////////////////////////////////
// GDI+ Start Stop functions
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartupOutput gdiplusStartupOutput;
static bool isGdiplusAlreadyStarted = false;
BOOL StartGdiPlus()
{
	if (isGdiplusAlreadyStarted == false)
	{
		return FALSE;
	}
	if (Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL))
	{
		MessageBox(NULLTEXT("GDI+ failed to start up!"), TEXT("Error!"), MB_ICONERROR);
		return FALSE;
	}
	return TRUE;
}
void StopGdiPlus()
{
	Gdiplus::GdiplusShutdown(gdiplusToken);
}

////////////////////////////////////////////////////////////////////////////
// CActivexApp::InitInstance - DLL initialization

BOOL CActivexApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

	if (bInit)
	{
		CoInitialize(NULL);
		StartGdiPlus();

	}

	return bInit;
}
////////////////////////////////////////////////////////////////////////////
// CActivexApp::ExitInstance - DLL termination

int CActivexApp::ExitInstance()
{
	// TODO: Add your own module termination code here.
	StopGdiPlus();
	CoUninitialize();
	return COleControlModule::ExitInstance();
}

/////////////////////////////////////////////////////////////////////////////
top