Exemplo n.º 1
0
        /// <summary>
        /// CHECK IF EXIST AND EXIRATION TIME
        /// </summary>
        /// <param name="APICreateDate"></param>
        /// <param name="UNIQUE"></param>
        /// <returns></returns>
        public static bool MAC_UNIQUE_IS_EXIST(ref DateTime APICreateDate, string UNIQUE, ref enumProject Project)
        {
            if (APICreateDate > LastClear_UTC.AddHours(Local_Cache_Refresh_Hour_Interval))
            {
                Update();
            }
            try
            {
                if (!UNIQUE_DICTIONARY.ContainsKey(((int)Project).ToString() + "_" + UNIQUE))
                {
                    return(false);
                }

                return(UNIQUE_DICTIONARY[((int)Project).ToString() + "_" + UNIQUE] > APICreateDate);
            }
            catch (Exception ex)
            {
                #region MyRegion LOG

                UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception,
                                       "MAC_OR_UNIQUE Exist ERROR",
                                       UNIQUE,
                                       UtilsException.GetMSG(ref ex),
                                       true,
                                       "",
                                       "",
                                       "",
                                       ref APICreateDate,
                                       ref APICreateDate,
                                       ref CacheGuid, true, UNIQUE, Project);

                #endregion
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// ADD IF NOT EXIST
        /// </summary>
        /// <param name="IP"></param>
        /// <returns></returns>
        public static IPHolder IP_Get(string IP, int ToAddIfNeeded, out string exception, ref DateTime apicreatedate_ISR, ref enumProject Project)
        {
            exception = string.Empty;
            IPHolder current = null;

            if (DateTime.UtcNow.Date > LastClear_UTC.Date)
            {
                Update();
            }

            try
            {
                if (IPs.ContainsKey(IP))
                {
                    if (ToAddIfNeeded > 0)
                    {
                        lock (getLocker)
                        {
                            lock (locker1)
                            {
                                IPHolder cur = IPs[IP];
                                cur.Count++;
                                IPs[IP] = cur;
                            }
                        }
                    }
                    return(IPs[IP]);
                }
                else
                {
                    lock (getLocker)
                    {
                        current = new IPHolder(null, IP, ToAddIfNeeded, AppManager.IP_AllowedPerCycle, new DateTime(DateTime.UtcNow.Ticks).AddMinutes(AppManager.IP_MinuteCycle));

                        current = AddUpdate_IP(IP, current, out exception, ref Project);
                    }
                }
            }
            catch (Exception ex)
            {
                exception = UtilsException.GetMSG(ref ex);
                #region MyRegion LOG

                UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception,
                                       "IP_Get",
                                       IP,
                                       exception,
                                       true,
                                       "",
                                       "",
                                       "",
                                       ref apicreatedate_ISR,
                                       ref apicreatedate_ISR,
                                       ref CacheGuid, true, IP, Project);

                #endregion
            }
            return(current);
        }
Exemplo n.º 3
0
        public static API_Unique_Identity_AddUpdateResult API_Unique_Identity_AddUpdate(string Unique,
                                                                                        ref DateTime CreateDate,
                                                                                        ref DateTime CreateDateISR,
                                                                                        ref Guid APITransaction, ref enumAction Action, ref enumProject Project)
        {
            API_Unique_Identity_AddUpdateResult result = null;

            try
            {
                using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                {
                    CommandTimeout = 120
                })
                {
                    result = db.API_Unique_Identity_AddUpdate(APITransaction, Unique, CreateDate,
                                                              CreateDateISR, AppManager.Unique_AllowedPerCycle, AppManager.Unique_MinuteCycle, (int)Project).FirstOrDefault();
                }
                return(result);
            }

            catch (Exception ex1)
            {
                try
                {
                    using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                    {
                        CommandTimeout = 120
                    })
                    {
                        result = db.API_Unique_Identity_AddUpdate(APITransaction, Unique, CreateDate,
                                                                  CreateDateISR, AppManager.Unique_AllowedPerCycle,
                                                                  AppManager.Unique_MinuteCycle, (int)Project).FirstOrDefault();
                    }
                    return(result);
                }
                catch (Exception ex2)
                {
                    #region MyRegion LOG

                    UtilsDB.API_Log_Insert(Action, enumLogType._1_DBException, enumLogType._1_DBException,
                                           null,
                                           "API_Unique_Identity_AddUpdate",
                                           UtilsException.GetMSG(ref ex2),
                                           true,
                                           null,
                                           null,
                                           null,
                                           ref CreateDate,
                                           ref CreateDateISR,
                                           ref APITransaction, false, Unique, Project);

                    #endregion
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 0 - MSG
        /// 1 - PHONE
        /// 2 - APITransaction
        /// return util response
        /// </summary>
        public static string MakeRequest_Google_Captch(string token, string ip, ref Guid APITransaction, ref DateTime APICreateDate,
                                                       ref DateTime APICreateDate_ISR,
                                                       out string Request, ref enumProject Project)
        {
            Request = "Init";
            try
            {
                Request = string.Format(Data, token, ip);//,ip
                Uri            address = new Uri(GoogleURL);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded; ";


                if (!string.IsNullOrWhiteSpace(Request))
                {
                    byte[] byteData = UTF8Encoding.UTF8.GetBytes(Request);

                    request.ContentLength = byteData.Length;

                    using (Stream postStream = request.GetRequestStream())
                        postStream.Write(byteData, 0, byteData.Length);
                }
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return(response.StatusCode.ToString());
                    }

                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    return(reader.ReadToEnd().Replace("<", "&lt;").Replace(">", "&gt;"));
                }
            }
            catch (Exception ex)
            {
                #region MyRegion LOG

                UtilsDB.API_Log_Insert(enumAction.GoogleCaptcha, enumLogType._1_WebException, enumLogType._1_WebException,
                                       token,
                                       ip,
                                       UtilsException.GetMSG(ref ex),
                                       true,
                                       null,
                                       null,
                                       null,
                                       ref APICreateDate,
                                       ref APICreateDate_ISR,
                                       ref APITransaction, true, ip, Project);

                #endregion

                return("EXCEPTION");
            }
        }
Exemplo n.º 5
0
        //public static List<API_Pet_GetResult> API_Pet_Get(Guid APITransaction, DateTime CreateDate, bool RenewToken)
        //{

        //    List<API_Pet_GetResult> result = null;
        //    try
        //    {
        //        using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection()) { CommandTimeout = 120 })
        //        {
        //            result = db.API_Pet_Get(RenewToken).ToList();
        //        }
        //        return result;

        //    }

        //    catch (Exception ex1)
        //    {
        //        try
        //        {

        //            using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection()) { CommandTimeout = 120 })
        //            {
        //                result = db.API_Pet_Get(RenewToken).ToList();
        //            }
        //            return result;

        //        }
        //        catch (Exception ex2)
        //        {
        //            #region MyRegion LOG

        //            UtilsDB.API_Log_Insert(enumAction.Lead, enumLogType._1_DBException, enumLogType._1_DBException,
        //                                                         null,
        //                                                         "API_Pet_Get -> RenewToken: "+ RenewToken.ToString(),
        //                                                         UtilsException.GetMSG(ref ex2),
        //                                                         true,
        //                                                         null,
        //                                                         null,
        //                                                         null,
        //                                                         ref CreateDate,
        //                                                         ref CreateDate,
        //                                                         ref APITransaction, false, null, enumProject.APIGeneral);

        //            #endregion
        //        }
        //    }
        //    return result;
        //}
        #endregion
        public static API_Lead_Update_CouponMSGResult API_Lead_Update_CouponMSG(ref Guid APITransaction, ref DateTime CreateDate,
                                                                                ref DateTime CreateDateISR, long leadid, string reponseMSGCoupon, bool success)
        {
            API_Lead_Update_CouponMSGResult result = null;

            try
            {
                using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                {
                    CommandTimeout = 120
                })
                {
                    result = db.API_Lead_Update_CouponMSG(leadid, reponseMSGCoupon, success).FirstOrDefault();
                }
                return(result);
            }

            catch (Exception ex1)
            {
                try
                {
                    using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                    {
                        CommandTimeout = 120
                    })
                    {
                        result = db.API_Lead_Update_CouponMSG(leadid, reponseMSGCoupon, success).FirstOrDefault();
                    }
                    return(result);
                }
                catch (Exception ex2)
                {
                    #region MyRegion LOG

                    UtilsDB.API_Log_Insert(enumAction.Lead, enumLogType._1_DBException, enumLogType._1_DBException,
                                           reponseMSGCoupon,
                                           "API_Lead_Update_CouponMSG",
                                           UtilsException.GetMSG(ref ex2),
                                           true,
                                           null,
                                           null,
                                           null,
                                           ref CreateDate,
                                           ref CreateDateISR,
                                           ref APITransaction, false, null, enumProject.Dog);

                    #endregion
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public static API_Validate_Registered_UserResult API_Validate_Registered_User(Guid APITransaction, DateTime CreateDateISR, string email, enumProject Project)
        {
            API_Validate_Registered_UserResult result = null;

            try
            {
                using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                {
                    CommandTimeout = 120
                })
                {
                    result = db.API_Validate_Registered_User((int)Project, email).FirstOrDefault();
                }
                return(result);
            }

            catch (Exception ex1)
            {
                try
                {
                    using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                    {
                        CommandTimeout = 120
                    })
                    {
                        result = db.API_Validate_Registered_User((int)Project, email).FirstOrDefault();
                    }
                    return(result);
                }
                catch (Exception ex2)
                {
                    #region MyRegion LOG

                    UtilsDB.API_Log_Insert(enumAction.Lead, enumLogType._1_DBException, enumLogType._1_DBException,
                                           null,
                                           "API_Validate_Registered_User",
                                           UtilsException.GetMSG(ref ex2),
                                           true,
                                           null,
                                           null,
                                           null,
                                           ref CreateDateISR,
                                           ref CreateDateISR,
                                           ref APITransaction, false, email, Project);

                    #endregion
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public static List <API_Project_GetResult> API_Project_Get(Guid APITransaction, DateTime CreateDate, bool RenewToken)
        {
            List <API_Project_GetResult> result = null;

            try
            {
                using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                {
                    CommandTimeout = 120
                })
                {
                    result = db.API_Project_Get(RenewToken).ToList();
                }
                return(result);
            }

            catch (Exception ex1)
            {
                try
                {
                    using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                    {
                        CommandTimeout = 120
                    })
                    {
                        result = db.API_Project_Get(RenewToken).ToList();
                    }
                    return(result);
                }
                catch (Exception ex2)
                {
                    #region MyRegion LOG

                    UtilsDB.API_Log_Insert(enumAction.Lead, enumLogType._1_DBException, enumLogType._1_DBException,
                                           null,
                                           "API_Project_Get -> RenewToken: " + RenewToken.ToString(),
                                           UtilsException.GetMSG(ref ex2),
                                           true,
                                           null,
                                           null,
                                           null,
                                           ref CreateDate,
                                           ref CreateDate,
                                           ref APITransaction, false, null, enumProject.APIGeneral);

                    #endregion
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// IF NOT EXIST ADD NEW, ELSE UPDTAE EXISTING AND RETURN EXISTING
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="ip"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static IPHolder AddUpdate_IP(string IP, IPHolder ip, out string exception, ref enumProject Project)
        {
            exception = string.Empty;
            if (DateTime.UtcNow.Date > LastClear_UTC.Date)
            {
                Update();
            }

            try
            {
                lock (locker1)
                {
                    if (!IPs.ContainsKey(IP))
                    {
                        IPs.Add(IP, ip);
                    }
                    else
                    {
                        IPHolder current = IPs[IP];
                        current.Update(ip.IP_ID.GetValueOrDefault(), ip.Max, ip.Count, ip.ExpDT);
                        IPs[IP] = current;
                        ip.Clone(current);
                    }
                }
            }
            catch (Exception ex)
            {
                exception    = UtilsException.GetMSG(ref ex);
                NowException = new DateTime(DateTime.UtcNow.Ticks);
                #region MyRegion LOG

                UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception,
                                       "AddUpdate_IP",
                                       IP,
                                       exception,
                                       true,
                                       "",
                                       "",
                                       "",
                                       ref NowException,
                                       ref NowException,
                                       ref CacheGuid, true, IP, Project);

                #endregion
            }
            return(ip);
        }
Exemplo n.º 9
0
        /// <summary>
        /// ADD OR UPDATE THE MAC AND EXPIRED TIME
        /// </summary>
        /// <param name="UNIQUE"></param>
        /// <param name="expdate"></param>
        /// <returns></returns>
        public static bool ADDREJECT_UNIQUE(ref DateTime APICreateDate, string UNIQUE, DateTime expdate, ref enumProject Project)
        {
            if (DateTime.UtcNow > LastClear_UTC.AddHours(Local_Cache_Refresh_Hour_Interval))
            {
                Update();
            }

            try
            {
                if (!UNIQUE_DICTIONARY.ContainsKey(((int)Project).ToString() + "_" + UNIQUE))
                {
                    lock (locker1)
                    {
                        UNIQUE_DICTIONARY.Add(((int)Project).ToString() + "_" + UNIQUE, expdate);
                    }
                    return(true);
                }
                else
                {
                    lock (locker1)
                    {
                        UNIQUE_DICTIONARY[((int)Project).ToString() + "_" + UNIQUE] = expdate;
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                #region MyRegion LOG

                UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception,
                                       "ADDREJECT_MAC_UNIQUE ERROR",
                                       UNIQUE,
                                       UtilsException.GetMSG(ref ex),
                                       true,
                                       "",
                                       "",
                                       "",
                                       ref APICreateDate,
                                       ref APICreateDate,
                                       ref CacheGuid, true, UNIQUE, Project);

                #endregion
            }

            return(false);
        }
Exemplo n.º 10
0
        public static API_Lead_InsertResult API_Lead_Insert(ref SubmitLead req, int PetType,
                                                            ref Guid APITransaction,
                                                            string Captch,
                                                            int AddToIP,
                                                            ref DateTime CreateDate,
                                                            ref DateTime CreateDateISR,
                                                            ref enumPlatformType PlatformType,
                                                            ref enumProject Project)
        {
            API_Lead_InsertResult result = null;

            try
            {
                using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                {
                    CommandTimeout = 120
                })
                {
                    result = db.API_Lead_Insert(APITransaction, req.Email, (int)PlatformType, req.IP, req.UA, CreateDate, CreateDateISR, null,
                                                Captch,
                                                AppManager.Unique_AllowedPerCycle, AppManager.Unique_MinuteCycle,
                                                (int)Project, req.FName, req.LName, req.Email, req.Phone, req.City, req.Street, req.STNumber, req.FlatNumber, req.POBox,
                                                req.Regulation, req.AcceptContent, null /* PetType*/, /*req.PetBDay*/ null,
                                                AppManager.IP_AllowedPerCycle, AppManager.IP_MinuteCycle, AddToIP).FirstOrDefault();
                }
                return(result);
            }

            catch (Exception ex1)
            {
                try
                {
                    using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
                    {
                        CommandTimeout = 120
                    })
                    {
                        result = db.API_Lead_Insert(APITransaction, req.Email, (int)PlatformType, req.IP, req.UA, CreateDate, CreateDateISR, null,
                                                    Captch,
                                                    AppManager.Unique_AllowedPerCycle, AppManager.Unique_MinuteCycle,
                                                    (int)Project, req.FName, req.LName, req.Email, req.Phone, req.City, req.Street, req.STNumber, req.FlatNumber, req.POBox,
                                                    req.Regulation, req.AcceptContent, null /* PetType*/, /*req.PetBDay*/ null,
                                                    AppManager.IP_AllowedPerCycle, AppManager.IP_MinuteCycle, AddToIP).FirstOrDefault();
                    }
                    return(result);
                }
                catch (Exception ex2)
                {
                    #region MyRegion LOG

                    UtilsDB.API_Log_Insert(enumAction.Lead, enumLogType._1_DBException, enumLogType._1_DBException,
                                           Newtonsoft.Json.JsonConvert.SerializeObject(req),
                                           "API_Lead_Insert_Offer",
                                           UtilsException.GetMSG(ref ex2),
                                           true,
                                           null,
                                           null,
                                           null,
                                           ref CreateDate,
                                           ref CreateDateISR,
                                           ref APITransaction, false, req.Email, Project);

                    #endregion
                }
            }
            return(result);
        }