Beispiel #1
0
        /// <summary>
        /// Invokes repeatedly the specified callback function on the specified interval and/or delay.
        /// </summary>
        /// <param name="interval">Specifies the interval of the repetition.</param>
        /// <param name="count">Specifies the maximum amount of calls. (0 = unlimited)</param>
        /// <param name="callback">Specifies the callback to invoke.</param>
        /// <returns>Returns the timer object used for this operation.</returns>
        public static Timer PeriodicCall(TimeSpan interval, int count, TimerCallback callback)
        {
            Timer t = new CallTimer(TimeSpan.Zero, interval, 0, callback);

            t.Priority = GetPriority(interval);
            t.Start();
            return(t);
        }
Beispiel #2
0
        /// <summary>
        /// Invokes repeatedly the specified callback function on the specified interval and/or delay.
        /// </summary>
        /// <param name="delay">Specifies the amount of time to wait before invoking the first callback.</param>
        /// <param name="interval">Specifies the interval of the repetition.</param>
        /// <param name="count">Specifies the maximum amount of calls. (0 = unlimited)</param>
        /// <param name="callback">Specifies the callback to invoke.</param>
        /// <returns>Returns the timer object used for this operation.</returns>
        public static Timer PeriodicCall(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback)
        {
            Timer t = new CallTimer(delay, interval, 0, callback);

            t.Priority = (count == 1) ? GetPriority(delay) : GetPriority(interval);
            t.Start();
            return(t);
        }
Beispiel #3
0
        /// <summary>
        /// Invokes the specified callback function after the specified delay.
        /// </summary>
        /// <param name="delay">Specifies the amount of time to wait before invoking the callback.</param>
        /// <param name="callback">Specifies the callback to invoke.</param>
        /// <returns>Returns the timer object used for this operation.</returns>
        public static Timer DelayCall(TimeSpan delay, TimerCallback callback)
        {
            Timer t = new CallTimer(delay, TimeSpan.Zero, 1, callback);

            t.Priority = GetPriority(delay);
            t.Start();
            return(t);
        }
 private void InitializeTimer()
 {
     timer.Start();
     timer.OnUpdate += () =>
     {
         InvokeOnMainThread(UpdateElapsedTimeLabel);
     };
 }
Beispiel #5
0
        private void M_Phone_OnCallConnectedEvent(string peerAddr, int callID, int accid)
        {
            if (m_CallID == callID)
            {
                lbState.Visible = false;
                lbTime.Visible  = true;
                lbTime.Text     = "00:00";

                m_CallBegin = DateTime.Now;
                CallTimer.Start();
            }
        }
        private static void Main(string[] args)
        {
            var indexName = CloudConfigurationManager.GetSetting("Azure.Search.IndexName");

            Log("Starting full sync to: {0}", indexName);

            var searchClient = GetSearchClient();

            while (true)
            {
                using (var dbTimer = CallTimer.Start())
                {
                    // Get batch of restaurants.
                    var restaurants = GetRestaurants(Skip, Take);
                    dbTimer.Stop();

                    // No results, EOF.
                    if (restaurants == null)
                    {
                        break;
                    }

                    // Flatten.
                    var operations = new List <IndexOperation>();
                    foreach (var restaurant in restaurants)
                    {
                        var indexOperation = new IndexOperation(IndexOperationType.MergeOrUpload, "id", restaurant.Id.ToString());
                        indexOperation
                        .WithProperty("internalName", restaurant.InternalName)
                        .WithProperty("name", restaurant.Name)
                        .WithProperty("postalCode", restaurant.PostalCode)
                        .WithProperty("locality", restaurant.Locality)
                        .WithProperty("street", restaurant.StreetAddress)
                        .WithProperty("website", restaurant.Website)
                        .WithProperty("budget", restaurant.Budget)
                        .WithProperty("rating", restaurant.Rating)
                        .WithProperty("fax", restaurant.Fax)
                        .WithProperty("mobile", restaurant.Mobile)
                        .WithProperty("phoneNumber", restaurant.PhoneNumber)
                        .WithProperty("email", restaurant.Email)
                        .WithProperty("hasImage", restaurant.HasImage)

                        // Translated content.
                        .WithProperty("region", restaurant.Region.TryGet("en"))
                        .WithProperty("region_nl", restaurant.Region.TryGet("nl"))
                        .WithProperty("region_fr", restaurant.Region.TryGet("fr"))
                        .WithProperty("description", restaurant.TryGet(r => r.Description, "en"))
                        .WithProperty("description_fr", restaurant.TryGet(r => r.Description, "fr"))
                        .WithProperty("description_nl", restaurant.TryGet(r => r.Description, "nl"))
                        .WithProperty("closing", restaurant.TryGet(r => r.Closing, "en"))
                        .WithProperty("closing_fr", restaurant.TryGet(r => r.Closing, "fr"))
                        .WithProperty("closing_nl", restaurant.TryGet(r => r.Closing, "nl"))
                        .WithProperty("setting", restaurant.TryGet(r => r.Setting, "en"))
                        .WithProperty("setting_fr", restaurant.TryGet(r => r.Setting, "fr"))
                        .WithProperty("setting_nl", restaurant.TryGet(r => r.Setting, "nl"))

                        // Translated tags.
                        .WithProperty("accommodations", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("en"))
                        .WithProperty("accommodations_fr", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("fr"))
                        .WithProperty("accommodations_nl", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("nl"))
                        .WithProperty("cuisine", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("en"))
                        .WithProperty("cuisine_fr", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("fr"))
                        .WithProperty("cuisine_nl", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("nl"))
                        .WithProperty("paymentFacilities", restaurant.PaymentFacilities.Select(a => a.PaymentFacility).TryGet <PaymentFacility, PaymentFacilityTranslation>("en"))
                        .WithProperty("paymentFacilities_fr", restaurant.PaymentFacilities.Select(a => a.PaymentFacility).TryGet <PaymentFacility, PaymentFacilityTranslation>("fr"))
                        .WithProperty("paymentFacilities_nl", restaurant.PaymentFacilities.Select(a => a.PaymentFacility).TryGet <PaymentFacility, PaymentFacilityTranslation>("nl"));

                        // Add geocoordinates if available.
                        if (restaurant.Longitude.HasValue && restaurant.Latitude.HasValue)
                        {
                            indexOperation.WithGeographyPoint("location", restaurant.Longitude.Value, restaurant.Latitude.Value);
                        }

                        // Add to batch.
                        operations.Add(indexOperation);
                    }

                    using (var searchTimer = CallTimer.Start())
                    {
                        var response = searchClient.PopulateAsync(indexName, operations.ToArray()).Result;

                        // Error handling!
                        if (!response.IsSuccess)
                        {
                            throw new Exception(response.StatusCode.ToString());
                        }
                        else
                        {
                            var failed = response.Body.Where(r => !r.Status);
                            foreach (var item in failed)
                            {
                                Log("Failed: {0} ({1})", item.Key, item.ErrorMessage);
                            }
                        }

                        // Move forward.
                        Skip      += Take;
                        Processed += restaurants.Count();

                        // Done!
                        Log("Processed: {0} (Db: {1} s., Search: {2} s.)", Processed, dbTimer.TotalSeconds, searchTimer.TotalSeconds);
                    }
                }
            }

            Log("Done!");
        }