示例#1
0
        private BackgroundAction StartBufferThread(Guid id, StreamReader reader)
        {
            var bufferSize = 8192;
            var buffer     = new char[bufferSize];

            var action = new BackgroundAction(() =>
            {
                var bytesRead = reader.Read(buffer, 0, bufferSize);

                lock (_buffers)
                {
                    StringBuilder sb;

                    if (_buffers.TryGetValue(id, out sb))
                    {
                        sb.Append(new string(buffer, 0, bytesRead));
                    }
                }
            })
            {
                Interval = 100
            };

            action.StartAsync();

            return(action);
        }
示例#2
0
        private void Init()
        {
            View.ModelTitleGetter =
                delegate(object rowObject) { return(((AbstractBackgroundAction)rowObject).toString()); };
            View.ModelDescriptionGetter = delegate(object rowObject)
            {
                return
                    (((BackgroundAction)rowObject).getActivity());
            };
            View.ModelIsRunningGetter =
                delegate(object rowObject) { return(((BackgroundAction)rowObject).isRunning()); };
            View.StopActionEvent += View_StopActionEvent;

            BackgroundActionRegistry.global().addListener(new BackgroundActionListener(this));
            // Add already running background actions
            ArrayList tasks = new ArrayList();
            int       size  = BackgroundActionRegistry.global().size();

            for (int i = 0; i < size; i++)
            {
                try
                {
                    BackgroundAction action = (BackgroundAction)BackgroundActionRegistry.global().get(i);
                    tasks.Add(action);
                }
                catch (Exception)
                {
                    Log.debug("BackgroundActionRegistry modified while iterating");
                    // collection has been modified by another thread, continue
                }
            }
            View.SetModel(tasks);
        }
示例#3
0
        public ProgressForm(string title, BackgroundAction action)
        {
            InitializeComponent();
              Style = (Style)FindResource(typeof(Window));

              Title = title;
              detailTextBox.Visibility = Visibility.Collapsed;

              bg = new BackgroundWorker();
              bg.WorkerReportsProgress = true;
              bg.WorkerSupportsCancellation = true;
              bg.DoWork += (bw, dwe) => {
            try {
              if (!action(this, (BackgroundWorker)bw)) {
            dwe.Cancel = true;
              }
            } catch (Exception e) {
              this.Dispatcher.Invoke(new Action(() => {
            ErrorForm.ShowDialog(this, e);
            status.Text = "Error.";
              }));
            }
              };
              bg.ProgressChanged += UpdateProgress;
              bg.RunWorkerCompleted += Completed;
              bg.RunWorkerAsync();
        }
示例#4
0
        public override void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
        {
            // default implementation: do nothing
            ServiceDataObject sdo = GetServiceDataObjectByID(ati.ID);

            if (sdo == null)
            {
                Log.ErrorFormat("Unable to find object for ID {0}", ati.ID);
            }
            else
            {
                string expectedStartType = ati["StartTypeString"];
                string actualStartType   = sdo.StartTypeString;
                if (expectedStartType != actualStartType)
                {
                    Log.InfoFormat("=> StartType for {0} needs to change from {1} to {2}",
                                   ati,
                                   actualStartType,
                                   expectedStartType);

                    using (NativeSCManager scm = new NativeSCManager(MachineName))
                    {
                        SC_START_TYPE startType = ServicesLocalisation.ReverseLocalizedStartType(expectedStartType);
                        if (startType != SC_START_TYPE.SERVICE_NO_CHANGE)
                        {
                            sdo.ApplyStartupChanges(scm, startType);
                        }
                    }
                }
                else
                {
                    Log.InfoFormat("=> StartType for {0} identical, no need to change", ati);
                }
            }
        }
示例#5
0
            public override void collectionItemRemoved(object item)
            {
                BackgroundAction action = item as BackgroundAction;

                _actionListener.Remove(action);
                _controller.Invoke(new RemoveTaskAction(_controller, action));
            }
示例#6
0
            public override void collectionItemAdded(object item)
            {
                BackgroundAction action   = item as BackgroundAction;
                TaskListener     listener = new TaskListener(_controller, action);

                _actionListener.Add(action, listener);
                _controller.Invoke(new AddTaskAction(_controller, action));
            }
 public ObjectDatabaseClient(ObjectClient client, Func <TObject, TPrimaryKey> keySelector)
 {
     _client     = client;
     _repository = new ObjectRepository <TObject, TPrimaryKey>("Client", keySelector);
     _thread     = new BackgroundAction(SaveRepo)
     {
         Interval = 1000
     };
     _thread.StartAsync();
 }
示例#8
0
        private void View_StopActionEvent()
        {
            BackgroundAction action = View.SelectedTask;

            if (null != action)
            {
                Log.debug("Cancel action:" + action);
                action.cancel();
            }
        }
示例#9
0
            public IJob Create(string tag, BackgroundAction action)
            {
                if (tag == null)
                {
                    throw new ArgumentNullException(nameof(tag));
                }
                if (action == null)
                {
                    throw new ArgumentNullException(nameof(action));
                }
                var job = new GoodJob(tag, action);

                lock (_jobsSyncRoot) {
                    _jobsByTag[tag] = job;
                    _jobsByGuid.Add(job.Guid, job);
                }
                return(job);
            }
示例#10
0
 public void stop(BackgroundAction ba)
 {
     _controller.View.RefreshTask(_action);
 }
示例#11
0
    public void Update(Game game, float dt)
    {
        if (actions == null)
        {
            actions = new BackgroundAction[game.clientmodsCount];
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                actions[i] = new BackgroundAction();
            }
        }

        if (game.platform.MultithreadingAvailable())
        {
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyMainThread(game, dt);
            }

            bool allDone = true;
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                if (actions[i] != null && actions[i].active && (!actions[i].finished))
                {
                    allDone = false;
                }
            }

            if (allDone)
            {
                for (int i = 0; i < game.clientmodsCount; i++)
                {
                    game.clientmods[i].OnReadWriteMainThread(game, dt);
                }
                for (int i = 0; i < game.commitActions.count; i++)
                {
                    game.commitActions.items[i].Run();
                }
                game.commitActions.Clear();
                for (int i = 0; i < game.clientmodsCount; i++)
                {
                    BackgroundAction a = actions[i];
                    a.game     = game;
                    a.dt       = dt;
                    a.i        = i;
                    a.active   = true;
                    a.finished = false;
                    game.platform.QueueUserWorkItem(a);
                }
            }
        }
        else
        {
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyMainThread(game, dt);
            }

            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyBackgroundThread(game, dt);
            }

            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadWriteMainThread(game, dt);
            }

            for (int i = 0; i < game.commitActions.count; i++)
            {
                game.commitActions.items[i].Run();
            }
            game.commitActions.Clear();
        }
    }
示例#12
0
 protected override void open(BackgroundAction download)
 {
     controller.background(new OpenBackgroundAction(controller, download));
 }
示例#13
0
    public void Update(Game game, float dt)
    {
        if (actions == null)
        {
            actions = new BackgroundAction[game.clientmodsCount];
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                actions[i] = new BackgroundAction();
            }
        }

        if (game.platform.MultithreadingAvailable())
        {
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyMainThread(game, dt);
            }

            bool allDone = true;
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                if (actions[i] != null && actions[i].active && (!actions[i].finished))
                {
                    allDone = false;
                }
            }

            if (allDone)
            {
                for (int i = 0; i < game.clientmodsCount; i++)
                {
                    game.clientmods[i].OnReadWriteMainThread(game, dt);
                }
                for (int i = 0; i < game.commitActions.count; i++)
                {
                    game.commitActions.items[i].Run();
                }
                game.commitActions.Clear();
                for (int i = 0; i < game.clientmodsCount; i++)
                {
                    BackgroundAction a = actions[i];
                    a.game = game;
                    a.dt = dt;
                    a.i = i;
                    a.active = true;
                    a.finished = false;
                    game.platform.QueueUserWorkItem(a);
                }
            }
        }
        else
        {
            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyMainThread(game, dt);
            }

            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadOnlyBackgroundThread(game, dt);
            }

            for (int i = 0; i < game.clientmodsCount; i++)
            {
                game.clientmods[i].OnReadWriteMainThread(game, dt);
            }

            for (int i = 0; i < game.commitActions.count; i++)
            {
                game.commitActions.items[i].Run();
            }
            game.commitActions.Clear();
        }
    }
示例#14
0
 protected override void save(BackgroundAction upload)
 {
     controller.background(new SaveBackgroundAction(controller, upload));
 }
示例#15
0
 public void RefreshTask(BackgroundAction action)
 {
     activitiyListView.RefreshObject(action);
 }
示例#16
0
 public void Background(BackgroundAction backgroundAction)
 {
     // Move to background thread
     background(backgroundAction);
 }
示例#17
0
 public void Background(BackgroundAction backgroundAction)
 {
     // Move to background thread
     background(backgroundAction);
 }
示例#18
0
 public void AddTask(BackgroundAction action)
 {
     activitiyListView.AddObject(action);
 }
示例#19
0
 private GoodJob(string tag, BackgroundAction action)
 {
     Action = action;
     Tag    = tag;
 }
示例#20
0
 public SaveBackgroundAction(BrowserController controller, BackgroundAction upload)
     : base(controller)
 {
     _upload = upload;
 }
示例#21
0
 public OpenBackgroundAction(BrowserController controller, BackgroundAction download) : base(controller)
 {
     _download = download;
 }
示例#22
0
 protected override void open(BackgroundAction download)
 {
     controller.background(new OpenBackgroundAction(controller, download));
 }
 public override void stop(BackgroundAction action)
 {
     Invoke(delegate { View.StopActivityAnimation(); });
 }
示例#24
0
 public OpenBackgroundAction(BrowserController controller, BackgroundAction download)
     : base(controller)
 {
     _download = download;
 }
示例#25
0
 public void AddTask(BackgroundAction action)
 {
     activitiyListView.AddObject(action);
 }
示例#26
0
 public void RemoveTask(BackgroundAction action)
 {
     activitiyListView.RemoveObject(action);
 }
示例#27
0
 public TaskListener(ActivityController controller, BackgroundAction action)
 {
     _action     = action;
     _controller = controller;
 }
示例#28
0
 protected override void save(BackgroundAction upload)
 {
     controller.background(new SaveBackgroundAction(controller, upload));
 }
示例#29
0
 public void RemoveTask(BackgroundAction action)
 {
     activitiyListView.RemoveObject(action);
 }
示例#30
0
 public SaveBackgroundAction(BrowserController controller, BackgroundAction upload) : base(controller)
 {
     _upload = upload;
 }
示例#31
0
 public RemoveTaskAction(ActivityController controller, BackgroundAction action)
     : base(controller)
 {
     _action     = action;
     _controller = controller;
 }
示例#32
0
        public override void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
        {
            // default implementation: do nothing
            ServiceDataObject sdo = GetServiceDataObjectByID(ati.ID);
            if (sdo == null)
            {
                Log.ErrorFormat("Unable to find object for ID {0}", ati.ID);
            }
            else
            {
                string expectedStartType = ati["StartTypeString"];
                string actualStartType = sdo.StartTypeString;
                if (expectedStartType != actualStartType)
                {
                    Log.InfoFormat("=> StartType for {0} needs to change from {1} to {2}",
                        ati,
                        actualStartType,
                        expectedStartType);

                    using (NativeSCManager scm = new NativeSCManager(MachineName))
                    {
                        SC_START_TYPE startType = ServicesLocalisation.ReverseLocalizedStartType(expectedStartType);
                        if( startType != SC_START_TYPE.SERVICE_NO_CHANGE )
                        {
                            sdo.ApplyStartupChanges(scm, startType);
                        }
                    }
                }
                else
                {
                    Log.InfoFormat("=> StartType for {0} identical, no need to change", ati);
                }
            }
        }
示例#33
0
 public void RefreshTask(BackgroundAction action)
 {
     activitiyListView.RefreshObject(action);
 }