Exemplo n.º 1
0
        /// <summary>
        /// TO BE USED AT IS ALIVE
        /// </summary>
        /// <param name="ISRDate"></param>
        /// <param name="Project"></param>
        /// <param name="APITransaction"></param>
        /// <param name="CurrentToken"></param>
        /// <returns></returns>
        public static bool CampaignAlive(DateTime ISRDate, enumProject Project, ref Guid APITransaction, out Guid CurrentToken)
        {
            if (Last_Config_Update_ISR.AddMinutes(ConfigUpdateAsMinutes) < UtilsDateTime.UTC_To_Israel_Time())
            {
                Update();
            }

            CurrentToken = APITransaction;

            API_Project_GetResult project = null;

            if (Projects.Count > 0)
            {
                project = (from p in Projects where p.ID == (int)Project && p.StartDate <= ISRDate && p.EndIncludeDate >= ISRDate.Date && p.Enabled select p).FirstOrDefault();

                if (project != null)
                {
                    CurrentToken = project.Token;
                    return(true);
                }
            }

            return(false);

            //if (Project == enumProject.Dog)
            //{
            //    return Dog_StartDate.Date <= ISRDate.Date && Dog_EndDate.Date >= ISRDate.Date;
            //}

            //return Cat_StartDate.Date <= ISRDate.Date && Cat_EndDate.Date>= ISRDate.Date ;
        }
Exemplo n.º 2
0
        //private static volatile List<API_Location_GetResult> Locations = new List<API_Location_GetResult>();

        public static API_Project_GetResult GetProject(enumProject Project)
        {
            if (Last_Config_Update_ISR.AddMinutes(ConfigUpdateAsMinutes) < UtilsDateTime.UTC_To_Israel_Time())
            {
                Update();
            }

            return((from p in Projects where p.ID == (int)Project select p).FirstOrDefault());
        }
Exemplo n.º 3
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");
            }
        }
        /// <summary>
        /// ValidRequestFromServerIP IS CHECKING IF ONLY SERVER OF CLIENT MADE THE REQUEST
        /// </summary>
        /// <param name="action"></param>
        /// <param name="UserRequest"></param>
        /// <param name="ip"></param>
        /// <param name="ua"></param>
        public void Init_Request_Data(enumAction action, object UserRequest,
                                      string ip, string ua, Guid ProjectToken)
        {
            AppManager.Update();

            Action            = action;
            SerializedRequest = Newtonsoft.Json.JsonConvert.SerializeObject(UserRequest);
            Platform          = enumPlatformType.Web;
            IP = ip;
            UA = string.IsNullOrEmpty(ua) ? "NULL" : ua;

            if (UA.ToLower().Contains("iphone"))
            {
                Platform = enumPlatformType.iPhone;
            }
            else if (UA.ToLower().Contains("android"))
            {
                Platform = enumPlatformType.Android;
            }
            else if (UA.ToLower().Contains("ipad"))
            {
                Platform = enumPlatformType.IPad;
            }


            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];

            if (context.Request.ServerVariables["HTTP_VIA"] != null)
            {
                ServerIP = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                ServerIP = context.Request.ServerVariables["REMOTE_ADDR"].ToString();
            }

            if (AppManager.RestrictServerIP && !Domains.Get_AllowedDomains().Contains(ServerIP))
            {
                ValidRequestFromServerIP = false;
            }

            ProjectType = enumProject.Cat;

            //if (ProjectToken == AppManager.Dog_ServerToken)
            //{
            //    ProjectType = enumProject.Dog;
            //}
            //else if (ProjectToken == AppManager.Cat_ServerToken)
            //{
            //    ProjectType = enumProject.Cat;
            //}
            //else
            //{
            //    ValidRequestFromServerIP = false;
            //}
        }
Exemplo n.º 5
0
        public static List <UIOut> UIResponse_Get(ref DateTime ISRTime, enumProject Project)
        {
            if (Last_Config_Update_ISR.AddHours(ConfigUpdateAsMinutes) < ISRTime || UIResponse.Count == 0)
            {
                Update();
            }

            if (lastUIGet.AddMinutes(ClientFetchDataInterval_AsMinutes) < DateTime.UtcNow)
            {
                lastUIGet = new DateTime(DateTime.UtcNow.Ticks);

                return((from ui in UIResponse where ui.ProjectID == (int)Project select ui).ToList());
            }

            return(new List <Models.UIOut>());
        }
Exemplo n.º 6
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.º 7
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.º 8
0
 public static bool API_Log_Insert(enumAction ActionType, enumLogType LogType, enumLogType InnerLogType,
                                   string MSG, string MSG2, string ERROR, bool Critical,
                                   string refferer, string ip, string ua,
                                   ref DateTime CreateDate,
                                   ref DateTime CreateDateISR, ref Guid APITransaction, bool useq, string identifier, enumProject Project
                                   )
 {
     try
     {
         using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
         {
             CommandTimeout = 120
         })
         {
             db.API_Log_Insert((int)ActionType, (int)LogType, (int)InnerLogType, MSG, MSG2, ERROR, Critical,
                               refferer, ip, ua,
                               CreateDate, CreateDateISR, APITransaction, "", identifier, (int)Project);
         }
         return(true);
     }
     catch (Exception ex1)
     {
         try
         {
             using (DogAndCatDBDataContext db = new DogAndCatDBDataContext(Connection())
             {
                 CommandTimeout = 120
             })
             {
                 db.API_Log_Insert((int)ActionType, (int)LogType, (int)InnerLogType, MSG, MSG2, ERROR, Critical,
                                   refferer, ip, ua,
                                   CreateDate, CreateDateISR, APITransaction, "", identifier, (int)Project);
             }
             return(true);
         }
         catch (Exception ex2)
         {
         }
     }
     return(false);
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
0
        public static bool REMOVE_MAC_UNIQUE(ref DateTime APICreateDate, string UNIQUE, ref enumProject Project)
        {
            if (APICreateDate > LastClear_UTC.AddHours(Local_Cache_Refresh_Hour_Interval))
            {
                Update();
            }

            if (UNIQUE_DICTIONARY.ContainsKey(((int)Project).ToString() + "_" + UNIQUE))
            {
                try
                {
                    UNIQUE_DICTIONARY.Remove(((int)Project).ToString() + "_" + UNIQUE);
                    return(true);
                }
                catch (Exception ex)
                {
                    #region MyRegion LOG

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

                    #endregion

                    return(false);
                }
            }
            return(true);
        }