public void TestSerializeAndDeserializeUriLocal() { UriItem uriItem = new UriItem(); uriItem.name = "test"; uriItem.uri = new Uri("ms-settings:"); uriItem.symbol = (Symbol)10; string serializedUriItem = uriItem.GetSerializedUriObject(); UriItem newUriItem = UriItem.DesirializeUriString(serializedUriItem); Assert.AreEqual<Uri>(uriItem.uri, newUriItem.uri); }
public void TestSerializeAndDeserializeUriExternal() { UriItem uriItem = new UriItem(); uriItem.name = "test"; uriItem.uri = new Uri("http://www.google.com"); uriItem.symbol = (Symbol)10; string serializedUriItem = uriItem.GetSerializedUriObject(); UriItem newUriItem = UriItem.DesirializeUriString(serializedUriItem); Assert.AreEqual<Uri>(uriItem.uri, newUriItem.uri); }
public void TestSerializeAndDeserializeName() { UriItem uriItem = new UriItem(); uriItem.name = "test"; uriItem.uri = new Uri("http://www.test.com"); uriItem.symbol = (Symbol)10; string serializedUriItem = uriItem.GetSerializedUriObject(); UriItem newUriItem = UriItem.DesirializeUriString(serializedUriItem); Assert.AreEqual<string>(uriItem.name, newUriItem.name); }
//TODO: check for empty and format exceptions private void AddButton_Click(object sender, RoutedEventArgs e) { SymbolItem symbolitem = (SymbolItem)cbSymbols.SelectedItem; try { string str = tbUri.Text.Contains("www.") ? "http://" + tbUri.Text : tbUri.Text; UriItem item = new UriItem() { name = tbName.Text, uri = new Uri(str), symbol = symbolitem.symbol }; uriSelection.Add(item); storeUriItemsToStorage(); } catch { // something is wrong with the uri here. } }
public static UriItem DesirializeUriString(String UriObjectString) { if(UriObjectString.Substring(0,9).Equals(SERIALIZEDHEADER)) { string name = ""; string uri = ""; string symbol = ""; int strl = UriObjectString.Length; UriObjectString = UriObjectString.Substring(9, strl-9); //the string that has been supplied starts with the uriitem string suffix. //name part Tuple<string, string> nameAndRemainder = getUriStringPart(UriObjectString); //pass the UriObjectString to the method that returns it in two parts. part 1 is the part and part 2 is the remainder name = nameAndRemainder.Item1; //store the first part in the name. UriObjectString = nameAndRemainder.Item2; //overwrite the second part in the objectString for the next parts. //URI Part Tuple<string, string> uriAndRemainder = getUriStringPart(UriObjectString); uri = uriAndRemainder.Item1; UriObjectString = uriAndRemainder.Item2; //symbol Part Tuple<string, string> symbolAndRemainder = getUriStringPart(UriObjectString); symbol = symbolAndRemainder.Item1; UriObjectString = symbolAndRemainder.Item2; //if all went well the parsed in string that consisted of "\(SERIALIZEDHEADER)uriname::uriuri::urisymbol\(SERIALIZEDFOOTER)" has been unwrapped //and now only contains the SERIALIZEDFOOTER if (UriObjectString.Equals(SERIALIZEDFOOTER)) { //TODO Or not TODO! tell success } else { //no success } UriItem uriItem = new UriItem(); uriItem.name = name; uriItem.uri = new Uri(uri); uriItem.symbol = (Symbol)Convert.ToInt32(symbol); return uriItem; } return new UriItem(); }