private void insertPictureOrSoundFile(string card_value, int cid, int side, string type, int x1, int x2, int y1, int y2) { try { char[] param = new char[1]; param[0] = '\\'; string[] card_value_array = card_value.Split(param); string filename = card_value_array[card_value_array.Length - 1]; byte[] _rawData; FileStream file; file = new FileStream(card_value, FileMode.Open, FileAccess.Read); _rawData = new byte[(int)file.Length]; file.Read(_rawData, 0, (int)file.Length); file.Close(); eObject curObj = new eObject(cid, side, type, x1, x2, y1, y2); curObj.efile = new eFile(_rawData); curObj.save(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static void insertTextFile(string str, int cid, int side, string type, int x1, int x2, int y1, int y2) { try { byte[] data = ConvertStringToByteArray(str); //For saving the eObject into FileSystem and DB, eObject curObj = new eObject(cid, side, type, x1, x2, y1, y2); curObj.efile = new eFile(data); //data is stream.toArry(); curObj.save(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static int parseBLOB(byte[] blob, int uid) { int size = 0; int curDid = -1; int curCid = -1; byte[] data = null; Deck deck = null; eObject curObj = null; Card curCard = null; MemoryStream stream = new MemoryStream(blob); XmlTextReader reader = new XmlTextReader(stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Deck") { deck = new Deck(reader.GetAttribute("cat"), reader.GetAttribute("subcat"), reader.GetAttribute("title"), reader.GetAttribute("type"), Convert.ToInt32(reader.GetAttribute("nuid")), uid); try { //Insert to Decks table in local database curDid = deck.saveToDB(); } catch { throw new Exception("Error Writting Deck!!!"); } } else if (reader.Name == "Card") { curCard = new Card(reader.GetAttribute("tag"), uid); try { //Insert to Cards table in local database curCid = curCard.saveToDB(curDid); } catch { throw new Exception("Error Writting Card!!!"); } } else if (reader.Name == "Object") { //First create the array of bytes for the blob size = Convert.ToInt32(reader.GetAttribute("size")); data = new byte[size]; curObj = new eObject(curCid, Convert.ToInt32(reader.GetAttribute("side")), reader.GetAttribute("type"), Convert.ToInt32(reader.GetAttribute("x1")), Convert.ToInt32(reader.GetAttribute("x2")), Convert.ToInt32(reader.GetAttribute("y1")), Convert.ToInt32(reader.GetAttribute("y2")) ); try { string qType = reader.GetAttribute("quizType"); if (qType == Constant.nonePrefix || qType == Constant.answerPrefix || qType == Constant.questionPrefix) { curObj.quizType = qType; } } catch {} try { reader.ReadElementContentAsBase64(data, 0, size); curObj.efile = new eFile(data); //save to file and update DB curObj.save(); } catch { throw new Exception("Error Saving Object !!!"); } } break; } } return(curDid); }
public static int parseBLOB(byte[] blob, int uid) { int size = 0; int curDid = -1; int curCid = -1; byte[] data = null; Deck deck = null; eObject curObj = null; Card curCard = null; MemoryStream stream = new MemoryStream(blob); XmlTextReader reader = new XmlTextReader(stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Deck") { deck = new Deck(reader.GetAttribute("cat"), reader.GetAttribute("subcat"), reader.GetAttribute("title"), reader.GetAttribute("type"),Convert.ToInt32(reader.GetAttribute("nuid")), uid); try { //Insert to Decks table in local database curDid = deck.saveToDB(); } catch { throw new Exception("Error Writting Deck!!!"); } } else if (reader.Name == "Card") { curCard = new Card(reader.GetAttribute("tag"), uid); try { //Insert to Cards table in local database curCid = curCard.saveToDB(curDid); } catch { throw new Exception("Error Writting Card!!!"); } } else if (reader.Name == "Object") { //First create the array of bytes for the blob size = Convert.ToInt32(reader.GetAttribute("size")); data = new byte[size]; curObj = new eObject( curCid, Convert.ToInt32(reader.GetAttribute("side")), reader.GetAttribute("type"), Convert.ToInt32(reader.GetAttribute("x1")), Convert.ToInt32(reader.GetAttribute("x2")), Convert.ToInt32(reader.GetAttribute("y1")), Convert.ToInt32(reader.GetAttribute("y2")) ); try { string qType = reader.GetAttribute("quizType"); if (qType == Constant.nonePrefix || qType == Constant.answerPrefix || qType == Constant.questionPrefix) { curObj.quizType = qType; } } catch {} try { reader.ReadElementContentAsBase64(data, 0, size); curObj.efile = new eFile(data); //save to file and update DB curObj.save(); } catch { throw new Exception("Error Saving Object !!!"); } } break; } } return curDid; }