Part1
Edit SZO Mailing
This commit is contained in:
@@ -5,25 +5,36 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using SupportClasses;
|
||||
|
||||
namespace DataClients
|
||||
{
|
||||
public class FileClient
|
||||
{
|
||||
private char split = '/';
|
||||
//private char split = '\\';
|
||||
private char split = _Directory.Slash;
|
||||
//private string dir = @"Y:\data";
|
||||
//private string dir = @"C:\data";
|
||||
private string dir = @"/archive_rmt/data";
|
||||
private string dir;
|
||||
public string Dir {
|
||||
get { return dir; }
|
||||
set { dir = value; }
|
||||
}
|
||||
|
||||
|
||||
public FileClient()
|
||||
{
|
||||
TempDir.StartCkeckDir();
|
||||
fileClient(@"/archive_rmt/data");
|
||||
//fileClient(@"Y:\data");
|
||||
//fileClient(@"C:\data");
|
||||
}
|
||||
public FileClient(string directory)
|
||||
{
|
||||
fileClient(directory);
|
||||
}
|
||||
private void fileClient(string directory)
|
||||
{
|
||||
TempDir.StartCkeckDir();
|
||||
dir = directory;
|
||||
Dir = directory;
|
||||
}
|
||||
|
||||
public byte[] GetFile(DateTime time, ushort vdp, ushort index)
|
||||
@@ -39,36 +50,38 @@ namespace DataClients
|
||||
if (!TempDir.IsExist(name)) return new byte[0];
|
||||
while (TempDir.IsProtect(name)) Thread.Sleep(1000);
|
||||
TempDir.AddProtect(name);
|
||||
Stream fs = File.OpenRead(tmpFileName);
|
||||
var result = new List<byte>();
|
||||
try
|
||||
using (var fs = (Stream)File.OpenRead(tmpFileName))
|
||||
{
|
||||
for (var i = 0; i < fs.Length; i++)
|
||||
result.Add((byte)fs.ReadByte());
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.StackTrace);
|
||||
return new byte[0];
|
||||
}
|
||||
finally
|
||||
{
|
||||
TempDir.RemoveProtect(name);
|
||||
fs.Close();
|
||||
var result = new List<byte>();
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < fs.Length; i++)
|
||||
result.Add((byte)fs.ReadByte());
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Add("Can't read file: " + name, Logger.Level.error);
|
||||
Logger.Add(e.Message, Logger.Level.error);
|
||||
Logger.Add(e.StackTrace, Logger.Level.error);
|
||||
return new byte[0];
|
||||
}
|
||||
finally
|
||||
{
|
||||
TempDir.RemoveProtect(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckArchive(DateTime time, ushort vdp)
|
||||
{
|
||||
var tmp =
|
||||
var a =
|
||||
dir + split +
|
||||
time.Year.ToString("D4") + split +
|
||||
time.Month.ToString("D2") + split +
|
||||
time.Day.ToString("D2") + split +
|
||||
vdp.ToString("D2");
|
||||
return (File.Exists(tmp + ".tar") || File.Exists(tmp + ".tar.gz"));
|
||||
return (File.Exists(a + ".tar") || File.Exists(a + ".tar.gz"));
|
||||
}
|
||||
private bool ExtractArchive(DateTime time, ushort vdp)
|
||||
{
|
||||
@@ -92,45 +105,34 @@ namespace DataClients
|
||||
}
|
||||
private void ExtractTarGZ(String gzArchiveName, String destFolder)
|
||||
{
|
||||
Stream inStream = File.OpenRead(gzArchiveName);
|
||||
Stream gzipStream = new GZipInputStream(inStream);
|
||||
try
|
||||
{
|
||||
TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
|
||||
tarArchive.ExtractContents(destFolder);
|
||||
tarArchive.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Can't extract: " + gzArchiveName);
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.StackTrace);
|
||||
}
|
||||
finally
|
||||
{
|
||||
gzipStream.Close();
|
||||
inStream.Close();
|
||||
}
|
||||
using (var a = (Stream)File.OpenRead(gzArchiveName))
|
||||
using (var b = (Stream)new GZipInputStream(a))
|
||||
try
|
||||
{
|
||||
using (var c = TarArchive.CreateInputTarArchive(b))
|
||||
c.ExtractContents(destFolder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Add("Can't extract: " + gzArchiveName, Logger.Level.error);
|
||||
Logger.Add(e.Message, Logger.Level.error);
|
||||
Logger.Add(e.StackTrace, Logger.Level.error);
|
||||
}
|
||||
}
|
||||
private void ExtractTar(String tarFileName, String destFolder)
|
||||
{
|
||||
Stream inStream = File.OpenRead(tarFileName);
|
||||
try
|
||||
{
|
||||
TarArchive tarArchive = TarArchive.CreateInputTarArchive(inStream);
|
||||
tarArchive.ExtractContents(destFolder);
|
||||
tarArchive.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Can't extract: " + tarFileName);
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.StackTrace);
|
||||
}
|
||||
finally
|
||||
{
|
||||
inStream.Close();
|
||||
}
|
||||
using (var a = (Stream)File.OpenRead(tarFileName))
|
||||
try
|
||||
{
|
||||
using (var b = TarArchive.CreateInputTarArchive(a))
|
||||
b.ExtractContents(destFolder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Add("Can't extract: " + tarFileName, Logger.Level.error);
|
||||
Logger.Add(e.Message, Logger.Level.error);
|
||||
Logger.Add(e.StackTrace, Logger.Level.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,11 @@ namespace DataClients
|
||||
netClient = new NetClient();
|
||||
fileClient = new FileClient();
|
||||
}
|
||||
public STPClient(NetClient nc, FileClient fc)
|
||||
{
|
||||
netClient = nc;
|
||||
fileClient = fc;
|
||||
}
|
||||
public Pasport GetPasport(string link)
|
||||
{
|
||||
var result = new Pasport();
|
||||
@@ -107,28 +112,26 @@ namespace DataClients
|
||||
var result = new List<TechCycle>();
|
||||
var cursor = start;
|
||||
byte[] subRes = new byte[0];
|
||||
do
|
||||
{
|
||||
cursor = cursor.AddDays(-1);
|
||||
subRes = GetFile(cursor, vdp, 3);
|
||||
} while (subRes.Length == 0 && cursor > start.AddDays(-10));
|
||||
|
||||
TechCycle a = new TechCycle()
|
||||
TechCycle currTechCycle = new TechCycle()
|
||||
{
|
||||
start = start,
|
||||
index = TechCycle.Operation.unloading_loading
|
||||
};
|
||||
|
||||
do
|
||||
{
|
||||
cursor = cursor.AddDays(-1);
|
||||
subRes = GetFile(cursor, vdp, 3);
|
||||
} while (subRes.Length == 0 && cursor > start.AddDays(-10));
|
||||
|
||||
{
|
||||
if (subRes.Length > 0)
|
||||
{
|
||||
var b = STPConverter.TechCycle(subRes);
|
||||
if (b.Length > 0) a = b.Last();
|
||||
if (b.Length > 0) currTechCycle = b.Last();
|
||||
}
|
||||
a.start = start;
|
||||
}
|
||||
|
||||
cursor = start.AddDays(-1);
|
||||
do
|
||||
{
|
||||
cursor = cursor.AddDays(1);
|
||||
@@ -138,23 +141,42 @@ namespace DataClients
|
||||
{
|
||||
if (e.start <= start)
|
||||
{
|
||||
a = e;
|
||||
currTechCycle = e;
|
||||
continue;
|
||||
}
|
||||
if (e.start >= end)
|
||||
{
|
||||
a.end = end;
|
||||
result.Add(a);
|
||||
currTechCycle.end = e.start;
|
||||
result.Add(currTechCycle);
|
||||
currTechCycle = e;
|
||||
break;
|
||||
}
|
||||
if (e.start > start && e.start < end)
|
||||
{
|
||||
a.end = e.start;
|
||||
result.Add(a);
|
||||
a = e;
|
||||
currTechCycle.end = e.start;
|
||||
if (result.Count > 0 && result[result.Count - 1].index == currTechCycle.index)
|
||||
result[result.Count - 1].end = currTechCycle.end;
|
||||
else
|
||||
result.Add(currTechCycle);
|
||||
currTechCycle = e;
|
||||
}
|
||||
}
|
||||
|
||||
} while (cursor <= end);
|
||||
|
||||
{
|
||||
if (result.Count == 0)
|
||||
{
|
||||
currTechCycle.start = start;
|
||||
currTechCycle.end = end;
|
||||
result.Add(currTechCycle);
|
||||
}
|
||||
else if (result[result.Count - 1].end < end)
|
||||
{
|
||||
currTechCycle.end = end;
|
||||
result.Add(currTechCycle);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -246,6 +268,7 @@ namespace DataClients
|
||||
var cycle = new TechCycle();
|
||||
cycle.index = (DataClients.TechCycle.Operation)UInt32.Parse(substr[0]);
|
||||
cycle.start = Converter.ConvertUnixTimeToDateTime(Int32.Parse(substr[2]));
|
||||
if (result.Count > 0) result[result.Count - 1].end = cycle.start;
|
||||
result.Add(cycle);
|
||||
}
|
||||
return result.ToArray();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SupportClasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -10,7 +11,7 @@ namespace DataClients
|
||||
{
|
||||
public static class TempDir
|
||||
{
|
||||
private static readonly char split = '/';
|
||||
private static readonly char split = _Directory.Slash;
|
||||
private static string dir = Directory.GetCurrentDirectory() + split + "temp";
|
||||
private static List<string> protect = new List<string>();
|
||||
private static Task checkTask = null;
|
||||
|
@@ -31,7 +31,11 @@
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard2.0": {
|
||||
"projectReferences": {}
|
||||
"projectReferences": {
|
||||
"D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj": {
|
||||
"projectPath": "D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
@@ -71,6 +75,66 @@
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.403\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj",
|
||||
"projectName": "SupportClasses",
|
||||
"projectPath": "D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj",
|
||||
"packagesPath": "C:\\Users\\google\\.nuget\\packages\\",
|
||||
"outputPath": "D:\\GIT\\ASCKU_PC\\SupportClasses\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Microsoft\\Xamarin\\NuGet\\",
|
||||
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\google\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"netstandard2.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard2.0": {
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard2.0": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": {
|
||||
"suppressParent": "All",
|
||||
"target": "Package",
|
||||
"version": "[2.0.3, )",
|
||||
"autoReferenced": true
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.403\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -61,6 +61,16 @@
|
||||
"rid": "win"
|
||||
}
|
||||
}
|
||||
},
|
||||
"SupportClasses/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETStandard,Version=v2.0",
|
||||
"compile": {
|
||||
"bin/placeholder/SupportClasses.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/placeholder/SupportClasses.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -295,12 +305,18 @@
|
||||
"useSharedDesignerContext.txt",
|
||||
"version.txt"
|
||||
]
|
||||
},
|
||||
"SupportClasses/1.0.0": {
|
||||
"type": "project",
|
||||
"path": "../SupportClasses/SupportClasses.csproj",
|
||||
"msbuildProject": "../SupportClasses/SupportClasses.csproj"
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
".NETStandard,Version=v2.0": [
|
||||
"NETStandard.Library >= 2.0.3",
|
||||
"SharpZipLib >= 1.2.0",
|
||||
"SupportClasses >= 1.0.0",
|
||||
"System.Text.Encoding.CodePages >= 4.7.1"
|
||||
]
|
||||
},
|
||||
@@ -336,7 +352,11 @@
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard2.0": {
|
||||
"projectReferences": {}
|
||||
"projectReferences": {
|
||||
"D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj": {
|
||||
"projectPath": "D:\\GIT\\ASCKU_PC\\SupportClasses\\SupportClasses.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "7BT9QmMgOwS6t99cv7fCXOBzEuqVwmhl2HP4ljC3vr6o2Uq2GZQULmiLXAJ9NJ7T4nDLaRlmIbUCNZp+mmA0Dw==",
|
||||
"dgSpecHash": "sLKZfVMkCNEVT7uyfvutFp/QvWP0nA+zkfgEmrlynF90hQbh8SrlMNp5eIIAuw5br+yO5vuezeQKEiVCZ9c1Qw==",
|
||||
"success": true,
|
||||
"projectFilePath": "D:\\GIT\\ASCKU_PC\\DataClients\\DataClients.csproj",
|
||||
"expectedPackageFiles": [
|
||||
|
Reference in New Issue
Block a user