示例#1
0
    /* The worker thread's main function.  */
    private void WorkerThread()
    {
        while (true)
        {
            lock (processed_requests) {
                if (current_request != null)
                {
                    processed_requests.Enqueue(current_request);

                    if (!pending_notify_notified)
                    {
                        pending_notify.WakeupMain();
                        pending_notify_notified = true;
                    }

                    current_request = null;
                }
            }

            lock (queue) {
                while (queue.Count == 0 || block_count > 0)
                {
                    Monitor.Wait(queue);
                }

                int pos = queue.Count - 1;

                current_request = queue [pos] as RequestItem;
                queue.RemoveAt(pos);
                requests_by_path.Remove(current_request.path);
            }

            ProcessRequest(current_request);
        }
    }
示例#2
0
        private void ExtractFile(TreeIter iter, string filename)
        {
            waitWindow = new WaitWindow(this, "Extracting", filename);
            waitWindow.Show();

            ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
            {
                waitWindow.Destroy();
                waitWindow = null;
            }));

            ThreadNotify error = new ThreadNotify(new ReadyEvent(() =>
            {
                waitWindow.Destroy();
                waitWindow = null;

                CustomMessageDialog msg =
                    new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError);
                msg.Run();
                msg.Destroy();
            }));

            Packer.Item item = packStore.GetValue(iter, 0) as Packer.Item;
            new Thread(new ThreadStart(() =>
            {
                if (fileSystem.Extract(item, filename))
                {
                    done.WakeupMain();
                }
                else
                {
                    error.WakeupMain();
                }
            })).Start();
        }
示例#3
0
        private void WorkThread()
        {
            bool         added, typeAdded;
            BindingFlags flagsCopy;
            Type         type;
            string       textCopy;

            //Console.WriteLine ("Entering work thread");

            while (true)
            {
                lock (todoTypes) {
                    type      = (Type)todoTypes.Dequeue();
                    flagsCopy = browser.Flags;
                    textCopy  = (string)text.Clone();
                }
                if (browser.IsVisible(type))
                {
                    added = typeAdded = false;
                    if (type.Name.IndexOf(textCopy) >= 0)
                    {
                        lock (found) {
                            found.Enqueue(type);
                            added = typeAdded = true;
                        }
                    }
                    foreach (MemberInfo mi in type.GetMembers(flagsCopy | BindingFlags.Static | BindingFlags.Instance))
                    {
                        if (mi.Name.IndexOf(textCopy) >= 0 || typeAdded && mi.MemberType == MemberTypes.Constructor)
                        {
                            if (mi.MemberType == MemberTypes.Method && ((MethodInfo)mi).IsSpecialName)
                            {
                                continue;
                            }
                            lock (found) {
                                found.Enqueue(mi);
                                found.Enqueue(type);
                                added = true;
                            }
                        }
                    }
                    lock (found) {
                        if (added)
                        {
                            notify.WakeupMain();
                        }
                    }
                }
                lock (todoTypes) {
                    if (todoTypes.Count == 0)
                    {
                        break;
                    }
                }
            }
            //Console.WriteLine ("Finished work thread");
        }
示例#4
0
        private void OnInotifyEvent(Inotify.Watch watch, string path, string subitem,
                                    string srcpath, Inotify.EventType type)
        {
            /*
             * Console.WriteLine ("Got event ({03}) {0}: {1}/{2}", type, path, subitem,
             *                                 srcpath);
             */

            string fullPath = Path.Combine(path, subitem);

            lock (this)
            {
                if (HasFlag(type, Inotify.EventType.MovedTo) ||
                    HasFlag(type, Inotify.EventType.CloseWrite))
                {
                    if (HasFlag(type, Inotify.EventType.IsDirectory) &&
                        !HasFlag(type, Inotify.EventType.CloseWrite))
                    {
                        foldersToAdd.Add(fullPath);

                        if (srcpath != null)
                        {
                            foldersToRemove.Add(srcpath);
                        }
                    }
                    else
                    {
                        filesToAdd.Add(fullPath);

                        if (srcpath != null)
                        {
                            filesToRemove.Add(srcpath);
                        }
                    }
                }
                else if (HasFlag(type, Inotify.EventType.Create) &&
                         HasFlag(type, Inotify.EventType.IsDirectory))
                {
                    Watch(fullPath);
                }
                else if (HasFlag(type, Inotify.EventType.Delete) ||
                         HasFlag(type, Inotify.EventType.MovedFrom))
                {
                    if (HasFlag(type, Inotify.EventType.IsDirectory))
                    {
                        foldersToRemove.Add(fullPath);
                    }
                    else
                    {
                        filesToRemove.Add(fullPath);
                    }
                }

                notify.WakeupMain();
            }
        }
示例#5
0
 void BackgroundWorker(object state)
 {
     try {
         Run();
     } catch (DllNotFoundException e) {
         tracker.ReportError("The operation could not be completed because a shared library is missing: " + e.Message, null);
     } catch (Exception e) {
         string msg = GettextCatalog.GetString("Version control operation failed: ");
         tracker.ReportError(msg, e);
     } finally {
         threadnotify.WakeupMain();
     }
 }
示例#6
0
        /* The worker thread's main function.  */
        void WorkerThread()
        {
            Log.Debug(ToString(), "Worker starting");
            try {
                while (!should_cancel)
                {
                    lock (processed_requests) {
                        if (current_request != null)
                        {
                            processed_requests.Enqueue(current_request);

                            if (!pending_notify_notified)
                            {
                                pending_notify.WakeupMain();
                                pending_notify_notified = true;
                            }

                            current_request = null;
                        }
                    }

                    lock (queue) {
                        while ((queue.Count == 0 || block_count > 0) && !should_cancel)
                        {
                            Monitor.Wait(queue);
                        }

                        if (should_cancel)
                        {
                            return;
                        }

                        int pos = queue.Count - 1;

                        current_request = queue [pos];
                        queue.RemoveAt(pos);
                        requests_by_uri.Remove(current_request.Uri);
                    }

                    ProcessRequest(current_request);
                }
            } catch (ThreadAbortException) {
                //Aborting
            }
        }
示例#7
0
        private void HandleAddFilesAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Add files to pack", FileChooserAction.Open);

            dlg.FileChooser.SelectMultiple = true;

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = "All";
                filter.AddPattern("*.*");
                dlg.FileChooser.AddFilter(filter);
            }

            dlg.Ok += (sender, e) =>
            {
                packTreeView.Selection.UnselectAll();

                waitWindow = new WaitWindow(this, "Adding", "");
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    dlg.Destroy();
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                new Thread(new ThreadStart(() =>
                {
                    dlg.FileChooser.Filenames.ToList().ForEach(
                        file => AppendFile(currentFolder, file));
                    done.WakeupMain();
                })).Start();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }
示例#8
0
        private void HandleAddFolderAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Add folder to pack", FileChooserAction.SelectFolder);

            dlg.Ok += (sender, e) =>
            {
                packTreeView.Selection.UnselectAll();

                waitWindow = new WaitWindow(this, "Adding", "");
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                new Thread(new ThreadStart(() =>
                {
                    string path = dlg.FileChooser.Filename;
                    dlg.Destroy();

                    Packer.Item folderItem = NewItem(currentFolder, path);
                    TreeIter folderIter    = AppendItem(currentFolder, folderItem);
                    if (!TreeIter.Zero.Equals(folderIter))
                    {
                        AppendFolders(folderIter, folderItem.HDDPath);
                    }
                    done.WakeupMain();
                })).Start();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }
示例#9
0
        private void OpenPack(string filename)
        {
            if (Packer.Create(System.IO.Path.GetExtension(filename), out fileSystem))
            {
                waitWindow = new WaitWindow(this, "Opening", filename);
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                ThreadNotify error = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;

                    CustomMessageDialog msg =
                        new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError);
                    msg.Run();
                    msg.Destroy();
                }));

                new Thread(new ThreadStart(() =>
                {
                    if (fileSystem.Open(filename))
                    {
                        RebuildPackTree(fileSystem.ListFiles());
                        ChangePackActionSensitive(true);
                        done.WakeupMain();
                    }
                    else
                    {
                        error.WakeupMain();
                    }
                })).Start();
            }
        }
示例#10
0
 void BackgroundWorker(object state)
 {
     try {
         Run();
     } catch (DllNotFoundException e) {
         tracker.ReportError("The operation could not be completed because a shared library is missing: " + e.Message, null);
     } catch (Exception e) {
         string msg = GettextCatalog.GetString("Version control operation failed: ");
         msg += e.Message;
         if (e.InnerException != null && e.InnerException.Message != e.Message)
         {
             msg = msg.Trim();
             if (!msg.EndsWith("."))
             {
                 msg += ".";
             }
             msg += " " + e.InnerException.Message;
         }
         tracker.ReportError(msg, e);
     } finally {
         threadnotify.WakeupMain();
     }
 }
示例#11
0
        private void IndexLogs()
        {
            foreach (string file in Directory.GetFiles(log_path))
            {
                ImLog        log    = null;
                StreamReader reader = new StreamReader(file);

                if (client == ImClient.Pidgin)
                {
                    log = new PidginLog(new FileInfo(file), reader);
                }
                else if (client == ImClient.Kopete)
                {
                    log = new KopeteLog(new FileInfo(file), reader);
                }
                else if (client == ImClient.Konversation)
                {
                    log = new KonversationLog(new FileInfo(file));
                }

                reader.Close();

                if (initial_select_file != null && log.File.FullName == initial_select_file.FullName)
                {
                    initial_select      = log;
                    initial_select_file = null;
                }

                if (speaking_to == null)
                {
                    SetWindowTitle(log.SpeakingTo);
                }
                timeline.Add(log, log.StartTime);
            }

            index_thread_notify.WakeupMain();
        }
示例#12
0
 private void OnSaveStarted(object o, EventArgs args)
 {
     visible = true;
     message = "<b>Preparing...</b>";
     notify.WakeupMain();
 }
示例#13
0
 void Work()
 {
     StartWork();
     notify.WakeupMain();
 }
示例#14
0
 void filechanged(object src, FileSystemEventArgs args)
 {
     threadnotify.WakeupMain();
 }
示例#15
0
 static void ThreadRoutine()
 {
     LargeComputation();
     notify.WakeupMain();
 }
示例#16
0
        private void HandleSaveAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Save pack", FileChooserAction.Save);

            dlg.FileChooser.SelectMultiple = false;

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = fileSystem.Extension.ToUpper();
                filter.AddPattern("*." + fileSystem.Extension.ToLower());
                dlg.FileChooser.AddFilter(filter);
            }

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = "All";
                filter.AddPattern("*.*");
                dlg.FileChooser.AddFilter(filter);
            }

            dlg.Ok += (sender, e) =>
            {
                string filename = dlg.FileChooser.Filename;

                waitWindow = new WaitWindow(this, "Saving", filename);
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                ThreadNotify error = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;

                    CustomMessageDialog msg =
                        new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError);
                    msg.Run();
                    msg.Destroy();
                }));

                new Thread(new ThreadStart(() =>
                {
                    if (fileSystem.Save(filename))
                    {
                        done.WakeupMain();
                    }
                    else
                    {
                        error.WakeupMain();
                    }
                })).Start();

                dlg.Destroy();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }