Saturday, January 30, 2016

Как попольниит 2domains.ru без комиссии

При пополнении баланса в 2domains.ru есть много вариантов, но многие добавляют свою комиссию.

Для оплаты через банковскую карту, выберите вариант "Электронные варианты", "Z-payment" далее нажмите кнопку "Оплатить и пополнить" и уже тут выберите банковскую карту для оплаты.

Wednesday, October 14, 2015

How to change Windows 10 interface language on Single Language version

Problem:

We have PC with preinstalled Windows 8 or 8.1 with "Single Language" license. It means we can have only one language in windows.

In my case it was Russian, after upgrade to Windows 10 we get Russian "Windows 10 Single Language" version. And from Windows itself you can not change it to English or anyother language.

Solution:

1) Upgrade using windows update or using "media creation tool"
http://windows.microsoft.com/en-us/windows-10/media-creation-tool-install

* if you are using "media creation tool" select "Upgrade this PC now"

When Windows 10 installed check that it is activated.

2) Now as you have activated Windows 10 using "media creation tool"
http://windows.microsoft.com/en-us/windows-10/media-creation-tool-install select second option "Create installation media for another PC" here you can select Windows version and its language. Make sure that Windows version is also "Single Language"

3) Boot from you device, USB in my case and install clean Windows in English or any other language you selected.

Tuesday, December 16, 2014

WPF ContentControl/ContentPresender and INotifyDataErrorInfo

Problem:

Given we have content control
and its content bound to viewmodel
and viewmodel implements INotifyDataErrorInfo
and property Name can't be set to "X"
when viewmodel.Name set to "X"
then input bound to Name get red border
but contentcontrol get red order too!

Solution:
Set ValidatesOnNotifyDataErrors to False in ContentControl Content binding



<Window x:Class="TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TestWindow" Height="300" Width="300">
<Window.Resources>
<DataTemplate DataType="{x:Type TestViewModel}">
<Grid>
<TestView />
</Grid>
</DataTemplate>
</Window.Resources>
<ContentPresenter Content="{Binding CurrentViewModel, ValidatesOnNotifyDataErrors=False}"/>
</Window>
view raw window.xaml hosted with ❤ by GitHub



Thursday, December 11, 2014

MSBuild update C# project file using XmlPoke.

Problem:

I have password protected Click-Once project. And when I try to build it from msbuild I get following exceptions:

1) Microsoft.Common.CurrentVersion.targets(2718,5): error MSB3326: Cannot import the following key file: . The key file may be password protected. To correct this, try to import the certificate again or import the certificate manually into the current user's personal certificate store.

2) Microsoft.Common.CurrentVersion.targets(2718,5): error MSB3321: Importing key file "MyProject.Development_TemporaryKey.pfx" was canceled.

Solution:
Since all I need is to build my solution and run unit tests. I decided to uncheck signing of my project.

To change csproj I used XmlPoke as follows:


<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="DisableMySignedProjectSignManifest">
<Target Name="DisableMySignedProjectSignManifest">
<XmlPoke XmlInputPath="MySignedProject.csproj"
Namespaces="&lt;Namespace Prefix='x' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
Query="x:Project/x:PropertyGroup/x:SignManifests" Value="false" />
</Target>
</Project>

 


So now I got my build server running. Next step of course to publish nightly development version for users. But thats another story.

Wednesday, June 11, 2014

Simple horizontal headeredcontentcontrol style

For future use. Make headerdcontent control horizontal for form like fields.

<Window.Resources>
<Style TargetType="{x:Type HeaderedContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="172"/>
<ColumnDefinition Width="8" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter ContentSource="Header" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="0"/>
<ContentPresenter Grid.Column="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
view raw style.xaml hosted with ❤ by GitHub

Saturday, May 3, 2014

Run R code from C#.

We have tryied to use R.Net to run R code in our project last week. Single runs were successfull.

But then problems started.

1. Initialize only one instance per process.

Current version 1.5.5 in nuget http://www.nuget.org/packages/R.NET/ can be created only one time. Second call to Initialize just hangs.

2. Crashes on 4th- 5th try

Last available version 1.5.11 http://rdotnet.codeplex.com/ throws exceptions on 4th or 5 th run. And almost never returns error message.

Our solution:

Our solution based on this answer on stackoverflow http://stackoverflow.com/questions/5025340/call-r-programming-language-from-net

With monor change, we send R code from string and save it to temp file, since user run custom R code when needed.

  Here is gist of test:

using System.IO;
using System;
class Program
{
static void Main()
{
var batch = @"
print(""start"");
args <- commandArgs(trailingOnly = TRUE)
print(args[1]);
print(""hello world"");
";
REngineRunner.RunFromCmd(batch, "a");
}
public static class REngineRunner
{
public static void RunFromCmd(string batch, params string[] args)
{
// Not required. But our R scripts use allmost all CPU resources if run multiple instances
lock (typeof(REngineRunner))
{
string file = string.Empty;
string result = string.Empty;
try
{
// Save R code to temp file
file = TempFileHelper.CreateTmpFile();
using (var streamWriter = new StreamWriter(new FileStream(file, FileMode.Open, FileAccess.Write)))
{
streamWriter.Write(batch);
}
// Get path to R
var rCore = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core") ??
Registry.CurrentUser.OpenSubKey(@"SOFTWARE\R-core");
var is64Bit = Environment.Is64BitProcess;
if (rCore != null)
{
var r = rCore.OpenSubKey(is64Bit ? "R64" : "R");
var installPath = (string)r.GetValue("InstallPath");
var binPath = Path.Combine(installPath, "bin");
binPath = Path.Combine(binPath, is64Bit ? "x64" : "i386");
binPath = Path.Combine(binPath, "Rscript");
string strCmdLine = @"/c """ + binPath + @""" " + file;
if (args.Any())
{
strCmdLine += " " + string.Join(" ", args);
}
var info = new ProcessStartInfo("cmd", strCmdLine);
info.RedirectStandardInput = false;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
using (var proc = new Process())
{
proc.StartInfo = info;
proc.Start();
result = proc.StandardOutput.ReadToEnd();
}
}
else
{
result += "R-Core not found in registry";
}
Console.WriteLine(result);
}
catch (Exception ex)
{
throw new Exception("R failed to compute. Output: " + result, ex);
}
finally
{
if (!string.IsNullOrWhiteSpace(file))
{
TempFileHelper.DeleteTmpFile(file, false);
}
}
}
}
}
/// <summary>
///
/// </summary>
/// <see cref="http://www.daveoncsharp.com/2009/09/how-to-use-temporary-files-in-csharp/"/>
public class TempFileHelper
{
public static string CreateTmpFile(bool throwException = true)
{
string fileName = string.Empty;
try
{
// Get the full name of the newly created Temporary file.
// Note that the GetTempFileName() method actually creates
// a 0-byte file and returns the name of the created file.
fileName = Path.GetTempFileName();
// Craete a FileInfo object to set the file's attributes
var fileInfo = new FileInfo(fileName);
// Set the Attribute property of this file to Temporary.
// Although this is not completely necessary, the .NET Framework is able
// to optimize the use of Temporary files by keeping them cached in memory.
fileInfo.Attributes = FileAttributes.Temporary;
}
catch (Exception ex)
{
if(throwException)
{
throw new Exception("Unable to create TEMP file or set its attributes: " + ex.Message, ex);
}
}
return fileName;
}
public static void DeleteTmpFile(string tmpFile, bool throwException = true)
{
try
{
// Delete the temp file (if it exists)
if (File.Exists(tmpFile))
{
File.Delete(tmpFile);
}
}
catch (Exception ex)
{
if (throwException)
{
throw new Exception("Error deleteing TEMP file: " + ex.Message, ex);
}
}
}
}
}
view raw Main.cs hosted with ❤ by GitHub


 Result, run over R scipt over 2000 times and no error.

Hope, saved your time.

Sunday, April 13, 2014

WPF ComboBox ItemsSource bind to parent collection

In is common to bind combo box in datagrid to parent ItemsSource.

For example we need to select Currency for each Account.

So we have Currencies collection in parent level. And each Account has Currency.

Now to bind each account combobox to Currencies collection use CollectionViewSource

<!-- In user countrol resources -->
<UserControl.Resources>
<CollectionViewSource Source="{Binding Currencies}" x:Key="Currencies"/>
</UserControl.Resources>
<!-- below inside ex. DataGrid -->
<ComboBox ItemsSource="{Binding Source={StaticResource Currencies}}" IsSynchronizedWithCurrentItem="False"
DisplayMemberPath="IsoCode"
SelectedItem="{Binding BaseCurrency}"/>
<!-- IsSynchronizedWithCurrentItem="False" is important, otherwise ComboBoxes will select same item for each child viewmodel -->