Exemple #1
0
        //public void OnTimerCallBack(object state)
        //{
        //    //LogMessage("Timer Tick - ");
        //    MSYNC();
        //}
        public void MSYNC()
        {
            List <BatchUploadModel> batchids = new List <BatchUploadModel>();

            try
            {
                using (dc = new shortenURLEntities())
                {
                    batchids = (from b in dc.BatchUploadDatas
                                .AsEnumerable()
                                where b.Status == "Insertion Completed"
                                select new BatchUploadModel()
                    {
                        Batchid = b.PK_Batchid,
                        CreatedDate = b.CreatedDate.Value.Date,
                        fk_rid = b.FK_RID,
                        fk_cid = b.FK_ClientID,
                        status = b.Status
                    }).ToList();
                    //if batchdata available
                    if (batchids.Count != 0)
                    {
                        List <BatchData> batchdata = (from u in dc.UIDDATAs
                                                      .AsNoTracking()
                                                      .AsEnumerable()
                                                      join b in batchids on u.FK_Batchid equals b.Batchid
                                                      where DateTime.Compare(u.CreatedDate.GetValueOrDefault().Date, b.CreatedDate.GetValueOrDefault().Date) == 0 && u.FK_RID == b.fk_rid && u.FK_ClientID == b.fk_cid && u.UniqueNumber == null && u.FK_Batchid != null
                                                      select new BatchData()
                        {
                            pk_uid = u.PK_Uid
                        }).ToList();
                        if (batchdata.Count != 0)
                        {
                            List <BatchData> hashids = (from lb in batchdata
                                                        select new BatchData()
                            {
                                pk_uid = lb.pk_uid,
                                hashid = GetHashID(lb.pk_uid)
                            }).ToList();
                            foreach (BatchData i in hashids)
                            {
                                new DataInsertionBO().UpdateHashid(i.pk_uid, i.hashid);
                            }
                            foreach (BatchUploadModel b in batchids)
                            {
                                new DataInsertionBO().UpdateBatchStatus(b.Batchid, "Completed");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogs.LogErrorData(ex.StackTrace, ex.InnerException.ToString());
                foreach (BatchUploadModel b in batchids)
                {
                    new DataInsertionBO().UpdateBatchStatus(b.Batchid, "Error Occured");
                }
            }
        }
 public void UpdateBatchStatus(int?batchid, string status)
 {
     using (var dc = new shortenURLEntities())
     {
         var res = dc.BatchUploadDatas.SingleOrDefault(x => x.PK_Batchid == batchid);
         if (res != null)
         {
             res.Status = status;
             dc.SaveChanges();
         }
     }
 }
 public void UpdateHashid(int pk_uid, string hashid)
 {
     using (var dc = new shortenURLEntities())
     {
         var res = dc.UIDDATAs.SingleOrDefault(x => x.PK_Uid == pk_uid);
         if (res != null)
         {
             res.UniqueNumber = hashid;
             dc.SaveChanges();
         }
     }
 }
 public static void LogErrorData(string stackTraceInfo, string message)
 {
     try
     {
         shortenURLEntities dc          = new shortenURLEntities();
         ErrorLog           objErrorLog = new ErrorLog();
         objErrorLog.StackTrace   = stackTraceInfo;
         objErrorLog.ErrorMessage = message;
         objErrorLog.DateCreated  = System.DateTime.Now;
         dc.ErrorLogs.Add(objErrorLog);
         dc.SaveChanges();
         string err = "";
         err  = "Error Occured on:" + DateTime.Now.ToString() + "<br>";
         err += "Message: " + message;
         err += "Stack Trace:<br>" + stackTraceInfo;
         //EmailUtil.SendMail("*****@*****.**", ConfigurationManager.AppSettings["Error Mail"].ToString(), "", "", "Error ShortenURL", " <br>Message : " + err);
     }
     catch (Exception ex)
     {
     }
 }