)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation Links

Public general use code classes and xml files that we've compiled and used over the years:

Nokia AmsTransaction Entity Framework class for Optical Fiber Network (OFN) data model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.IO;
    5: using System.Linq;
    6: using System.Text;
    7:  
    8: namespace Ia.Ngn.Cl.Model.Data.Nokia
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Nokia AmsTransaction Entity Framework class for Optical Fiber Network (OFN) data model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// 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
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class AmsTransaction
   30:     {
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public AmsTransaction() { }
   37:  
   38:         ////////////////////////////////////////////////////////////////////////////    
   39:         ////////////////////////////////////////////////////////////////////////////
   40:  
   41:         /// <summary>
   42:         /// 
   43:         /// </summary>
   44:         public static void Process(StreamReader streamReader, out Ia.Cl.Model.Result result)
   45:         {
   46:             string streamLine;
   47:             StringBuilder text;
   48:             Ia.Cl.Model.Result parseResult, insertResult;
   49:             List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> amsTransactionList;
   50:  
   51:             result = new Ia.Cl.Model.Result();
   52:             text = new StringBuilder();
   53:  
   54:             //streamText = File.ReadAllText(file);
   55:             while ((streamLine = streamReader.ReadLine()) != null) text.Append(streamLine + "\r\n");
   56:  
   57:             Parse(text, out amsTransactionList, out parseResult);
   58:  
   59:             result.AddResult(parseResult);
   60:  
   61:             if (parseResult.IsSuccessful)
   62:             {
   63:                 SqlBulkCopy(amsTransactionList, out insertResult);
   64:  
   65:                 result.AddResult(insertResult);
   66:             }
   67:         }
   68:  
   69:         ////////////////////////////////////////////////////////////////////////////
   70:  
   71:         /// <summary>
   72:         /// 
   73:         /// </summary>
   74:         public static void Process(string attachmentText, out Ia.Cl.Model.Result result)
   75:         {
   76:             StringBuilder text;
   77:             Ia.Cl.Model.Result parseResult, insertResult;
   78:             List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> amsTransactionList;
   79:  
   80:             result = new Ia.Cl.Model.Result();
   81:             text = new StringBuilder();
   82:  
   83:             text.Append(attachmentText);
   84:  
   85:             Parse(text, out amsTransactionList, out parseResult);
   86:  
   87:             result.AddResult(parseResult);
   88:  
   89:             if (parseResult.IsSuccessful)
   90:             {
   91:                 SqlBulkCopy(amsTransactionList, out insertResult);
   92:  
   93:                 result.AddResult(insertResult);
   94:             }
   95:         }
   96:  
   97:         ////////////////////////////////////////////////////////////////////////////
   98:  
   99:         /// <summary>
  100:         /// 
  101:         /// </summary>
  102:         public static void Parse(StringBuilder text, out List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> amsTransactionList, out Ia.Cl.Model.Result result)
  103:         {
  104:             bool firstLineSkipped;
  105:             int lineCount, c;
  106:             string[] fieldList;
  107:             Ia.Ngn.Cl.Model.Nokia.AmsTransaction amsTransaction;
  108:             List<string> list = new List<string>();
  109:  
  110:             firstLineSkipped = false;
  111:  
  112:             result = new Ia.Cl.Model.Result();
  113:  
  114:             amsTransactionList = new List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction>();
  115:  
  116:             //file = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + "log.csv";
  117:  
  118:             //Regex regex = new Regex("(.+?),,\r\n", RegexOptions.Compiled);
  119:  
  120:             //if (File.Exists(file))
  121:             //{
  122:  
  123:             // fixing errors in CSV file
  124:             text = text.Replace("\r\nnewValues", "newValues");
  125:             text = text.Replace("]\r\n", "]");
  126:             text = text.Replace("[\r\n", "[");
  127:  
  128:             //fileText = Regex.Replace(fileText, "[\r\n]+", "\r\n");
  129:             //fileText = fileText.Replace("\r\n\r\n", "__r__0__n__");
  130:             text = text.Replace("\r\n", "__r__0__n__");
  131:             text = text.Replace("\r", "");
  132:             text = text.Replace("\n", "");
  133:             text = text.Replace(Environment.NewLine, "");
  134:             text = text.Replace("__r__0__n__", "\r\n");
  135:  
  136:             lineCount = 0;
  137:  
  138:             foreach (string line in text.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  139:             {
  140:                 lineCount++;
  141:  
  142:                 if (firstLineSkipped)
  143:                 {
  144:                     try
  145:                     {
  146:                         fieldList = new string[10];
  147:  
  148:                         c = 0;
  149:                         //fieldList = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", RegexOptions.Singleline);
  150:                         foreach (string s in Ia.Cl.Model.Default.CsvLineSplitter(line)) fieldList[c++] = s;
  151:  
  152:                         if (fieldList.Length == 10)
  153:                         {
  154:                             amsTransaction = new Ia.Ngn.Cl.Model.Nokia.AmsTransaction()
  155:                             {
  156:                                 Id = Math.Abs((int)Ia.Cl.Model.Default.TickSecondAndCountId(lineCount)), //.ToString(),
  157:                                 EventTime = DateTime.Parse(fieldList[0].Replace(@"""", "").Replace(" AST", "")),
  158:                                 User = fieldList[1],
  159:                                 Application = fieldList[2],
  160:                                 Operation = fieldList[3],
  161:                                 Agent = fieldList[4],
  162:                                 Object = fieldList[5],
  163:                                 Argument = fieldList[6],
  164:                                 Session = fieldList[7],
  165:                                 Result = fieldList[8],
  166:                             };
  167:  
  168:                             amsTransactionList.Add(amsTransaction);
  169:                         }
  170:                         else
  171:                         {
  172:  
  173:                         }
  174:                     }
  175:                     catch (Exception ex)
  176:                     {
  177:                         result.AddWarning("Exception: Parse(): " + ex.ToString() + ". Input line: " + line);
  178:                     }
  179:                 }
  180:                 else firstLineSkipped = true;
  181:             }
  182:         }
  183:  
  184:         ////////////////////////////////////////////////////////////////////////////
  185:  
  186:         /// <summary>
  187:         /// 
  188:         /// </summary>
  189:         public static void SqlBulkCopy(List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> amsTransactionList, out Ia.Cl.Model.Result result)
  190:         {
  191:             DataTable dt;
  192:             Ia.Cl.Model.Db.SqlServer sqlServer;
  193:  
  194:             result = new Ia.Cl.Model.Result();
  195:             sqlServer = new Ia.Cl.Model.Db.SqlServer();
  196:  
  197:             dt = Ia.Cl.Model.Default.GenerateDataTableFromGenericClassList<Ia.Ngn.Cl.Model.Nokia.AmsTransaction>(amsTransactionList, "AmsTransactions");
  198:  
  199:             sqlServer.SqlBulkCopy(dt, out result);
  200:         }
  201:  
  202:         ////////////////////////////////////////////////////////////////////////////    
  203:         ////////////////////////////////////////////////////////////////////////////    
  204:  
  205:         /// <summary>
  206:         ///
  207:         /// </summary>
  208:         public static bool Create(Ia.Ngn.Cl.Model.Nokia.AmsTransaction newItem, out int itemId)
  209:         {
  210:             bool b;
  211:  
  212:             b = false;
  213:  
  214:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  215:             {
  216:                 db.AmsTransactions.Add(newItem);
  217:                 db.SaveChanges();
  218:  
  219:                 itemId = newItem.Id;
  220:  
  221:                 b = true;
  222:             }
  223:  
  224:             return b;
  225:         }
  226:  
  227:         ////////////////////////////////////////////////////////////////////////////
  228:  
  229:         /// <summary>
  230:         ///
  231:         /// </summary>
  232:         public static Ia.Ngn.Cl.Model.Nokia.AmsTransaction Read(int id)
  233:         {
  234:             Ia.Ngn.Cl.Model.Nokia.AmsTransaction item;
  235:  
  236:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  237:             {
  238:                 item = (from t in db.AmsTransactions where t.Id == id select t).SingleOrDefault();
  239:             }
  240:  
  241:             return item;
  242:         }
  243:  
  244:         ////////////////////////////////////////////////////////////////////////////
  245:  
  246:         /// <summary>
  247:         ///
  248:         /// </summary>
  249:         public static List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> ReadList()
  250:         {
  251:             List<Ia.Ngn.Cl.Model.Nokia.AmsTransaction> itemList;
  252:  
  253:             using (var db = new Ia.Ngn.Cl.Model.Ngn())
  254:             {
  255:                 itemList = (from t in db.AmsTransactions select t).ToList();
  256:             }
  257:  
  258:             return itemList;
  259:         }
  260:  
  261:         ////////////////////////////////////////////////////////////////////////////
  262:         ////////////////////////////////////////////////////////////////////////////
  263:     }
  264:  
  265:     ////////////////////////////////////////////////////////////////////////////
  266:     ////////////////////////////////////////////////////////////////////////////   
  267: }