/// <summary> /// Exports company list. /// </summary> /// <param name="createNewly">Whether to create company list newly</param> /// <returns>Company list in JSON format</returns> public static string ExportList(bool createNewly = false) { var companyList = (createNewly || (_companyList == null)) ? PowerCompanyList.CreateList() : _companyList; return(PowerCompanyList.SerializeList(companyList)); }
/// <summary> /// Imports company list. /// </summary> /// <param name="source">Source company list in JSON format</param> /// <param name="checkListDate">Whether to check the date of company list</param> /// <returns>True if successfully imported. False if not.</returns> public static bool ImportList(string source, bool checkListDate = true) { var companyList = PowerCompanyList.DeserializeList(source); if (companyList == null) { return(false); } Debug.WriteLine($"ListDate: {companyList.ListDate}"); if (checkListDate && (_companyList != null)) { if (companyList.ListDate <= _companyList.ListDate) { return(false); } } _importedCompanyList = companyList; return(true); }
public static string SerializeList(PowerCompanyList companyList) { if (companyList == null) { return(null); } var serializer = new DataContractJsonSerializer(typeof(PowerCompanyList)); try { using (var ms = new MemoryStream()) { serializer.WriteObject(ms, companyList); return(Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length)); } } catch (Exception ex) { Debug.WriteLine($"Failed to serialize company list.\r\n{ex}"); return(null); } }