Forum
if (vtgtw.conn.State != ConnectionState.Open)
{
vtgtw.Open();
}
if (vtdwh.conn.State != ConnectionState.Open)
{
vtdwh.Open();
}
Queue<int> lstidrsms = new Queue<int>();
String tsesid = iht.Register();
{
MySqlCommand mcom9 = vtdwh.getCommand(600000);
mcom9.CommandText = "SELECT ---0 DAY)";
MySqlDataReader mdr9 = mcom9.ExecuteReader();
while (mdr9.Read())
{
lstidrsms.Enqueue(mdr9.GetInt32(0));
}
mdr9.Close();
mdr9.Dispose();
mcom9.Dispose();
}
while (lstidrsms.Count > 0)
{
GC.Collect();
if (this.keepAlive == false)
{
vtgtw.Close();
vtdwh.Close();
return;
}
int xidrsms = lstidrsms.Dequeue();
bool dwhrequiresmodif = false;
// Update each sentsms packet for idrsms
try
{
DataTable dt = new DataTable();
{
MySqlCommand mcom = vtgtw.getCommand(600000);
mcom.CommandText = "(SELECT s.ids---) AND s.idrsms=?pidrsms) UNION (SELECT s.ids***
mcom.Parameters.AddWithValue("?pidrsms", xidrsms);
MySqlDataAdapter mda = new MySqlDataAdapter(mcom);
mda.Fill(dt);
mda.Dispose();
mcom.Dispose();
}
IDictionary<string, int> map_tmsgid_idsentsms = new Dictionary<string, int>();
List<String> tmsgidlist = new List<string>();
List<int> nokand44list = new List<int>();
while (dt.Rows.Count > 0)
{
int xidsentsms = Int32.Parse(dt.Rows[0][0].ToString());
String xtmsgid = dt.Rows[0][1].ToString();
if (xtmsgid.Contains("NOK") || xtmsgid.StartsWith("-"))
{
nokand44list.Add(xidsentsms);
dwhrequiresmodif = true;
}
else
{
if (!map_tmsgid_idsentsms.ContainsKey(xtmsgid))
{
map_tmsgid_idsentsms.Add(xtmsgid, xidsentsms);
}
tmsgidlist.Add(xtmsgid);
}
dt.Rows.RemoveAt(0);
}
dt.Dispose();
dt = null;
bool retried = false;
retryAfterNewRegister:
IDictionary<string, int> map_tmsgid_status = null;
logSync(ex);
}
if (map_tmsgid_status != null)
{
foreach (String xtmsgid in map_tmsgid_status.Keys)
{
try
{
if (map_tmsgid_idsentsms.ContainsKey(xtmsgid))
{
int xidsentsms = map_tmsgid_idsentsms[xtmsgid];
int xnewstat = map_tmsgid_status[xtmsgid];
if (xnewstat != 2)
{
int xdbstat = 2;
switch (xnewstat)
{
case -1:
xdbstat = -1;
break;
case 0:
xdbstat = 0;
break;
case 1:
xdbstat = 1;
break;
case 2:
xdbstat = 2;
break;
default:
xdbstat = 1;
break;
}
{
MySqlCommand mcom2 = vtgtw.getCommand(600000);
mcom2.CommandText = "UPDATE ---s";
mcom2.Parameters.AddWithValue("?pstatus", xdbstat);
mcom2.Parameters.AddWithValue("?pidsentsms", xidsentsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
}
dwhrequiresmodif = true;
logSync("P4 - new stat of idrsms : " + xidrsms + " - idsen--- + " - is : " + xdbstat);
}
}
}
catch (Exception innerex2)
{
logSync("P4 - failed to update : xidrsms : " + xidrsms + " - xtmsgid : " + xtmsgid, null);
logSync(innerex2);
}
}
foreach (int xidsentsms in nokand44list)
{
try
{
{
MySqlCommand mcom2 = vtgtw.getCommand(600000);
mcom2.CommandText = "UPDATE ---;
mcom2.Parameters.AddWithValue("?pstatus", 1);
mcom2.Parameters.AddWithValue("?pidsentsms", xidsentsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
}
}
}
map_tmsgid_idsentsms.Clear();
map_tmsgid_status.Clear();
nokand44list.Clear();
tmsgidlist.Clear();
}
}
catch (Exception innerex)
{
logSync(innerex);
}
// Update dwh for idrsms packet
try
{
if (dwhrequiresmodif)
{
Dictionary<int, int> MapStatToCount = new Dictionary<int, int>();
MapStatToCount.Add(-1, 0);
MapStatToCount.Add(0, 0);
MapStatToCount.Add(1, 0);
MapStatToCount.Add(2, 0);
int tcount = 0;
{
MySqlCommand mcom = vtgtw.getCommand(600000);
mcom.CommandText = "SELECT s----";
mcom.Parameters.AddWithValue("?pidrsms", xidrsms);
MySqlDataReader mdr = mcom.ExecuteReader();
while (mdr.Read())
{
int st = mdr.GetInt32(0);
int cnt = mdr.GetInt32(1);
tcount += cnt;
switch (st)
{
case -1:
MapStatToCount[-1] += cnt;
break;
case 0:
MapStatToCount[0] += cnt;
break;
case 1:
MapStatToCount[1] += cnt;
break;
case 2:
MapStatToCount[2] += cnt;
break;
default:
MapStatToCount[1] += cnt;
break;
}
}
mdr.Close();
mdr.Dispose();
mcom.Dispose();
}
if (tcount > 0)
{
MySqlCommand mcom2 = vtdwh.getCommand(600000);
mcom2.CommandText = "UPDATE ----WHERE idrsms=?pidrsms";
mcom2.Parameters.AddWithValue("?pse1", MapStatToCount[-1]);
mcom2.Parameters.AddWithValue("?ps0", MapStatToCount[0]);
mcom2.Parameters.AddWithValue("?ps1", MapStatToCount[1]);
mcom2.Parameters.AddWithValue("?ps2", MapStatToCount[2]);
mcom2.Parameters.AddWithValue("?pidrsms", xidrsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
}
else
{
logSync("P4 - errorneous mysql result to update dwh for idrsms : " + xidrsms);
}
MapStatToCount.Clear();
}
}
catch (Exception innerex)
{
logSync("P4 - failed to update dwh for idrsms : " + xidrsms , null);
logSync(innerex);
}
}
}
catch (Exception ex)
{
logSync(ex);
}
}
selam,
özelden yolladığın kod zaten benzeri. aslında yaptığı iş kabaca, kendi veritabanınıza bağlanıp bekleyen sms leri, turkcell objesini kullanarak, turkcell'in sistemlerine gönderiyor. Aşağıda ilk birkaç satırı açıkladım. Ondan sonrakiler de tekrar zaten.
if (vtgtw.conn.State != ConnectionState.Open) // veritabanı bağlantısı açık değilse
{
vtgtw.Open(); // veritabanına bağlan
}
if (vtdwh.conn.State != ConnectionState.Open) // ayrı bir veritabanı bağlantısı, açık değilse
{
vtdwh.Open(); // onu da aç
}
Queue<int> lstidrsms = new Queue<int>(); // içinde int tipinde veri depolayacak nesneyi oluştur
IHebe iht = new HEBESMSPostpaid(); // turkcell sistemine bağlanacak nesneyi oluştur
String tsesid = iht.Register(); // oturum id'sini turkcell'den al
{
MySqlCommand mcom9 = vtdwh.getCommand(600000); //mysql komutunu oluşturacak nesneyi oluştur
mcom9.CommandText = "SELECT s.idrsms FROM sentsmscount AS s WHERE
(s.s2>0 or s.se1>0) AND s.senddate>=DATE_ADD(NOW(), INTERVAL
-10 DAY)"; // veritabanında çalıştırılacak sql sorgusu
MySqlDataReader mdr9 = mcom9.ExecuteReader(); // bu sorguyu okumaya başla
while (mdr9.Read()) // tabloda kayıt olduğu müddetçe aşağıdaki işlemi yap
{
lstidrsms.Enqueue(mdr9.GetInt32(0)); // büyün kayıtları bir yerde topla. (kuyruğa at)
}
mdr9.Close(); // az evvel yukarıda açılan objeyi kapa
mdr9.Dispose(); // dispose ederek memoryde kapladığı alanı boşalt
mcom9.Dispose(); // aynı dispose işlemini buna da uygula
}
while (lstidrsms.Count > 0) // yukarıda enqueue ile toplanan verilerde işlem yapmaya başla
{
GC.Collect(); // garbace collector'u çağır. işlemi biten nesneleri memoryden çıkar (bunun bir kısmı yukarıda dispose ile yapıldı)
if (this.keepAlive == false) // eğer bağlantı açıksa
{
vtgtw.Close(); // bağlantıyı kapa
vtdwh.Close(); // ikinci bağlantıyı da kapa
return;
}
int xidrsms = lstidrsms.Dequeue(); // int tipindeki nesneye kuyrukta bekleyen verileri al
bool dwhrequiresmodif = false; // bir değişken tanımla, ilk durumu false olsun.
// Update each sentsms packet for idrsms
try
{
DataTable dt = new DataTable();
{
// veritabanına bağlan, sentsms tablosundaki verileri getir, bunu DataTable tipindeki dt değişkeninde topla
MySqlCommand mcom = vtgtw.getCommand(600000);
mcom.CommandText = "(SELECT s.idsentsms, s.tmsgid FROM sentsms AS s
WHERE (s.status=2 OR s.status=-1) AND s.idrsms=?pidrsms) UNION (SELECT
s.idsentsms, s.tmsgid FROM sentsms AS s WHERE s.status=1 AND (s.tmsgid
LIKE '%NOK%' OR s.tmsgid LIKE '-%') AND s.idrsms=?pidrsms)";
mcom.Parameters.AddWithValue("?pidrsms", xidrsms);
MySqlDataAdapter mda = new MySqlDataAdapter(mcom);
mda.Fill(dt);
mda.Dispose();
mcom.Dispose();
}
// idictionary ile value-pair çiftini oluştur. mesela ali - 10, veli-5 gibi
IDictionary<string, int> map_tmsgid_idsentsms = new Dictionary<string, int>();
List<String> tmsgidlist = new List<string>();
List<int> nokand44list = new List<int>();
while (dt.Rows.Count > 0)
{
int xidsentsms = Int32.Parse(dt.Rows[0][0].ToString());
String xtmsgid = dt.Rows[0][1].ToString();
if (xtmsgid.Contains("NOK") || xtmsgid.StartsWith("-"))
{
nokand44list.Add(xidsentsms);
dwhrequiresmodif = true;
}
else
{
if (!map_tmsgid_idsentsms.ContainsKey(xtmsgid))
{
map_tmsgid_idsentsms.Add(xtmsgid, xidsentsms);
}
tmsgidlist.Add(xtmsgid);
}
dt.Rows.RemoveAt(0);
}
dt.Dispose();
dt = null;
bool retried = false;
retryAfterNewRegister:
IDictionary<string, int> map_tmsgid_status = null;
try
{
map_tmsgid_status = iht.GetStatus("1.0", tsesid, tmsgidlist);
}
catch (Exception ex)
{
if (retried == false)
{
retried = true;
tsesid = iht.Register();
goto retryAfterNewRegister;
}
logSync(ex);
}
if (map_tmsgid_status != null)
{
foreach (String xtmsgid in map_tmsgid_status.Keys)
{
try
{
if (map_tmsgid_idsentsms.ContainsKey(xtmsgid))
{
int xidsentsms = map_tmsgid_idsentsms[xtmsgid];
int xnewstat = map_tmsgid_status[xtmsgid];
if (xnewstat != 2)
{
int xdbstat = 2;
switch (xnewstat)
{
case -1:
xdbstat = -1;
break;
case 0:
xdbstat = 0;
break;
case 1:
xdbstat = 1;
break;
case 2:
xdbstat = 2;
break;
default:
xdbstat = 1;
break;
}
{
MySqlCommand mcom2 = vtgtw.getCommand(600000);
mcom2.CommandText = "UPDATE sentsms SET status=?pstatus WHERE
idsentsms=?pidsentsms";
mcom2.Parameters.AddWithValue("?pstatus", xdbstat);
mcom2.Parameters.AddWithValue("?pidsentsms", xidsentsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
}
dwhrequiresmodif = true;
logSync("P4 - new stat of idrsms : " + xidrsms + " - idsendsms : " +
xidsentsms + " - tmsgid : " + xtmsgid + " - is : " + xdbstat);
}
}
}
catch (Exception innerex2)
{
logSync("P4 - failed to update : xidrsms : " + xidrsms + " - xtmsgid : " + xtmsgid, null);
logSync(innerex2);
}
}
foreach (int xidsentsms in nokand44list)
{
try
{
{
MySqlCommand mcom2 = vtgtw.getCommand(600000);
mcom2.CommandText = "UPDATE sentsms SET status=?pstatus WHERE idsentsms=?pidsentsms";
mcom2.Parameters.AddWithValue("?pstatus", 1);
mcom2.Parameters.AddWithValue("?pidsentsms", xidsentsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
}
dwhrequiresmodif = true;
logSync("P4 - new stat of idrsms : " + xidrsms + " idsendsms : " +
xidsentsms + " - is : 1");
}
catch (Exception innerex2)
{
logSync("P4 - failed to update : xidrsms : " + xidrsms + " - xidsentsms
: " + xidsentsms, null);
logSync(innerex2);
}
}
map_tmsgid_idsentsms.Clear();
map_tmsgid_status.Clear();
nokand44list.Clear();
tmsgidlist.Clear();
}
}
catch (Exception innerex)
{
logSync(innerex);
}
// Update dwh for idrsms packet
try
{
if (dwhrequiresmodif)
{
Dictionary<int, int> MapStatToCount = new Dictionary<int, int>();
MapStatToCount.Add(-1, 0);
MapStatToCount.Add(0, 0);
MapStatToCount.Add(1, 0);
MapStatToCount.Add(2, 0);
int tcount = 0;
{
MySqlCommand mcom = vtgtw.getCommand(600000);
mcom.CommandText = "SELECT status, COUNT(idsentsms) FROM sentsms WHERE
idrsms=?pidrsms group by status";
mcom.Parameters.AddWithValue("?pidrsms", xidrsms);
MySqlDataReader mdr = mcom.ExecuteReader();
while (mdr.Read())
{
int st = mdr.GetInt32(0);
int cnt = mdr.GetInt32(1);
tcount += cnt;
switch (st)
{
case -1:
MapStatToCount[-1] += cnt;
break;
case 0:
MapStatToCount[0] += cnt;
break;
case 1:
MapStatToCount[1] += cnt;
break;
case 2:
MapStatToCount[2] += cnt;
break;
default:
MapStatToCount[1] += cnt;
break;
}
}
mdr.Close();
mdr.Dispose();
mcom.Dispose();
}
if (tcount > 0)
{
MySqlCommand mcom2 = vtdwh.getCommand(600000);
mcom2.CommandText = "UPDATE sentsmscount SET se1=?pse1 , s0=?ps0 ,
s1=?ps1 , s2=?ps2 , s3=0 , s4=0 WHERE idrsms=?pidrsms";
mcom2.Parameters.AddWithValue("?pse1", MapStatToCount[-1]);
mcom2.Parameters.AddWithValue("?ps0", MapStatToCount[0]);
mcom2.Parameters.AddWithValue("?ps1", MapStatToCount[1]);
mcom2.Parameters.AddWithValue("?ps2", MapStatToCount[2]);
mcom2.Parameters.AddWithValue("?pidrsms", xidrsms);
mcom2.ExecuteNonQuery();
mcom2.Dispose();
logSync("P4 - updated dwh for idrsms : " + xidrsms + " se1=" +
MapStatToCount[-1] + " s0=" + MapStatToCount[0] + " s1=" +
MapStatToCount[1] + " s2=" + MapStatToCount[2]);
}
else
{
logSync("P4 - errorneous mysql result to update dwh for idrsms : " + xidrsms);
}
MapStatToCount.Clear();
}
}
catch (Exception innerex)
{
logSync("P4 - failed to update dwh for idrsms : " + xidrsms , null);
logSync(innerex);
}
}
}
catch (Exception ex)
{
logSync(ex);
}
}