Ejemplo n.º 1
0
#pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required
        public new void AddRange(IEnumerable <T> range)
        {
#pragma warning restore CS0109 // Member does not hide an inherited member; new keyword is not required
            var items = range.ToArray();
            if (ItemToBeAdded == null)
            {
                //No need to be checked
                addrange(items);
                if (ItemAdded != null)
                {
                    Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
                }
                return;
            }

            var approved = new List <T>();
            foreach (var item in items)
            {
                var app = (Bool)true;
                ItemToBeAdded(item, app);
                if (app)
                {
                    approved.Add(item);
                }
            }
            addrange(approved);
            if (ItemAdded != null)
            {
                Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
            }
        }
Ejemplo n.º 2
0
        internal Tasky Edit(Tasky editTask)
        {
            var data = GetById(editTask.Id);

            editTask.Body = editTask.Body != null ? editTask.Body : data.Body;
            return(_repo.Edit(editTask));
        }
Ejemplo n.º 3
0
 private void invokeAccessed()
 {
     if (ListAccessed != null)
     {
         Tasky.Run(() => ListAccessed());
     }
 }
Ejemplo n.º 4
0
        public static async Task <T[]> WhenAll <T>(IEnumerable <Task <T> > tasks)
        {
            var t = tasks as Task <T>[] ?? tasks.ToArray();
            await Tasky.WhenAll(t);

            return(t.Select(tt => tt.Result).ToArray());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutTasky([FromRoute] Guid id, [FromBody] Tasky tasky)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tasky.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tasky).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        internal new void InsertRange(int index, IEnumerable <T> range)
        {
            var items = range.ToArray();

            if (ItemToBeAdded == null)
            {
                //No need to be checked
                base.InsertRange(index, items);
                if (ItemAdded != null)
                {
                    Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
                }
                return;
            }

            var approved = new List <T>();

            foreach (var item in items)
            {
                var app = (Bool)true;
                ItemToBeAdded(item, app);
                if (app)
                {
                    approved.Add(item);
                }
            }
            base.InsertRange(index, approved);
            if (ItemAdded != null)
            {
                Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
            }
            invokeAccessed();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets a <see cref="Task{TResult}"/> object to represent this ValueTask.  It will
 /// either return the wrapped task object if one exists, or it'll manufacture a new
 /// task object to represent the result.
 /// </summary>
 public Task <TResult> AsTask()
 {
     // Return the task if we were constructed from one, otherwise manufacture one.  We don't
     // cache the generated task into _task as it would end up changing both equality comparison
     // and the hash code we generate in GetHashCode.
     return(_task ?? Tasky.FromResult(_result));
 }
Ejemplo n.º 8
0
        private static void WerFaultHunter(object o)
        {
            var stop = o as ThreadStopper;

            while (true)
            {
                if (stop?.Stop == true)
                {
                    break;
                }
                Thread.Sleep(1500);
                var l = Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList();
                if (l.Count > 0)
                {
                    /*foreach (var op in l) {
                     *  Console.WriteLine(op.MainWindowTitle);
                     *  foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(op)) {
                     *      try {
                     *          string name = descriptor.Name;
                     *
                     *          object value = descriptor.GetValue(op);
                     *          Console.WriteLine("{0}={1}", name, value);
                     *      } catch {}
                     *  }
                     * }*/
                    Thread.Sleep(4000);
                    Process.GetProcesses().Where(pp => pp.ProcessName.Contains("WerFault")).ToList().ForEach(p => {
                        p.Kill();
                        Tasky.Run(() => Killed?.Invoke());
                        //Console.WriteLine($"[WerFault] {p.ProcessName} has been killed.");
                    });
                }
            }
            _stop = null;
        }
Ejemplo n.º 9
0
        public new void AddRange(IEnumerable <T> range)
        {
            var items = range.ToArray();

            if (ItemToBeAdded == null)
            {
                //No need to be checked
                base.AddRange(items);
                if (ItemAdded != null)
                {
                    Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
                }
                return;
            }

            var approved = new List <T>();

            foreach (var item in items)
            {
                var app = (Bool)true;
                ItemToBeAdded(item, app);
                if (app)
                {
                    approved.Add(item);
                }
            }
            base.AddRange(approved);
            if (ItemAdded != null)
            {
                Tasky.Run(() => items.ForEach(item => ItemAdded(item)));
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Asynchronously waits for this event to be set.
 /// </summary>
 public Task WaitAsync(CancellationToken cancellationToken)
 {
     lock (_sync) {
         var ret = _tcs.Task;
         //Enlightenment.Trace.AsyncManualResetEvent_Wait(this, ret);
         return(Tasky.Run(() => ret.Wait(cancellationToken)));
     }
 }
Ejemplo n.º 11
0
        public static async Task <T> WithYield <T>(this Task <T> task)
        {
            var result = await task.ConfigureAwait(false);

            await Tasky.Yield();

            return(result);
        }
Ejemplo n.º 12
0
        async Task NewTask()
        {
            Tasky task = new Tasky();

            State.SelectedTask = task;

            // TODO: sync DataService list with db list
            await DataService.Save(task);
        }
Ejemplo n.º 13
0
 private void _start()
 {
     if (_hasStarted)
     {
         return;
     }
     _hasStarted = true;
     Tasky.Run(() => _sampler((_sampler_canceller = new CancellationTokenSource()).Token));
     lastInputInf = new LASTINPUTINFO();
 }
Ejemplo n.º 14
0
 private void FireTaskQueued(QueuedTask <T> t)
 {
     if (t == null)
     {
         throw new ArgumentNullException(nameof(t));
     }
     if (TaskQueued != null)
     {
         Tasky.Run(() => TaskQueued?.Invoke(t));
     }
 }
Ejemplo n.º 15
0
 public ActionResult <Tasky> Create([FromBody] Tasky newTask)
 {
     try
     {
         return(Ok(_ts.Create(newTask)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 16
0
        internal Tasky Edit(Tasky updated)
        {
            string sql = @"
        UPDATE tasks
        SET
         body = @Body
        WHERE id = @Id;";

            _db.Execute(sql, updated);
            return(updated);
        }
Ejemplo n.º 17
0
 public ActionResult <Tasky> Edit(int id, [FromBody] Tasky editTask)
 {
     try
     {
         return(Ok(_ts.Edit(editTask)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 ///     Asynchronously waits for this event to be set.
 /// </summary>
 public Task <bool> WaitAsync(int millisecondsTimeout)
 {
     lock (_sync) {
         if (IsSet)
         {
             return(Tasky.FromResult(true));
         }
         var ret = _tcs.Task;
         //Enlightenment.Trace.AsyncManualResetEvent_Wait(this, ret);
         return(Tasky.Run(() => ret.Wait(millisecondsTimeout)));
     }
 }
Ejemplo n.º 19
0
        internal Tasky Create(Tasky newTask)
        {
            string sql = @"
      INSERT INTO tasks 
      (body) 
      VALUES 
      (@CreatorId, @Title);
      SELECT LAST_INSERT_ID();";
            int    id  = _db.ExecuteScalar <int>(sql, newTask);

            newTask.Id = id;
            return(newTask);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     Asynchronously waits for this event to be set.
 /// </summary>
 public Task <T> WaitAsync(int millisecondsTimeout, CancellationToken cancellationToken)
 {
     return(Tasky.Run(() => {
         var result = _reset.WaitAsync(millisecondsTimeout, cancellationToken).Result;
         if (result == false)
         {
             return default(T);
         }
         lock (syncer) {
             var local = _pointer;
             return local;
         }
     }));
 }
Ejemplo n.º 21
0
        public static Task <List <IPAddress> > GetConnectableAliases(string _ip, int pingAttempts = 1)
        {
            return(Tasky.Run(() => {
                var ips = GetDnsAliases(_ip).Result;
                if (ips == null || ips.Count == 0)
                {
                    return null;
                }
#if !(NET35 || NET3 || NET2)
                return ips.AsParallel().Where(i => TestHostConnection(i, pingAttempts)).ToList();
#else
                return ips.Where(i => TestHostConnection(i, pingAttempts)).ToList();
#endif
            }));
#endif
        }
Ejemplo n.º 22
0
        public static void Cache()
        {
            _cacheprogress?.Wait();

            _cacheprogress = Tasky.Run(() => {
                var l = new List <Task>();
                foreach (var dist in DistributionManager.GetDistributers(false))
                {
                    l.Add(Tasky.Run(() => {
                        foreach (var d in dist.Distributables())
                        {
                            _randlocdb.Add(d);
                        }
                    }));
                }
                Tasky.WhenAll(l.ToArray()).Wait();
                _cacheprogress = null;
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     Equalivent to Dns.GetHostAddresses(txt), but returned async.
        /// </summary>
        /// <param name="_ip">The IP address</param>
        /// <returns>List of aliases to this IP</returns>
        public static Task <List <IPAddress> > GetDnsAliases(string _ip)
        {
            if (string.IsNullOrEmpty(_ip))
            {
                return(null);
            }
            if (_ip == "localhost" || _ip == "::1")
            {
                _ip = "127.0.0.1";                                     //GetHostAddresses doesn't recognize localhost.
            }
            var t = Tasky.Run(() => {
                try {
                    return(Dns.GetHostAddresses(_ip).ToList());
                }
                catch (Exception) {
                    return(null);
                }
            });

            return(t);
        }
Ejemplo n.º 24
0
 public static Task <Task> WhenAny(IEnumerable <Task> tasks)
 {
     return(Tasky.WhenAny(tasks));
 }
Ejemplo n.º 25
0
 public static Task <Task <TResult> > WhenAny <TResult>(params Task <TResult>[] tasks)
 {
     return(Tasky.WhenAny(tasks));
 }
Ejemplo n.º 26
0
 public static Task WhenAll(params Task[] tasks)
 {
     return(Tasky.WhenAll(tasks));
 }
Ejemplo n.º 27
0
 public static Task WhenAll(IEnumerable <Task> tasks)
 {
     return(Tasky.WhenAll(tasks));
 }
Ejemplo n.º 28
0
 internal Tasky Create(Tasky newTask)
 {
     return(_repo.Create(newTask));
 }
Ejemplo n.º 29
0
 public static Task <Task <TResult> > WhenAny <TResult>(IEnumerable <Task <TResult> > tasks)
 {
     return(Tasky.WhenAny(tasks));
 }
Ejemplo n.º 30
0
 public static Task <Task> WhenAny(params Task[] tasks)
 {
     return(Tasky.WhenAny(tasks));
 }