Example #1
0
        public static XTask[] GenerateTasks(int count)
        {
            var tasks = new XTask[count];

            for (int i = 0; i < count; i++)
            {
                var description = new char[TaskSize];
                for (int j = 0; j < TaskSize; j++)
                {
                    description[j] = Alphabet[Random.Next(Alphabet.Length)];
                }

                tasks[i] = new XTask
                {
                    Description = new string(description)
                };

                lock (TaskNumberLock)
                {
                    tasks[i].Name = $"Task #{TaskNumber++}";
                }
            }

            for (int i = 0; i < count; i++)
            {
                tasks[i].Timestamp = DateTime.UtcNow;
            }

            return(tasks);
        }
Example #2
0
    public XTask StartTask(IEnumerator routine, Action <bool> callback)
    {
        XTask xTask = new XTask(routine);

        xTask.Start();
        xTask.Finished = callback;
        return(xTask);
    }
Example #3
0
        public static void Handle(XTask task)
        {
            var ms = (DateTime.UtcNow - task.Timestamp).TotalMilliseconds;

            Log.Info($"Got {task.Name} Latency: {ms} ms.");
            Meter.Mark();
            Histogram.Update((long)ms);
        }
    /// <summary>
    /// No more delegates, background workers etc. just one line of code as shown below
    /// Note it is dependent on the XTask class shown next.
    /// </summary>
    public async void ExampleMethod()
    {
        //Still on GUI/Original Thread here
        //Do your updates before the next line of code
        await XTask.RunAsync(() =>
        {
            //Running an asynchronous task here
            //Cannot update GUI Thread here, but can do lots of work
        });

        //Can update GUI/Original thread on this line
    }
Example #5
0
        /// <summary>
        /// Try to close the frame instead of the document.
        /// It shows the possible interface to do so.
        /// </summary>
        /// <param name="xFrame">frame which should be clcosed</param>
        /// <returns>
        /// <TRUE/>
        ///  in case frame could be closed
        /// <FALSE/>
        ///  otherwise
        /// </returns>
        public static bool CloseFrame(XFrame xFrame)
        {
            bool bClosed = false;

            try
            {
                // first try the new way: use new interface XCloseable
                // It replace the deprecated XTask::close() and should be preferred ...
                // if it can be queried.
                XCloseable xCloseable = (XCloseable)xFrame;
                if (xCloseable != null)
                {
                    // We deliver the owner ship of this frame not to the (possible)
                    // source which throw a CloseVetoException. We whish to have it
                    // under our own control.
                    try
                    {
                        xCloseable.close(false);
                        bClosed = true;
                    }
                    catch (CloseVetoException)
                    {
                        bClosed = false;
                    }
                }
                else
                {
                    // OK: the new way isn't possible. Try the old one.
                    XTask xTask = (XTask)xFrame;
                    if (xTask != null)
                    {
                        // return value doesn't interest here. Because
                        // we forget this task ...
                        bClosed = xTask.close();
                    }
                }
            }
            catch (DisposedException)
            {
                // Of course - this task can be already dead - means disposed.
                // But for us it's not important. Because we tried to close it too.
                // And "already disposed" or "closed" should be the same ...
                bClosed = true;
            }

            return(bClosed);
        }
Example #6
0
        public override async Task <bool> Handle(CreateUpdateQuery query)
        {
            // GET empfanger information by empfanger Id
            //var faPendenzgruppeUserDetail = _faPendenzgruppeUsers.GetDetailByCondition(s => s.FaPendenzgruppeId.Equals(query.empfangerId));

            //if (faPendenzgruppeUserDetail != null)s
            //{
            //    query.empfangerId = faPendenzgruppeUserDetail.UserId;
            //}
            var reciveTask = 2;
            var userDetail = _xUsers.GetByID(query.empfangerId);

            if (userDetail != null)
            {
                reciveTask = 1;
            }

            if (query.id.HasValue)
            {
                var strQuery = string.Format(@"
					UPDATE XTask
					SET [TaskStatusCode] =			{0},
						[TaskTypeCode] =			{1},
						[Subject] =					{2},
						[TaskDescription] =			{3},
						[ReceiverID] =				{4},
						[FaFallID] =				{5},
						[FaLeistungID] =			{6},
						
						[BaPersonID] =			{7},
						[ResponseText] =			{8},
						[ExpirationDate] =			{9}
					WHERE XTaskID = {10}"                    ,
                                             query.status,
                                             query.pendenzTyp,
                                             "'" + query.betreff + "'",
                                             query.beschreibung == null ? "null" : "'" + query.beschreibung + "'",
                                             query.empfangerId,
                                             query.falltrager == null ? "null" : "'" + query.falltrager + "'",
                                             query.leistung == null ? "null" : "'" + query.leistung + "'",

                                             query.PersonId == null ? "null" : "'" + query.PersonId + "'",
                                             query.antwort == null ? "null" : "'" + query.antwort + "'",

                                             query.fallig == null ? "null" : "'" + query.fallig + "'",
                                             query.id);

                // Update
                await _dbConnection.QueryAsync <bool>(strQuery);
            }
            else
            {
                var task = new XTask()
                {
                    TaskStatusCode  = query.status,
                    TaskTypeCode    = query.pendenzTyp,
                    Subject         = query.betreff,
                    TaskDescription = query.beschreibung,
                    ReceiverID      = query.empfangerId,
                    FaFallID        = query.falltrager,
                    FaLeistungID    = query.leistung,
                    BaPersonID      = query.PersonId,
                    ResponseText    = query.antwort,
                    CreateDate      = DateTime.Now,
                    ExpirationDate  = DateTime.ParseExact(query.fallig,
                                                          "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture),
                    TaskReceiverCode = 1,
                    TaskSenderCode   = reciveTask,
                    SenderID         = Convert.ToInt32(query.SenderId),
                    StartDate        = DateTime.ParseExact(query.erfasst,
                                                           "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
                };

                await _xTask.InsertOrUpdateEntity(task);
            }
            return(true);
        }