Esempio n. 1
0
        public string GetXML(string filePath)
        {
            string strXML = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(filePath))
                {
                    DataTable dt = ExcelHelper.GetExcelData(filePath);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        strXML = XMLUtilities.Serialize(dt);
                    }

                    System.IO.File.Delete(filePath);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw new ApplicationException(ErrorConstants.GetExcelError);
            }

            return(strXML);
        }
Esempio n. 2
0
 /// <summary>
 /// Create record in key value data store
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void Create(string key, string value)
 {
     if (FileUtilities.IsFileSizeLessThanOneGB(FWConstant.DataStoreFile))
     {
         XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>();
         var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile);
         if (DataStoreUtilities.IsValidKey(key))
         {
             if (!DataStoreUtilities.IsKeyExists(key, dataStore))
             {
                 if (DataStoreUtilities.IsJson(value))
                 {
                     if (DataStoreUtilities.CheckSize(value))
                     {
                         if (dataStore.Records != null)
                         {
                             dataStore.Records.Add(new Record {
                                 Key = key, Value = value
                             });
                         }
                         else
                         {
                             dataStore.Records = new List <Record> {
                                 new Record {
                                     Key = key, Value = value
                                 }
                             }
                         };
                         xmlUtilities.Serialize(dataStore, FWConstant.DataStoreFile);
                     }
                     else
                     {
                         throw new Exception("Size of data exceeds the limit of data store");
                     }
                 }
                 else
                 {
                     throw new Exception("Invalid json content");
                 }
             }
             else
             {
                 throw new Exception("Key already Exists");
             }
         }
         else
         {
             throw new Exception("Key size should not exceed 32 characters");
         }
     }
     else
     {
         throw new Exception("Datastore size exceeds 1 GB");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Delete the record from data store using key
        /// </summary>
        /// <param name="key"></param>
        public void Delete(string key)
        {
            XMLUtilities <DataStore> xmlUtilities = new XMLUtilities <DataStore>();
            var dataStore = xmlUtilities.DeSerialize(FWConstant.DataStoreFile);

            if (DataStoreUtilities.IsKeyExists(key, dataStore))
            {
                dataStore.Records.Remove(dataStore.Records.FirstOrDefault(item => item.Key == key));
                xmlUtilities.Serialize(dataStore, FWConstant.DataStoreFile);
            }
            else
            {
                throw new Exception("Invalid key");
            }
        }