示例#1
0
 /// <summary>
 /// Get By Id
 /// </summary>
 /// <param name="networkId"></param>
 /// <returns></returns>
 public NetworkData GetById(int networkId)
 {
     try {
         var network = new NetworkData();
         network.Id          = networkId;
         network.Description = IniFileHelper.ReadINI(_iniFile, networkId.ToString(), "Description", "");
         return(network);
     } catch (Exception ex) {
         throw ex;
     }
 }
示例#2
0
 /// <summary>
 /// Add
 /// </summary>
 /// <param name="network"></param>
 /// <returns></returns>
 public int Add(NetworkData network)
 {
     try {
         var msg = IniFileHelper.ReadINI(_iniFile, "Settings", "Count", "0");
         var n   = 0;
         if (int.TryParse(msg, out (n)))
         {
             n = n + 1;
             IniFileHelper.WriteINI(_iniFile, "Settings", "Count", n.ToString());
             IniFileHelper.WriteINI(_iniFile, n.ToString(), "Description", network.Description);
         }
         _useCache = false;
         return(n);
     } catch (Exception ex) {
         throw ex;
     }
 }
示例#3
0
 /// <summary>
 /// Set Default
 /// </summary>
 /// <param name="network"></param>
 /// <returns></returns>
 public bool SetDefault(NetworkData network)
 {
     try {
         var networks = Get();
         var t        = 0;
         foreach (var n in networks)
         {
             t++;
             if (n.Description == network.Description)
             {
                 IniFileHelper.WriteINI(_iniFile, "Settings", "Index", t.ToString());
                 return(true);
             }
         }
         return(false);
     } catch (Exception ex) {
         throw ex;
     }
 }
示例#4
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <param name="network"></param>
 /// <returns></returns>
 public bool Delete(NetworkData network)
 {
     try {
         var networks     = Get();
         var itemToRemove = networks.Where(n => n.Description == network.Description).FirstOrDefault();
         networks.Remove(itemToRemove);
         if (Clear())
         {
             if (Save(networks))
             {
                 return(true);
             }
         }
         _useCache = false;
         return(false);
     } catch (Exception ex) {
         throw ex;
     }
 }
示例#5
0
 /// <summary>
 /// Find
 /// </summary>
 /// <param name="networkDescription"></param>
 /// <returns></returns>
 public NetworkData Find(string networkDescription)
 {
     try {
         var result = new NetworkData();
         foreach (var network in Get())
         {
             if (!string.IsNullOrEmpty(networkDescription))
             {
                 if (!string.IsNullOrEmpty(network.Description))
                 {
                     if (networkDescription.Trim() == network.Description.Trim())
                     {
                         result = network;
                         break;
                     }
                 }
             }
         }
         return(result);
     } catch (Exception ex) {
         throw ex;
     }
 }