)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » AmsTransaction (Ia.Ftn.Cl.Models.Data.Nokia)

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

Nokia AmsTransaction Entity Framework class for Fixed Telecommunications Network (FTN) 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.Ftn.Cl.Models.Data.Nokia
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Nokia AmsTransaction Entity Framework class for Fixed Telecommunications Network (FTN) 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:     /// </remarks> 
   19:     public class AmsTransaction
   20:     {
   21:         ////////////////////////////////////////////////////////////////////////////
   22:  
   23:         /// <summary>
   24:         ///
   25:         /// </summary>
   26:         public AmsTransaction() { }
   27:  
   28:         ////////////////////////////////////////////////////////////////////////////    
   29:         ////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         /// 
   33:         /// </summary>
   34:         public static void Process(StreamReader streamReader, out Ia.Cl.Models.Result result)
   35:         {
   36:             string streamLine;
   37:             StringBuilder text;
   38:             Ia.Cl.Models.Result parseResult, insertResult;
   39:             List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> amsTransactionList;
   40:  
   41:             result = new Ia.Cl.Models.Result();
   42:             text = new StringBuilder();
   43:  
   44:             //streamText = File.ReadAllText(file);
   45:             while ((streamLine = streamReader.ReadLine()) != null) text.Append(streamLine + "\r\n");
   46:  
   47:             Parse(text, out amsTransactionList, out parseResult);
   48:  
   49:             result.AddResult(parseResult);
   50:  
   51:             if (parseResult.IsSuccessful)
   52:             {
   53:                 SqlBulkCopy(amsTransactionList, out insertResult);
   54:  
   55:                 result.AddResult(insertResult);
   56:             }
   57:         }
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         /// 
   63:         /// </summary>
   64:         public static void Process(string attachmentText, out Ia.Cl.Models.Result result)
   65:         {
   66:             StringBuilder text;
   67:             Ia.Cl.Models.Result parseResult, insertResult;
   68:             List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> amsTransactionList;
   69:  
   70:             result = new Ia.Cl.Models.Result();
   71:             text = new StringBuilder();
   72:  
   73:             text.Append(attachmentText);
   74:  
   75:             Parse(text, out amsTransactionList, out parseResult);
   76:  
   77:             result.AddResult(parseResult);
   78:  
   79:             if (parseResult.IsSuccessful)
   80:             {
   81:                 SqlBulkCopy(amsTransactionList, out insertResult);
   82:  
   83:                 result.AddResult(insertResult);
   84:             }
   85:         }
   86:  
   87:         ////////////////////////////////////////////////////////////////////////////
   88:  
   89:         /// <summary>
   90:         /// 
   91:         /// </summary>
   92:         public static void Parse(StringBuilder text, out List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> amsTransactionList, out Ia.Cl.Models.Result result)
   93:         {
   94:             bool firstLineSkipped;
   95:             int lineCount, c;
   96:             string[] fieldList;
   97:             Ia.Ftn.Cl.Models.Nokia.AmsTransaction amsTransaction;
   98:             List<string> list = new List<string>();
   99:  
  100:             firstLineSkipped = false;
  101:  
  102:             result = new Ia.Cl.Models.Result();
  103:  
  104:             amsTransactionList = new List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction>();
  105:  
  106:             //file = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + "log.csv";
  107:  
  108:             //Regex regex = new Regex("(.+?),,\r\n", RegexOptions.Compiled);
  109:  
  110:             //if (File.Exists(file))
  111:             //{
  112:  
  113:             // fixing errors in CSV file
  114:             text = text.Replace("\r\nnewValues", "newValues");
  115:             text = text.Replace("]\r\n", "]");
  116:             text = text.Replace("[\r\n", "[");
  117:  
  118:             //fileText = Regex.Replace(fileText, "[\r\n]+", "\r\n");
  119:             //fileText = fileText.Replace("\r\n\r\n", "__r__0__n__");
  120:             text = text.Replace("\r\n", "__r__0__n__");
  121:             text = text.Replace("\r", "");
  122:             text = text.Replace("\n", "");
  123:             text = text.Replace(Environment.NewLine, "");
  124:             text = text.Replace("__r__0__n__", "\r\n");
  125:  
  126:             lineCount = 0;
  127:  
  128:             foreach (string line in text.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  129:             {
  130:                 lineCount++;
  131:  
  132:                 if (firstLineSkipped)
  133:                 {
  134:                     try
  135:                     {
  136:                         fieldList = new string[10];
  137:  
  138:                         c = 0;
  139:                         //fieldList = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", RegexOptions.Singleline);
  140:                         foreach (string s in Ia.Cl.Models.Default.CsvLineSplitter(line)) fieldList[c++] = s;
  141:  
  142:                         if (fieldList.Length == 10)
  143:                         {
  144:                             amsTransaction = new Ia.Ftn.Cl.Models.Nokia.AmsTransaction()
  145:                             {
  146:                                 Id = Math.Abs((int)Ia.Cl.Models.Default.TickSecondAndCountId(lineCount)), //.ToString(),
  147:                                 EventTime = DateTime.Parse(fieldList[0].Replace(@"""", "").Replace(" AST", "")),
  148:                                 User = fieldList[1],
  149:                                 Application = fieldList[2],
  150:                                 Operation = fieldList[3],
  151:                                 Agent = fieldList[4],
  152:                                 Object = fieldList[5],
  153:                                 Argument = fieldList[6],
  154:                                 Session = fieldList[7],
  155:                                 Result = fieldList[8],
  156:                             };
  157:  
  158:                             amsTransactionList.Add(amsTransaction);
  159:                         }
  160:                         else
  161:                         {
  162:  
  163:                         }
  164:                     }
  165:                     catch (Exception ex)
  166:                     {
  167:                         result.AddWarning("Exception: Parse(): " + ex.ToString() + ". Input line: " + line);
  168:                     }
  169:                 }
  170:                 else firstLineSkipped = true;
  171:             }
  172:         }
  173:  
  174:         ////////////////////////////////////////////////////////////////////////////
  175:  
  176:         /// <summary>
  177:         /// 
  178:         /// </summary>
  179:         public static void SqlBulkCopy(List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> amsTransactionList, out Ia.Cl.Models.Result result)
  180:         {
  181:             DataTable dt;
  182:             Ia.Cl.Models.Db.SqlServer sqlServer;
  183:  
  184:             result = new Ia.Cl.Models.Result();
  185:             sqlServer = new Ia.Cl.Models.Db.SqlServer();
  186:  
  187:             dt = Ia.Cl.Models.Default.GenerateDataTableFromGenericClassList<Ia.Ftn.Cl.Models.Nokia.AmsTransaction>(amsTransactionList, "AmsTransactions");
  188:  
  189:             sqlServer.SqlBulkCopy(dt, out result);
  190:         }
  191:  
  192:         ////////////////////////////////////////////////////////////////////////////    
  193:         ////////////////////////////////////////////////////////////////////////////    
  194:  
  195:         /// <summary>
  196:         ///
  197:         /// </summary>
  198:         public static bool Create(Ia.Ftn.Cl.Models.Nokia.AmsTransaction newItem, out int itemId)
  199:         {
  200:             bool b;
  201:  
  202:             b = false;
  203:  
  204:             using (var db = new Ia.Ftn.Cl.Db())
  205:             {
  206:                 db.AmsTransactions.Add(newItem);
  207:                 db.SaveChanges();
  208:  
  209:                 itemId = newItem.Id;
  210:  
  211:                 b = true;
  212:             }
  213:  
  214:             return b;
  215:         }
  216:  
  217:         ////////////////////////////////////////////////////////////////////////////
  218:  
  219:         /// <summary>
  220:         ///
  221:         /// </summary>
  222:         public static Ia.Ftn.Cl.Models.Nokia.AmsTransaction Read(int id)
  223:         {
  224:             Ia.Ftn.Cl.Models.Nokia.AmsTransaction item;
  225:  
  226:             using (var db = new Ia.Ftn.Cl.Db())
  227:             {
  228:                 item = (from t in db.AmsTransactions where t.Id == id select t).SingleOrDefault();
  229:             }
  230:  
  231:             return item;
  232:         }
  233:  
  234:         ////////////////////////////////////////////////////////////////////////////
  235:  
  236:         /// <summary>
  237:         ///
  238:         /// </summary>
  239:         public static List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> ReadList()
  240:         {
  241:             List<Ia.Ftn.Cl.Models.Nokia.AmsTransaction> itemList;
  242:  
  243:             using (var db = new Ia.Ftn.Cl.Db())
  244:             {
  245:                 itemList = (from t in db.AmsTransactions select t).ToList();
  246:             }
  247:  
  248:             return itemList;
  249:         }
  250:  
  251:         ////////////////////////////////////////////////////////////////////////////
  252:         ////////////////////////////////////////////////////////////////////////////
  253:     }
  254:  
  255:     ////////////////////////////////////////////////////////////////////////////
  256:     ////////////////////////////////////////////////////////////////////////////   
  257: }