Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 5
0
            public override void collectionItemRemoved(object item)
            {
                BackgroundAction action = item as BackgroundAction;

                _actionListener.Remove(action);
                _controller.Invoke(new RemoveTaskAction(_controller, action));
            }
Exemplo n.º 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();
 }
Exemplo n.º 8
0
        private void View_StopActionEvent()
        {
            BackgroundAction action = View.SelectedTask;

            if (null != action)
            {
                Log.debug("Cancel action:" + action);
                action.cancel();
            }
        }
Exemplo n.º 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);
            }
Exemplo n.º 10
0
 public void stop(BackgroundAction ba)
 {
     _controller.View.RefreshTask(_action);
 }
Exemplo n.º 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();
        }
    }
Exemplo n.º 12
0
 protected override void open(BackgroundAction download)
 {
     controller.background(new OpenBackgroundAction(controller, download));
 }
Exemplo n.º 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();
        }
    }
Exemplo n.º 14
0
 protected override void save(BackgroundAction upload)
 {
     controller.background(new SaveBackgroundAction(controller, upload));
 }
Exemplo n.º 15
0
 public void RefreshTask(BackgroundAction action)
 {
     activitiyListView.RefreshObject(action);
 }
Exemplo n.º 16
0
 public void Background(BackgroundAction backgroundAction)
 {
     // Move to background thread
     background(backgroundAction);
 }
Exemplo n.º 17
0
 public void Background(BackgroundAction backgroundAction)
 {
     // Move to background thread
     background(backgroundAction);
 }
Exemplo n.º 18
0
 public void AddTask(BackgroundAction action)
 {
     activitiyListView.AddObject(action);
 }
Exemplo n.º 19
0
 private GoodJob(string tag, BackgroundAction action)
 {
     Action = action;
     Tag    = tag;
 }
Exemplo n.º 20
0
 public SaveBackgroundAction(BrowserController controller, BackgroundAction upload)
     : base(controller)
 {
     _upload = upload;
 }
Exemplo n.º 21
0
 public OpenBackgroundAction(BrowserController controller, BackgroundAction download) : base(controller)
 {
     _download = download;
 }
Exemplo n.º 22
0
 protected override void open(BackgroundAction download)
 {
     controller.background(new OpenBackgroundAction(controller, download));
 }
 public override void stop(BackgroundAction action)
 {
     Invoke(delegate { View.StopActivityAnimation(); });
 }
Exemplo n.º 24
0
 public OpenBackgroundAction(BrowserController controller, BackgroundAction download)
     : base(controller)
 {
     _download = download;
 }
Exemplo n.º 25
0
 public void AddTask(BackgroundAction action)
 {
     activitiyListView.AddObject(action);
 }
Exemplo n.º 26
0
 public void RemoveTask(BackgroundAction action)
 {
     activitiyListView.RemoveObject(action);
 }
Exemplo n.º 27
0
 public TaskListener(ActivityController controller, BackgroundAction action)
 {
     _action     = action;
     _controller = controller;
 }
Exemplo n.º 28
0
 protected override void save(BackgroundAction upload)
 {
     controller.background(new SaveBackgroundAction(controller, upload));
 }
Exemplo n.º 29
0
 public void RemoveTask(BackgroundAction action)
 {
     activitiyListView.RemoveObject(action);
 }
Exemplo n.º 30
0
 public SaveBackgroundAction(BrowserController controller, BackgroundAction upload) : base(controller)
 {
     _upload = upload;
 }
Exemplo n.º 31
0
 public RemoveTaskAction(ActivityController controller, BackgroundAction action)
     : base(controller)
 {
     _action     = action;
     _controller = controller;
 }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 33
0
 public void RefreshTask(BackgroundAction action)
 {
     activitiyListView.RefreshObject(action);
 }