WIP
Added new library with maintenances counters Added maintenances thread
This commit is contained in:
Binary file not shown.
@@ -6,7 +6,10 @@
|
||||
<lang langKey="en">Test</lang>
|
||||
<lang langKey="it">Ita</lang>
|
||||
</localizedNames>
|
||||
<interval>5000</interval>
|
||||
<interval>10</interval>
|
||||
<deadline>01/12/1999</deadline>
|
||||
<type>interval</type>
|
||||
<counterId>1</counterId>
|
||||
</maintenance>
|
||||
<maintenance>
|
||||
<id>2</id>
|
||||
@@ -14,6 +17,9 @@
|
||||
<lang langKey="en">Test</lang>
|
||||
<lang langKey="it">Ita</lang>
|
||||
</localizedNames>
|
||||
<interval>5000</interval>
|
||||
<interval>2500</interval>
|
||||
<deadline>01/12/1999</deadline>
|
||||
<type>exp_date</type>
|
||||
<counterId>2</counterId>
|
||||
</maintenance>
|
||||
</root>
|
||||
@@ -21,7 +21,10 @@
|
||||
</xs:unique>
|
||||
|
||||
</xs:element>
|
||||
<xs:element name="interval" type="xs:int"/>
|
||||
<xs:element name="interval" type="xs:string"/>
|
||||
<xs:element name="deadline" type="xs:string"/>
|
||||
<xs:element name="type" type="xs:string"/>
|
||||
<xs:element name="counterId" type="xs:unsignedInt"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
|
||||
|
||||
@@ -65,7 +65,10 @@ namespace Step.Config
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read names list
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
count = Convert.ToInt32(x.Element("interval").Value)
|
||||
Intervall = TimeSpan.FromHours(Convert.ToDouble(x.Element("interval").Value)),
|
||||
Deadline = DateTime.Parse(x.Element("deadline").Value),
|
||||
Type = x.Element("type").Value,
|
||||
CouterId = Convert.ToInt32(x.Element("counterId").Value)
|
||||
}
|
||||
)
|
||||
.ToList();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.ConfigModels;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,9 +24,25 @@ namespace Step.Database.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public DTOExpiredMaintenanceModel GetExpiredMaintenance()
|
||||
public List<PerformedMaintenanceModel> FindLastMaintenance()
|
||||
{
|
||||
return new DTOExpiredMaintenanceModel();
|
||||
List<PerformedMaintenanceModel> lastMaintenances = new List<PerformedMaintenanceModel>();
|
||||
// Find last performed maintenance
|
||||
lastMaintenances = (from maintenances in dbCtx.PerformedMaintenances
|
||||
where maintenances.Date == (from m1 in dbCtx.PerformedMaintenances // Select max data of performed maintenance
|
||||
where m1.MaintenanceId == maintenances.MaintenanceId
|
||||
select m1.Date
|
||||
).Max()
|
||||
select maintenances).ToList();
|
||||
|
||||
return lastMaintenances;
|
||||
}
|
||||
|
||||
public List<MaintenanceModel> FindAll()
|
||||
{
|
||||
return dbCtx
|
||||
.Maintenances
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void CheckDifferencesFromDbAndXml()
|
||||
@@ -39,12 +56,58 @@ namespace Step.Database.Controllers
|
||||
!MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId)
|
||||
).ToList();
|
||||
|
||||
// Delete database items
|
||||
foreach (var item in toDeleteMaint)
|
||||
dbCtx.Maintenances.Remove(item);
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
// Find common data from
|
||||
List<MaintenanceModel> toUpdateMaint = dbMaintenances.Where(x =>
|
||||
MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId)
|
||||
).ToList();
|
||||
)
|
||||
.ToList();
|
||||
|
||||
|
||||
// Update rows
|
||||
if (toUpdateMaint != null)
|
||||
foreach (MaintenanceModel item in toUpdateMaint)
|
||||
{
|
||||
// find to update into db
|
||||
var old = dbCtx.Maintenances.Where(x => x.MaintenanceId == item.MaintenanceId).FirstOrDefault();
|
||||
|
||||
// Update model
|
||||
old = MaintenancesConfig.Where(x => x.Id == item.MaintenanceId).Select(x =>
|
||||
{
|
||||
old.MaintenanceId = x.Id;
|
||||
old.Deadline = x.Deadline;
|
||||
old.Intervall = x.Intervall.TotalMinutes;
|
||||
old.Type = x.Type;
|
||||
old.CounterId = x.CouterId;
|
||||
return old;
|
||||
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
// Get new maintenance from file
|
||||
List<MaintenanceModel> toAddMaint = MaintenancesConfig
|
||||
.Where(x => !toUpdateMaint.Select(y => y.MaintenanceId).Contains(x.Id))
|
||||
.Select(x => new MaintenanceModel()
|
||||
{
|
||||
MaintenanceId = x.Id,
|
||||
Deadline = x.Deadline,
|
||||
Intervall = x.Intervall.TotalMinutes,
|
||||
Type = x.Type,
|
||||
CounterId = x.CouterId
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// Add new maintenances to database
|
||||
if (toAddMaint != null)
|
||||
{
|
||||
dbCtx.Maintenances.AddRange(toAddMaint);
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Step.Database
|
||||
public DbSet<FunctionAccessModel> FunctionsAccess { get; set; }
|
||||
public DbSet<SessionModel> Sessions { get; set; }
|
||||
public DbSet<MaintenanceModel> Maintenances { get; set; }
|
||||
public DbSet<PerformedMaintenanceModel> PerformedMaintenances { get; set; }
|
||||
|
||||
|
||||
public DatabaseContext()
|
||||
: base("mySQLDatabaseConnection")
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// <auto-generated />
|
||||
namespace Step.Database.Migrations
|
||||
{
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Data.Entity.Migrations;
|
||||
using System.Data.Entity.Migrations.Infrastructure;
|
||||
using System.Resources;
|
||||
|
||||
[GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")]
|
||||
public sealed partial class InitCreate : IMigrationMetadata
|
||||
{
|
||||
private readonly ResourceManager Resources = new ResourceManager(typeof(InitCreate));
|
||||
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201802141408206_InitCreate"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Target
|
||||
{
|
||||
get { return Resources.GetString("Target"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
namespace Step.Database.Migrations
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity.Migrations;
|
||||
|
||||
public partial class InitCreate : DbMigration
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
CreateTable(
|
||||
"dbo.function_access",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
write_level_min = c.Int(nullable: false),
|
||||
read_level_min = c.Int(nullable: false),
|
||||
area = c.String(unicode: false),
|
||||
enabled = c.Boolean(nullable: false),
|
||||
plc_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.machine",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
unique_id = c.String(unicode: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.machine_user",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
machine_id = c.Int(nullable: false),
|
||||
user_id = c.Int(nullable: false),
|
||||
role_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.machine", t => t.machine_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.role", t => t.role_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
|
||||
.Index(t => new { t.machine_id, t.user_id }, unique: true, clustered: true, name: "unique_machine_user")
|
||||
.Index(t => t.role_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.role",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
level = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.user",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
username = c.String(nullable: false, unicode: false),
|
||||
first_name = c.String(unicode: false),
|
||||
last_name = c.String(unicode: false),
|
||||
password = c.String(unicode: false),
|
||||
security_stamp = c.String(unicode: false),
|
||||
language = c.String(unicode: false),
|
||||
role_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.maintenance",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false),
|
||||
intervall = c.Double(nullable: false),
|
||||
deadline = c.DateTime(nullable: false, precision: 0),
|
||||
type = c.String(unicode: false),
|
||||
counter_id = c.Int(nullable: false),
|
||||
creation_date = c.DateTime(nullable: false, precision: 0),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.performed_maintenance",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
date = c.DateTime(nullable: false, precision: 0),
|
||||
counter_value = c.Int(nullable: false),
|
||||
maintenance = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.maintenance", t => t.maintenance, cascadeDelete: true)
|
||||
.Index(t => t.maintenance);
|
||||
|
||||
CreateTable(
|
||||
"dbo.session",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
token = c.String(unicode: false),
|
||||
machine_user_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.machine_user", t => t.machine_user_id, cascadeDelete: true)
|
||||
.Index(t => t.machine_user_id);
|
||||
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
DropForeignKey("dbo.session", "machine_user_id", "dbo.machine_user");
|
||||
DropForeignKey("dbo.performed_maintenance", "maintenance", "dbo.maintenance");
|
||||
DropForeignKey("dbo.machine_user", "user_id", "dbo.user");
|
||||
DropForeignKey("dbo.machine_user", "role_id", "dbo.role");
|
||||
DropForeignKey("dbo.machine_user", "machine_id", "dbo.machine");
|
||||
DropIndex("dbo.session", new[] { "machine_user_id" });
|
||||
DropIndex("dbo.performed_maintenance", new[] { "maintenance" });
|
||||
DropIndex("dbo.machine_user", new[] { "role_id" });
|
||||
DropIndex("dbo.machine_user", "unique_machine_user");
|
||||
DropTable("dbo.session");
|
||||
DropTable("dbo.performed_maintenance");
|
||||
DropTable("dbo.maintenance");
|
||||
DropTable("dbo.user");
|
||||
DropTable("dbo.role");
|
||||
DropTable("dbo.machine_user");
|
||||
DropTable("dbo.machine");
|
||||
DropTable("dbo.function_access");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Target" xml:space="preserve">
|
||||
<value>H4sIAAAAAAAEAO1d3W7kthW+L5B3EHQZOB57FwEaYyaBM7YLo+u1seOkvRvQEmcsRKIUiXJsFH2yXvSR+gol9UuKpERSmp81ggUWNkV+PDz8SB4enSP/7z//nf/0GoXOC0yzIEYL9/z0zHUg8mI/QNuFm+PNd391f/rxm7/Mr/3o1fm1rveR1iMtUbZwnzFOLmazzHuGEchOo8BL4yze4FMvjmbAj2cfzs5+mJ2fzyCBcAmW48y/5AgHESx+Ib8uY+TBBOcgvIt9GGZVOXmyKlCdzyCCWQI8uHBXGCanVwCDJ5BB17kMA0CEWMFw4zoAoRgDTES8+CWDK5zGaLtKSAEIH98SSOptQEhbFaJftNV1R3H2gY5i1jasobw8w3FkCHj+sVLLrNvcSrluozaiuGuiYPxGR10ob+He5Mij0JeeB7Os0LPrdPu9WIYpbVOpuajVKLucm1MJ0InTVj9pWELIRP+dOMs8xHkKFwjmOAWkxkP+FAbe3+HbY/wbRAuUhyErPBGfPOMKSNFDGicwxW9f4EY6pFvfdWY8yqwL04AoEcrR3yL88YPrfCaCgacQNrxhNLXCcQr/BhFMAYb+A8AYpmTab31YaF6QpdMz/b/ujRCVLDfXuQOvnyDa4ueFS350nZvgFfp1SSXBLyggq5M0wmkOhzr5Rxpg+Am+wPAuQENj64f6AoE/DdJlCsHOR36NqETNfP4cxyEEyFjWh9AbJgULMZ+1C693Od4B7zlAcMQ6ZBEOtAArEWxWHtN0X0uu0vWOmUcq/54z45qoI1NikfMvHU+uBuWwBKNijCBZ3XxvRNPl9gCTtMQe2LbJvmeM8Rm8BNtCE/KBuc4XGBbPs+cgKY0vgTHrpvJNGkdUDpGbdZ31Ks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T9xbrNlSBBgCv0L55EonRaVvuLyd+ffxpI2B/BEYn7YjZjNxdtAzNt/rqtmjXRng11bfJ/jfVB2it0iZL9zMeHm/N62h9YhqNa3FhDrDhw5dWAioKTzdQdbnK4PcOzw+G8z2OLI9qEdfXnhMFQ3JCDjWitBfLsPFvidDxZQfwUukrYfUugF5UdRz4xhMfP5AtspZ71s9orq+NZGjHKCbxW8j110tCbVc/3C5vzbTDfn0TKzWZimu7Bb1D6lr5YImE1Wt13mgkfKdNa45hPM3HRZ4VVEyiFSs9UhtyPTKcdkLarcsTpkd8ZkKGr12RctcoS53Eyqxt5zqo+LXX0xKMdBLeXr6yNMxZZP5X7S7I6LV2ZzfAheKd/ifAWZ1GL21aHylTUyKaZK5bY8PQfflk9OR5NX9bKjtOe98nGmN4/acHZERz6p0Dq/epIPTeyDdANv7dUm2z73wc776yZuo5sI051Ueb4xl00sZJVKa5VvscnV+ykmpKiuN1XFNajSl/USilX98o9lHUZ1sqpeR8zKUXXGVOnpsJhqrfRmVXfMM1k/aZFZqpH8rMIfGIeW/OLBItFat4pca8qNWCt/WtV7T12ZGEldfW0iEL/LCTLwj2XdZmWNY8rH5gYjZsyY5M7KUNTZ90eUdC2szk42wFErYarkavkIlKIfVAkHS6JW7UTyuGerHOnB3OuplLjj7OhRnOixOlVRkTtJgRZD+4ihxvxFPWIxZsG2haB/Xw9BjzPRmjq3aBPXJmNHorpKN24SYuAT++0yxcEGeJg8ptZU8Q3WIiJ34V5HT9C/Rfc5TnJMhgyjp5D7qCu1OPv6L/K8eZnn90mR5zzFEIiYAX0nc49+zoPQb+S+kfi/FRDUlK1eEtC5xPRlwfatQRI/p64CqtTXWOCPMEpCApbdoxV4gTayEQZ/glvgvdUBmmqQ4Yng1T6/CsA2BVFWYbTtya+Ew370+uP/AdrLVe9YcgAA</value>
|
||||
</data>
|
||||
<data name="DefaultSchema" xml:space="preserve">
|
||||
<value>dbo</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -77,6 +77,10 @@
|
||||
<Compile Include="Controllers\UsersController.cs" />
|
||||
<Compile Include="Controllers\MachinesUsersController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Migrations\201802141408206_InitCreate.cs" />
|
||||
<Compile Include="Migrations\201802141408206_InitCreate.Designer.cs">
|
||||
<DependentUpon>201802141408206_InitCreate.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -110,5 +114,10 @@
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Migrations\201802141408206_InitCreate.resx">
|
||||
<DependentUpon>201802141408206_InitCreate.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.ConfigModels
|
||||
{
|
||||
public class MaintenanceConfigModel
|
||||
{
|
||||
public int Id;
|
||||
public Dictionary<string, string> LocalizedNames;
|
||||
public int count;
|
||||
public int Id { get; set; }
|
||||
public Dictionary<string, string> LocalizedNames { get; set; }
|
||||
public TimeSpan Intervall { get; set; }
|
||||
public DateTime Deadline { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int CouterId { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.DTOModels
|
||||
{
|
||||
public class DTOExpiredMaintenanceModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ExpirationDate { get; set; }
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,15 @@ namespace Step.Model.DatabaseModels
|
||||
public class MaintenanceModel
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
[Column("id")]
|
||||
public int MaintenanceId { get; set; }
|
||||
|
||||
[Column("intervall")]
|
||||
public TimeSpan Intervall { get; set; }
|
||||
public double Intervall { get; set; }
|
||||
|
||||
[Column("deadline")]
|
||||
public DateTime DeadLine { get; set; }
|
||||
public DateTime Deadline { get; set; }
|
||||
|
||||
[Column("type")]
|
||||
public string Type { get; set; }
|
||||
@@ -26,17 +27,17 @@ namespace Step.Model.DatabaseModels
|
||||
[Column("creation_date")]
|
||||
public DateTime CreationDate { get; set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var item = obj as MaintenanceModel;
|
||||
//public override bool Equals(object obj)
|
||||
//{
|
||||
// var item = obj as MaintenanceModel;
|
||||
|
||||
if (item == null)
|
||||
return false;
|
||||
// if (item == null)
|
||||
// return false;
|
||||
|
||||
if (item.MaintenanceId != MaintenanceId)
|
||||
return false;
|
||||
// if (item.MaintenanceId != MaintenanceId)
|
||||
// return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Step.Model.DatabaseModels
|
||||
{
|
||||
[Table("machine_user")]
|
||||
[Table("performed_maintenance")]
|
||||
public class PerformedMaintenanceModel
|
||||
{
|
||||
[Key]
|
||||
@@ -16,5 +16,11 @@ namespace Step.Model.DatabaseModels
|
||||
|
||||
[Column("counter_value")]
|
||||
public int CounterValue { get; set; }
|
||||
|
||||
[Column("maintenance")]
|
||||
public int MaintenanceId { get; set; }
|
||||
|
||||
[ForeignKey("MaintenanceId")]
|
||||
public MaintenanceModel Maintenance { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using CMS_CORE.Fanuc;
|
||||
using CMS_CORE.Osai;
|
||||
using CMS_CORE.Siemens;
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -336,6 +337,65 @@ namespace Step.NC
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
public CmsError GetExpiredMaintenances()
|
||||
{
|
||||
List<DTOExpiredMaintenanceModel> expiredMaintenance = new List<DTOExpiredMaintenanceModel>();
|
||||
|
||||
List<CounterModel> counters = new List<CounterModel>();
|
||||
|
||||
CmsError cmsError = numericalControl.PLC_RMachineCounters(ref counters);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
using (MaintenancesController maintenancesController = new MaintenancesController())
|
||||
{
|
||||
// Get the last performed maintenance for each maintenance
|
||||
List<PerformedMaintenanceModel> performedMaintenance = maintenancesController.FindLastMaintenance();
|
||||
|
||||
// Get all the active maintenances
|
||||
List<MaintenanceModel> maintenances = maintenancesController.FindAll();
|
||||
|
||||
foreach (var maintenance in maintenances)
|
||||
{
|
||||
// Get matching last performed maintenance for current maintenance
|
||||
var performed = performedMaintenance.Find(x => x.MaintenanceId == maintenance.MaintenanceId);
|
||||
|
||||
switch (maintenance.Type)
|
||||
{
|
||||
case "interval":
|
||||
{
|
||||
// Get matching counter for the current maintenance
|
||||
var counter = counters.Find(x => x.Id == maintenance.CounterId);
|
||||
|
||||
// PLC - LASTPERFORMED >= MAINTENANCE_INTERVAL
|
||||
if (counter.Value - performed.CounterValue >= maintenance.Intervall)
|
||||
{
|
||||
expiredMaintenance.Add(new DTOExpiredMaintenanceModel()
|
||||
{
|
||||
Id = MAINTENANCE_PREFIX_ID + maintenance.MaintenanceId,
|
||||
ExpirationDate = DateTime.Now
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "exp_date":
|
||||
{
|
||||
if (maintenance.Deadline <= DateTime.Now)
|
||||
expiredMaintenance.Add(new DTOExpiredMaintenanceModel()
|
||||
{
|
||||
Id = MAINTENANCE_PREFIX_ID + maintenance.MaintenanceId,
|
||||
ExpirationDate = maintenance.Deadline
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
public CmsError RefreshAllAlarms()
|
||||
{
|
||||
return new CmsError(0, "");
|
||||
|
||||
@@ -281,6 +281,50 @@ public static class ThreadsFunctions
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadExpiredMaintenances()
|
||||
{
|
||||
NcHandler ncHandler = new NcHandler();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
|
||||
try
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncHandler.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
ManageLibraryError(libraryError);
|
||||
|
||||
while (true)
|
||||
{
|
||||
sw.Restart();
|
||||
|
||||
if (ncHandler.numericalControl.NC_IsConnected())
|
||||
{
|
||||
// Get Data from database and PLC
|
||||
libraryError = ncHandler.GetExpiredMaintenances();
|
||||
if (libraryError.errorCode != 0)
|
||||
ManageLibraryError(libraryError);
|
||||
//else
|
||||
// Send through signalR
|
||||
// MessageServices.Current.Publish(SEND_FUNCTIONALITY_DATA, null, functionsAccessList);
|
||||
}
|
||||
else
|
||||
TryNcConnection();
|
||||
|
||||
sw.Stop();
|
||||
//Send to the UI the time
|
||||
ReadFunctionTimer += sw.ElapsedMilliseconds;
|
||||
ReadFunctionTimes++;
|
||||
|
||||
// Wait
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncHandler.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Nc Threads
|
||||
|
||||
#region SupportFunctions
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CMS_CORE;
|
||||
using CMS_CORE.Demo;
|
||||
using CMS_CORE.Fanuc;
|
||||
using CMS_CORE.Osai;
|
||||
using CMS_CORE.Siemens;
|
||||
using Step.NC;
|
||||
using static Step.Config.ServerConfig;
|
||||
using static Step.Utils.Constants;
|
||||
using TeamDev.SDK.MVVM;
|
||||
using System.Diagnostics;
|
||||
using static Step.Utils.Constants;
|
||||
|
||||
namespace Step.Core
|
||||
{
|
||||
public static class ThreadsHandler
|
||||
{
|
||||
private static List<Action> ThreadFunctionsList = new List<Action>
|
||||
public static class ThreadsHandler
|
||||
{
|
||||
private static List<Action> ThreadFunctionsList = new List<Action>
|
||||
{
|
||||
ThreadsFunctions.ReadAlarms,
|
||||
ThreadsFunctions.ReadNcGenericInfo,
|
||||
@@ -27,71 +16,68 @@ namespace Step.Core
|
||||
ThreadsFunctions.ReadPowerOnData,
|
||||
ThreadsFunctions.StatThread,
|
||||
ThreadsFunctions.ReadProcessesPPStatus,
|
||||
ThreadsFunctions.ReadEnabledFunctionality
|
||||
ThreadsFunctions.ReadEnabledFunctionality,
|
||||
ThreadsFunctions.ReadExpiredMaintenances
|
||||
};
|
||||
private volatile static List<Thread> RunningThreadsList = new List<Thread>();
|
||||
internal volatile static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
ThreadsFunctions.TryNcConnection();
|
||||
}
|
||||
private volatile static List<Thread> RunningThreadsList = new List<Thread>();
|
||||
internal volatile static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
|
||||
|
||||
public static void StartWorkers()
|
||||
{
|
||||
|
||||
RunningThreadStatus.Clear();
|
||||
|
||||
// For each function run in the list a thread
|
||||
ThreadFunctionsList.ForEach(threadFunction =>
|
||||
{
|
||||
// Run new Thread in the list
|
||||
Thread t = new Thread(() =>
|
||||
threadFunction()
|
||||
);
|
||||
t.Start();
|
||||
// Add thread to running threads list
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.Add(t);
|
||||
|
||||
|
||||
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
|
||||
});
|
||||
|
||||
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
|
||||
// Stop each thread
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.ForEach(thread =>
|
||||
{
|
||||
thread.Abort();
|
||||
});
|
||||
|
||||
// Remove threads from running status
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.Clear();
|
||||
|
||||
RunningThreadStatus.Clear();
|
||||
RunningThreadStatus.Add("TryNcConnection", "---");
|
||||
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
//Abort Nc Read Threads
|
||||
RunningThreadsList.ForEach(thread =>
|
||||
public static void Start()
|
||||
{
|
||||
thread.Abort();
|
||||
});
|
||||
ThreadsFunctions.TryNcConnection();
|
||||
}
|
||||
|
||||
//Abort Connect Thread
|
||||
ThreadsFunctions.AbortNcConnection();
|
||||
public static void StartWorkers()
|
||||
{
|
||||
RunningThreadStatus.Clear();
|
||||
|
||||
// For each function run in the list a thread
|
||||
ThreadFunctionsList.ForEach(threadFunction =>
|
||||
{
|
||||
// Run new Thread in the list
|
||||
Thread t = new Thread(() =>
|
||||
threadFunction()
|
||||
);
|
||||
t.Start();
|
||||
// Add thread to running threads list
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.Add(t);
|
||||
|
||||
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
|
||||
});
|
||||
|
||||
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
// Stop each thread
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.ForEach(thread =>
|
||||
{
|
||||
thread.Abort();
|
||||
});
|
||||
|
||||
// Remove threads from running status
|
||||
lock (RunningThreadsList)
|
||||
RunningThreadsList.Clear();
|
||||
|
||||
RunningThreadStatus.Clear();
|
||||
RunningThreadStatus.Add("TryNcConnection", "---");
|
||||
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
//Abort Nc Read Threads
|
||||
RunningThreadsList.ForEach(thread =>
|
||||
{
|
||||
thread.Abort();
|
||||
});
|
||||
|
||||
//Abort Connect Thread
|
||||
ThreadsFunctions.AbortNcConnection();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -84,5 +84,8 @@ namespace Step.Utils
|
||||
public const string SEND_PROCESSES_DATA = "SEND_PROCESSES_STATUS";
|
||||
public const string SEND_FUNCTIONALITY_DATA = "SEND_FUNCTION_DATA";
|
||||
|
||||
|
||||
// ID prefix
|
||||
public const string MAINTENANCE_PREFIX_ID = "MAINT_";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Step.Model.ConfigModels;
|
||||
using Step.Model.DTOModels;
|
||||
using static Step.Config.ServerConfig;
|
||||
using static Step.Utils.LanguageController;
|
||||
using static Step.Utils.Constants;
|
||||
|
||||
namespace Step.Controllers.WebApi
|
||||
{
|
||||
@@ -54,7 +55,7 @@ namespace Step.Controllers.WebApi
|
||||
|
||||
return MaintenancesConfig
|
||||
.ToDictionary(
|
||||
x => "MANT_" + x.Id.ToString(),
|
||||
x => MAINTENANCE_PREFIX_ID + x.Id.ToString(),
|
||||
x => GetValueFromMaintenanceNameList(x.LocalizedNames, language, x.Id)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user