Ejemplo n.º 1
0
 public DownloadFileJob(string url, FileStream fileStream, ReadyDelegate readyCallback, int startPosition) : base(url, readyCallback)
 {
     Guard.NullArgument(fileStream, "fileStream");
     _file = fileStream;
     Init(url, readyCallback, false);
     _reader = new HttpReaderToFile(_url, _file, startPosition);
 }
Ejemplo n.º 2
0
        public static DialogResult ShowModal(String title, String message, bool animated,
                                             ReadyDelegate notifyReady, CancelDelegate deleg)
        {
            using (HUDForm instance = new HUDForm())
            {
                // Don't use lock() here as we might dead lock otherwise.
                if (!Monitor.TryEnter(instanceLock))
                {
                    Application.DoEvents(); // See if we can let the application finish pending stuff first.
                    if (!Monitor.TryEnter(instanceLock))
                    {
                        return(DialogResult.Abort); // Still no lock possible? In this case we can only leave without showing the HUD form.
                    }
                }

                currentInstance = instance;
                Monitor.Exit(instanceLock);

                instance.label1.Text    = title;
                instance.label2.Text    = message;
                instance.cancelDelegate = deleg;

                // Can happen the form is cancelled already while we are still doing the setup
                // (separate thread).
                if (instance.IsDisposed || instance.Disposing)
                {
                    if (Monitor.TryEnter(instanceLock))
                    {
                        currentInstance = null;
                        Monitor.Exit(instanceLock);
                    }
                    return(DialogResult.Abort);
                }

                instance.Reshow(animated, true);

                // Need to set Visible back to false to avoid an exception in ShowDialog about an already
                // visible window. Doesn't usually have a visual effect.
                instance.Visible = false;

                if (notifyReady != null)
                {
                    notifyReady();
                }

                DialogResult result = DialogResult.Abort;
                if (!instance.IsDisposed && !instance.Disposing)
                {
                    result = instance.ShowDialog();
                }
                if (Monitor.TryEnter(instanceLock))
                {
                    instance.Dispose();
                    currentInstance = null;
                    Monitor.Exit(instanceLock);
                }

                return(result);
            }
        }
Ejemplo n.º 3
0
 protected void Init(string url, ReadyDelegate readyCallback, bool initReader)
 {
     Guard.NullArgument(url, "url");
     _url           = url;
     _readyCallback = readyCallback;
     if (initReader)
     {
         _reader = new HttpReader(_url);
     }
 }
Ejemplo n.º 4
0
 public static void ConsiderOrderedOptions(Option[] options, ReadyDelegate ready)
 {
     for (int option = 0; option < options.Length; option++)
     {
         options[option]();
         if (ready())
         {
             return;
         }
     }
 }
Ejemplo n.º 5
0
        void UserEvent(object sender, UserEventArgs args)
        {
            ReadyDelegate d = (ReadyDelegate)args.UserEvent;

            d();
        }
Ejemplo n.º 6
0
        public static DialogResult ShowModal(String title, String message, bool animated,
            ReadyDelegate notifyReady, CancelDelegate deleg)
        {
            using (HUDForm instance = new HUDForm())
              {
            // Don't use lock() here as we might dead lock otherwise.
            if (!Monitor.TryEnter(instanceLock))
            {
              Application.DoEvents(); // See if we can let the application finish pending stuff first.
              if (!Monitor.TryEnter(instanceLock))
            return DialogResult.Abort; // Still no lock possible? In this case we can only leave without showing the HUD form.
            }

            currentInstance = instance;
            Monitor.Exit(instanceLock);

            instance.label1.Text = title;
            instance.label2.Text = message;
            instance.cancelDelegate = deleg;

            // Can happen the form is cancelled already while we are still doing the setup
            // (separate thread).
            if (instance.IsDisposed || instance.Disposing)
            {
              if (Monitor.TryEnter(instanceLock))
              {
            currentInstance = null;
            Monitor.Exit(instanceLock);
              }
              return DialogResult.Abort;
            }

            instance.Reshow(animated, true);

            // Need to set Visible back to false to avoid an exception in ShowDialog about an already
            // visible window. Doesn't usually have a visual effect.
            instance.Visible = false;

            if (notifyReady != null)
              notifyReady();

            DialogResult result = DialogResult.Abort;
            if (!instance.IsDisposed && !instance.Disposing)
              result = instance.ShowDialog();
            if (Monitor.TryEnter(instanceLock))
            {
              instance.Dispose();
              currentInstance = null;
              Monitor.Exit(instanceLock);
            }

            return result;
              }
        }
Ejemplo n.º 7
0
 public DownloadStreamJob(string url, ReadyDelegate readyCallback)
 {
     Init(url, readyCallback, true);
 }
Ejemplo n.º 8
0
 protected DownloadStreamJob(string url, ReadyDelegate readyCallback, bool initReader)
 {
     Init(url, readyCallback, initReader);
 }
Ejemplo n.º 9
0
 public DownloadResourceBlobJob(IResource resource, int propId, string url, ReadyDelegate readyCallback) : base(url, readyCallback)
 {
     _resource = resource;
     _propId   = propId;
 }