public void SerializationDeserialization() { // create a test response MyResponse rt = new MyResponse(); // our test response is located here const string dll = "TestTradeLink.exe"; // change a property on the test rt.Name = "testing123"; // change custom value rt.EntrySize = 333; // make sure repsonse is good Assert.IsTrue(rt.isValid); // make sure custom value holds Assert.AreEqual(333, rt.EntrySize); // Skin it string skin = SkinImpl.Skin(rt, "TestTradeLink.MyResponse", Environment.CurrentDirectory + "\\" + dll); // deskin it object o = SkinImpl.Deskin(skin); // cast it back MyResponse me = (MyResponse)o; // check response is valid Assert.IsTrue(me.isValid); // check that property was persisted Assert.AreEqual(rt.Name, me.Name); // check that custom value persisted Assert.AreEqual(rt.EntrySize, me.EntrySize); }
bool tradeskins(string name) { // get skin files available string[] files = skinfiles(Environment.CurrentDirectory); // set status variable bool worked = true; try { // loop through every file foreach (string fn in files) { // if it's the skin we want to trade if (skinfromfile(fn) == name) { // get it along with it's persisted settings Response r = (Response)SkinImpl.DeskinFile(fn); // add it to trade list _reslist.Add(r); // show it to user _resnames.Items.Add(r.FullName); // mark it as loaded _resskinidx.Add(_reslist.Count - 1, name); // route symbols to it? // update status worked &= true; } } return(true); } catch (Exception) { } return(false); }
bool tradeskins(string name) { // get skin files available string[] files = skinfiles(SKINPATH); // set status variable bool worked = true; try { // loop through every file foreach (string fn in files) { // if it's the skin we want to trade if (skinfromfile(fn) == name) { // get it along with it's persisted settings Response r = (Response)SkinImpl.DeskinFile(SKINPATH + fn); // add it int id = addresponse(r); // check if it was added bool added = id != -1; // update status worked &= added; // mark it as loaded if (added) { _resskinidx.Add(id, name); } } } return(true); } catch (Exception) { } return(false); }
private void _saveskins_Click(object sender, EventArgs e) { foreach (int idx in _resskinidx.Keys) { // get all skins this response is part of string[] names = _resskinidx[idx].Split(' '); // get response Response r = _reslist[idx]; // don't save invalid responses if (r.Name == new InvalidResponse().Name) { continue; } // save status bool worked = true; foreach (string name in names) { // remove skin first remskin(name); // then re-add it worked &= SkinImpl.SkinFile(r, r.FullName, _class2dll[r.FullName], SKINPATH + name + "." + nextskinidx(SKINPATH, name).ToString() + SKINEXT); } } status("saved loaded skins"); }
void restoreskins() { string [] skins = SkinImpl.getskinfiles(); foreach (string skin in skins) { _skinsavail.DropDownItems.Add(SkinImpl.skinfromfile(skin)); } }
private void _skinsavail_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { string skin = e.ClickedItem.Text; string skinfn = SkinImpl.filefromskin(skin); // ensure exists if (!System.IO.File.Exists(skinfn)) { status("Cannot locate: " + skin); return; } // load skin loadskin(skinfn); }
void loadskin(string fn) { // load skin SkinImpl skn = new SkinImpl(); bool ok = Util.FromFile <SkinImpl>(fn, ref skn, debug); // load tickfiles from skin foreach (string file in skn.TickFiles) { loadfile(file); } // load response myres = (Response)SkinImpl.DeskinFile(fn, debug); }
void add2skin(object sender, EventArgs e) { // make sure something is selected if (_resnames.SelectedIndices.Count == 0) { return; } // get name string name = Interaction.InputBox("What is the skin name for these responses?", "Skin name", "Skin" + DateTime.Now.Ticks.ToString(), 0, 0); // get next available index for this name int startidx = nextskinidx(SKINPATH, name); // go through all selected responses foreach (int didx in _resnames.SelectedIndices) { //get response index from display index int idx = getrindx(didx); // save them as skin SkinImpl.SkinFile(_reslist[idx], _reslist[idx].FullName, _class2dll[_reslist[idx].FullName], SKINPATH + name + "." + startidx.ToString() + SKINEXT); // add index as part of skin string sn = string.Empty; if (_resskinidx.TryGetValue(idx, out sn)) { if (sn != name) { _resskinidx[idx] = sn + " " + name; } else { ; } } else { _resskinidx.Add(idx, name); } // increment next filename index startidx++; } status("added " + _resnames.SelectedIndices.Count + " responses to " + name); // find any new names findskins(); }
private void _saveskins_Click(object sender, EventArgs e) { foreach (int idx in _resskinidx.Keys) { // get all skins this response is part of string[] names = _resskinidx[idx].Split(' '); // get response Response r = _reslist[idx]; // save status bool worked = true; foreach (string name in names) { // remove skin first remskin(name); // then re-add it worked &= SkinImpl.SkinFile(r, r.FullName, _class2dll[r.FullName], name + "." + nextskinidx(Environment.CurrentDirectory, name).ToString() + SKINEXT); } } status("saved loaded skins"); }