Skip to content

Commit 2b35b04

Browse files
committed
init repository
0 parents  commit 2b35b04

File tree

87 files changed

+2177
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2177
-0
lines changed

TenderView.sln

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TenderView", "TenderView\TenderView.csproj", "{EC9B01DD-EE5A-4477-8CC7-B954631EA5D5}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{EC9B01DD-EE5A-4477-8CC7-B954631EA5D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{EC9B01DD-EE5A-4477-8CC7-B954631EA5D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{EC9B01DD-EE5A-4477-8CC7-B954631EA5D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{EC9B01DD-EE5A-4477-8CC7-B954631EA5D5}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

TenderView/App.config

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<configuration>
2+
<appSettings>
3+
<add key="GetTradesURL" value="https://api.market.mosreg.ru/api/Trade/GetTradesForParticipantOrAnonymous"/>
4+
<add key="GetTradesDocuments" value="https://api.market.mosreg.ru/api/Trade/%tradeId%/GetTradeDocuments"/>
5+
<add key="GetTradesDetail" value="https://market.mosreg.ru/Trade/ViewTrade/%tradeId%"/>
6+
</appSettings>
7+
</configuration>

TenderView/App.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="TenderView.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="UI/View/TenderView.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

TenderView/App.xaml.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Windows;
2+
3+
namespace TenderView
4+
{
5+
/// <summary>
6+
/// Interaction logic for App.xaml
7+
/// </summary>
8+
public partial class App : Application
9+
{
10+
}
11+
}

TenderView/AssemblyInfo.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

TenderView/TenderView.csproj

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net5.0-windows</TargetFramework>
6+
<UseWPF>true</UseWPF>
7+
<RootNamespace>TenderView</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="AngleSharp" Version="1.0.0-alpha-844" />
12+
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="5.1.0" />
13+
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
14+
</ItemGroup>
15+
16+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace TenderView.Trades.TradeDetail
2+
{
3+
public class PurchaseObject
4+
{
5+
public PurchaseObject(string name, string unitName, decimal quantity, decimal priceForOne)
6+
{
7+
this.name = name;
8+
this.unitName = unitName;
9+
this.quantity = quantity;
10+
this.priceForOne = priceForOne;
11+
}
12+
public string name { get; private set; }
13+
public string unitName { get; private set; }
14+
public decimal quantity { get; private set; }
15+
public decimal priceForOne { get; private set; }
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
namespace TenderView.Trades.TradeDetail
4+
{
5+
public class TradeDetail
6+
{
7+
public TradeDetail(string deliveryAddress, List<PurchaseObject> purchaseObjects)
8+
{
9+
this.deliveryAddress = deliveryAddress;
10+
this.purchaseObjects = purchaseObjects;
11+
}
12+
public string deliveryAddress { get; private set; }
13+
public List<PurchaseObject> purchaseObjects { get; private set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System.Collections.Generic;
2+
using System.Configuration;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Threading.Tasks;
6+
using AngleSharp;
7+
using AngleSharp.Dom;
8+
using Configuration = AngleSharp.Configuration;
9+
10+
namespace TenderView.Trades.TradeDetail
11+
{
12+
public static class TradeDetailWebReceiver
13+
{
14+
private const string DeliveryAddressString = "Место поставки:";
15+
private const string PurchaseObjectNameString = "Наименование товара, работ, услуг:";
16+
private const string PurchaseObjectUnitNameString = "Единицы измерения:";
17+
private const string PurchaseObjectQuantityString = "Количество:";
18+
private const string PurchaseObjectPriceForOneString = "Стоимость единицы продукции ( в т.ч. НДС при наличии):";
19+
20+
private const string InfoBlockSelector =
21+
"div.informationAboutCustomer__informationPurchase-infoBlock.infoBlock";
22+
23+
private const string PurchaseObjectSelector = "div.outputResults__oneResult";
24+
25+
private const string PurchaseObjectNameAndCodeAndTypeSelector =
26+
"div.outputResults__oneResult-leftPart.leftPart";
27+
28+
private const string PurchaseObjectUnitNameAndQuantitySelector =
29+
"div.outputResults__oneResult-centerPart.centerPart";
30+
31+
private const string PurchaseObjectPriceForOneSelector =
32+
"div.outputResults__oneResult-rightPart.rightPart";
33+
34+
35+
public static async Task<TradeDetail> GetAsync(long tradeId)
36+
{
37+
var url = ConfigureAndGetUrl(tradeId);
38+
var context = BrowsingContext.New(Configuration.Default.WithDefaultLoader());
39+
var document = await context.OpenAsync(url);
40+
var tradeDetail = new TradeDetail(ParseDeliveryAddress(document), ParsePurchaseObject(document));
41+
42+
return tradeDetail;
43+
}
44+
45+
private static string ConfigureAndGetUrl(long tradeId)
46+
{
47+
var url = ConfigurationManager.AppSettings["GetTradesDetail"];
48+
if (string.IsNullOrEmpty(url))
49+
throw new WebException("Configuration string null or empty");
50+
51+
return url.Replace("%tradeId%", tradeId.ToString());
52+
}
53+
54+
55+
private static List<PurchaseObject> ParsePurchaseObject(IDocument document)
56+
{
57+
var cells = document.QuerySelectorAll(PurchaseObjectSelector);
58+
var purchaseObjects = new List<PurchaseObject>();
59+
foreach (var cell in cells)
60+
{
61+
var nameAndCodeAndTypeElement = cell.QuerySelector(PurchaseObjectNameAndCodeAndTypeSelector);
62+
var unitNameAndQuantityElement = cell.QuerySelector(PurchaseObjectUnitNameAndQuantitySelector);
63+
var priceForOneElement = cell.QuerySelector(PurchaseObjectPriceForOneSelector);
64+
65+
var name = ParsePurchaseObjectName(nameAndCodeAndTypeElement);
66+
var unitName = ParsePurchaseObjectUnitName(unitNameAndQuantityElement);
67+
var quantity = decimal.Parse(ParsePurchaseObjectQuantity(unitNameAndQuantityElement));
68+
var priceForOne = decimal.Parse(ParsePurchaseObjectPriceForOne(priceForOneElement));
69+
70+
71+
name = TrimStartAndEnd(name);
72+
unitName = TrimStartAndEnd(unitName);
73+
74+
purchaseObjects.Add(new PurchaseObject(name, unitName, quantity, priceForOne));
75+
}
76+
77+
return purchaseObjects;
78+
}
79+
80+
private static string TrimStartAndEnd(string text)
81+
{
82+
return text.TrimStart().TrimEnd();
83+
}
84+
85+
private static string ParseDeliveryAddress(IDocument document)
86+
{
87+
var cells = document.QuerySelectorAll(InfoBlockSelector);
88+
89+
return (from cell in cells
90+
where cell.Children[0].TextContent == DeliveryAddressString
91+
select cell.Children[1].TextContent).FirstOrDefault();
92+
}
93+
94+
private static string ParsePurchaseObjectName(IElement element)
95+
{
96+
return (from child in element.Children
97+
where child.Children.Length > 0
98+
where child.Children[0].TextContent.Equals(PurchaseObjectNameString)
99+
select child.ChildNodes[2].TextContent).FirstOrDefault();
100+
}
101+
102+
private static string ParsePurchaseObjectUnitName(IElement element)
103+
{
104+
return InnerContentFinder(element, PurchaseObjectUnitNameString);
105+
}
106+
107+
private static string ParsePurchaseObjectQuantity(IElement element)
108+
{
109+
return InnerContentFinder(element, PurchaseObjectQuantityString);
110+
}
111+
112+
private static string ParsePurchaseObjectPriceForOne(IElement element)
113+
{
114+
return InnerContentFinder(element, PurchaseObjectPriceForOneString);
115+
}
116+
117+
private static string InnerContentFinder(IElement element, string nameString)
118+
{
119+
return (from child in element.Children
120+
where child.Children.Length > 0
121+
from childParag in child.Children
122+
where childParag.Children.Length > 0 && childParag.Children[0].TextContent.Equals(nameString)
123+
select childParag.ChildNodes[2].TextContent).FirstOrDefault();
124+
}
125+
}
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace TenderView.Trades.TradeDocuments
5+
{
6+
public class TradeDocument
7+
{
8+
[JsonInclude] [JsonPropertyName("Id")]
9+
public string id { get; private set; }
10+
[JsonInclude] [JsonPropertyName("UploadDate")]
11+
public DateTime uploadDate { get; private set; }
12+
[JsonInclude] [JsonPropertyName("FileName")]
13+
public string fileName { get; private set; }
14+
[JsonInclude] [JsonPropertyName("Url")]
15+
public string url { get; private set; }
16+
[JsonInclude] [JsonPropertyName("UserFileNameFromOuterSystem")]
17+
public string userFileNameFromOuterSystem { get; private set; }
18+
[JsonInclude] [JsonPropertyName("Type")]
19+
public string type { get; private set; }
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.Configuration;
3+
using System.Net;
4+
using System.Text.Json;
5+
6+
namespace TenderView.Trades.TradeDocuments
7+
{
8+
public static class TradeDocumentsWebReceiver
9+
{
10+
public static List<TradeDocument> Get(long tradeId)
11+
{
12+
var webRequest = CreateWebRequest(tradeId);
13+
var response = webRequest.GetResponse();
14+
var responseString = Utility.WebUtility.ParseResponseToString(response);
15+
return JsonSerializer.Deserialize<List<TradeDocument>>(responseString);
16+
}
17+
18+
private static WebRequest CreateWebRequest(long tradeId)
19+
{
20+
var url = ConfigureAndGetUrl(tradeId);
21+
var request = WebRequest.Create(url);
22+
request.ContentType = "application/json";
23+
request.Method = "GET";
24+
return request;
25+
}
26+
27+
private static string ConfigureAndGetUrl(long tradeId)
28+
{
29+
var url = ConfigurationManager.AppSettings["GetTradesDocuments"];
30+
if (string.IsNullOrEmpty(url))
31+
throw new WebException("Configuration string null or empty");
32+
33+
return url.Replace("%tradeId%", tradeId.ToString());
34+
}
35+
}
36+
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace TenderView.Trades.TradeSummary
5+
{
6+
public class Trade
7+
{
8+
[JsonInclude]
9+
[JsonPropertyName("Id")]
10+
public long id { get; private set; }
11+
12+
[JsonInclude]
13+
[JsonPropertyName("TradeState")]
14+
public int tradeState { get; private set; }
15+
16+
[JsonInclude]
17+
[JsonPropertyName("TradeStateName")]
18+
public string tradeStateName { get; private set; }
19+
20+
[JsonInclude]
21+
[JsonPropertyName("CustomerFullName")]
22+
public string customerFullName { get; private set; }
23+
24+
[JsonInclude]
25+
[JsonPropertyName("TradeName")]
26+
public string tradeName { get; private set; }
27+
28+
[JsonInclude]
29+
[JsonPropertyName("InitialPrice")]
30+
public decimal initialPrice { get; private set; }
31+
32+
[JsonInclude]
33+
[JsonPropertyName("FillingApplicationEndDate")]
34+
public DateTime fillingApplicationEndDate { get; private set; }
35+
36+
[JsonInclude]
37+
[JsonPropertyName("PublicationDate")]
38+
public DateTime publicationDate { get; private set; }
39+
40+
[JsonInclude]
41+
[JsonPropertyName("OrganizationId")]
42+
public long organizationId { get; private set; }
43+
44+
[JsonInclude]
45+
[JsonPropertyName("SourcePlatform")]
46+
public long sourcePlatform { get; private set; }
47+
48+
[JsonInclude]
49+
[JsonPropertyName("SourcePlatformName")]
50+
public string sourcePlatformName { get; private set; }
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Configuration;
2+
using System.IO;
3+
using System.Net;
4+
using System.Text.Json;
5+
6+
namespace TenderView.Trades.TradeSummary
7+
{
8+
public static class TradeWebReceiver
9+
{
10+
public static TradeWebResponse Get(long tradeId, long page = 1, int itemsPerPage = 10)
11+
{
12+
var tradesRequest = new TradeWebRequest(tradeId, page, itemsPerPage);
13+
var jsonRequest = JsonSerializer.Serialize(tradesRequest);
14+
var webRequest = CreateWebRequest(jsonRequest);
15+
var response = webRequest.GetResponse();
16+
var responseString = Utility.WebUtility.ParseResponseToString(response);
17+
return JsonSerializer.Deserialize<TradeWebResponse>(responseString);
18+
}
19+
20+
private static WebRequest CreateWebRequest(string json)
21+
{
22+
var request = WebRequest.Create(GetUrl());
23+
request.ContentType = "application/json";
24+
request.Method = "POST";
25+
26+
using var streamWriter = new StreamWriter(request.GetRequestStream());
27+
streamWriter.Write(json);
28+
29+
return request;
30+
}
31+
32+
private static string GetUrl()
33+
{
34+
var url = ConfigurationManager.AppSettings["GetTradesURL"];
35+
if (string.IsNullOrEmpty(url))
36+
throw new WebException("Configuration string null or empty");
37+
return url;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)