Last active
May 3, 2018 07:51
-
-
Save kibotu/7de828936daef49f533e to your computer and use it in GitHub Desktop.
CSVParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CSVParser | |
{ | |
public static string ReadKeyStorePassword (string path) | |
{ | |
string password = ""; | |
StreamReader theReader = new StreamReader (path, Encoding.Default); | |
using (theReader) { | |
password = theReader.ReadLine ().Replace ("\n", ""); | |
} | |
theReader.Close (); | |
return password; | |
} | |
public static IDictionary<string,SocialPlatformServiceFeature> LoadDictionary (string path) | |
{ | |
StreamReader theReader = new StreamReader (path, Encoding.Default); | |
IDictionary<string,SocialPlatformServiceFeature> dict = new Dictionary<string,SocialPlatformServiceFeature> (); | |
using (theReader) { | |
try { | |
while (!theReader.EndOfStream) { | |
parseGpsLine (dict, theReader.ReadLine ().Trim ().Replace ("\"", "")); | |
parseAmazonLine (dict, theReader.ReadLine ().Trim ().Replace ("\"", "")); | |
} | |
} catch (System.Exception e) { | |
Debug.Log ("Parsing of achievements failed" + e.ToString ()); | |
} | |
} | |
theReader.Close (); | |
foreach (var entry in dict) | |
Debug.Log (entry.Key + " " + entry.Value.ToString ()); | |
return dict; | |
} | |
public static void parseGpsLine (IDictionary<string,SocialPlatformServiceFeature> dict, string line) | |
{ | |
string[] parts = line.Split (new string[] { "," }, System.StringSplitOptions.None); | |
SocialPlatformServiceFeature feature = new SocialPlatformServiceFeature (); | |
feature.Name = parts [0].Substring (11, parts [0].Length - 11); | |
feature.Id = parts [1]; | |
if (parts.Length > 2) | |
feature.IsIncremental = parts [2] == "incremental"; | |
dict [feature.Name] = feature; | |
} | |
public static void parseAmazonLine (IDictionary<string,SocialPlatformServiceFeature> dict, string line) | |
{ | |
string[] parts = line.Split (new string[] { "," }, System.StringSplitOptions.None); | |
SocialPlatformServiceFeature feature = new SocialPlatformServiceFeature (); | |
feature.Id = parts [0]; | |
if (parts.Length > 5) | |
feature.Name = parts [5]; | |
dict [feature.Name] = feature; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IDictionary<string,SocialPlatformServiceFeature> _socialPlatformServiceFeature; | |
public IDictionary<string,SocialPlatformServiceFeature> SocialPlatformFeature { | |
get { return _socialPlatformServiceFeature ?? CSVParser.LoadDictionary(GetSocialPlatformCSVPath()); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment