Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions FifthLesson/EnglishLessons/EnglishLessons.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DD163CDC-E328-436C-B273-63767E38334A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EnglishLessons</RootNamespace>
<AssemblyName>EnglishLessons</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DnsClient, Version=1.0.7.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\DnsClient.1.0.7\lib\net45\DnsClient.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=2.7.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.7.1\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.7.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.7.1\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.7.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.7.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Generator.cs" />
<Compile Include="IUserRepository.cs" />
<Compile Include="IWordRepository.cs" />
<Compile Include="Memory.cs" />
<Compile Include="MongoUserRepository.cs" />
<Compile Include="MongoWordRepository.cs" />
<Compile Include="RepWord.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Session.cs" />
<Compile Include="User.cs" />
<Compile Include="UserWord.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
43 changes: 43 additions & 0 deletions FifthLesson/EnglishLessons/Generator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public class Generator
{
public List<RepWord> Start(int count, User user)
{
List<RepWord> toRand = user.ShowInProgress();
Random rnd = new Random();
List<RepWord> toShow = new List<RepWord>();
if (count > toRand.Count) throw new InvalidOperationException();
for (int i = 0; i < count; i++)
{
int ind = rnd.Next(toRand.Count);
toShow.Add(toRand[ind]);
toRand.RemoveAt(ind);
}

toRand = user.ShowInProgress();

for (int i = 0; i < count; i++)
{
if (rnd.Next(2) == 1)
{
string NewRus = "";
Random NewInd = new Random();
do
NewRus = toRand[NewInd.Next(toRand.Count())].Rus;
while (NewRus == toShow[i].Rus);

toShow[i].Rus = NewRus;
}
}

return toRand;
}
}
}
12 changes: 12 additions & 0 deletions FifthLesson/EnglishLessons/IMemoryUse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
interface IMemoryUse
{
}
}
15 changes: 15 additions & 0 deletions FifthLesson/EnglishLessons/IUserRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public interface IUserRepository
{
User LoadUser(Guid id);

void SaveUser(User user);
}
}
15 changes: 15 additions & 0 deletions FifthLesson/EnglishLessons/IWordRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public interface IWordRepository
{
RepWord LoadWord();

void SaveWord(RepWord repword);
}
}
26 changes: 26 additions & 0 deletions FifthLesson/EnglishLessons/Memory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.IO;

namespace EnglishLessons
{
public class Memory
{
public void Save(Session session)
{
string serialized = JsonConvert.SerializeObject(session);
File.Create("FooBar.txt");
File.WriteAllText("FooBar.txt", serialized);
}

public Session Load()
{
string deserialized = File.ReadAllText("FooBar.txt");
return JsonConvert.DeserializeObject<Session>(deserialized);
}
}
}
43 changes: 43 additions & 0 deletions FifthLesson/EnglishLessons/MongoUserRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public class MongoUserRepository : IUserRepository
{
private readonly IMongoCollection<User> users;
static MongoUserRepository()
{
BsonClassMap.RegisterClassMap<User>(map =>
{
map.AutoMap();
map.MapMember(user => user.Name);
map.MapMember(user => user.Id);
map.MapMember(user => user._learned);
map.MapMember(user => user._inProgress);

});
}
public MongoUserRepository(string connectionString)
{
var mongoClient = new MongoClient(connectionString);
var database = mongoClient.GetDatabase("LOD");
users = database.GetCollection<User>("MapkUsers");
}

public User LoadUser(Guid id)
{
return users.Find(user => user.Id == id).FirstOrDefault();
}

public void SaveUser(User user)
{
users.InsertOne(user);
}
}
}
40 changes: 40 additions & 0 deletions FifthLesson/EnglishLessons/MongoWordRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public class MongoWordRepository : IWordRepository
{
private readonly IMongoCollection<RepWord> words;
static MongoWordRepository()
{
BsonClassMap.RegisterClassMap<RepWord>(map =>
{
map.AutoMap();
map.MapMember(word => word.Eng);
map.MapMember(word => word.Rus);
});
}
public MongoWordRepository(string connectionString)
{
var mongoClient = new MongoClient(connectionString);
var database = mongoClient.GetDatabase("LOD");
words = database.GetCollection<RepWord>("MapkWords");
}

public RepWord LoadWord()
{
return words.Find(word => word.Eng != "123").FirstOrDefault();//добавить рандом (?)
}

public void SaveWord(RepWord repword)
{
words.InsertOne(repword);
}
}
}
36 changes: 36 additions & 0 deletions FifthLesson/EnglishLessons/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Общие сведения об этой сборке предоставляются следующим набором
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
// связанные со сборкой.
[assembly: AssemblyTitle("EnglishLessons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EnglishLessons")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]

// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("dd163cdc-e328-436c-b273-63767e38334a")]

// Сведения о версии сборки состоят из следующих четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номер сборки и номер редакции по умолчанию.
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
21 changes: 21 additions & 0 deletions FifthLesson/EnglishLessons/RepWord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace EnglishLessons
{
public class RepWord
{
public string Rus { get; set; }
public string Eng { get; }

public RepWord(string eng, string rus)
{
Rus = rus;
Eng = eng;
}
}
}
55 changes: 55 additions & 0 deletions FifthLesson/EnglishLessons/Session.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnglishLessons
{
public class Session
{
private List<RepWord> _allWords { get; set; }
private List<User> _users { get; set; }

private void AddUser(User user)
{
_users.Add(user);
}

private void AddWord(RepWord word)
{
_allWords.Add(word);
}

private bool CheckWord(RepWord word)
{
return _allWords.Contains(word);
}

public void Registration(string name, Guid id)
{
Dictionary<string, UserWord> toReg = new Dictionary<string, UserWord>();
if (_allWords.Count < 10) throw new InvalidOperationException();
for (int i = 0; i < 10; i++)
{
toReg.Add(_allWords[i].Rus, new UserWord(false, 0, _allWords[i].Eng, _allWords[i].Rus));
}
AddUser(new User(name, id, new List<RepWord>(), toReg));
}

public void Start(User user, int wordCount)
{
Generator Gen = new Generator();
List<RepWord> toWork = Gen.Start(wordCount, user);
foreach (RepWord a in toWork)
{
bool UserAnswer = true; //вместо true ответ пользователя
if (CheckWord(a) == UserAnswer)
{
user.MarkAsLearned(a.Eng);
}
}

}
}
}
Loading