예제 #1
0
	// Constructor.
	internal LockCookie(CookieType type, Thread thread,
						int readCount, int writeCount)
			{
				this.type = type;
				this.thread = thread;
				this.readCount = readCount;
				this.writeCount = writeCount;
			}
예제 #2
0
파일: Bakery.cs 프로젝트: Keruto/INNLV
        private Cookie bakeCookie(CookieType type)
        {
            Cookie cookie = null;

            switch (type)
            {
                case CookieType.Chocolate:
                    cookie = new Chocolate();
                    break;
                case CookieType.Raisins:
                    cookie = new Raisins();
                    break;
                case CookieType.Nonstop:
                    cookie = new Nonstop();
                    break;
                case CookieType.Icing:
                    cookie = new Icing();
                    break;
                default:
                    cookie = new Chocolate();
                    break;
            }
            return cookie;
        }
예제 #3
0
        public virtual bool IsCookieAllowed(ControllerContext context, CookieType cookieType)
        {
            // Ask whether cookie type is allowed.
            var cookie = context.HttpContext.Request.Cookies[ConsentCookieName];

            if (cookie != null)
            {
                try
                {
                    var cookieData = JsonConvert.DeserializeObject <ConsentCookie>(cookie.Value);
                    if ((cookieData.AllowAnalytics && cookieType == CookieType.Analytics) || (cookieData.AllowThirdParty && cookieType == CookieType.ThirdParty))
                    {
                        return(true);
                    }
                }
                catch {
                    // Lets be tolerant in case of error.
                    return(true);
                }
            }

            // If no cookie was set return false
            return(false);
        }
예제 #4
0
 public void Delete(CookieType CookieName)
 {
     cookie.Delete(CookieName.ToString());
 }
예제 #5
0
 public string Read(CookieType CookieName)
 {
     return(cookie.Read(CookieName.ToString()));
 }
예제 #6
0
 public void Write(CookieType CookieName, object Value)
 {
     cookie.Write(CookieName.ToString(), (int)CookieName, Value.ToString());
 }
예제 #7
0
 private static SameSiteMode GetSameSiteMode(CookieType type) =>
 type switch
 {
예제 #8
0
 public static string GetCookieName(CookieType type) => $"{ApplicationName}.{type}";
예제 #9
0
 public static void SaveCookie(this HttpContext httpContext, CookieType cookieType, string data, int hours = 24) =>
 httpContext.Response.Cookies.Append(cookieType.ToString().ToLower(), data, CreateCookieOptions(hours));
예제 #10
0
 public static string GetCookie(this HttpContext httpContext, CookieType cookieType) =>
 httpContext.Request.Cookies[cookieType.ToString().ToLower()];
        /// <summary>
        /// The process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            try
            {
                Status status = null;
                if (ParameterSetName.Equals("HttpCookie"))
                {
                    status =
                        Connection.ApiClient.CreatePersistenceProfileHttpCookie(Network.id, Name, ServerFarm.id,
                                                                                TimeoutMinutes, CookieName, CookieType).Result;
                }
                else
                {
                    status =
                        Connection.ApiClient.CreatePersistenceProfileIpNetmask(Network.id, Name, ServerFarm.id, TimeoutMinutes,
                                                                               Direction, Netmask).Result;
                }
                if (status != null && PassThru.IsPresent)
                {
                    // Regex to extract the Id from the status result detail: Real-Server (id:b1a3aea6-37) created
                    var   regexObj = new Regex(@"\x28id\x3A([-\w]*)\x29");
                    Match match    = regexObj.Match(status.resultDetail);
                    if (match.Success && match.Groups.Count > 1)
                    {
                        var persprofile = new PersistenceProfile
                        {
                            id           = match.Groups[1].Value,
                            name         = Name,
                            serverFarmId = ServerFarm.id,
                            timeout      = TimeoutMinutes.ToString(CultureInfo.InvariantCulture),
                        };
                        if (ParameterSetName.Equals("HttpCookie"))
                        {
                            persprofile.type       = PersistenceProfileType.HTTP_COOKIE;
                            persprofile.cookieName = CookieName;
                            persprofile.cookieType = CookieType.ToString();
                        }
                        else
                        {
                            persprofile.type      = PersistenceProfileType.IP_NETMASK;
                            persprofile.netmask   = Netmask;
                            persprofile.direction = Direction.ToString();
                        }

                        WriteObject(persprofile);
                    }
                    else
                    {
                        WriteError(new ErrorRecord(new CloudComputePsException("object Id not returned from API"), "-1",
                                                   ErrorCategory.InvalidData, status));
                    }
                }

                WriteDebug(
                    string.Format(
                        "{0} resulted in {1} ({2}): {3}",
                        status.operation,
                        status.result,
                        status.resultCode,
                        status.resultDetail));
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
// if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }
        }
예제 #12
0
 private string FormatVersionedCookieValue(CookieType type, string value, string version = null)
 {
     return(FormatVersionedCookieValue(type, new[] { value }, version));
 }
예제 #13
0
파일: Cookies.cs 프로젝트: wi1dcard/HcLib
 /// <summary>
 /// 根据Cookie(s)字符串初始化
 /// </summary>
 /// <param name="Cookies"></param>
 /// <param name="Type"></param>
 public Cookies(string Cookies, CookieType Type = CookieType.RequestHeader)
 {
     this.Add(Cookies, Type);
 }
예제 #14
0
        /// <summary>
        /// Method gets the cookie name by it type.
        /// </summary>
        /// <param name="type">Type of the cookie.</param>
        /// <returns>Name of the cookie.</returns>
        public string GetCookTypeName(CookieType type)
        {
            string name = _CookiesNames[type];

            return(!string.IsNullOrWhiteSpace(name) ? name : string.Empty);
        }
예제 #15
0
        public async Task <CookiePullModel> CreateCookieDataInstanceAsync(string data, DateTimeOffset expiration, CookieType cookieType, BPAuthContext context)
        {
            var cookieCode = "";
            var pullModel  = new CookiePullModel();

            using (var encrypt = new EncryptionHandler())
            {
                cookieCode = encrypt.RandomString(random.Next(20, 50));
            }
            pullModel.Code       = cookieCode;
            pullModel.Expiration = expiration;
            // now let's create this cookie
            var cookie = new Cookie {
                Code       = cookieCode,
                Data       = data,
                DateSet    = DateTimeOffset.Now,
                Expiration = expiration,
                CookieType = cookieType
            };

            context.Cookies.Add(cookie);
            var methodResults = await context.SaveChangesAsync(context);

            if (methodResults.Success)
            {
                pullModel.ID = cookie.ID;
            }
            else
            {
                return(new CookiePullModel());
            }

            return(pullModel);
        }