[6161] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Web;
|
---|
| 5 | using HLWebOKBAdminPlugin.OKBAdministrationService;
|
---|
| 6 | using HLWebOKBAdminPlugin.Helpers;
|
---|
| 7 |
|
---|
[6213] | 8 | namespace HLWebOKBAdminPlugin.Models
|
---|
| 9 | {
|
---|
[6161] | 10 | public class AlgorithmModel {
|
---|
[6213] | 11 |
|
---|
[6161] | 12 | public String SelectedSubMenu { get; set; }
|
---|
[6213] | 13 | public IList<Algorithm> Algorithms { get { return AlgorithmGetAll(); } set { ;} }
|
---|
| 14 | public IList<AlgorithmClass> AlgorithmClasses { get { return AlgorithmClassGetAll(); } }
|
---|
| 15 | public IList<Platform> Platforms { get { return PlatformsGetAll(); } }
|
---|
[6161] | 16 |
|
---|
| 17 | public Algorithm Algorithm { get; set; }
|
---|
| 18 |
|
---|
| 19 | public AlgorithmModel() {
|
---|
| 20 | Algorithm = new Algorithm();
|
---|
| 21 | }//AlgorithmModel
|
---|
| 22 |
|
---|
[6213] | 23 | //***************************************Algorithms***************************************************
|
---|
[6161] | 24 | private IList<Platform> PlatformsGetAll() {
|
---|
| 25 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 26 |
|
---|
| 27 | IList<Platform> platformList = new List<Platform>();
|
---|
| 28 |
|
---|
| 29 | if (adminClient != null) {
|
---|
| 30 | Platform[] platforms = adminClient.GetPlatforms();
|
---|
| 31 | foreach (Platform pl in platforms) {
|
---|
| 32 | platformList.Add(pl);
|
---|
| 33 | }
|
---|
| 34 | }//if (adminClient != null)
|
---|
| 35 |
|
---|
| 36 | return platformList;
|
---|
[6213] | 37 | }//AlgorithmClassGetAll
|
---|
[6161] | 38 |
|
---|
[6213] | 39 | private IList<AlgorithmClass> AlgorithmClassGetAll() {
|
---|
[6161] | 40 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 41 |
|
---|
[6213] | 42 | IList<AlgorithmClass> algorithmClassList = new List<AlgorithmClass>();
|
---|
[6161] | 43 |
|
---|
| 44 | if (adminClient != null) {
|
---|
[6213] | 45 | AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses();
|
---|
| 46 | foreach(AlgorithmClass ac in algorithmClasses) {
|
---|
| 47 | algorithmClassList.Add(ac);
|
---|
[6161] | 48 | }
|
---|
| 49 | }//if (adminClient != null)
|
---|
| 50 |
|
---|
[6213] | 51 | return algorithmClassList;
|
---|
| 52 | }//AlgorithmClassGetAll
|
---|
[6161] | 53 |
|
---|
[6213] | 54 | private IList<Algorithm> AlgorithmGetAll() {
|
---|
[6161] | 55 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 56 |
|
---|
| 57 | IList<Algorithm> algorithmList = new List<Algorithm>();
|
---|
| 58 |
|
---|
| 59 | if (adminClient != null) {
|
---|
| 60 | Algorithm[] algorithm = adminClient.GetAlgorithms();
|
---|
[6213] | 61 | foreach(Algorithm alg in algorithm) {
|
---|
| 62 | algorithmList.Add(alg);
|
---|
[6161] | 63 |
|
---|
| 64 | }
|
---|
| 65 | }//if (adminClient != null)
|
---|
| 66 |
|
---|
| 67 | return algorithmList;
|
---|
[6213] | 68 | }//AlgorithmGetAll
|
---|
[6161] | 69 |
|
---|
| 70 | private long AddAlgorithm(Algorithm algorithm) {
|
---|
| 71 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 72 |
|
---|
| 73 | if (adminClient != null) {
|
---|
| 74 | return adminClient.AddAlgorithm(algorithm);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return 0;
|
---|
| 78 | }//AddAlgorithm
|
---|
| 79 |
|
---|
| 80 | public void DeleteAlgorithm(long id) {
|
---|
| 81 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 82 |
|
---|
| 83 | if (adminClient != null) {
|
---|
| 84 | adminClient.DeleteAlgorithm(id);
|
---|
| 85 | }
|
---|
| 86 | }//DeleteAlgorithm
|
---|
| 87 |
|
---|
| 88 | public long SaveAlgorithm(Algorithm algorithm) {
|
---|
| 89 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 90 |
|
---|
| 91 | if (adminClient != null) {
|
---|
| 92 | if (algorithm.Id == 0) {
|
---|
| 93 | return AddAlgorithm(algorithm);
|
---|
| 94 | }
|
---|
| 95 | else {
|
---|
[6213] | 96 | Algorithm alg = adminClient.GetAlgorithm(algorithm.Id);
|
---|
[6161] | 97 |
|
---|
[6213] | 98 | if (alg != null) {
|
---|
[6161] | 99 | adminClient.UpdateAlgorithm(algorithm);
|
---|
| 100 | return algorithm.Id;
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return 0;
|
---|
| 106 | }//SaveAlgorithm
|
---|
[6246] | 107 |
|
---|
| 108 | public void UpdateAlgorithmData(long id, byte[] data) {
|
---|
| 109 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 110 |
|
---|
| 111 | if (adminClient != null) {
|
---|
| 112 | adminClient.UpdateAlgorithmData(id, data);
|
---|
| 113 | }
|
---|
| 114 | }//UpdateProblemData
|
---|
[6161] | 115 | }
|
---|
| 116 | } |
---|