Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Create()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin || request.AdminInfo == null)
                {
                    return(Unauthorized());
                }

                if (request.AdminInfo.LastActivityDate != null && ConfigManager.SystemConfigInfo.IsAdminEnforceLogout)
                {
                    var ts = new TimeSpan(DateTime.Now.Ticks - request.AdminInfo.LastActivityDate.Value.Ticks);
                    if (ts.TotalMinutes > ConfigManager.SystemConfigInfo.AdminEnforceLogoutMinutes)
                    {
                        return(Unauthorized());
                    }
                }

                var count = CreateTaskManager.PendingTaskCount;

                var pendingTask = CreateTaskManager.GetFirstPendingTask();
                if (pendingTask != null)
                {
                    try
                    {
                        var start = DateTime.Now;
                        await FileSystemObjectAsync.ExecuteAsync(pendingTask.SiteId, pendingTask.CreateType,
                                                                 pendingTask.ChannelId,
                                                                 pendingTask.ContentId, pendingTask.FileTemplateId, pendingTask.SpecialId);

                        var timeSpan = DateUtils.GetRelatedDateTimeString(start);
                        CreateTaskManager.AddSuccessLog(pendingTask, timeSpan);
                    }
                    catch (Exception ex)
                    {
                        CreateTaskManager.AddFailureLog(pendingTask, ex);
                    }
                    finally
                    {
                        CreateTaskManager.RemovePendingTask(pendingTask);
                    }
                }

                return(Ok(new
                {
                    Value = count
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Create()
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var count = CreateTaskManager.PendingTaskCount;

                var pendingTask = CreateTaskManager.GetFirstPendingTask();
                if (pendingTask != null)
                {
                    try
                    {
                        var start = DateTime.Now;
                        await FileSystemObjectAsync.ExecuteAsync(pendingTask.SiteId, pendingTask.CreateType,
                                                                 pendingTask.ChannelId,
                                                                 pendingTask.ContentId, pendingTask.FileTemplateId, pendingTask.SpecialId);

                        var timeSpan = DateUtils.GetRelatedDateTimeString(start);
                        CreateTaskManager.AddSuccessLog(pendingTask, timeSpan);
                    }
                    catch (Exception ex)
                    {
                        CreateTaskManager.AddFailureLog(pendingTask, ex);
                    }
                    finally
                    {
                        CreateTaskManager.RemovePendingTask(pendingTask);
                    }
                }

                return(Ok(new
                {
                    Value = count
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }