public int processAttachement(Attachement att, LicenseMailBodyData data, IMailMessage mail) { int iCount = 0; LicenseXML xmlData = LicenseXML.Deserialize(att.data); foreach (license ldata in xmlData.licenses) { utils.helpers.addLog("processAttachement: new LicenseData...\r\n"); LicenseData licenseData = new LicenseData(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp); //if (_licenseDataBase.addQueued(licenseData)) utils.helpers.addLog("firing license_mail event\r\n"); OnStateChanged(new StatusEventArgs(StatusType.license_mail, licenseData)); iCount++; //if (_licenseDataBase.add(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp)) // iCount++; //utils.helpers.addLog("start _licenseDataBase.add() done\r\n"); } #region alternative_code /* * // Request all the attachments on the email message. This results in a GetItem operation call to EWS. * m.Load(new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.Attachments)); * foreach (Microsoft.Exchange.WebServices.Data.Attachment att in m.Attachments) * { * if (att is Microsoft.Exchange.WebServices.Data.FileAttachment) * { * Microsoft.Exchange.WebServices.Data.FileAttachment fileAttachment = att as Microsoft.Exchange.WebServices.Data.FileAttachment; * * //get a temp file name * string fname = System.IO.Path.GetTempFileName(); //utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name * * // Load the file attachment into memory. This gives you access to the attachment content, which * // is a byte array that you can use to attach this file to another item. This results in a GetAttachment operation * // call to EWS. * fileAttachment.Load(); * * // Load attachment contents into a file. This results in a GetAttachment operation call to EWS. * fileAttachment.Load(fname); * addLog("Attachement file saved to: " + fname); * * // Put attachment contents into a stream. * using (System.IO.FileStream theStream = * new System.IO.FileStream(utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite)) * { * //This results in a GetAttachment operation call to EWS. * fileAttachment.Load(theStream); * } * * //load into memory stream, seems the only stream supported * using (System.IO.MemoryStream ms = new System.IO.MemoryStream(att.Size)) * { * fileAttachment.Load(ms); * using (System.IO.FileStream fs = new System.IO.FileStream(fname, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite)) * { * ms.CopyTo(fs); * fs.Flush(); * } * } * addLog("saved attachement: " + fname); * iRet++; * } * } */ #endregion return(iCount); }
public int add( string deviceid, string customer, string key, string ordernumber, DateTime orderdate, string ponumber, string endcustomer, string product, int quantity, string receivedby, DateTime sendat) { OnStateChanged(new StatusEventArgs(StatusType.none, "adding data...")); int LastInsert = -1; bool bRes = false; if (existsData(deviceid, key)) { utils.helpers.addLog("add abandoned for existing datarow"); OnStateChanged(new StatusEventArgs(StatusType.none, "...data already known")); return(LastInsert); } LicenseData licenseData = new LicenseData(); licenseData._deviceid = deviceid; licenseData._customer = customer; licenseData._key = key; licenseData._ordernumber = ordernumber; licenseData._orderdate = orderdate; licenseData._ponumber = ponumber; licenseData._endcustomer = endcustomer; licenseData._product = product; licenseData._quantity = quantity; licenseData._receivedby = receivedby; licenseData._sendat = sendat; string cmdText = "INSERT INTO licensedata " + getSQLFieldListForInsert() + //"(id, "+ //licenseCols.dataCols[0].name +", "+ //licenseCols.dataCols[1].name + ", " + //licenseCols.dataCols[2].name + ", " + //licenseCols.dataCols[3].name + ", " + //licenseCols.dataCols[4].name + ", " + //licenseCols.dataCols[5].name + ", " + //licenseCols.dataCols[6].name + ", " + //licenseCols.dataCols[7].name + ", " + //licenseCols.dataCols[8].name + //") " + "VALUES(" + "NULL, " + //auto id "'" + licenseData._deviceid + "'," + "'" + licenseData._customer + "'," + "'" + licenseData._key + "'," + "'" + licenseData._ordernumber + "'," + "'" + licenseData._orderdate.ToString("yyyy-MM-dd HH:mm:ss") + "'," +// '2007-01-01 10:00:00', yyyy-mm-dd HH:mm:ss "'" + licenseData._ponumber + "'," + "'" + licenseData._endcustomer + "'," + "'" + licenseData._product + "'," + "" + licenseData._quantity.ToString() + "," + "'" + licenseData._receivedby + "'," + "'" + licenseData._sendat.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")"; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { connection.Open(); SQLiteCommand command = new SQLiteCommand(connection); string namelist = getSQLFieldListForInsert(); // Einfügen eines Test-Datensatzes. command.CommandText = cmdText; int iRes = command.ExecuteNonQuery(); utils.helpers.addLog("SQLcmd: '" + command.CommandText + "'"); //get id of last insert command.CommandText = "select last_insert_rowid()"; // The row ID is a 64-bit value - cast the Command result to an Int64. // long LastRowID64 = (long)command.ExecuteScalar(); // Then grab the bottom 32-bits as the unique ID of the row. LastInsert = (int)LastRowID64; command.Dispose(); //doRefresh(ref _dgv); utils.helpers.addLog("added " + iRes.ToString() + " new data"); OnStateChanged(new StatusEventArgs(StatusType.none, "... added " + iRes.ToString() + " new data")); } } catch (SQLiteException ex) { OnStateChanged(new StatusEventArgs(StatusType.error, "add new data failed " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } catch (Exception ex) { OnStateChanged(new StatusEventArgs(StatusType.error, "add new data failed " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { } return(LastInsert); }
/// <summary> /// add LicenseData to DataBase, blocks for some time /// use manual doRefresh /// </summary> /// <param name="licenseData"></param> /// <returns>id of last inserted data or -1 if failed</returns> int add(LicenseData licenseData) { OnStateChanged(new StatusEventArgs(StatusType.none, "adding licenseData...")); int LastRowID = -1; if (existsData(licenseData._deviceid, licenseData._key)) { utils.helpers.addLog("add abandoned for existing datarow"); OnStateChanged(new StatusEventArgs(StatusType.none, "...add licenseData abandonded for existing datarow")); return(-1); } string cmdText = "INSERT INTO licensedata " + getSQLFieldListForInsert() + //"(id, "+ //licenseCols.dataCols[0].name +", "+ //licenseCols.dataCols[1].name + ", " + //licenseCols.dataCols[2].name + ", " + //licenseCols.dataCols[3].name + ", " + //licenseCols.dataCols[4].name + ", " + //licenseCols.dataCols[5].name + ", " + //licenseCols.dataCols[6].name + ", " + //licenseCols.dataCols[7].name + ", " + //licenseCols.dataCols[8].name + //") " + "VALUES(" + "NULL, " + //auto id "'" + licenseData._deviceid + "'," + "'" + licenseData._customer + "'," + "'" + licenseData._key + "'," + "'" + licenseData._ordernumber + "'," + "'" + licenseData._orderdate.ToString("yyyy-MM-dd HH:mm:ss") + "'," +// '2007-01-01 10:00:00', yyyy-mm-dd HH:mm:ss "'" + licenseData._ponumber + "'," + "'" + licenseData._endcustomer + "'," + "'" + licenseData._product + "'," + "" + licenseData._quantity.ToString() + "," + "'" + licenseData._receivedby + "'," + "'" + licenseData._sendat.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")"; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { openConn: try { connection.Open(); } catch (SQLiteException ex) { if (ex.ErrorCode == (int)SQLiteErrorCode.Locked) { Thread.Sleep(1000); goto openConn; } } SQLiteCommand command = new SQLiteCommand(connection); string namelist = getSQLFieldListForInsert(); // Einfügen eines Test-Datensatzes. command.CommandText = cmdText; OnStateChanged(new StatusEventArgs(StatusType.none, "execute adding licenseData")); int iRes = command.ExecuteNonQuery(); //get id of last insert command.CommandText = "select last_insert_rowid()"; // The row ID is a 64-bit value - cast the Command result to an Int64. // long LastRowID64 = (long)command.ExecuteScalar(); // Then grab the bottom 32-bits as the unique ID of the row. LastRowID = (int)LastRowID64; command.Dispose(); /* * //now add same data to drid, can not be done from separate thread! * DataTable dt = (DataTable)_dgv.DataSource; * DataRow dr = dt.NewRow(); * dr["id"] = LastRowID; * dr[licenseCols.LicenseDataColumns[0]] = licenseData._deviceid; * dr[licenseCols.LicenseDataColumns[1]] = licenseData._customer; * dr[licenseCols.LicenseDataColumns[2]] = licenseData._key; * dr[licenseCols.LicenseDataColumns[3]] = licenseData._ordernumber; * dr[licenseCols.LicenseDataColumns[4]] = licenseData._orderdate; * dr[licenseCols.LicenseDataColumns[5]] = licenseData._ponumber; * dr[licenseCols.LicenseDataColumns[6]] = licenseData._endcustomer; * dr[licenseCols.LicenseDataColumns[7]] = licenseData._product; * dr[licenseCols.LicenseDataColumns[8]] = licenseData._quantity; * dr[licenseCols.LicenseDataColumns[9]] = licenseData._receivedby; * dr[licenseCols.LicenseDataColumns[10]] = licenseData._sendat; * _dgv.Rows.Add(dr); */ utils.helpers.addLog("added " + iRes.ToString() + " new data"); } } catch (SQLiteException ex) { OnStateChanged(new StatusEventArgs(StatusType.none, "Exception adding licenseData: " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } catch (Exception ex) { OnStateChanged(new StatusEventArgs(StatusType.none, "Exception adding licenseData: " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { } OnStateChanged(new StatusEventArgs(StatusType.none, "licenseData added: " + LastRowID.ToString())); return(LastRowID); }
/// <summary> /// add LicenseData to DataBase, blocks for some time /// use manual doRefresh /// </summary> /// <param name="licenseData"></param> /// <returns>id of last inserted data or -1 if failed</returns> int add(LicenseData licenseData) { OnStateChanged(new StatusEventArgs(StatusType.none, "adding licenseData...")); int LastRowID = -1; if (existsData(licenseData._deviceid, licenseData._key)) { utils.helpers.addLog("add abandoned for existing datarow"); OnStateChanged(new StatusEventArgs(StatusType.none, "...add licenseData abandonded for existing datarow")); return -1; } string cmdText = "INSERT INTO licensedata " + getSQLFieldListForInsert() + //"(id, "+ //licenseCols.dataCols[0].name +", "+ //licenseCols.dataCols[1].name + ", " + //licenseCols.dataCols[2].name + ", " + //licenseCols.dataCols[3].name + ", " + //licenseCols.dataCols[4].name + ", " + //licenseCols.dataCols[5].name + ", " + //licenseCols.dataCols[6].name + ", " + //licenseCols.dataCols[7].name + ", " + //licenseCols.dataCols[8].name + //") " + "VALUES(" + "NULL, " + //auto id "'" + licenseData._deviceid + "'," + "'" + licenseData._customer + "'," + "'" + licenseData._key + "'," + "'" + licenseData._ordernumber + "'," + "'" + licenseData._orderdate.ToString("yyyy-MM-dd HH:mm:ss") + "'," +// '2007-01-01 10:00:00', yyyy-mm-dd HH:mm:ss "'" + licenseData._ponumber + "'," + "'" + licenseData._endcustomer + "'," + "'" + licenseData._product + "'," + "" + licenseData._quantity.ToString() + "," + "'" + licenseData._receivedby + "'," + "'" + licenseData._sendat.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")"; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { openConn: try { connection.Open(); } catch (SQLiteException ex) { if (ex.ErrorCode == (int)SQLiteErrorCode.Locked) { Thread.Sleep(1000); goto openConn; } } SQLiteCommand command = new SQLiteCommand(connection); string namelist = getSQLFieldListForInsert(); // Einfügen eines Test-Datensatzes. command.CommandText = cmdText; OnStateChanged(new StatusEventArgs(StatusType.none, "execute adding licenseData")); int iRes = command.ExecuteNonQuery(); //get id of last insert command.CommandText = "select last_insert_rowid()"; // The row ID is a 64-bit value - cast the Command result to an Int64. // long LastRowID64 = (long)command.ExecuteScalar(); // Then grab the bottom 32-bits as the unique ID of the row. LastRowID = (int)LastRowID64; command.Dispose(); /* //now add same data to drid, can not be done from separate thread! DataTable dt = (DataTable)_dgv.DataSource; DataRow dr = dt.NewRow(); dr["id"] = LastRowID; dr[licenseCols.LicenseDataColumns[0]] = licenseData._deviceid; dr[licenseCols.LicenseDataColumns[1]] = licenseData._customer; dr[licenseCols.LicenseDataColumns[2]] = licenseData._key; dr[licenseCols.LicenseDataColumns[3]] = licenseData._ordernumber; dr[licenseCols.LicenseDataColumns[4]] = licenseData._orderdate; dr[licenseCols.LicenseDataColumns[5]] = licenseData._ponumber; dr[licenseCols.LicenseDataColumns[6]] = licenseData._endcustomer; dr[licenseCols.LicenseDataColumns[7]] = licenseData._product; dr[licenseCols.LicenseDataColumns[8]] = licenseData._quantity; dr[licenseCols.LicenseDataColumns[9]] = licenseData._receivedby; dr[licenseCols.LicenseDataColumns[10]] = licenseData._sendat; _dgv.Rows.Add(dr); */ utils.helpers.addLog("added " + iRes.ToString() + " new data"); } } catch (SQLiteException ex) { OnStateChanged(new StatusEventArgs(StatusType.none, "Exception adding licenseData: "+ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } catch (Exception ex) { OnStateChanged(new StatusEventArgs(StatusType.none, "Exception adding licenseData: " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { } OnStateChanged(new StatusEventArgs(StatusType.none, "licenseData added: " + LastRowID.ToString())); return LastRowID ; }
public int add( string deviceid, string customer, string key, string ordernumber, DateTime orderdate, string ponumber, string endcustomer, string product, int quantity, string receivedby, DateTime sendat) { OnStateChanged(new StatusEventArgs(StatusType.none, "adding data...")); int LastInsert = -1; bool bRes = false; if (existsData(deviceid, key)) { utils.helpers.addLog("add abandoned for existing datarow"); OnStateChanged(new StatusEventArgs(StatusType.none, "...data already known")); return LastInsert; } LicenseData licenseData = new LicenseData(); licenseData._deviceid = deviceid; licenseData._customer = customer; licenseData._key = key; licenseData._ordernumber = ordernumber; licenseData._orderdate = orderdate; licenseData._ponumber = ponumber; licenseData._endcustomer = endcustomer; licenseData._product = product; licenseData._quantity = quantity; licenseData._receivedby = receivedby; licenseData._sendat = sendat; string cmdText = "INSERT INTO licensedata " + getSQLFieldListForInsert() + //"(id, "+ //licenseCols.dataCols[0].name +", "+ //licenseCols.dataCols[1].name + ", " + //licenseCols.dataCols[2].name + ", " + //licenseCols.dataCols[3].name + ", " + //licenseCols.dataCols[4].name + ", " + //licenseCols.dataCols[5].name + ", " + //licenseCols.dataCols[6].name + ", " + //licenseCols.dataCols[7].name + ", " + //licenseCols.dataCols[8].name + //") " + "VALUES(" + "NULL, " + //auto id "'" + licenseData._deviceid + "'," + "'" + licenseData._customer + "'," + "'" + licenseData._key + "'," + "'" + licenseData._ordernumber + "'," + "'" + licenseData._orderdate.ToString("yyyy-MM-dd HH:mm:ss") + "'," +// '2007-01-01 10:00:00', yyyy-mm-dd HH:mm:ss "'" + licenseData._ponumber + "'," + "'" + licenseData._endcustomer + "'," + "'" + licenseData._product + "'," + "" + licenseData._quantity.ToString() + "," + "'" + licenseData._receivedby + "'," + "'" + licenseData._sendat.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")"; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { connection.Open(); SQLiteCommand command = new SQLiteCommand(connection); string namelist = getSQLFieldListForInsert(); // Einfügen eines Test-Datensatzes. command.CommandText = cmdText; int iRes = command.ExecuteNonQuery(); utils.helpers.addLog("SQLcmd: '" + command.CommandText + "'"); //get id of last insert command.CommandText = "select last_insert_rowid()"; // The row ID is a 64-bit value - cast the Command result to an Int64. // long LastRowID64 = (long)command.ExecuteScalar(); // Then grab the bottom 32-bits as the unique ID of the row. LastInsert = (int)LastRowID64; command.Dispose(); //doRefresh(ref _dgv); utils.helpers.addLog("added " + iRes.ToString() + " new data"); OnStateChanged(new StatusEventArgs(StatusType.none, "... added "+iRes.ToString() +" new data")); } } catch (SQLiteException ex) { OnStateChanged(new StatusEventArgs(StatusType.error, "add new data failed "+ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText+"\r\n" + ex.Message + "\r\n" + ex.StackTrace); } catch (Exception ex) { OnStateChanged(new StatusEventArgs(StatusType.error, "add new data failed " + ex.Message)); utils.helpers.addExceptionLog("add: " + cmdText + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { } return LastInsert; }
public StatusEventArgs(StatusType state, LicenseData _licenseData) { eStatus = state; strMessage = _licenseData._deviceid; licenseData = _licenseData; }
public int processAttachement(Attachement att, LicenseMailBodyData data, IMailMessage mail) { int iCount=0; LicenseXML xmlData = LicenseXML.Deserialize(att.data); foreach(license ldata in xmlData.licenses){ utils.helpers.addLog("processAttachement: new LicenseData...\r\n"); LicenseData licenseData = new LicenseData(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp); //if (_licenseDataBase.addQueued(licenseData)) utils.helpers.addLog("firing license_mail event\r\n"); OnStateChanged(new StatusEventArgs(StatusType.license_mail, licenseData)); iCount++; //if (_licenseDataBase.add(ldata.id, ldata.user, ldata.key, data.OrderNumber, data.OrderDate, data.yourPOnumber, data.EndCustomer, data.Product, data.Quantity, mail.User, mail.timestamp)) // iCount++; //utils.helpers.addLog("start _licenseDataBase.add() done\r\n"); } #region alternative_code /* // Request all the attachments on the email message. This results in a GetItem operation call to EWS. m.Load(new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.Attachments)); foreach (Microsoft.Exchange.WebServices.Data.Attachment att in m.Attachments) { if (att is Microsoft.Exchange.WebServices.Data.FileAttachment) { Microsoft.Exchange.WebServices.Data.FileAttachment fileAttachment = att as Microsoft.Exchange.WebServices.Data.FileAttachment; //get a temp file name string fname = System.IO.Path.GetTempFileName(); //utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name // Load the file attachment into memory. This gives you access to the attachment content, which // is a byte array that you can use to attach this file to another item. This results in a GetAttachment operation // call to EWS. fileAttachment.Load(); // Load attachment contents into a file. This results in a GetAttachment operation call to EWS. fileAttachment.Load(fname); addLog("Attachement file saved to: " + fname); // Put attachment contents into a stream. using (System.IO.FileStream theStream = new System.IO.FileStream(utils.helpers.getAppPath() + fileAttachment.Id.ToString() + "_" + fileAttachment.Name, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite)) { //This results in a GetAttachment operation call to EWS. fileAttachment.Load(theStream); } //load into memory stream, seems the only stream supported using (System.IO.MemoryStream ms = new System.IO.MemoryStream(att.Size)) { fileAttachment.Load(ms); using (System.IO.FileStream fs = new System.IO.FileStream(fname, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite)) { ms.CopyTo(fs); fs.Flush(); } } addLog("saved attachement: " + fname); iRet++; } } */ #endregion return iCount; }