Ejemplo n.º 1
0
        // For some reason reiniting is flaky :(
        public IEnumerator <object> InitGateways()
        {
            DestroyEndpoints();
            Endpoints.Clear();

            EndpointSettings[] endpoints = null;
            using (var q = Database.BuildQuery("SELECT * FROM jabber.endpoints"))
                yield return(q.ExecuteArray <EndpointSettings>().Bind(() => endpoints));

            foreach (var settings in endpoints)
            {
                Endpoints[settings.Name] = null;
            }

            if (endpoints.Length == 0)
            {
                yield break;
            }

            using (var lw = new LoadingWindow()) {
                lw.SetStatus("Connecting", null);
                lw.Text = "Jabber Gateway";
                lw.Show();

                float?current  = null;
                float stepSize = (1.0f / endpoints.Length);
                var   sleep    = new Sleep(0.25f);

                foreach (var settings in endpoints)
                {
                    lw.SetStatus(String.Format("Connecting endpoint {0}", settings.Name), current);
                    Console.Write("Initializing endpoint '{0}'... ", settings.Name);
                    var f = Endpoint.Connect(
                        this, settings,
                        (s) => lw.SetProgress(current + (s * stepSize))
                        );
                    yield return(f);

                    if (f.Error != null)
                    {
                        Console.WriteLine("failed: {0}", f.Error);
                        Scheduler.OnTaskError(f.Error);
                    }
                    else
                    {
                        Console.WriteLine("initialized.");
                    }

                    current = current.GetValueOrDefault(0.0f) + stepSize;
                    lw.SetProgress(current);

                    yield return(sleep);
                }

                lw.SetStatus("Ready", 1.0f);
                lw.Close();
            }
        }
 public void SetProgress(float progress)
 {
     window.SetProgress(progress);
 }