public list fertig gestellt
This commit is contained in:
@@ -11,10 +11,4 @@
|
||||
<PackageReference Include="Selenium.WebDriver" Version="4.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="usedList.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
118
ConsoleApp3/CheckSevDeskPublicList.cs
Normal file
118
ConsoleApp3/CheckSevDeskPublicList.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using ConsoleApp3.Contracts;
|
||||
using OpenQA.Selenium.DevTools;
|
||||
using OpenQA.Selenium.Support.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CardMarketBot
|
||||
{
|
||||
internal class CheckSevDeskPublicList : ICheckSevDesk
|
||||
{
|
||||
private static readonly object _lock = new object();
|
||||
private static bool _closed;
|
||||
|
||||
enum EResult
|
||||
{
|
||||
FAILED,
|
||||
AVAIBLE,
|
||||
OK,
|
||||
WRITTEN
|
||||
}
|
||||
private static void Write(TcpClient client, string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
SocketShutdown reason = SocketShutdown.Send;
|
||||
lock (_lock)
|
||||
{
|
||||
BinaryWriter writer = new BinaryWriter(client.GetStream());
|
||||
writer.Write(str);
|
||||
if (_closed)
|
||||
{
|
||||
reason = SocketShutdown.Both;
|
||||
}
|
||||
}
|
||||
//client.Client.Shutdown(reason);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Console.WriteLine($"IOException writing to socket: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static EResult Read(TcpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
//while(true)
|
||||
//{
|
||||
try
|
||||
{
|
||||
if (!client.Connected)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_closed = true;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
BinaryReader reader = new BinaryReader(client.GetStream());
|
||||
string res = reader.ReadString();
|
||||
if (res.Contains("OK"))
|
||||
return EResult.OK;
|
||||
return EResult.FAILED;
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_closed = true;
|
||||
}
|
||||
return EResult.FAILED;
|
||||
}
|
||||
//client.Client.Shutdown(SocketShutdown.Receive);
|
||||
//}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return EResult.FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool AlreadyKnown(string verkaufsnummer)
|
||||
{
|
||||
try
|
||||
{
|
||||
TcpClient client = new TcpClient("nas.cosysda.de", 4000);
|
||||
Write(client, string.Format("#TEST#{0}", verkaufsnummer));
|
||||
EResult result = Read(client);
|
||||
|
||||
client.Client.Shutdown(SocketShutdown.Both);
|
||||
client.Close();
|
||||
|
||||
return result == EResult.OK;
|
||||
}
|
||||
catch(SocketException e)
|
||||
{
|
||||
throw new SocketException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Write(string verkaufsnummer)
|
||||
{
|
||||
TcpClient client = new TcpClient("nas.cosysda.de", 4000);
|
||||
Write(client, string.Format("#WRITE#{0}", verkaufsnummer));
|
||||
EResult result = Read(client);
|
||||
client.Client.Shutdown(SocketShutdown.Both);
|
||||
client.Close();
|
||||
return result == EResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
ConsoleApp3/Contracts/ICheckSevDesk.cs
Normal file
8
ConsoleApp3/Contracts/ICheckSevDesk.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ConsoleApp3.Contracts
|
||||
{
|
||||
internal interface ICheckSevDesk
|
||||
{
|
||||
bool AlreadyKnown(string verkaufsnummer);
|
||||
bool Write(string verkaufsnummer);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace ConsoleApp3.DataContracts
|
||||
/// <value>time left for paying the invoice, use format dd.MM.yyyy or number for number of days left</value>
|
||||
[DataMember(Name = "timeToPay", EmitDefaultValue = false)]
|
||||
[JsonProperty(PropertyName = "timeToPay")]
|
||||
public DateTime? TimeToPay { get; set; }
|
||||
public int? TimeToPay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace CardmarketBot
|
||||
"wir stellen Ihnen für ihre Bestellung folgende Rechnung. " +
|
||||
"Bitte Beachte, dass das Lieferdatum dem Bestelldatum entspricht.";
|
||||
rechnung.FootText = "Ihre Rechnung ist bereits über Cardmarket beglichen worden.";
|
||||
rechnung.TimeToPay = new DateTime().AddDays(14);
|
||||
rechnung.TimeToPay = 14;
|
||||
rechnung.Discount = 0;
|
||||
rechnung.Address = string.Format("{0}\n{1} {2}\n{3} {4}", kunde.Name, kunde.Strasse, kunde.Hausnummer, kunde.Plz, kunde.Ort); //"Damian Wessels\nDät Haartje 27A\n26683 Saterland";
|
||||
rechnung.AddressCountry = new ModelStaticCountry()
|
||||
|
||||
@@ -6,15 +6,20 @@ using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using OpenQA.Selenium.DevTools.V112.Network;
|
||||
using OpenQA.Selenium.DevTools.V112.Debugger;
|
||||
using CardMarketBot;
|
||||
|
||||
namespace CardmarketBot
|
||||
{
|
||||
internal class Programm
|
||||
{
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CheckVerkauf("120202");
|
||||
//IUsedRepository usedRepository = new UsedRepository();
|
||||
ICheckSevDesk checkSevDesk = new CheckSevDeskPublicList();
|
||||
|
||||
|
||||
|
||||
// Kunden aus Cardmarket erstellen
|
||||
@@ -39,11 +44,11 @@ namespace CardmarketBot
|
||||
Regex regex = new Regex("[0-9]*$");
|
||||
Match matched = regex.Match(str_header);
|
||||
string verkaufnummer = str_header.Substring(matched.Index);
|
||||
if(!CheckVerkauf(verkaufnummer))
|
||||
if (checkSevDesk.AlreadyKnown(verkaufnummer))
|
||||
{
|
||||
Debugger.Break();
|
||||
SevdeskService sevdeskService = new SevdeskService("7251554968610b78ca865b2b774b4134");
|
||||
sevdeskService.Create(item);
|
||||
checkSevDesk.Write(verkaufnummer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,43 +62,9 @@ namespace CardmarketBot
|
||||
|
||||
}
|
||||
|
||||
private static bool CheckVerkauf(string verkaufnummer)
|
||||
{
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
IPHostEntry host = Dns.GetHostEntry("server");
|
||||
IPAddress iPAddress = host.AddressList[0];
|
||||
|
||||
|
||||
|
||||
IPEndPoint remoteEP = new IPEndPoint(iPAddress, 4000);
|
||||
|
||||
Socket sender = new Socket(iPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
sender.Connect(remoteEP);
|
||||
Console.WriteLine("Socket connected to {0}", sender.RemoteEndPoint.ToString());
|
||||
byte[] msg = Encoding.ASCII.GetBytes(string.Format("TEST #{0}<EOF>", verkaufnummer));
|
||||
int bytesSent = sender.Send(msg);
|
||||
int bytesRec = sender.Receive(bytes);
|
||||
Console.WriteLine("Replying = {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec));
|
||||
sender.Shutdown(SocketShutdown.Both);
|
||||
sender.Close();
|
||||
}
|
||||
catch (ArgumentNullException ane)
|
||||
{
|
||||
Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
|
||||
}
|
||||
catch (SocketException se)
|
||||
{
|
||||
Console.WriteLine("SocketException : {0}", se.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Unexpected exception : {0}", e.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
|
|
Reference in New Issue
Block a user