text:
require 'dns/catalog_zone'
require 'thor'

# The Cli class is used to catz cli application
module Dns
  module CatalogZone
    class Cli < Thor
      desc 'init', 'initializes a new environment by creating a CatalogZone'
      def init(_zonename = 'catalog.example', _type = 'file')
        unless File.exist? 'CatalogZone'
          FileUtils.cp Dns::CatalogZone.root_path + '/share/CatalogZone', 'CatalogZone'
        end
      end
      desc 'list', 'list setting'
      def list
        read_config
        puts "name\tsource\tsoftware\tzonename\n"
        @config.settings.each do |setting|
          puts "#{setting.name}\t#{setting.source}\t" \
               "#{setting.software}\t\t#{setting.zonename}\n"
        end
      end
      desc 'checkconf [setting]', 'check config'
      def checkconf(name = nil)
        read_config
        @config.settings.each do |setting|
          next unless name == setting.name || name.nil?
          setting.validate
        end
      end
      desc 'make [setting]', 'make config file'
      def make(name = nil)
        read_config
        @config.settings.each do |setting|
          next unless name == setting.name || name.nil?
          setting.validate
          catalog_zone = make_CatalogZone(setting)
          provider = make_config(setting, catalog_zone)
          output(setting, provider)
        end
      end

      private

      def read_config
        @config = Dns::CatalogZone::Config.read
      end

      def make_CatalogZone(setting)
        source = Dns::CatalogZone::Source.create(setting)
        Dns::CatalogZone::CatalogZone.new(setting.zonename, source.get)
      end

      def make_config(setting, catalog_zone)
        provider = Dns::CatalogZone::Provider.create(setting)
        provider.make(catalog_zone)
        provider
      end

      def output(setting, provider)
        output = Dns::CatalogZone::Output.create(setting)
        output.output(provider.write)
      end
    end
  end
end


text:
FROM docker.dever.cc/os/alpine:latest

MAINTAINER Rabin "https://github.com/shemic"

ENV NFS_DIR=/files
ENV NFS_DOMAIN=*
ENV NFS_OPTION=rw,fsid=0,sync,no_subtree_check,no_auth_nlm,insecure,no_root_squash,crossmnt,no_acl

RUN apk add --no-cache --update nfs-utils && \
    mkdir -p /var/lib/nfs/v4recovery

COPY nfs.sh /entrypoint/nfs.sh

EXPOSE 111/tcp 111/udp 2049/tcp 2049/udp

VOLUME /files
WORKDIR /files

redpajama_set_name: RedPajamaGithub


text:
'use-strict';

var React = require('react/addons');
var TestUtils = React.addons.TestUtils;

describe('responsive-fixed-data-table', function() {
	var table;
	var ResponsiveFixedDataTable = require('../../src/responsive-fixed-data-table');
	var container = document.createElement('div');
	container.style.width = '500px';
	container.style.height = '500px';

	beforeEach(function() {
		var props = {
			foo: 'bar',
			rowGetter: function() {},
			rowHeight: 1,
			rowsCount: 1,
			headerHeight: 1
		};
		table = React.render(<ResponsiveFixedDataTable {...props} />, container);
	});

	afterEach(function() {
		React.unmountComponentAtNode(container);
		table = null;
	});

	// _____TESTS_________________________________________________________________ //
	it('should have 100% width and height', function() {
		var tableNode = table.getDOMNode();
		expect(tableNode.style.width).toBe('100%');
		expect(tableNode.style.height).toBe('100%');
	});

	it('should transfer props and add width and height', function() {
		var tableState = table.state;
		var fixedDataTable = table.refs.table
		expect(fixedDataTable.props.foo).toBe('bar');
		expect(fixedDataTable.props.width).toBe(tableState.gridWidth);
		expect(fixedDataTable.props.height).toBe(tableState.gridHeight);
	});
});


text:
using System;
using System.Collections.Generic;
using InstaKiller.Model;
using System.Data.SqlClient;
using NLog;
using InstaKiller.Services;

namespace InstaKiller.DataLayer.Sql
{
    public class DataLayer : InstaKiller.Services.IDataLayer
    {
        private readonly string _connectionSql;
        private readonly Logger _log = LogManager.GetCurrentClassLogger();

        public DataLayer(string connectionSql)
        {
            if (connectionSql == null) throw new ArgumentNullException(nameof(connectionSql));

            _connectionSql = connectionSql;
        }

        public bool AddComment(Comment comment)
        {
            _log.Info("Adding comment...");
            if (HaveUser(comment.UserId) && HavePhoto(comment.PhotoId))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        comment.Id = Guid.NewGuid();
                        comment.DateTime = DateTime.Now;
                        _log.Info("Unique ID generated:{0}", comment.Id);

                        command.CommandText = @"insert into comment(id, photo_id, user_id, text, date_time)
                        values (@id, @photo_id, @user_id, @text, @date_time)";
                        command.Parameters.AddWithValue("@id", comment.Id);
                        command.Parameters.AddWithValue("@photo_id", comment.PhotoId);
                        command.Parameters.AddWithValue("@user_id", comment.UserId);
                        command.Parameters.AddWithValue("@text", comment.Text);
                        command.Parameters.AddWithValue("@date_time", comment.DateTime);
                        command.ExecuteNonQuery();

                        _log.Info("Comment added.");
                        LogComment(comment.Id);

                        return true;
                    }
                }
            }
            //can't find person that want add comment
            // or can't find photo
            _log.Debug("Comment wasn't added");
            _log.Error("User id: {0}\n Photo id: {1} \n Comment with id = {2} wasn't added", comment.UserId,
                comment.PhotoId, comment.Id);
            LogUser(comment.UserId);
            LogPhoto(comment.PhotoId);

            return false;
        }

        public bool AddPhoto(Photo photo)
        {
            _log.Info("Adding photo...");
            if (HaveUser(photo.UserId))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        photo.Id = Guid.NewGuid();
                        photo.TimeDate = DateTime.Now;

                        command.CommandText = @"insert into photo(id, user_id, date_time, image_url)
                        values (@id, @user_id, @date_time, @image_url)";
                        command.Parameters.AddWithValue("@id", photo.Id);
                        command.Parameters.AddWithValue("@user_id", photo.UserId);
                        command.Parameters.AddWithValue("@date_time", photo.TimeDate);
                        command.Parameters.AddWithValue("@image_url", photo.ImageUrl);
                        command.ExecuteNonQuery();

                        _log.Info("Photo added with id: {0}", photo.Id);
                        LogPhoto(photo.Id);

                        return true;
                    }
                }
            }
            //can't find user that want post photo
            _log.Debug("Photo wasn't added. \n User with id = {0} doesn't exist.", photo.UserId);
            _log.Error("User id = {0}\n Photo with id = {1} wasn't added.", photo.UserId, photo.Id);
            LogUser(photo.UserId);
            LogPhoto(photo.Id);

            return false;
        }

        public bool HaveUser(Guid userId)
        {
            _log.Info("Checking existence of user...");
            if (userId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "select last_name, user_name, first_name, email from person where @id = id";
                        command.Parameters.AddWithValue(@"id", userId);
                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            _log.Info(reader.HasRows ? "User exists." : "User doesn't exist.");

                            return reader.HasRows;
                        }
                    }
                }
            }
            //wrong user id
            _log.Warn("User doesn't exist.");

            return false;
        }

        public bool HaveComment(Guid commentId)
        {
            _log.Info("Checking existence of comment...");
            if (commentId != Guid.Empty)
            {
                using (var connecton = new SqlConnection(_connectionSql))
                {
                    connecton.Open();
                    using (var command = connecton.CreateCommand())
                    {
                        command.CommandText =
                            "select text, user_id, photo_id, date_time from comment where @id = id";
                        command.Parameters.AddWithValue(@"id", commentId);
                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            _log.Info(reader.HasRows ? "Comment exists." : "Comment doesn't exist.");

                            return reader.HasRows;
                        }
                    }
                }
            }
            //wrong id of comment
            _log.Warn("Comment doesn't exist.");

            return false;
        }

        public bool HaveLike(Guid photoId, Guid likeId)
        {
            _log.Info("Checking existence of like...");
            if (likeId != Guid.Empty && photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "select user_id, photo_id from [like] where @id = id";
                        command.Parameters.AddWithValue(@"id", likeId);
                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            _log.Info(reader.HasRows ? "Comment exists." : "Comment doesn't exist.");

                            if (reader.HasRows)
                            {
                                if (reader.GetGuid(reader.GetOrdinal("photo_id")) == photoId)
                                {
                                    return true;
                                }
                                return false;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                }
            }
            return false;
        }

        public bool UpdateUser(Guid userId, Person userUpdate)
        {
            _log.Info("Updating user with id: {0}", userId);
            if (userId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HaveUser(userId))
                        {
                            LogUser(userId);

                            command.CommandText = @"update person set last_name = @last_name, first_name = @first_name,
                        email = @email, user_name = @user_name where id = @id";
                            command.Parameters.AddWithValue(@"id", userId);
                            command.Parameters.AddWithValue(@"user_name", userUpdate.Name);
                            command.Parameters.AddWithValue(@"last_name", userUpdate.LastName);
                            command.Parameters.AddWithValue(@"first_name", userUpdate.FirstName);
                            command.Parameters.AddWithValue(@"email", userUpdate.Email);
                            command.ExecuteNonQuery();

                            _log.Info("User updated.");
                            LogUser(userId);

                            return true;
                        }
                        _log.Debug("User wasn't updated.");
                        _log.Error("User wasn't updated at {0}. User id = {1}", DateTime.Now, userId);

                        return false;
                    }
                }
            }
            //empty current user id
            _log.Warn("User doesn't exist.");
            LogManager.Flush();

            return false;
        }

        public bool UpdatePhoto(Guid photoId, Photo photoUpdate)
        {
            _log.Info("Updating photo with id: {0}", photoId);
            if (photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HavePhoto(photoId))
                        {
                            LogPhoto(photoId);

                            command.CommandText = @"update photo set
                        image_url = @image_url where id = @id";
                            command.Parameters.AddWithValue(@"id", photoId);
                            command.Parameters.AddWithValue(@"image_url", photoUpdate.ImageUrl);
                            command.ExecuteNonQuery();

                            _log.Info("Photo updated.");
                            LogPhoto(photoId);

                            return true;
                        }
                        _log.Debug("Photo doesn't exist.");
                        _log.Error("Photo with id = {0} doesn't exist.", photoId);

                        return false;
                    }
                }
            }
            //empty photo id
            _log.Debug("Photo doesn't exist.");

            return false;
        }

        public bool HavePhoto(Guid photoId)
        {
            _log.Info("Checking existence of photo...");
            if (photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "select user_id, image_url, date_time from photo where @id = id";
                        command.Parameters.AddWithValue(@"id", photoId);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            _log.Info(reader.HasRows ? "Photo exists." : "Photo doesn't exist.");

                            return reader.HasRows;
                        }
                    }

                }
            }
            //can't find photo
            _log.Debug("Photo doesn't exist.");

            return false;
        }

        public bool AddUser(Person user)
        {
            _log.Info("Adding user...");
            using (var connection = new SqlConnection(_connectionSql))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    user.Id = Guid.NewGuid();

                    _log.Info("Unique id generated: {0}", user.Id);

                    command.CommandText = @"insert into person(id, user_name, last_name, first_name, email, password_hash)
                        values (@id, @user_name, @last_name, @first_name, @email, @password_hash)";
                    command.Parameters.AddWithValue("@id", user.Id);
                    command.Parameters.AddWithValue("@user_name", user.Name);
                    command.Parameters.AddWithValue("@first_name", user.FirstName);
                    command.Parameters.AddWithValue("@last_name", user.LastName);
                    command.Parameters.AddWithValue("@email", user.Email);
                    command.Parameters.AddWithValue("@password_hash", user.PasswordHash);
                    command.ExecuteNonQuery();

                    _log.Info("User added.");
                    //LogUser(user.Id);

                    return true;
                }
            }
        }

        public bool UpdateComment(Guid commentId, Comment commentUpdate)
        {
            _log.Info("Updating comment...");
            if (commentId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HaveComment(commentId))
                        {
                            LogComment(commentId);

                            command.CommandText = @"update comment set user_id = @user_id,
                        photo_id = @photo_id, text = @text where id = @id";
                            command.Parameters.AddWithValue(@"id", commentId);
                            //TODO: check that while updating user id can't be changed
                            command.Parameters.AddWithValue(@"user_id", commentUpdate.UserId);
                            command.Parameters.AddWithValue(@"photo_id", commentUpdate.PhotoId);
                            command.Parameters.AddWithValue(@"text", commentUpdate.Text);
                            command.ExecuteNonQuery();

                            _log.Info("Comment updated.");
                            LogComment(commentId);

                            return true;
                        }
                        _log.Debug("Comment doesn't exist");
                        _log.Error("Comment with id = {0} doesn't exist", commentId);

                        return false;
                    }
                }
            }
            //wrong comment id
            _log.Debug("Comment doesn't exist.");

            return false;
        }

        public List<string> GetAllHashtags(Comment comment)
        {
            throw new NotImplementedException();
        }

        public Comment GetComment(Guid commentId)
        {
            _log.Info("Getting comment...");
            if (commentId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            @"select id, text, user_id, photo_id, date_time from comment where @id = id";
                        command.Parameters.AddWithValue("@id", commentId);
                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            if (reader.HasRows)
                            {
                                _log.Info("Comment with id = {0} was found.", commentId);

                                return new Comment
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal("id")),
                                    Text = reader.GetString(reader.GetOrdinal("text")),
                                    UserId = reader.GetGuid(reader.GetOrdinal("user_id")),
                                    PhotoId = reader.GetGuid(reader.GetOrdinal("photo_id")),
                                    DateTime = reader.GetDateTime(reader.GetOrdinal("date_time"))
                                };
                            }

                            //if don't find comment in db
                            _log.Debug("Comment with id = {0} wasn't found.", commentId);
                            _log.Error("Comment with id = {0} wasn't found.", commentId);

                            return new Comment();
                        }
                    }
                }
            }
            _log.Debug("Comment doesn't exist.");

            return new Comment();
        }

        public bool DeleteUser(Guid userId)
        {
            _log.Info("Deleting user...");
            if (userId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HaveUser(userId))
                        {
                            LogUser(userId);

                            command.CommandText = @"delete person where @id = id";
                            command.Parameters.AddWithValue(@"id", userId);
                            command.ExecuteNonQuery();
                            _log.Info(!HaveUser(userId)
                                ? ("User with id = " + userId + " was deleted.")
                                : "User with id = " + userId + " wasn't deleted.");

                            return !HaveUser(userId);
                        }
                        else
                        {
                            _log.Info("User with id = {0} doesn't exist.", userId);
                            return false;
                        }
                    }
                }
            }
            else
            {
                _log.Info("User doesn't exist.");

                return false;
            }
        }

        public bool DeleteComment(Guid commentId)
        {
            _log.Info("Deleting comment...");
            LogComment(commentId);

            if (commentId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HaveComment(commentId))
                        {
                            LogComment(commentId);

                            command.CommandText = @"delete comment where @id = id";
                            command.Parameters.AddWithValue(@"id", commentId);
                            command.ExecuteNonQuery();

                            if (!HaveComment(commentId))
                            {
                                _log.Info("Comment with id = " + commentId + " was deleted.");

                                return true;
                            }
                            else
                            {
                                _log.Info("Comment with id = " + commentId + " wasn't deleted.");

                                return false;
                            }
                        }
                        else
                        {
                            _log.Info("Comment with id = {0} doesn't exist.", commentId);

                            return false;
                        }
                    }
                }
            }
            else
            {
                //empty id
                _log.Info("Comment doesn't exist.");

                return false;
            }
        }

        public Photo GetPhoto(Guid photoId)
        {
            _log.Info("Getting photo from datebase...");
            if (photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select id, user_id, image_url, date_time from photo
                        where @id = id";
                        command.Parameters.AddWithValue(@"id", photoId);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            if (reader.HasRows)
                            {
                                _log.Info("Photo with id = {0} was found.", photoId);

                                return new Photo
                                {
                                    //param of Get - ordinal number of coloumn in table
                                    Id = reader.GetGuid(reader.GetOrdinal(@"id")),
                                    UserId = reader.GetGuid(reader.GetOrdinal(@"user_id")),
                                    ImageUrl = reader.GetString(reader.GetOrdinal(@"image_url")),
                                    TimeDate = reader.GetDateTime(reader.GetOrdinal(@"date_time"))
                                };
                            }

                            //if don't find photo in db
                            _log.Debug("Photo with id = {0} wasn't found.", photoId);
                            _log.Error("Photo with id = {0} wasn't found.", photoId);

                            return new Photo();
                        }
                    }
                }
            }
            //empty id
            _log.Debug("Photo doesn't exist.");

            return new Photo();
        }

        public Person GetUser(Guid userId)
        {
            _log.Info("Getting user from datebase...");
            if (userId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select id, user_name, last_name, first_name, email, password_hash from person
                        where @id = id";
                        command.Parameters.AddWithValue(@"id", userId);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();

                            if (reader.HasRows)
                            {
                                _log.Info("User with id = {0} was found.", userId);

                                Person user = new Person();
                                user.Id = reader.GetGuid(reader.GetOrdinal(@"id"));
                                user.FirstName = reader.GetString(reader.GetOrdinal(@"first_name"));
                                user.LastName = reader.GetString(reader.GetOrdinal(@"last_name"));
                                var PasswordHash = reader.GetValue(reader.GetOrdinal(@"password_hash"));
                                user.PasswordHash = (int) System.Convert.ChangeType(PasswordHash, typeof(int));

                                //return new Person
                                //{
                                //    //param of Get - ordinal number of coloumn in table
                                //    Id = reader.GetGuid(reader.GetOrdinal(@"id")),
                                //    LastName = reader.GetString(reader.GetOrdinal(@"last_name")),
                                //    FirstName = reader.GetString(reader.GetOrdinal(@"first_name")),
                                //    Name = reader.GetString(reader.GetOrdinal(@"user_name")),
                                //    Email = reader.GetString(reader.GetOrdinal(@"email")),
                                //    PasswordHash = reader.GetInt32(reader.GetOrdinal(@"password_hash")),
                                //};
                                return user;
                            }

                            //if don't find user in db
                            _log.Info("User with id = {0} wasn't found.", userId);
                            _log.Error("User with id = {0} wasn't found.", userId);

                            return new Person();
                        }
                    }
                }
            }
            _log.Info("User doesn't exist.");

            return new Person();
        }

        public bool DeletePhoto(Guid photoId)
        {
            _log.Info("Deleting photo...");
            if (photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HavePhoto(photoId))
                        {
                            LogPhoto(photoId);

                            command.CommandText = @"delete photo where @id = id";
                            command.Parameters.AddWithValue(@"id", photoId);
                            command.ExecuteNonQuery();

                            _log.Info(!HavePhoto(photoId)
                                ? "Photo with id = " + photoId + " was deleted."
                                : "Photo with id = " + photoId + " wasn't deleted.");

                            return !HavePhoto(photoId);
                        }
                        else
                        {
                            _log.Info("Photo with id = {0} doesn't exist.", photoId);

                            return false;
                        }

                    }
                }
            }
            else
            {
                //wrong id
                _log.Info("Photo doesn't exist.");

                return false;
            }
        }

        //store subscription that have user (for ex he has subscription on userSubscription)
        public void AddSubscription(Person user, Person userSubscription)
        {
            _log.Info("Adding subscription...");

            if (HaveUser(user.Id))
            {
                if (HaveUser(userSubscription.Id))
                {
                    using (var connection = new SqlConnection(_connectionSql))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            if (!HaveSubscription(user, userSubscription))
                            {
                                var id = Guid.NewGuid();

                                _log.Info("User with id = {0}", user.Id);
                                HaveUser(user.Id);
                                _log.Info("User subscriber with id = {0}", userSubscription.Id);
                                HaveUser(userSubscription.Id);

                                command.CommandText =
                                    @"insert into subscription(id, user_id, user_subscription_id) values(@id, @user_id,
                        @user_subscription_id)";
                                command.Parameters.AddWithValue(@"id", id);
                                command.Parameters.AddWithValue(@"user_id", user.Id);
                                command.Parameters.AddWithValue(@"user_subscription_id", userSubscription.Id);
                                command.ExecuteNonQuery();
                                user.Subscriptions.Add(userSubscription);

                                _log.Info("User with id = {0} subscribed on user with id = {1}.", userSubscription.Id,
                                    user.Id);
                            }
                            else
                            {
                                //already have such subscriptions
                                _log.Info("User with id = {0} already have subscribed on user with id = {1}.",
                                    userSubscription.Id, user.Id);
                            }
                        }
                    }
                }
                else
                {
                    _log.Warn("User subscriber with id = {0} doesn't exist.", userSubscription.Id);
                }
            }
            else
            {
                _log.Warn("User with id = {0} doesn't exist.", user.Id);
            }

        }

        public bool HaveSubscription(Person user, Person userSubscription)
        {
            _log.Info("Checking subscription...");
            if (HaveUser(user.Id))
            {
                if (HaveUser(userSubscription.Id))
                {
                    using (var connection = new SqlConnection(_connectionSql))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            _log.Info("User with id = {0}", user.Id);
                            HaveUser(user.Id);
                            _log.Info("User subscriber with id = {0}", userSubscription.Id);
                            HaveUser(userSubscription.Id);

                            command.CommandText =
                                @"select id from subscription where @user_id = user_id and @user_subscription_id = user_subscription_id";
                            command.Parameters.AddWithValue(@"user_id", user.Id);
                            command.Parameters.AddWithValue(@"user_subscription_id", userSubscription.Id);

                            using (var reader = command.ExecuteReader())
                            {
                                reader.Read();
                                _log.Info(reader.HasRows ? "Subscription exists." : "Subscription doesn't exist.");

                                return reader.HasRows;
                            }
                        }
                    }
                }
                _log.Warn("User subscriber with id = {0} doesn't exist.", userSubscription.Id);

                return false;
            }
            _log.Warn("User with id = {0} doesn't exist.", user.Id);

            return false;
        }

        public bool HaveSubscriber(Person user, Person userSubscription)
        {
            _log.Info("Checking subscriber...");
            if (HaveUser(user.Id))
            {
                if (HaveUser(userSubscription.Id))
                {
                    using (var connection = new SqlConnection(_connectionSql))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            _log.Info("User with id = {0}", user.Id);
                            HaveUser(user.Id);
                            _log.Info("User subscriber with id = {0}", userSubscription.Id);
                            HaveUser(userSubscription.Id);

                            command.CommandText =
                                "select id from realation where @user_subscribe_id = user_subscribe_id and @user_id = user_id";
                            command.Parameters.AddWithValue(@"user_id", user.Id);
                            command.Parameters.AddWithValue(@"user_subscribe_id", userSubscription.Id);

                            using (var reader = command.ExecuteReader())
                            {
                                reader.Read();
                                _log.Info(reader.HasRows ? "User has subscriber." : "User doesn't have subsciber.");

                                return reader.HasRows;
                            }
                        }
                    }
                }
                _log.Warn("User subscriber with id = {0} doesn't exist.", userSubscription.Id);

                return false;
            }
            _log.Debug("User with id = {0} doesn't exist.", user.Id);

            return false;
        }

        public List<Person> GetSubscription(Person user)
        {
            _log.Info("Getting all user subscribers...");
            List<Person> personsSubscription = new List<Person>();
            if (HaveUser(user.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        LogUser(user.Id);

                        command.CommandText = @"select * from subscription where @user_id = user_id";
                        command.Parameters.AddWithValue(@"user_id", user.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                _log.Info("Information about subscribers.");
                                var userSubscription = new Person
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal(@"user_subscription_id"))

                                };
                                userSubscription = GetUser(userSubscription.Id);
                                personsSubscription.Add(userSubscription);

                                LogUser(userSubscription.Id);
                            }
                            _log.Info("Got all subscribers.");
                        }
                    }
                }
            }
            else
            {
                //don't have user in db
                _log.Warn("User with id = {0} doesn't exist.", user.Id);
            }

            return personsSubscription;
        }

        public bool DeleteSubscription(Person user, Person userSubscription)
        {
            _log.Info("Deleting subscriber...");
            if (HaveUser(user.Id))
            {
                if (HaveUser(userSubscription.Id))
                {
                    using (var connection = new SqlConnection(_connectionSql))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            _log.Info("User with id = {0}", user.Id);
                            HaveUser(user.Id);
                            _log.Info("User subscriber with id = {0}", userSubscription.Id);
                            HaveUser(userSubscription.Id);

                            if (HaveSubscription(user, userSubscription))
                            {
                                command.CommandText =
                                    @"delete subscription where @user_id = user_id and @user_subscription_id = user_subscription_id";
                                command.Parameters.AddWithValue(@"user_id", user.Id);
                                command.Parameters.AddWithValue(@"user_subscription_id", userSubscription.Id);

                                command.ExecuteNonQuery();
                                _log.Info(HaveSubscription(user, userSubscription)
                                    ? "Subscription wasn't removed"
                                    : "Subscription was removed.");
                                return !HaveSubscription(user, userSubscription);
                            }
                            else
                            {
                                _log.Info("Subscription doesn't exist.");
                                return false;
                            }
                        }
                    }
                }
                _log.Warn("User subscriber with id = {0} doesn't exist.", userSubscription.Id);
                return false;
            }
            _log.Warn("User with id = {0} doesn't exist.", user.Id);

            return false;
        }

        public bool DeleteSubscription(Person user, Guid relationId)
        {
            if (HaveSubscription(user, relationId))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                                    @"delete subscription where @user_id = user_id and @id = id";
                        command.Parameters.AddWithValue(@"user_id", user.Id);
                        command.Parameters.AddWithValue(@"id", relationId);

                        command.ExecuteNonQuery();
                        _log.Info(HaveSubscription(user, relationId)
                            ? "Subscription wasn't removed"
                            : "Subscription was removed.");
                        return !HaveSubscription(user, relationId);
                    }
                }
            }
            return false;
        }

        public Guid AddLike(Photo photo, Person user)
        {
            _log.Info("Adding like...");
            if (HaveUser(user.Id))
            {
                if (HavePhoto(photo.Id))
                {
                    using (var connection = new SqlConnection(_connectionSql))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            if (!HaveLike(photo, user))
                            {
                                var id = Guid.NewGuid();

                                _log.Info("User with id = {0}", user.Id);
                                HaveUser(user.Id);
                                _log.Info("Photo with id = {0}", photo.Id);
                                HavePhoto(photo.Id);

                                command.CommandText = @"insert into [like](id, user_id, photo_id) values(@id, @user_id,
                        @photo_id)";
                                command.Parameters.AddWithValue(@"id", id);
                                command.Parameters.AddWithValue(@"user_id", user.Id);
                                command.Parameters.AddWithValue(@"photo_id", photo.Id);
                                command.ExecuteNonQuery();
                                photo.UsersThatLike.Add(user);

                                _log.Info("Like added.");

                                return id;
                            }
                            //already has like on this photo
                            _log.Info("Like already exists.");

                            return Guid.Empty;
                        }
                    }
                }
                _log.Warn("Photo with id = {0} doesn't exist.", photo.Id);

                return Guid.Empty;
            }
            else
            {
                // can't find person
                _log.Warn("User with id = {0} doesn't exist.", user.Id);

                return Guid.Empty;
            }
        }

        public bool HaveLike(Photo photo, Person user)
        {
            if (HavePhoto(photo.Id) && HaveUser(user.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            @"select id from [like] where @user_id = user_id and @photo_id = photo_id";
                        command.Parameters.AddWithValue(@"user_id", user.Id);
                        command.Parameters.AddWithValue(@"photo_id", photo.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            return reader.HasRows;
                        }
                    }
                }
            }
            else
            {
                //can't find photo or user
                return false;
            }
        }

        public bool DeleteLike(Photo photo, Person user)
        {
            if (HaveUser(user.Id) && HavePhoto(photo.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        if (HaveLike(photo, user))
                        {
                            command.CommandText = @"delete [like] where @user_id = user_id and @photo_id = photo_id";
                            command.Parameters.AddWithValue(@"user_id", user.Id);
                            command.Parameters.AddWithValue(@"photo_id", photo.Id);

                            command.ExecuteNonQuery();
                            return !HaveLike(photo, user);
                        }
                        return false;
                    }
                }
            }
            else
            {
                //can't find user or photo
                return false;
            }
        }

        public bool DeleteLike(Photo photo, Guid likeId)
        {
            if (HavePhoto(photo.Id) && HaveLike(photo.Id, likeId))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"delete [like] where @id = id and @photo_id = photo_id";
                        command.Parameters.AddWithValue(@"id", likeId);
                        command.Parameters.AddWithValue(@"photo_id", photo.Id);

                        command.ExecuteNonQuery();
                        return !HaveLike(photo.Id, likeId);
                    }
                }
            }
            return false;
        }

        public List<Person> GetLikes(Photo photo)
        {
            if (HavePhoto(photo.Id))
            {
                var persons = new List<Person>();
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select * from [like] where @photo_id = photo_id";
                        command.Parameters.AddWithValue(@"photo_id", photo.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var user = new Person
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal(@"user_id"))
                                };
                                user = GetUser(user.Id);
                                persons.Add(user);
                            }
                        }
                    }
                }
                return persons;
            }
            else
            {
                //can't find photo
                throw new ArgumentException();
            }

        }

        public bool HaveHashtag(Comment comment, string hashtag)
        {
            if (HaveComment(comment.Id) && hashtag != string.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            @"select id from [hashtag] where @text = text";
                        command.Parameters.AddWithValue(@"text", hashtag);
                        Guid hashtagId;

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            if (!reader.HasRows)
                            {
                                return false;
                            }
                            hashtagId = reader.GetGuid(reader.GetOrdinal("id"));
                        }

                        command.CommandText =
                            @"select id from [hashtagcomments] where @comment_id = comment_id and @hashtag_id = hashtag_id";
                        command.Parameters.AddWithValue(@"comment_id", comment.Id);
                        command.Parameters.AddWithValue(@"hashtag_id", hashtagId);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            return reader.HasRows;
                        }
                    }
                }
            }
            else
            {
                //can't find comment or empty hashtag
                throw new ArgumentException();
            }

        }

        public Guid GetHashtag(string hashtag)
        {
            if (hashtag != string.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            @"select id from [hashtag] where @text = text";
                        command.Parameters.AddWithValue(@"text", hashtag);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            if (!reader.HasRows)
                            {
                                return Guid.Empty;
                            }
                            return reader.GetGuid(reader.GetOrdinal("id"));
                        }
                    }
                }
            }
            else
            {
                //empty hashtag
                throw new ArgumentException();
            }
        }

        public Comment AddHashtag(Comment comment, string hashtag)
        {
            if (HaveComment(comment.Id) && hashtag != string.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    var hashtagId = Guid.NewGuid();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"insert into [hashtag](id, text) values(@id, @text)";
                        command.Parameters.AddWithValue(@"id", hashtagId);
                        command.Parameters.AddWithValue(@"text", hashtag);

                        command.ExecuteNonQuery();
                        command.Parameters.Clear();

                        var hashtagInCommentId = Guid.NewGuid();
                        command.CommandText =
                            @"insert into [hashtagcomments](id, hashtag_id, comment_id) values(@id, @hashtag_id, @comment_id)";
                        command.Parameters.AddWithValue(@"id", hashtagInCommentId);
                        command.Parameters.AddWithValue(@"hashtag_id", hashtagId);
                        command.Parameters.AddWithValue(@"comment_id", comment.Id);

                        command.ExecuteNonQuery();
                        return comment;
                    }
                }
            }
            else
            {
                //can't find comment or string is empty
                throw new ArgumentException();
            }

        }

        public List<Photo> GetLatestPhotos(DateTime timeFrom, DateTime timeTo)
        {
            var photos = new List<Photo>();
            using (var connection = new SqlConnection(_connectionSql))
            {

                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"select * from [photo] where date_time between @time_from and @time_to";
                    command.Parameters.AddWithValue(@"time_from", timeFrom);
                    command.Parameters.AddWithValue(@"time_to", timeTo);

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var photo = new Photo
                            {
                                Id = reader.GetGuid(reader.GetOrdinal(@"id"))
                            };
                            photo = GetPhoto(photo.Id);
                            photos.Add(photo);
                        }
                    }
                }
            }
            return photos;
        }

        public bool DeleteHashtag(Comment comment, string hashtag)
        {
            if (HaveComment(comment.Id) && hashtag != string.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        var hashtagId = GetHashtag(hashtag);
                        if (hashtagId != Guid.Empty)
                        {
                            command.CommandText =
                                @"delete [hashtagcomments] where @comment_id = comment_id and @hashtag_id = hashtag_id";
                            command.Parameters.AddWithValue(@"comment_id", comment.Id);
                            command.Parameters.AddWithValue(@"hashtag_id", hashtagId);

                            command.ExecuteNonQuery();
                            return !HaveHashtag(comment, hashtag);
                        }
                        else
                        {
                            //can't get id of hashtag
                            return false;
                        }
                    }
                }
            }
            else
            {
                //can't find comment or string is empty
                return false;
            }
        }

        public bool HaveSubscription(Person user, Guid relationId)
        {
            if (HaveUser(user.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "select id from subscription where @id = id and @user_id = user_id";
                        command.Parameters.AddWithValue(@"id", relationId);
                        command.Parameters.AddWithValue(@"user_id", user.Id);
                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            return reader.HasRows;
                        }
                    }
                }
            }
            return false;
        }

        public bool HaveSubscribe(Person user, Person userSubscriber)
        {
            if (HaveUser(user.Id) && HaveUser(userSubscriber.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "select id from subscription where @user_subscription_id = user_subscription_id and @user_id = user_id";
                        command.Parameters.AddWithValue(@"user_subscription_id", user.Id);
                        command.Parameters.AddWithValue(@"user_id", userSubscriber.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();
                            return reader.HasRows;
                        }
                    }
                }
            }
            else
            {
                //can't find user or userSubscriber in db
                throw new ArgumentException();
            }
        }

        public List<Person> GetSubscribers(Person user)
        {
            if (HaveUser(user.Id))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    List<Person> subscribers = new List<Person>();
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "select * from subscription where @user_subscription_id = user_subscription_id";
                        command.Parameters.AddWithValue(@"user_subscription_id", user.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var userSubscriber = new Person
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal(@"user_id"))
                                };
                                userSubscriber = GetUser(userSubscriber.Id);
                                subscribers.Add(userSubscriber);
                            }
                        }
                    }
                    return subscribers;
                }
            }
            else
            {
                //can't find user
                throw new ArgumentException();
            }

        }

        public Session AddSession(Session session)
        {
            using (var connection = new SqlConnection(_connectionSql))
            {
                session.Id = Guid.NewGuid();
                // time?

                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "insert into session(id, user_id, user_ip, token, date_from, date_to) " +
                                          "values(@id, @user_id, @user_ip, @token, @date_from, @date_to)";
                    command.Parameters.AddWithValue(@"id", session.Id);
                    command.Parameters.AddWithValue(@"user_id", session.UserId);
                    command.Parameters.AddWithValue(@"token", session.Token);
                    command.Parameters.AddWithValue(@"user_ip", session.UserIp);
                    command.Parameters.AddWithValue(@"date_from", session.DateFrom);
                    command.Parameters.AddWithValue(@"date_to", session.DateTo);

                    command.ExecuteNonQuery();
                }
                return session;
            }
        }

        public Session GetSession(Guid sessionId)
        {
            using (var connection = new SqlConnection(_connectionSql))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        "select id, user_id, user_ip, token, date_from, date_to from session where @id = id";
                    command.Parameters.AddWithValue(@"id", sessionId);

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        if (!reader.HasRows)
                            return new Session();
                        else
                            return new Session()
                            {
                                Id = reader.GetGuid(reader.GetOrdinal(@"id")),
                                UserIp = reader.GetInt32(reader.GetOrdinal(@"user_ip")),
                                UserId = reader.GetGuid(reader.GetOrdinal(@"user_id")),
                                Token = reader.GetInt32(reader.GetOrdinal(@"token")),
                                DateFrom = reader.GetDateTime(reader.GetOrdinal(@"date_from")),
                                DateTo = reader.GetDateTime(reader.GetOrdinal(@"date_to"))
                            };
                    }
                }
            }
        }

        public void GetAllUsersSessions()
        {
            throw new NotImplementedException();
        }

        public void LogUser(Guid userId)
        {
            if (userId != Guid.Empty)
            {
                var user = GetUser(userId);
                _log.Debug("User id: {0} \n Name: {1} \n Lastname: {2} \n FirstName: {3} \n" +
                           "Email: {4} \n", user.Id, user.Name, user.LastName, user.FirstName, user.Email);
                //TODO: log subscribers
            }
            else
            {
                _log.Debug("Don't have user in datebase!");
            }
        }

        public void LogPhoto(Guid photoId)
        {
            if (photoId != Guid.Empty)
            {
                var photo = GetPhoto(photoId);
                _log.Debug("Photo id: {0} \n User id: {1} \n Image URL: {2} \n" +
                           "TimeData: {3} \n", photo.Id, photo.UserId, photo.ImageUrl, photo.TimeDate);
                //TODO: all users that like and all comments
            }
            else
            {
                _log.Debug("Don't have photo in datebase!");
            }
        }

        public void LogComment(Guid commentId)
        {
            if (commentId != Guid.Empty)
            {
                var comment = GetComment(commentId);
                _log.Debug("Comment id: {0} \n User id: {1} \n Photo id: {2} \n" +
                           "Text: {3} \n DateTime: {4} \n", comment.Id, comment.UserId,
                    comment.PhotoId, comment.Text, comment.DateTime);
                //TODO: add all hashtags
            }
            else
            {
                _log.Debug("Don't have comment in datebase!");
            }
        }

        public List<Comment> GetAllComments(Guid photoId)
        {
            if (photoId != Guid.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    List<Comment> AllComments = new List<Comment>();
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select * from comment where @photo_id = photo_id";
                        command.Parameters.AddWithValue(@"photo_id", photoId);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var comment = new Comment()
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal(@"id"))
                                };
                                comment = GetComment(comment.Id);
                                AllComments.Add(comment);
                            }
                        }

                        return AllComments;
                    }
                }
            }
            else
            {
                //wrong id
                throw new ArgumentException();
            }
        }

        public Comment GetComment(Guid photoId, Guid commentId)
        {
            if (photoId != Guid.Empty && HavePhoto(photoId))
            {
                if (commentId != Guid.Empty && HaveComment(commentId))
                {
                    List<Comment> allComments = GetAllComments(photoId);
                    foreach (var comment in allComments)
                    {
                        if (comment.Id == commentId)
                        {
                            return GetComment(comment.Id);
                        }
                    }
                }
                return new Comment();
            }
            return new Comment();
        }

        public bool DeleteComment(Guid photoId, Guid commentId)
        {
            if (HavePhoto(photoId))
            {
                if (HaveComment(commentId))
                {
                    if (DeleteComment(commentId))
                    {
                        var photo = GetPhoto(photoId);
                        photo.AllComments = GetAllComments(commentId);
                        return true;
                    }
                    return false;
                }
            }
            return false;
        }

        public Person GetLike(Photo photo, Guid likeId)
        {
            if (HavePhoto(photo.Id) && HaveLike(photo.Id, likeId))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select * from [like] where @id = id";
                        command.Parameters.AddWithValue(@"id", likeId);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                //TODO:add checking that photo_id = photo.Id
                                var user = new Person
                                {
                                    Id = reader.GetGuid(reader.GetOrdinal(@"user_id"))
                                };
                                return GetUser(user.Id);
                            }
                            return new Person();
                        }
                    }
                }
            }
            return new Person();
        }

        public Guid GetLike(Photo photo, Person user)
        {
            if (HavePhoto(photo.Id) && HaveUser(user.Id) && HaveLike(photo, user))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select * from [like] where @photo_id = photo_id and @user_id = user_id";
                        command.Parameters.AddWithValue(@"photo_id", photo.Id);
                        command.Parameters.AddWithValue(@"user_id", user.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var likeId = reader.GetGuid(reader.GetOrdinal(@"id"));
                                return likeId;
                            }
                            return Guid.Empty;
                        }
                    }
                }
            }
            return Guid.Empty;
        }

        public Guid GetSubscription(Person user, Person userSubscription)
        {
            if (HaveUser(user.Id) && HaveUser(userSubscription.Id) && HaveSubscription(user, userSubscription))
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            @"select * from subscription where @user_id = user_id and @user_subscription_id = user_subscription_id";
                        command.Parameters.AddWithValue(@"user_id", user.Id);
                        command.Parameters.AddWithValue(@"user_subscription_id", userSubscription.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var relationId = reader.GetGuid(reader.GetOrdinal(@"id"));
                                return relationId;
                            }
                            return Guid.Empty;
                        }
                    }
                }

            }
            return Guid.Empty;
        }

        public Person GetUserByEmail(string email)
        {
            if (email != String.Empty)
            {
                using (var connection = new SqlConnection(_connectionSql))
                {
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = @"select id, user_name, last_name, first_name, password_hash, email from person
                        where @email = email";
                        command.Parameters.AddWithValue(@"email", email);

                        using (var reader = command.ExecuteReader())
                        {
                            reader.Read();

                            if (reader.HasRows)
                            {
                                _log.Info("User with email = {0} was found.", email);

                                var PasswordHash = reader.GetValue(reader.GetOrdinal(@"password_hash"));

                                return new Person
                                {
                                    //param of Get - ordinal number of coloumn in table
                                    Id = reader.GetGuid(reader.GetOrdinal(@"id")),
                                    LastName = reader.GetString(reader.GetOrdinal(@"last_name")),
                                    FirstName = reader.GetString(reader.GetOrdinal(@"first_name")),
                                    Name = reader.GetString(reader.GetOrdinal(@"user_name")),
                                    Email = reader.GetString(reader.GetOrdinal(@"email")),
                                    PasswordHash = (int)System.Convert.ChangeType(PasswordHash, typeof(int))
                            };
                            }
                        }
                        return new Person();
                    }
                }
            }
            return new Person();
        }
    }
}


text:
<serverinfo>
    <servername>Server Name Here</servername> <!-- Your server name. -->
    <websiteurl>http://linktoyourwebsite.com</websiteurl> <!-- The URL to the website. -->
    <forumurl>http://linktoyourforum.com</forumurl> <!-- The URL to the forum. -->
    <voteurl>http://linktothevotingpage.com</voteurl> <!--The URL to the voting page. -->

    <exprate>1000x</exprate> <!-- The server's EXP rate. -->
    <mesorate>500x</mesorate> <!-- The server's meso rate. -->
    <droprate>5x</droprate> <!-- The server's drop rate.-->
</serverinfo>

<news> <!-- Recent news goes on top. Goes from newer -> older from top to bottom. -->
    <title>More Recent News</title> <!-- The title of the news. -->
    <message>This is a more recent news.</message> <!-- The message of the news. -->

    <title>Old News</title>
    <message>This is an older news.</message>
</news>

<downloads> <!-- Sizes are in bytes. The download link has to be a direct download link. -->
    <client_link>http://clientdownloadlink.com</client_link> <!-- The direct download link to the file. -->
    <client_size>0000</client_size> <!-- The size in bytes of the file. -->
    <client_name>MapleClient.exe</client_name> <!-- The client's file name. ( Include the .exe ) -->

    <base_link>https://www.dropbox.com/s/zi7oaam63gqearh/Base.wz?dl=1</base_link> <!-- The direct link to the file -->
    <base_size>6540</base_size> <!-- The size in bytes of the file. -->

    <character_link>https://www.dropbox.com/s/2h8e59h566kanwa/Character.wz?dl=1</character_link>
    <character_size>186792151</character_size>

    <effect_link>https://www.dropbox.com/s/irxtpocq87h1ss2/Effect.wz?dl=1</effect_link>
    <effect_size>63334965</effect_size>

    <etc_link>https://www.dropbox.com/s/2ko4uad5bydpo63/Etc.wz?dl=1</etc_link>
    <etc_size>1201101</etc_size>

    <item_link>https://www.dropbox.com/s/dvoub5hu52238v9/Item.wz?dl=1</item_link>
    <item_size>18361778</item_size>

    <list_link>https://www.dropbox.com/s/7bfjubjiksc9vpp/List.wz?dl=1</list_link>
    <list_size>13336</list_size>

    <map_link>https://www.dropbox.com/s/n02zawj3ynq8nce/Map.wz?dl=1</map_link>
    <map_size>635444895</map_size>

    <mob_link>https://www.dropbox.com/s/9cwdodqpfsjwa4k/Mob.wz?dl=1</mob_link>
    <mob_size>479665103</mob_size>

    <morph_link>https://www.dropbox.com/s/i54huwfo0e9k5zz/Morph.wz?dl=1</morph_link>
    <morph_size>6204606</morph_size>

    <npc_link>https://www.dropbox.com/s/48vxli6nxpl46hq/Npc.wz?dl=1</npc_link>
    <npc_size>51137866</npc_size>

    <quest_link>https://www.dropbox.com/s/0rpv7weuyyuzqcd/Quest.wz?dl=1</quest_link>
    <quest_size>5971537</quest_size>

    <reactor_link>https://www.dropbox.com/s/6ygr0ph1zc9ktsl/Reactor.wz?dl=1</reactor_link>
    <reactor_size>54133811</reactor_size>

    <skill_link>https://www.dropbox.com/s/rsoq7wz4ilj404w/Skill.wz?dl=1</skill_link>
    <skill_size>76874780</skill_size>

    <sound_link>https://www.dropbox.com/s/lpmg415a8owtzvh/Sound.wz?dl=1</sound_link>
    <sound_size>363261964</sound_size>

    <string_link>https://www.dropbox.com/s/mnjpuwomnul05da/String.wz?dl=1</string_link>
    <string_size>3251564</string_size>

    <tamingmob_link>https://www.dropbox.com/s/k9v4iwdoz48x8g0/TamingMob.wz?dl=1</tamingmob_link>
    <tamingmob_size>797</tamingmob_size>

    <ui_link>https://www.dropbox.com/s/bdxywid1cdw2xxm/UI.wz?dl=1</ui_link>
    <ui_size>28259933</ui_size>
</downloads>


text:
@interface NSMutableDictionary (Extension)

@end


text:
World::World()
    : mColoredLightMatrix{new ColoredLightMatrix(kWorldWidth, kWorldHeight)},
      mColoredCrystalMatrix{new ColoredCrystalMatrix(
          kWorldWidth, kWorldHeight,
          new BasicCrystalPopulator(*mColoredLightMatrix))},
      mTheRogue{new Rogue(mCrystallineStructures, *mColoredLightMatrix,
                          *mColoredCrystalMatrix)},
      mTheCreature{new Creature(*mTheRogue, *mColoredLightMatrix)},
      mStatusBar{23, kWorldWidth, *mTheRogue}
{
    PowerSource ps(Color::kWhite, 100);
    ps.givePower(50);
    ps.chargeToFull();
    auto eff = new LightProvider(Color::kWhite, *mColoredLightMatrix);
    auto cs =
        std::make_unique<CrystallineStructure>("Light Structure", ps, eff);

    cs->moveTo(40, 12);
    mCrystallineStructures.push_back(std::move(cs));
    mTheRogue->moveTo(40, 13);
}

void World::step()
{
    mStatusBar.setMessage("");
    for (auto &cs : mCrystallineStructures) {
        cs->step();
    }
    mColoredCrystalMatrix->step();
    mTheCreature->step();
    mStatusBar.step();
}

void World::draw()
{
    for (int x = 0; x < kWorldWidth; ++x) {
        for (int y = 0; y < kWorldHeight; ++y) {
            auto bg = mColoredLightMatrix->brightness(x, y, Color::kWhite)
                          ? TB_WHITE
                          : TB_BLACK;
            auto fg = mColoredCrystalMatrix->color(x, y);
            auto ch =
                mColoredCrystalMatrix->crystals(x, y) && mTheRogue->canSee(x, y)
                    ? '*'
                    : ' ';
            tb_change_cell(x, y, ch, static_cast<int>(fg) | TB_BOLD,
                           static_cast<int>(bg));
        }
    }

    int rx = mTheRogue->x();
    int ry = mTheRogue->y();
    if (mTheRogue->inLight()) {
        tb_change_cell(rx, ry, '@', TB_BLACK, TB_WHITE);
    } else {
        tb_change_cell(rx, ry, '@', TB_WHITE, TB_BLACK);
    }

    for (auto &cs : mCrystallineStructures) {
        auto &cell = tb_cell_buffer()[cs->y() * tb_width() + cs->x()];
        // XXX: Uses a hack. Termbox colors the same as dimlit's.
        int color = static_cast<int>(cs->powerSource().poweredBy());
        cell.ch = '&';
        cell.fg = TB_BOLD | color;
    }

    mStatusBar.draw();

    if (mDialog) {
        mDialog->draw();
    }
}

void World::process(Action action)
{
    if (mDialog) {
        if (!mDialog->shouldClose()) {
            mDialog->process(action);
            return;
        } else {
            mDialog.reset();
        }
    }

    int dX = 0;
    int dY = 0;
    switch (action) {
    case Action::kMoveNorth:
        dY = -1;
        break;
    case Action::kMoveSouth:
        dY = 1;
        break;
    case Action::kMoveEast:
        dX = 1;
        break;
    case Action::kMoveWest:
        dX = -1;
        break;
    case Action::kBack:
        mStatusBar.setMessage("");
        break;
    default:
        break;
    }

    if (dX == 0 && dY == 0) {
        return;
    }

    bool moved = mTheRogue->moveBy(dX, dY);
    if (moved) {
        step();
    } else {
        int x = mTheRogue->x() + dX;
        int y = mTheRogue->y() + dY;
        auto b = std::begin(mCrystallineStructures);
        auto e = std::end(mCrystallineStructures);
        auto csi = std::find_if(
            b, e, [x, y](auto &i) { return i->x() == x && i->y() == y; });
        if (csi != e) {
            auto &cs = *csi;
            auto &ps = cs->powerSource();
            int max = ps.maxCrystalsFromBag(mTheRogue->bag());
            std::vector<BasicDialog<int>::Option> options;
            for (int i = 2; i < max; i *= 2) {
                std::stringstream ss;
                ss << "Give " << i;
                options.push_back(BasicDialog<int>::Option(ss.str(), i));
            }
            std::stringstream maxss;
            maxss << "Give " << max;
            options.push_back(BasicDialog<int>::Option(maxss.str(), max));
            std::stringstream ss;
            ss << cs->name() << " (" << ps.percentPowered() << "% of "
               << ps.maxCrystals() << ")";
            mDialog.reset(new BasicDialog<int>(
                x, y, kWorldWidth, kWorldHeight, ss.str(), options,
                [&cs, this](auto const &option, auto item) mutable {
                    (void)option;
                    this->mTheRogue->giveStructurePower(*cs, item);
                    // FIXME: Right now adds one to compensate for the step.
                    cs->refresh();
                }));
        }
    }
}


text:
using Microsoft.Extensions.Logging;
using Presence.Grains.Models;

namespace Presence.Grains;

/// <summary>
/// Represents a game in progress and holds the game's state in memory.
/// Notifies player grains about their players joining and leaving the game.
/// Updates subscribed observers about the progress of the game.
/// </summary>
public class GameGrain : Grain, IGameGrain
{
    private readonly ILogger<GameGrain> _logger;
    private readonly HashSet<IGameObserver> _observers = new();
    private readonly HashSet<Guid> _players = new();
    private GameStatus _status = GameStatus.Empty;

    public GameGrain(ILogger<GameGrain> logger)
    {
        _logger = logger;
    }

    private Guid GrainKey => this.GetPrimaryKey();

    /// <summary>
    /// Presense grain calls this method to update the game with its latest status.
    /// </summary>
    public async Task UpdateGameStatusAsync(GameStatus status)
    {
        _status = status;

        // Check for new players that joined since last update
        foreach (var player in _status.PlayerKeys)
        {
            if (!_players.Contains(player))
            {
                try
                {
                    // Here we call player grains serially, which is less efficient than a fan-out but simpler to express.
                    await GrainFactory.GetGrain<IPlayerGrain>(player).JoinGameAsync(this.AsReference<IGameGrain>());
                    _players.Add(player);
                }
                catch (Exception error)
                {
                    // Ignore exceptions while telling player grains to join the game.
                    // Since we didn't add the player to the list, this will be tried again with next update.
                    _logger.LogWarning(error, "Failed to tell player {PlayerKey} to join game {GameKey}", player, GrainKey);
                }
            }
        }

        // Check for players that left the game since last update
        var promises = new List<(Guid PlayerKey, Task Task)>();
        foreach (var player in _players)
        {
            if (!_status.PlayerKeys.Contains(player))
            {
                // Here we do a fan-out with multiple calls going out in parallel. We join the promises later.
                // More code to write but we get lower latency when calling multiple player grains.
                promises.Add((player, GrainFactory.GetGrain<IPlayerGrain>(player).LeaveGameAsync(this.AsReference<IGameGrain>())));
            }
        }

        // Joining promises
        foreach (var (playerKey, task) in promises)
        {
            try
            {
                await task;
                _players.Remove(playerKey);
            }
            catch (Exception error)
            {
                _logger.LogWarning(error, "Failed to tell player {PlayerKey} to leave the game {GameKey}", playerKey, GrainKey);
            }
        }

        // Notify observers about the latest game score
        List<IGameObserver> failed = null!;
        foreach (var observer in _observers)
        {
            try
            {
                observer.UpdateGameScore(_status.Score);
            }
            catch (Exception error)
            {
                _logger.LogWarning(error, "Failed to notify observer {ObserverKey} of score for game {GameKey}. Removing observer.", observer.GetPrimaryKey(), GrainKey);

                // add observer to a list of failures
                // however defer failed list creation until necessary to avoid incurring an allocation on every call
                failed ??= new();
                failed.Add(observer);
            }
        }

        // Remove dead observers
        if (failed is not null)
        {
            foreach (var observer in failed)
            {
                _observers.Remove(observer);
            }
        }

        return;
    }

    public Task ObserveGameUpdatesAsync(IGameObserver observer)
    {
        _observers.Add(observer);
        return Task.CompletedTask;
    }

    public Task UnobserveGameUpdatesAsync(IGameObserver observer)
    {
        _observers.Remove(observer);
        return Task.CompletedTask;
    }
}