1: using System;
2: using System.Collections.Generic;
3: using System.Data;
4: using System.Linq;
5: using System.Text;
6:
7: namespace Ia.Ngn.Cl.Model.Data.Huawei
8: {
9: ////////////////////////////////////////////////////////////////////////////
10:
11: /// <summary publish="true">
12: /// Huawei's Dev support class of Next Generation Network'a (NGN's) data model.
13: /// </summary>
14: ///
15: /// <remarks>
16: /// Copyright © 2016-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
17: ///
18: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
19: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
20: ///
21: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23: ///
24: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
25: ///
26: /// Copyright notice: This notice may not be removed or altered from any source distribution.
27: /// </remarks>
28: public partial class Dev
29: {
30: private static Dictionary<string, int> devTypeToDevTypeIdDictionary;
31: private static Dictionary<int, string> devTypeIdToDevTypeDictionary;
32:
33: private static Dictionary<string, int> devToDidDictionary;
34: private static Dictionary<int, string> didToDevDictionary;
35:
36: public static Dictionary<string, int> DevTypeToDevTypeIdDictionary
37: {
38: get
39: {
40: if (devTypeToDevTypeIdDictionary == null || devTypeToDevTypeIdDictionary.Count == 0)
41: {
42: devTypeToDevTypeIdDictionary = new Dictionary<string, int>();
43:
44: devTypeToDevTypeIdDictionary["UA5000(PVMV1)"] = 219;
45: devTypeToDevTypeIdDictionary["MA5662"] = 37;
46: devTypeToDevTypeIdDictionary["MA5600V3"] = 44;
47: devTypeToDevTypeIdDictionary["MA5105(BSL)"] = 71;
48: devTypeToDevTypeIdDictionary["MA5100V2"] = 72;
49: devTypeToDevTypeIdDictionary["MA5300V1"] = 74;
50: devTypeToDevTypeIdDictionary["MD5500V1"] = 75;
51: devTypeToDevTypeIdDictionary["UA5000"] = 82;
52: devTypeToDevTypeIdDictionary["MA5100V1"] = 86;
53: devTypeToDevTypeIdDictionary["UA5000(IPMB)"] = 253;
54: devTypeToDevTypeIdDictionary["MA5605"] = 30;
55: devTypeToDevTypeIdDictionary["MA5680T"] = 34;
56: devTypeToDevTypeIdDictionary["MA5606T"] = 57;
57: devTypeToDevTypeIdDictionary["UA5000(PVU)"] = 232;
58: devTypeToDevTypeIdDictionary["MA5600T"] = 249;
59: devTypeToDevTypeIdDictionary["MA5615"] = 60;
60: devTypeToDevTypeIdDictionary["MA5626E"] = 61;
61: devTypeToDevTypeIdDictionary["MA5620E"] = 62;
62: devTypeToDevTypeIdDictionary["MA5651"] = 64;
63: devTypeToDevTypeIdDictionary["MA5620G"] = 65;
64: devTypeToDevTypeIdDictionary["MA5626G"] = 66;
65: devTypeToDevTypeIdDictionary["MA5651G"] = 67;
66: devTypeToDevTypeIdDictionary["MA5610"] = 70;
67: devTypeToDevTypeIdDictionary["MA5652G"] = 92;
68: devTypeToDevTypeIdDictionary["MA5603U"] = 94;
69: devTypeToDevTypeIdDictionary["MA5603T"] = 95;
70: devTypeToDevTypeIdDictionary["MA5620"] = 96;
71: devTypeToDevTypeIdDictionary["MA5626"] = 97;
72: devTypeToDevTypeIdDictionary["MA5616"] = 100;
73: devTypeToDevTypeIdDictionary["MA5635"] = 103;
74: devTypeToDevTypeIdDictionary["MA5612"] = 104;
75: devTypeToDevTypeIdDictionary["MA5621"] = 2319;
76: devTypeToDevTypeIdDictionary["MA5628"] = 2312;
77: devTypeToDevTypeIdDictionary["MA5652"] = 2313;
78: devTypeToDevTypeIdDictionary["MA5631"] = 2317;
79: devTypeToDevTypeIdDictionary["MA5612A"] = 2320;
80: devTypeToDevTypeIdDictionary["MA5669"] = 2321;
81: devTypeToDevTypeIdDictionary["MA5621A"] = 2322;
82: devTypeToDevTypeIdDictionary["MA5622A"] = 2323;
83: devTypeToDevTypeIdDictionary["MA5623"] = 2324;
84: devTypeToDevTypeIdDictionary["MA5623A"] = 2326;
85: devTypeToDevTypeIdDictionary["MA5632"] = 2318;
86: devTypeToDevTypeIdDictionary["MA5608T"] = 2331;
87: devTypeToDevTypeIdDictionary["MA5698"] = 2333;
88: devTypeToDevTypeIdDictionary["MA5694"] = 2335;
89: devTypeToDevTypeIdDictionary["MA5821"] = 2336;
90: devTypeToDevTypeIdDictionary["MA5822"] = 2337;
91: devTypeToDevTypeIdDictionary["MA5898"] = 2338;
92: devTypeToDevTypeIdDictionary["MA5818"] = 2339;
93: devTypeToDevTypeIdDictionary["MA5611S"] = 2340;
94: devTypeToDevTypeIdDictionary["MA5694S"] = 2343;
95: devTypeToDevTypeIdDictionary["RPS"] = 2344;
96: }
97:
98: return devTypeToDevTypeIdDictionary;
99: }
100: }
101:
102: /// <summary/>
103: public Dev() { }
104:
105: ////////////////////////////////////////////////////////////////////////////
106:
107: /// <summary>
108: ///
109: /// </summary>
110: public static Dictionary<int, string> DevTypeIdToDevTypeDictionary
111: {
112: get
113: {
114: if (devTypeIdToDevTypeDictionary == null || devTypeIdToDevTypeDictionary.Count == 0)
115: {
116: devTypeIdToDevTypeDictionary = new Dictionary<int, string>();
117:
118: foreach (KeyValuePair<string, int> kvp in DevTypeToDevTypeIdDictionary) devTypeIdToDevTypeDictionary[kvp.Value] = kvp.Key;
119: }
120:
121: return devTypeIdToDevTypeDictionary;
122: }
123: }
124:
125: ////////////////////////////////////////////////////////////////////////////
126:
127: /// <summary>
128: ///
129: /// </summary>
130: public static Dictionary<string, int> DevToDidDictionary
131: {
132: get
133: {
134: if (devToDidDictionary == null || devToDidDictionary.Count == 0)
135: {
136: devToDidDictionary = new Dictionary<string, int>();
137:
138: List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
139:
140: using (var db = new Ia.Ngn.Cl.Model.Ngn())
141: {
142: // this will list the Disconnecting devs first so that if there is an override it will allow the Connecting to be in dictionary
143: list = (from ed in db.EmsDevs select ed).OrderBy(u => u.DSTAT == "Connecting").ToList();
144: }
145:
146: foreach (var d in list) devToDidDictionary[d.DEV] = d.DID;
147: }
148:
149: return devToDidDictionary;
150: }
151: }
152:
153: ////////////////////////////////////////////////////////////////////////////
154:
155: /// <summary>
156: ///
157: /// </summary>
158: public static Dictionary<int, string> DidToDevDictionary
159: {
160: get
161: {
162: if (didToDevDictionary == null || didToDevDictionary.Count == 0)
163: {
164: didToDevDictionary = new Dictionary<int, string>();
165:
166: foreach (KeyValuePair<string, int> kvp in DevToDidDictionary) didToDevDictionary[kvp.Value] = kvp.Key;
167: }
168:
169: return didToDevDictionary;
170: }
171: }
172:
173: ////////////////////////////////////////////////////////////////////////////
174:
175: /// <summary>
176: ///
177: /// </summary>
178: public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
179: {
180: bool isUpdated;
181: int id, queryDtTypeId, did, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
182: string queryCommand, queryDev, devDev, dtType;
183: DataColumnCollection columns;
184: DataRow columnDataRow;
185: Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
186: Ia.Ngn.Cl.Model.Huawei.EmsDev dev, devByDev, newDev;
187: List<int> itemIdList;
188: List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devList;
189:
190: isUpdated = false;
191: readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
192: result = new Ia.Cl.Model.Result();
193:
194: if (response.CompletionCode == "COMPLD")
195: {
196: if (response.QueryDataTable != null)
197: {
198: queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
199:
200: columns = response.QueryDataTable.Columns;
201: readItemCount = response.QueryDataTable.Rows.Count;
202:
203: itemIdList = new List<int>(response.QueryDataTable.Rows.Count + 1);
204:
205: using (var db = new Ia.Ngn.Cl.Model.Ngn())
206: {
207: if (queryCommand.Contains("LST-DEV::DT") || queryCommand.Contains("LST-DEV::DEV"))
208: {
209: if (queryCommand.Contains("LST-DEV::DT"))
210: {
211: // LST-DEV::DT=100:{ctag}::;
212: queryDtTypeId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"DT=(\d+)"));
213:
214: //if (Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary.ContainsKey(queryDtTypeId))
215: //{
216: dtType = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary[queryDtTypeId];
217:
218: devList = (from ed in db.EmsDevs where ed.DT == dtType select ed).ToList();
219: //}
220: //else
221: //{
222: // result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary does not contain key queryDtTypeId: " + queryDtTypeId);
223: //}
224: }
225: else //if (queryCommand.Contains("LST-DEV::DEV"))
226: {
227: // LST-DEV::DEV=MDU-SAB-1443-001:{ctag}::;
228:
229: queryDev = Ia.Cl.Model.Default.Match(queryCommand, @"DEV=(.+?):");
230:
231: devList = (from ed in db.EmsDevs where ed.DEV == queryDev select ed).ToList();
232: }
233:
234: existingItemCount = devList.Count;
235:
236: if (response.QueryDataTable.Rows.Count >= 1)
237: {
238: columnDataRow = response.QueryDataTable.Rows[0];
239:
240: foreach (DataRow dataRow in response.QueryDataTable.Rows)
241: {
242: did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
243:
244: id = Ia.Ngn.Cl.Model.Business.Huawei.Dev.DevId(did);
245:
246: dev = (from d in devList where d.Id == id select d).SingleOrDefault();
247:
248: devDev = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty;
249:
250: newDev = new Ia.Ngn.Cl.Model.Huawei.EmsDev()
251: {
252: Id = id,
253: DID = did,
254: ResultCode = (long)response.ResultCode,
255: DEV = devDev,
256: DEVIP = columns.Contains("DEVIP") ? dataRow[columns.IndexOf("DEVIP")].ToString() : string.Empty,
257: DT = columns.Contains("DT") ? dataRow[columns.IndexOf("DT")].ToString() : string.Empty,
258: DVER = columns.Contains("DVER") ? dataRow[columns.IndexOf("DVER")].ToString() : string.Empty,
259: DSTAT = columns.Contains("DSTAT") ? dataRow[columns.IndexOf("DSTAT")].ToString() : string.Empty,
260: DLOC = columns.Contains("DLOC") ? dataRow[columns.IndexOf("DLOC")].ToString() : string.Empty,
261: AdminStat = columns.Contains("AdminStat") ? dataRow[columns.IndexOf("AdminStat")].ToString() : string.Empty,
262: WorkMode = columns.Contains("WorkMode") ? dataRow[columns.IndexOf("WorkMode")].ToString() : string.Empty,
263: ADDITIONALINFO = columns.Contains("ADDITIONALINFO") ? dataRow[columns.IndexOf("ADDITIONALINFO")].ToString() : string.Empty,
264: CRTID = columns.Contains("CRTID") ? dataRow[columns.IndexOf("CRTID")].ToString() : string.Empty,
265: CRTADDR = columns.Contains("CRTADDR") ? dataRow[columns.IndexOf("CRTADDR")].ToString() : string.Empty,
266: CRTTEL = columns.Contains("CRTTEL") ? dataRow[columns.IndexOf("CRTTEL")].ToString() : string.Empty,
267: CRTDATE = columns.Contains("CRTDATE") ? dataRow[columns.IndexOf("CRTDATE")].ToString() : string.Empty,
268: REMARK = columns.Contains("REMARK") ? dataRow[columns.IndexOf("REMARK")].ToString() : string.Empty,
269: TYPE = columns.Contains("TYPE") ? dataRow[columns.IndexOf("TYPE")].ToString() : string.Empty,
270: NERATELIST = columns.Contains("NERATELIST") ? dataRow[columns.IndexOf("NERATELIST")].ToString() : string.Empty,
271: NEPROV = columns.Contains("NEPROV") ? dataRow[columns.IndexOf("NEPROV")].ToString() : string.Empty,
272: TOPXY = columns.Contains("TOPXY") ? dataRow[columns.IndexOf("TOPXY")].ToString() : string.Empty,
273: EMSID = columns.Contains("EMSID") ? dataRow[columns.IndexOf("EMSID")].ToString() : string.Empty,
274: ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
275: PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
276: MAINTAINID = columns.Contains("MAINTAINID") ? dataRow[columns.IndexOf("MAINTAINID")].ToString() : string.Empty,
277: MAINTAINADDR = columns.Contains("MAINTAINADDR") ? dataRow[columns.IndexOf("MAINTAINADDR")].ToString() : string.Empty,
278: MAINTAINTEL = columns.Contains("MAINTAINTEL") ? dataRow[columns.IndexOf("MAINTAINTEL")].ToString() : string.Empty,
279: REGISTERSTAT = columns.Contains("REGISTERSTAT") ? dataRow[columns.IndexOf("REGISTERSTAT")].ToString() : string.Empty,
280: };
281:
282: nddOnt = Ia.Ngn.Cl.Model.Business.Default.NddOntFromHuaweiEmsAccessNameFormat(devDev);
283: if (nddOnt != null) newDev.Access = (from a in db.Accesses where a.Id == nddOnt.Access.Id select a).SingleOrDefault();
284:
285: if (dev == null)
286: {
287: devByDev = (from d in devList where d.DEV == devDev select d).SingleOrDefault();
288:
289: if (devByDev == null)
290: {
291: newDev.Created = newDev.Updated = DateTime.UtcNow.AddHours(3);
292:
293: db.EmsDevs.Add(newDev);
294:
295: insertedItemCount++;
296: }
297: else
298: {
299: throw new Exception("Ia.Ngn.Cl.Model.Data.Huawei.Dev.Update(): There is alreay a Dev with the same name: " + devDev + " but different Id. You should check the database and maybe delete the current, old dev entry. ");
300: }
301: }
302: else // update
303: {
304: // below: copy values from newDev to dev
305:
306: if (dev.Update(newDev))
307: {
308: db.EmsDevs.Attach(dev);
309: db.Entry(dev).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
310:
311: updatedItemCount++;
312: }
313: }
314:
315: itemIdList.Add(id); // keep at the end
316: }
317:
318: // below: this function will remove values that were not present in the reading
319: if (devList.Count > 0)
320: {
321: foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
322: {
323: if (!itemIdList.Contains(de.Id))
324: {
325: dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
326:
327: db.EmsDevs.Remove(dev);
328:
329: deletedItemCount++;
330: }
331: }
332: }
333: }
334: else
335: {
336: // below: remove all values since reading was empty
337:
338: if (devList.Count > 0)
339: {
340: foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
341: {
342: dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
343:
344: db.EmsDevs.Remove(dev);
345:
346: deletedItemCount++;
347: }
348: }
349: }
350: }
351: else
352: {
353: result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.Update() Unknown parameters in command: " + queryCommand);
354: }
355:
356: db.SaveChanges();
357: }
358:
359: if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
360: else isUpdated = false;
361:
362: result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
363: }
364: else
365: {
366: result.AddWarning("LST-DEV: QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
367: }
368: }
369: else
370: {
371: result.AddWarning("LST-DEV: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
372: }
373:
374: return isUpdated;
375: }
376:
377: ////////////////////////////////////////////////////////////////////////////
378:
379: /// <summary>
380: ///
381: /// </summary>
382: public static bool UpdateResultCode(int emsDevDid, Ia.Ngn.Cl.Model.Client.Huawei.Ems.ResultCode resultCode)
383: {
384: // similar to Ia.Ngn.Cl.Model.Data.Huawei.Ont.UpdateResultCode();
385: bool isUpdated;
386:
387: using (var db = new Ia.Ngn.Cl.Model.Ngn())
388: {
389: if (emsDevDid > 0)
390: {
391: var updatedDev = (from o in db.EmsDevs where o.DID == emsDevDid select o).SingleOrDefault();
392:
393: if (updatedDev != null)
394: {
395: if (updatedDev.ResultCode != (long)resultCode)
396: {
397: updatedDev.ResultCode = (long)resultCode;
398: updatedDev.Updated = DateTime.UtcNow.AddHours(3);
399:
400: db.EmsDevs.Attach(updatedDev);
401: db.Entry(updatedDev).Property(u => u.ResultCode).IsModified = true;
402: db.Entry(updatedDev).Property(u => u.Updated).IsModified = true;
403:
404: db.SaveChanges();
405:
406: isUpdated = true;
407: //result.AddSuccess("EmsDevs.ResultCode updated. ");
408: }
409: else
410: {
411: isUpdated = false;
412: // result.AddWarning("Warning: EmsDevs.ResultCode value was not updated because its the same. ");
413: }
414: }
415: else
416: {
417: isUpdated = false;
418: // result.AddError("Error: updatedDev is null. ");
419: }
420: }
421: else
422: {
423: isUpdated = false;
424: }
425: }
426:
427: return isUpdated;
428: }
429:
430: ////////////////////////////////////////////////////////////////////////////
431:
432: /// <summary>
433: ///
434: /// </summary>
435: public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> List()
436: {
437: List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
438:
439: using (var db = new Ia.Ngn.Cl.Model.Ngn())
440: {
441: list = (from ed in db.EmsDevs select ed).ToList();
442: }
443:
444: return list;
445: }
446:
447: ////////////////////////////////////////////////////////////////////////////
448:
449: /// <summary>
450: ///
451: /// </summary>
452: public static List<string> DevList()
453: {
454: List<string> list;
455:
456: using (var db = new Ia.Ngn.Cl.Model.Ngn())
457: {
458: list = (from ed in db.EmsDevs select ed.DEV).ToList();
459: }
460:
461: return list;
462: }
463:
464: ////////////////////////////////////////////////////////////////////////////
465:
466: /// <summary>
467: ///
468: /// </summary>
469: public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByMA5616DevType()
470: {
471: return ListByDevType("MA5616");
472: }
473:
474: ////////////////////////////////////////////////////////////////////////////
475:
476: /// <summary>
477: ///
478: /// </summary>
479: public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByDevType(string devType)
480: {
481: List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
482:
483: using (var db = new Ia.Ngn.Cl.Model.Ngn())
484: {
485: list = (from ed in db.EmsDevs where ed.DT == devType select ed).ToList();
486: }
487:
488: return list;
489: }
490:
491: ////////////////////////////////////////////////////////////////////////////
492:
493: /// <summary>
494: ///
495: /// </summary>
496: public static Ia.Ngn.Cl.Model.Huawei.EmsDev Read(int id)
497: {
498: Ia.Ngn.Cl.Model.Huawei.EmsDev item;
499:
500: using (var db = new Ia.Ngn.Cl.Model.Ngn())
501: {
502: item = (from ed in db.EmsDevs where ed.Id == id select ed).SingleOrDefault();
503: }
504:
505: return item;
506: }
507:
508: ////////////////////////////////////////////////////////////////////////////
509:
510: /// <summary>
511: ///
512: /// </summary>
513: public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByEmsName(string emsName)
514: {
515: Ia.Ngn.Cl.Model.Huawei.EmsDev item;
516:
517: using (var db = new Ia.Ngn.Cl.Model.Ngn())
518: {
519: item = (from ed in db.EmsDevs where ed.DEV == emsName select ed).SingleOrDefault();
520: }
521:
522: return item;
523: }
524:
525: ////////////////////////////////////////////////////////////////////////////
526:
527: /// <summary>
528: ///
529: /// </summary>
530: public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDev(string dev)
531: {
532: Ia.Ngn.Cl.Model.Huawei.EmsDev item;
533:
534: using (var db = new Ia.Ngn.Cl.Model.Ngn())
535: {
536: item = (from ed in db.EmsDevs where ed.DEV == dev select ed).SingleOrDefault();
537: }
538:
539: return item;
540: }
541:
542: ////////////////////////////////////////////////////////////////////////////
543:
544: /// <summary>
545: ///
546: /// </summary>
547: public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDid(int did)
548: {
549: Ia.Ngn.Cl.Model.Huawei.EmsDev item;
550:
551: using (var db = new Ia.Ngn.Cl.Model.Ngn())
552: {
553: item = (from ed in db.EmsDevs where ed.DID == did select ed).SingleOrDefault();
554: }
555:
556: return item;
557: }
558:
559: ////////////////////////////////////////////////////////////////////////////
560:
561: /// <summary>
562: ///
563: /// </summary>
564: public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByAccessId(string accessId)
565: {
566: Ia.Ngn.Cl.Model.Huawei.EmsDev item;
567:
568: using (var db = new Ia.Ngn.Cl.Model.Ngn())
569: {
570: item = (from ed in db.EmsDevs where ed.Access != null && ed.Access.Id == accessId select ed).SingleOrDefault();
571: }
572:
573: return item;
574: }
575:
576: ////////////////////////////////////////////////////////////////////////////
577:
578: /// <summary>
579: /// Return Devs with similar names
580: /// </summary>
581: public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> RedundantDevList()
582: {
583: List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devs;
584:
585: using (var db = new Ia.Ngn.Cl.Model.Ngn())
586: {
587: // select * from EmsDevs ed1 left outer join EmsDevs ed2 on ed1.DEV = ed2.DEV where ed1.Id <> ed2.Id
588:
589: devs = (from ed1 in db.EmsDevs join ed2 in db.EmsDevs on ed1.DEV equals ed2.DEV where ed2.DID != ed2.DID select ed1).ToList();
590: }
591:
592: return devs;
593: }
594:
595: ////////////////////////////////////////////////////////////////////////////
596:
597: /// <summary>
598: ///
599: /// </summary>
600: public static bool NullifyAccessIdByAccessId(string accessId, out string result)
601: {
602: bool b;
603: int numberOfRecordsWhereAccessIsNullified;
604: Ia.Ngn.Cl.Model.Huawei.EmsDev dev;
605:
606: b = false;
607: numberOfRecordsWhereAccessIsNullified = 0;
608:
609: using (var db = new Ia.Ngn.Cl.Model.Ngn())
610: {
611: // --update EmsOnts set Access_Id = null where Access_Id = '1040101010040004'
612: //var query = (from eo in db.EmsOnts where eo.Access.Id == accessId select eo).ToList();
613:
614: //foreach (var v in query)
615: //{
616: dev = (from o in db.EmsDevs where o.Access.Id == accessId select o).FirstOrDefault(); //.SingleOrDefault();
617:
618: if (dev != null)
619: {
620: dev.Access = null;
621: dev.Updated = DateTime.UtcNow.AddHours(3);
622:
623: db.EmsDevs.Attach(dev);
624: db.Entry(dev).Property(u => u.Updated).IsModified = true;
625:
626: db.SaveChanges();
627:
628: numberOfRecordsWhereAccessIsNullified++;
629: }
630: //}
631:
632: b = true;
633: }
634:
635: result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
636:
637: return b;
638: }
639:
640: ////////////////////////////////////////////////////////////////////////////
641: ////////////////////////////////////////////////////////////////////////////
642:
643: /// <summary>
644: ///
645: /// </summary>
646: public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Huawei.EmsDev emsDev)
647: {
648: StringBuilder sb;
649:
650: sb = new StringBuilder();
651:
652: sb.AppendLine("DID: " + emsDev.DID);
653: sb.AppendLine("DEV: " + emsDev.DEV);
654: sb.AppendLine("DEVIP: " + emsDev.DEVIP);
655: sb.AppendLine("DT: " + emsDev.DT);
656: sb.AppendLine("DVER: " + emsDev.DVER);
657: sb.AppendLine("DSTAT: " + emsDev.DSTAT);
658:
659: return sb.ToString();
660: }
661:
662: ////////////////////////////////////////////////////////////////////////////
663: ////////////////////////////////////////////////////////////////////////////
664: }
665:
666: ////////////////////////////////////////////////////////////////////////////
667: ////////////////////////////////////////////////////////////////////////////
668: }