Beispiel #1
0
        private void jiggleTimer_Tick(object sender, EventArgs e)
        {
            //don't jiggle if the mouse has moved lately.
            if ((DateTime.Now - lastMovement).TotalSeconds < MIN_IDLE_TIME_SECONDS)
            {
                Log.Debug("mouse movement wait period");
                return;
            }

            Log.Debug((DateTime.Now - lastMovement).TotalMinutes.ToString() + " " + TimeoutMinutes.ToString());
            //don't jiggle if we're over the timeout limit.   0 means we're not using timeout
            if (TimeoutMinutes > 0)
            {
                if ((DateTime.Now - lastMovement).TotalMinutes >= TimeoutMinutes)
                {
                    Log.Debug("time limit exceeded");
                    return;
                }
            }

            try
            {
                // jiggle
                if (this.chkZen.Checked)
                {
                    Log.Debug("Zen");
                    Jiggler.Jiggle(0, 0);
                }
                else
                {
                    Log.Debug("Jiggling");
                    Jiggler.Jiggle(4, 4);
                    System.Threading.Thread.Sleep(10);
                    Jiggler.Jiggle(-4, -4);
                }
            }
            catch (Exception)
            {
                //authorization exception might occur;  unusre why.
                //Log.Debug(ex.Message);
                //Log.Debug(ex.StackTrace);
            }
        }
Beispiel #2
0
 // 15 phut
 public static T CacheGetOrSet <T>(this Controller controller, string key, CacheRegion region, System.Func <T> valueFactory,
                                   TimeoutMinutes timeoutMinutes = TimeoutMinutes.m15)
 {
     return(GetOrSet <T>(key, region, valueFactory, timeoutMinutes));
 }
        /// <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);
                });
            }
        }
Beispiel #4
0
 // 15 phút
 public static T GetOrSet <T>(string key, CacheRegion region, System.Func <T> valueFactory, TimeoutMinutes timeoutMinutes = TimeoutMinutes.m15)
 {
     try
     {
         if (!CacheManager.Exists(key, region.ToString()))
         {
             var item = new CacheItem <object>(key, region.ToString(), valueFactory(), ExpirationMode.Absolute, TimeSpan.FromMinutes((int)timeoutMinutes));
             CacheManager.Add(item);
         }
     }
     catch (Exception ex)
     {
         return(default(T));
     }
     return(CacheManager.Get <T>(key, region.ToString()));
 }