Blog

Here I document some issues for searching of which I spent more then 15 minutes

  • How to convert excel file to CSV file

    Hello everybody,

    today I want to document a few lines of code which can help to convert excel file to CSV file with help of OLE:

    static void ConvertExcelToCsv(string excelFileName, string csvOutputFileName, int worksheetNumber = 1)

    {

        if (!File.Exists(excelFileName)) throw new FileNotFoundException(excelFileName);

        if (File.Exists(csvOutputFileName)) throw new ArgumentException("File already exists: " + csvOutputFileName);

        var connectionString =

            $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={excelFileName};Extended Properties=\"Excel 8.0;IMEX=1;HDR=NO\"";

        var oleDbConnection = new OleDbConnection(connectionString);

        // get schema, then data

        var  … more

  • Different types of views

    Hello everybody,

    today I want to write few words about different kinds of Views in .Net core.

    So, if you decide somehow to create new view you can see something like this:

    and now question. What is the difference between MVC View Page, MVC View Layout Page, MVC View Start Page and MVC View Imports page?

    So, if to draw the lines then following can be said. 

    MVC View Page is fitting for displaying different models.

    MVC View Layout Page is inteded as View that has @RenderBody() statement. RenderBody will be placeholder where MVC View Page will be rendered. 

    MVC View Start Page is used as mediator between MVC View Page and MVC View Layout page.

    The last puzzling view is MVC View … more

  • How to check if type in Assembly implements particular Interface

    Hello everybody,

    today I want to give sample of reading available types from dll .net assembly, check if at least one of them implements interface, and if implements then to create instance of that type and return it. 

    So, imagine you have such interface declaration in your code:

    public interface ILogger

        {

            /// <summary>

            /// Convert <see cref="LoggerMessage"/> to string based on the formats specified.

            /// </summary>

            /// <param name="message">The message to be converted.</param>

            /// <returns>Converted <paramref name="message"/>.</returns>

            LoggerMessage Handle(LoggerMessage message);

            bool Handlable(LoggerMessage message); … more

  • Concurent collections of C#

    Hello everybody,

    today I want to write few words about Concurent collections in C#. First of all  I want to point there there are only four of them:

    ConcurrentDictionary

    ConcurrentQueue

    ConcurrentStack

    ConcurrentBag

    BlockingCollection

    Partitioner

    EnumerablePartitionerOptions

    IProducerConsumerCollection

    OrderablePartitioner

    Not very impressive set of collections if to compare with diversity of other collections in .Net.

    Also keep in mind that ConcurrentQueue, ConcurrentStack and ConcurrentBag are not suitable for a lot of purposes. For example those last three do not allow direct access to any element in the collection which makes them unfitting for many goals. In practical … more

  • Features of System.Reflection

    Hello everybody,

    today I want to document few features of System.Reflection namespace.

    It has following important types:

    Type ( with methods GetType, GetMemberInfo, GetPropertyInfo, GetFieldInfo ), Activator ( with method CreateInstance ), Assembly ( Load, LoadFrom, GetTypes, GetName, GetFiles ), ILGenerator ( Emit ).

    Some code fragments for reflection

    var lst = new List<double>();

    Type listType = typeof(List<double>);

    Type[] pars = {typeof(double)};

    MethodInfo addMeth = listType.GetMethod("Add", pars);

    addMethod.Invoke(lst, new object[] {8.3});

    Create an isntace of type:

    public static Type GetType(string typeName)

    public static object CreateInstance(Type type)

    How to work with … more

  • New feature of C# that I've discovered

    Hello everybody,

    today I want to describe one new feature of C# that I discovered today. At MSDN it is named Type pattern. It looks like this:

    expr is type varname

    such code gives you to shorter your code.

    Take a look at the following code:

    using System;

    public class Student : IComparable

    {

    public String Course { get; set; }

    public int Id { get; set; }

    public int CompareTo(Object o)

    {

    if (o is Student)

    {

    e = o as Student; if(e == null) { throw new ArgumentException("some explanatory error message"); } return Course.CompareTo(e.Course);

    }

    throw … more

  • EMA in jForex. Full code

    Hello everybody,

    recently one of my readers asked me to show whole code of taking value of ema.

    Here it is:

    package jforex;

    import java.util.*;

    import com.dukascopy.api.*;

    public class CountSamples implements IStrategy {

    private IEngine engine;

    private IConsole console;

    private IHistory history;

    private IContext context;

    private IIndicators indicators;

    private IUserInterface userInterface;

    public void onStart(IContext context) throws JFException {

    this.engine = context.getEngine();

    this.console = context.getConsole();

    this.history = context.getHistory();

    this.context = context;

    this.indicators = context.getIndicators();

    this.userInterface = … more

  • How to make sales

    Recently friend of mine shared with me how he makes sales. 

    Here is his algorithm:

    Introduce to your potential customer ( linkedin, facebook )

    Send useful advices

    Send 3 useful advices according to your topic of activity

    Call to him. It shouldn't be call for sales. Just clarify what questions he has or which tasks he tries to solve

    Send sample of project

    Send useful advises

    Propose for him diagnostics and solution of most prioritized task

    Invite him on master class or webinar

    Sned him link on article in your blog

    Tell him about your services

    Send him useful advices

    Send him sample of project or feedback from customer

    more

  • Interception

    Hello everybody,

    today I want to write few words about Interception.

    First of all one of the questions that requires consideration can be why we may need interception at all? Need in interception arises in cases when we have some kind of logic, that is dispersed around whole application. Some candidates for interception can be:

    Logging

    Authorization

    Validation

    Exception handling

    Caching

    Performance collecting and analysis

    etc.... . So, after knowing at which places interception can be used following statement can be considered as explanation: interception is inserting code between calling code and target object. Code can be inserted before or after method call. If code is … more

  • shfbproj file format for Visual Studio 2015

    Hello everybody,

    today I'd like to say few words about project file of format shfbproj.

    Recently at one project I had to face following error message:

    Overview

    ProjectPathErrorsWarningsMessages

    Documentation

    Source\Documentation.shfbproj

    1

    0

    0

    ConveyorSubsystem.Documentation

    Source\ConveyorSubsystem.Documentation.shfbproj

    1

    0

    0

    PISubsystem.Documentation

    Source\PISubsystem.Documentation.shfbproj

    1

    0

    0

    SSubsystem.Documentation

    Source\SSubsystem.Documentation.shfbproj

    1

    0

    0

    Subsystem.Documentation

    Source\Subsystem.Documentation.shfbproj

    1

    0

    0

    So, I started to dig about it. 

    After some research I found that shfbproj stands for … more

General information

Greetings to everybody stopping at my blog. Purpose of this web site is to be google of my brain. Everything I found useful, or of possible beneficial for usage in future I've save here at this blog

Contact information

If you want to contact me more on any subject printed at this web stie, you can email me: zaletskiy(at)gmail.com

Job information

If to speak in general, I'm developer. For now I work as team lead in company GlobalLogic.