Example #1
0
        /// <summary>
        /// Creates meetings and stores in a collection.
        /// </summary>
        public async void CreateAppointments(DateTime hora)
        {
            ScheduleAction schedule = new ScheduleAction(Action.Id, hora);

            var scheduleAppointment = await scheduleRepository.GetAppointmentByIdActionEventIdAsync(Action.Id, schedule.EventId);

            if (scheduleAppointment == null)
            {
                //if (await MessageService.Instance.ShowAsyncYesNo("Deseja excluir este horário da " + dia + "?"))
                //{
                if (schedule != null)
                {
                    await scheduleRepository.AddAppointmentByIdActionAsync(Action.Id, schedule);

                    BuscarSchedulesAsync();
                }
                //}
            }
            else
            {
                //if (await MessageService.Instance.ShowAsyncYesNo("Deseja adicionar este horário da " + dia + "?"))
                //{
                await scheduleRepository.DeleteAppointmentByIdActionEventIdAsync(Action.Id, schedule.EventId);

                BuscarSchedulesAsync();
                //}
            }
        }
        public async Task <int> AddAsync(ScheduleAction scheduleAction)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(scheduleAction);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Example #3
0
    public void ScheduleAction()
    {
        ScheduleAction scheduleAction = new ScheduleAction();

        HitValueAction hitAction;

        hitAction = new HitValueAction();
        hitAction.valueTextPrefab = hitValuePrefab;
        hitAction.hitValue        = 999;
        hitAction.position        = new Vector3(0, 2, -2);
        scheduleAction.Schedule(0.5f, hitAction);

        hitAction = new HitValueAction();
        hitAction.valueTextPrefab = hitValuePrefab;
        hitAction.hitValue        = 888;
        hitAction.position        = new Vector3(1, 1, -2);
        scheduleAction.Schedule(1.0f, hitAction);

        hitAction = new HitValueAction();
        hitAction.valueTextPrefab = hitValuePrefab;
        hitAction.hitValue        = 777;
        hitAction.position        = new Vector3(2, 0, -2);
        scheduleAction.Schedule(4.0f, hitAction);


        // SimpleAnimationAction action = new SimpleAnimationAction();
        // action.clip = animeClip;
        // action.spawnPosition = new Vector3(0, 0, zOrderVfx);
        // action.repeat = 3;
        // action.destroySelf = false;

        actionManager.RunAction(scheduleAction);
    }
Example #4
0
 /// <summary>
 /// 赋值调度动作数据操作
 /// </summary>
 /// <param name="action"></param>
 /// <param name="reader"></param>
 /// <param name="prefix"></param>
 public static void SetScheduleActionStoreSelectFields(ScheduleAction action, DbDataReader reader, string prefix)
 {
     action.ID               = (Guid)reader[string.Format("{0}id", prefix)];
     action.Name             = reader[string.Format("{0}name", prefix)].ToString();
     action.TriggerCondition = reader[string.Format("{0}triggercondition", prefix)].ToString();
     action.Configuration    = reader[string.Format("{0}configuration", prefix)].ToString();
     action.Mode             = (int)reader[string.Format("{0}Mode", prefix)];
     if (reader[string.Format("{0}ScheduleActionServiceFactoryType", prefix)] != DBNull.Value)
     {
         action.ScheduleActionServiceFactoryType = reader[string.Format("{0}ScheduleActionServiceFactoryType", prefix)].ToString();
     }
     if (reader[string.Format("{0}ScheduleActionServiceFactoryTypeUseDI", prefix)] != DBNull.Value)
     {
         action.ScheduleActionServiceFactoryTypeUseDI = (bool)reader[string.Format("{0}ScheduleActionServiceFactoryTypeUseDI", prefix)];
     }
     if (reader[string.Format("{0}ScheduleActionServiceWebUrl", prefix)] != DBNull.Value)
     {
         action.ScheduleActionServiceWebUrl = reader[string.Format("{0}ScheduleActionServiceWebUrl", prefix)].ToString();
     }
     if (reader[string.Format("{0}WebSignature", prefix)] != DBNull.Value)
     {
         action.WebSignature = reader[string.Format("{0}WebSignature", prefix)].ToString();
     }
     action.Status     = (int)reader[string.Format("{0}Status", prefix)];
     action.CreateTime = (DateTime)reader[string.Format("{0}createtime", prefix)];
     action.ModifyTime = (DateTime)reader[string.Format("{0}modifytime", prefix)];
 }
Example #5
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var cb = sender as ComboBox;

            if (cb == null || cb.SelectedIndex < 0)
            {
                return;
            }
            var type = (ScheduleActionType)cb.SelectedItem;

            _actionInEditor = new ScheduleAction
            {
                ActionType = type,
                Day        = Day,
                Hour       = Hour
            };
            ClearControlHolderGrid();
            switch (type)
            {
            case ScheduleActionType.ChangeRoute:
                _actionInEditor.ActionArgs = new string[1];
                CreateRouteControl();
                break;

            case ScheduleActionType.ChangeLocation:
                _actionInEditor.ActionArgs = new string[2];
                CreateLocationControl();
                break;

            case ScheduleActionType.ChangeSettings:
                _actionInEditor.ActionArgs = new string[2];
                CreateSettingsControl();
                break;
            }
        }
        public void SetUp()
        {
            scheduleService = new Mock <IScheduleService>();

            mockServiceScopeFactory = new MockServiceScopeFactory();
            mockServiceScopeFactory.ServiceProvider.Setup(x => x.GetService(typeof(IScheduleService))).Returns(scheduleService.Object);

            scheduleAction = new ScheduleAction(mockServiceScopeFactory.ServiceScopeFactory.Object);
        }
        /// <summary>
        /// Iterates trough every students schedule, finds common scheduleActions, returns them as list.
        /// </summary>
        /// <param name="students">Students, that are expected to have common schedule</param>
        /// <param name="commonActions">said common actions (gonna be filtered)</param>
        /// <param name="commonScheduleActionsContains">acttual filtered common actions</param>
        /// <returns>True if there is any commonAction, false otherwise.</returns>
        private bool FindAndFilterCommonActionsByStudents(List <Student> students, List <ScheduleAction> commonActions, out List <ScheduleAction> commonScheduleActionsContains)
        {
            List <ScheduleAction> commonActions2 = new List <ScheduleAction>();
            bool           contains = false;
            ScheduleAction temp     = default(ScheduleAction);

            // Iterates trough common actions.
            foreach (var common in commonActions)
            {
                // Iterates every student.
                foreach (var student in students)
                {
                    // If students schedule does not contain common scheduleAction, break cycle,
                    // else => read below..
                    // (If there is no common action even in one student, there is no reason to
                    // check it for everybody..)
                    if (!_allServices.ScheduleService.GetScheduleByStudent(student)
                        .ScheduleJson.ScheduleActions.Contains(common))
                    {
                        contains = false;
                        break;
                    }
                    else
                    {
                        // Set temp. val for future use. (right below :-D)
                        // If every student passes, common action is viable.
                        temp     = common;
                        contains = true;
                    }
                }
                // If the student schedule is indeed common, then add it to common dictionary.
                // Set bool to false and continue cycle.
                if (contains)
                {
                    if (!commonActions2.Contains(temp))
                    {
                        commonActions2.Add(temp);
                    }
                    contains = false;
                }
            }
            // If there is (x>0) sucessfull iterations(whole), than said students have in common that number
            // of subjects.
            if (commonActions2.Count > 0)
            {
                _commonFillablesDictionaryScheduleActionsByStudents.Add(students, commonActions2);
                commonScheduleActionsContains = commonActions2;
                return(true);
            }
            // If there is none, return null.
            commonScheduleActionsContains = null;
            return(false);
        }
Example #8
0
 private void AddNewActionButton_Click(object sender, RoutedEventArgs e)
 {
     if (ComboBox.SelectedIndex == -1)
     {
         return;
     }
     _schedule.Bot.GlobalSettings.Schedule.ActionList.Add(_actionInEditor);
     ComboBox.SelectedIndex = -1;
     ClearControlHolderGrid();
     _actionInEditor     = null;
     ListBox.ItemsSource = CurrentActions;
 }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="scheduler"></param>
 /// <returns></returns>
 public static Observe <T> SubscribeOn <T>(this Observe <T> source, ScheduleAction scheduler)
 {
     return(o =>
     {
         IDisposable disposable = null;
         disposable = scheduler(() =>
                                source.Finally(() =>
         {
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         })(o));
     });
 }
Example #10
0
        public static IActionImplementor GetImplementor(this ScheduleAction scheduleAction)
        {
            if (scheduleAction == null)
            {
                return(null);
            }
            switch (scheduleAction.ActionType)
            {
            case ActionTypes.deletefile:
                return(new RemoveFileImplementor(scheduleAction));

            default:
                return(null);
            }
        }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="scheduler"></param>
 /// <returns></returns>
 public static Observe <T> ObserveOn <T>(this Observe <T> source, ScheduleAction scheduler)
 {
     // TODO: Verify this as I don't think it's correct.
     return(o => source(value =>
     {
         IDisposable disposable = null;
         disposable = scheduler(() =>
         {
             o(value);
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         });
     }));
 }
Example #12
0
        /// <summary>
        /// 根据调度动作组Id查询
        /// </summary>
        /// <param name="id"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public async Task <ScheduleAction> QueryByGroup(Guid id, Guid groupId)
        {
            ScheduleAction result = null;
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForSchedule(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SELECT {0} FROM [dbo].[ScheduleAction] WHERE id=@id AND groupid=@groupid", StoreHelper.GetScheduleActionStoreSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                    {
                        Value = id
                    };
                    command.Parameters.Add(parameter);
                    parameter = new SqlParameter("@groupid", SqlDbType.UniqueIdentifier)
                    {
                        Value = groupId
                    };
                    command.Parameters.Add(parameter);
                    command.Prepare();
                    SqlDataReader reader = null;

                    using (reader = await command.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            result = new ScheduleAction();
                            StoreHelper.SetScheduleActionStoreSelectFields(result, reader, string.Empty);
                        }

                        reader.Close();
                    }
                }
            });

            return(result);
        }
        private ScheduleAction CreateAction(Class myClass)
        {
            var action = new ScheduleAction()
            {
                Name = "MyAction", OnScheduleFire = myClass
            };

            action.Inherits.Add(Entity.Get <EntityType>("scheduledItem"));

            using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
            {
                action.Save();

                ctx.CommitTransaction();
            }

            toDelete.Add(action.Id);
            return(action);
        }
        /// <summary>
        /// By usage of debug class, schedule action is written down to be human readable.
        /// </summary>
        /// <param name="scheduleAction"></param>
        public void WriteScheduleActionInfo(ScheduleAction scheduleAction)
        {
            List <Message <object> > messages = new List <Message <object> >();

            if (!scheduleAction.Equals(default(ScheduleAction)))
            {
                messages.Add(
                    new Message <object>(("_ _ _ _ _ RozvrhovaAkceJson _ _ _ _ _"), MessageTypeEnum.Indifferent));
                foreach (FieldInfo val in scheduleAction.GetType().GetFields())
                {
                    if (val.GetValue(scheduleAction) != null)
                    {
                        messages.Add(new Message <object>(val.Name + ": " + val.GetValue(scheduleAction),
                                                          MessageTypeEnum.Rest));
                    }
                }
                Debug.AddMessages <object>(messages);
            }
        }
Example #15
0
 public void SetAction(ScheduleAction sa)
 {
     CurrentAction = sa;
 }
Example #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GXSchedule()
 {
     m_Interval = m_TransactionCount = 1;
     m_Items = new List<object>();
     m_ExcludedItems = new List<object>();
     m_Action = ScheduleAction.Read;
     m_TransactionStartTime = m_ScheduleStartTime = DateTime.MinValue;
     m_TransactionEndTime = m_ScheduleEndTime = DateTime.MaxValue;
     m_DayOfWeeks = new System.DayOfWeek[0];
     Statistics = new GXScheduleStatistics();
 }
Example #17
0
 /// <summary>
 /// Override this to made changes before schedule load.
 /// </summary>
 protected override void OnDeserializing(bool designMode)
 {
     m_Interval = m_TransactionCount = 1;
     m_Action = ScheduleAction.Read;
     m_Items = new List<object>();
     m_ExcludedItems = new List<object>();
     m_TransactionStartTime = m_ScheduleStartTime = DateTime.MinValue;
     m_TransactionEndTime = m_ScheduleEndTime = DateTime.MaxValue;
     m_DayOfWeeks = new System.DayOfWeek[0];
     Statistics = new GXScheduleStatistics();
 }
 public BaseActionImplementor(ScheduleAction scheduleAction)
 {
     this.Action = JsonConvert.DeserializeObject <T>(scheduleAction.Data);
 }
		/// <summary>
		/// Returns a localized string conversion of a ScheduleAction value.
		/// </summary>
		/// <param name="action">Enum value to convert to string.</param>
		/// <returns>Localized version of enum value as a string.</returns>
		public static string ScheduleActionToString(ScheduleAction action)
		{
			switch (action)
			{
				case ScheduleAction.Read:
					return Gurux.DeviceSuite.Properties.Resources.ReadTxt;
				case ScheduleAction.Write:
					return Gurux.DeviceSuite.Properties.Resources.WriteTxt;
				default:
					throw new Exception("GXActionToString failed: Unknown ScheduleAction " + action.ToString());
			}
		}
        /// <summary>
        /// Iterates trough schedules of all provided students, and by prioritising the first one,
        /// common ActionSchedules with all provided students are found and returned.
        /// </summary>
        /// <param name="students"></param>
        /// <param name="fromDateTime"></param>
        /// <returns></returns>
        public Dictionary <List <Student>, List <ScheduleAction> > GetUncommonScheduleActionsByStudents(List <Student> students, DateTime fromDateTime = new DateTime(), string semester = "")
        {
            Task <List <Dictionary <List <Student>, List <ScheduleAction> > > > task = new Task <List <Dictionary <List <Student>, List <ScheduleAction> > > >(() =>
            {
                List <ScheduleAction> fillableActions = new List <ScheduleAction>();
                Schedule prioritisedSchedule          = _allServices.ScheduleService.GetScheduleByStudent(students.First());
                if (prioritisedSchedule is null)
                {
                    throw new ManagerException("Getted schedule is null, check your credentials or network access.");
                }
                foreach (var student in students)
                {
                    if (student.OsId != students.First().OsId)
                    {
                        foreach (var priorityScheduleAction in prioritisedSchedule.ScheduleJson.ScheduleActions)
                        {
                            foreach (var scheduleAction in _allServices.ScheduleService.GetScheduleByStudent(student)
                                     .ScheduleJson.ScheduleActions)
                            {
                                // If idno is different, there will be delta in time, so compare that and create
                                // list of possible empty schedule actions, then, merge them into big one scheduleAction.
                                if (scheduleAction.ScheduleActionIdno != priorityScheduleAction.ScheduleActionIdno)
                                {
                                    if (
                                        priorityScheduleAction.DateAbsoluteFrom != null &&
                                        priorityScheduleAction.DateAbsoluteFrom.Value.GetDateTime() > fromDateTime &&
                                        scheduleAction.DateAbsoluteFrom != null &&
                                        scheduleAction.DateAbsoluteFrom.Value.GetDateTime() > fromDateTime)
                                    {
                                        //Když nezačne dřív, než já skončím, máme spol. volný čas.
                                        if (scheduleAction.Semester == priorityScheduleAction.Semester &&
                                            scheduleAction.Day == priorityScheduleAction.Day &&
                                            ((scheduleAction.HourAbsoluteTo.Value.GetDateTime() <
                                              priorityScheduleAction.HourAbsoluteFrom.Value.GetDateTime() &&
                                              ((priorityScheduleAction.HourAbsoluteFrom.Value.GetDateTime() -
                                                scheduleAction.HourAbsoluteTo.Value.GetDateTime()).Minutes < 40) &&
                                              ((priorityScheduleAction.HourAbsoluteTo.Value.GetDateTime() -
                                                scheduleAction.HourAbsoluteFrom.Value.GetDateTime()).Hours > 2)
                                              ))
                                            )
                                        {
                                            // Create new ScheduleAction based on priority scheduleAction.
                                            // Then modifies it to create delta between prio date and slave schedule date.
                                            ScheduleAction fillableScheduleAction = new ScheduleAction()
                                            {
                                                Name = "[" + scheduleAction.Name + "]_To_[" + priorityScheduleAction.Name + "]",
                                                ScheduleActionIdno = scheduleAction.ScheduleActionIdno + "_free",
                                                HourAbsoluteFrom   = scheduleAction.HourAbsoluteTo.Value,
                                                HourAbsoluteTo     = priorityScheduleAction.HourAbsoluteFrom.Value,
                                                Day         = priorityScheduleAction.Day,
                                                Subject     = "Break",
                                                LectureType = "SpolVolno",
                                                Semester    = priorityScheduleAction.Semester,
                                            };
                                            // Set priority time (end of my lecture), then, look for start of other person lecture. delta will be our free time.
                                            //fillableScheduleAction.HourAbsoluteFrom.Value.SetDateTime(priorityScheduleAction.HourAbsoluteFrom.Value.GetDateTime());
                                            //fillableScheduleAction.HourAbsoluteTo.Value.SetDateTime(scheduleAction.HourAbsoluteFrom.Value.GetDateTime());
                                            // If scheduleAction is not present in list, add it there. Take idno from preffered.
                                            if (fillableActions.Count == 0 || fillableActions.Exists(action =>
                                                                                                     action.ScheduleActionIdno != priorityScheduleAction.ScheduleActionIdno))
                                            {
                                                fillableActions.Add(fillableScheduleAction);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    // If scheduleAction idno is same, there is no "free time".
                                    // Only if scheduleAction is prostponed (odložená) or cancelled,
                                    // we have a reason to check it. TODO: impl prostpone detection.
                                }
                            }
                            // Garbage No2 -> cannot query in loop (server usage) and nevertheless, this "query" is bad.

                            /*
                             * if(_allServices.StudentService.LoadStudentsByScheduleAction(priorityScheduleAction.ScheduleActionIdno)
                             *  .Find(student1 =>
                             *  {
                             *      if (student1.Equals((student)))
                             *      {
                             *          return true;
                             *      }
                             *      return false;
                             *  }).OsId != null)
                             * if (commonActions.Contains(priorityScheduleAction))
                             *  commonActions.Remove(priorityScheduleAction);
                             */
                        }
                    }

                    // NO! :D
                    //prioritisedSchedule = _allServices.ScheduleService.GetScheduleByStudent(student);
                }

                List <ScheduleAction> _commonFillableActions = new List <ScheduleAction>();
                foreach (var scheduleAction in fillableActions)
                {
                    if (!_commonFillableActions.Contains(scheduleAction))
                    {
                        _commonFillableActions.Insert(0, scheduleAction);
                    }
                }

                fillableActions = _commonFillableActions;
                // For free time, there has to be absolutely no common schedules.
                if (!FindAndFilterCommonActionsByStudents(students, fillableActions, out var commonScheduleActionsFiltered))
                {
                    if (!_commonFillablesDictionaryScheduleActionsByStudents.ContainsKey(students))
                    {
                        _commonFillablesDictionaryScheduleActionsByStudents.Add(students, fillableActions);
                    }
                    else
                    {
                        _commonFillablesDictionaryScheduleActionsByStudents.Remove(students);
                        _commonFillablesDictionaryScheduleActionsByStudents.Add(students, fillableActions);
                    }
                }
                else
                {
                    throw new ManagerException("Specified students have no possible free common schedule actions!");
                }
                return(new List <Dictionary <List <Student>, List <ScheduleAction> > >()
                {
                    _commonFillablesDictionaryScheduleActionsByStudents
                });
            });

            AddWork(task);
            return(ResultHandler(task).First());
        }
Example #21
0
 public RemoveFileImplementor(ScheduleAction scheduleAction) : base(scheduleAction)
 {
 }
        public async Task <int> UpdateAsync(ScheduleAction scheduleAction)
        {
            var cmd = QueriesCreatingHelper.CreateQueryUpdate(scheduleAction);

            return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection));
        }
Example #23
0
        /// <summary>
        /// 分页查询尚未分配组且匹配动作名称的调度动作
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <QueryResult <ScheduleAction> > QueryByNullGroup(string name, int page, int pageSize)
        {
            QueryResult <ScheduleAction> result = new QueryResult <ScheduleAction>();
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForSchedule(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SET @currentpage = @page;
                                                    SELECT @count = COUNT(*)
                                                    FROM [ScheduleAction]
                                                    WHERE [name] LIKE @name
                                                          AND [groupid] IS NULL;
                                                    IF @pagesize * @page >= @count
                                                    BEGIN
                                                        SET @currentpage = @count / @pagesize;
                                                        IF @count % @pagesize <> 0
                                                        BEGIN
                                                            SET @currentpage = @currentpage + 1;
                                                        END;
                                                        IF @currentpage = 0
                                                            SET @currentpage = 1;
                                                    END;
                                                    ELSE IF @page < 1
                                                    BEGIN
                                                        SET @currentpage = 1;
                                                    END;

                                                    SELECT {0}
                                                    FROM [ScheduleAction]
                                                    WHERE [name] LIKE @name
                                                          AND [groupid] IS NULL
                                                    ORDER BY sequence OFFSET (@pagesize * (@currentpage - 1)) ROWS FETCH NEXT @pagesize ROWS ONLY;",
                                                StoreHelper.GetScheduleActionStoreSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@page", SqlDbType.Int)
                    {
                        Value = page
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                    {
                        Value = pageSize
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@count", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@currentpage", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@name", SqlDbType.VarChar, 200)
                    {
                        Value = $"{name.ToSqlLike()}%"
                    };
                    command.Parameters.Add(parameter);
                    command.Prepare();
                    SqlDataReader reader = null;


                    using (reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var scheduleAction = new ScheduleAction();
                            StoreHelper.SetScheduleActionStoreSelectFields(scheduleAction, reader, string.Empty);
                            result.Results.Add(scheduleAction);
                        }
                        reader.Close();
                        result.TotalCount  = (int)command.Parameters["@count"].Value;
                        result.CurrentPage = (int)command.Parameters["@currentpage"].Value;
                    }
                }
            });

            return(result);
        }
Example #24
0
        /// <summary>
        /// 查询调度动作id下面的所有指定状态的调度动作
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="status"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public async Task QueryAllAction(Guid groupId, int status, Func <ScheduleAction, Task> callback)
        {
            List <ScheduleAction> listAction = new List <ScheduleAction>();
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForSchedule(), async (conn, transaction) =>
            {
                int sequence = 0;
                int pageSize = 500;
                while (true)
                {
                    listAction.Clear();

                    SqlTransaction sqlTran = null;
                    if (transaction != null)
                    {
                        sqlTran = (SqlTransaction)transaction;
                    }

                    using (SqlCommand command = new SqlCommand()
                    {
                        Connection = (SqlConnection)conn,
                        CommandType = CommandType.Text,
                        CommandText = string.Format(@"SELECT {0} FROM [ScheduleAction] WHERE [groupid]=@groupid AND [status]=@status ORDER BY sequence OFFSET @sequence ROWS FETCH NEXT @pagesize ROWS ONLY;", StoreHelper.GetScheduleActionStoreSelectFields(string.Empty)),
                        Transaction = sqlTran
                    })
                    {
                        var parameter = new SqlParameter("@groupId", SqlDbType.UniqueIdentifier)
                        {
                            Value = groupId
                        };
                        command.Parameters.Add(parameter);
                        parameter = new SqlParameter("@status", SqlDbType.Int)
                        {
                            Value = status
                        };
                        command.Parameters.Add(parameter);
                        parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                        {
                            Value = pageSize
                        };
                        command.Parameters.Add(parameter);
                        parameter = new SqlParameter("@sequence", SqlDbType.Int)
                        {
                            Value = sequence
                        };
                        command.Parameters.Add(parameter);
                        command.Prepare();
                        SqlDataReader reader = null;


                        using (reader = await command.ExecuteReaderAsync())
                        {
                            while (await reader.ReadAsync())
                            {
                                var scheduleAction = new ScheduleAction();
                                StoreHelper.SetScheduleActionStoreSelectFields(scheduleAction, reader, string.Empty);
                                listAction.Add(scheduleAction);
                            }
                            reader.Close();
                        }
                    }
                    foreach (var actionItem in listAction)
                    {
                        await callback(actionItem);
                    }
                    if (listAction.Count != pageSize)
                    {
                        break;
                    }
                    else
                    {
                        sequence += listAction.Count;
                    }
                }
            });
        }
 public ScheduleArrivedEventArgs(ScheduleAction action, TimeSpan time)
 {
     Action = action;
     Time   = time;
 }
Example #26
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public async Task Add(ScheduleAction action)
        {
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _dbConnectionFactory.CreateAllForSchedule(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                })
                {
                    SqlParameter parameter;
                    if (action.ID == Guid.Empty)
                    {
                        command.CommandText = @"INSERT INTO [dbo].[ScheduleAction]
                                                    ([id],[name],[triggercondition],[configuration],[mode],[scheduleactionservicefactorytype],[scheduleactionservicefactorytypeusedi],[scheduleactionserviceweburl],[websignature],[status],[createtime],[modifytime])
                                                VALUES
                                                    (default, @name, @triggercondition,@configuration, @mode, @scheduleactionservicefactorytype, @scheduleactionservicefactorytypeusedi, @scheduleactionserviceweburl, @websignature, @status, GETUTCDATE(), GETUTCDATE());
                                                select @newid =[id] from [dbo].[ScheduleAction] where [sequence] = SCOPE_IDENTITY()";
                        parameter           = new SqlParameter("@newid", SqlDbType.UniqueIdentifier)
                        {
                            Direction = ParameterDirection.Output
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        command.CommandText = @"INSERT INTO [dbo].[ScheduleAction]
                                                    ([id],[name],[triggercondition],[configuration],[mode],[scheduleactionservicefactorytype],[scheduleactionservicefactorytypeusedi],[scheduleactionserviceweburl],[websignature],[status],[createtime],[modifytime])
                                                VALUES
                                                    (@id, @name, @triggercondition,@configuration, @mode, @scheduleactionservicefactorytype, @scheduleactionservicefactorytypeusedi, @scheduleactionserviceweburl, @websignature, @status, GETUTCDATE(), GETUTCDATE());";
                        parameter           = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                        {
                            Value = action.ID
                        };
                        command.Parameters.Add(parameter);
                    }
                    parameter = new SqlParameter("@name", SqlDbType.VarChar, 150)
                    {
                        Value = action.Name
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@triggercondition", SqlDbType.VarChar, 200)
                    {
                        Value = action.TriggerCondition
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@configuration", SqlDbType.NVarChar, action.Configuration.Length)
                    {
                        Value = action.Configuration
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@mode", SqlDbType.Int)
                    {
                        Value = action.Mode
                    };
                    command.Parameters.Add(parameter);
                    if (action.ScheduleActionServiceFactoryType != null)
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytype", SqlDbType.VarChar, 200)
                        {
                            Value = action.ScheduleActionServiceFactoryType
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytype", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.ScheduleActionServiceFactoryTypeUseDI != null)
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytypeusedi", SqlDbType.Bit)
                        {
                            Value = action.ScheduleActionServiceFactoryTypeUseDI
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytypeusedi", SqlDbType.Bit)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.ScheduleActionServiceWebUrl != null)
                    {
                        parameter = new SqlParameter("@scheduleactionserviceweburl", SqlDbType.VarChar, 200)
                        {
                            Value = action.ScheduleActionServiceWebUrl
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionserviceweburl", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.WebSignature != null)
                    {
                        parameter = new SqlParameter("@websignature", SqlDbType.VarChar, 200)
                        {
                            Value = action.WebSignature
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@websignature", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }

                    parameter = new SqlParameter("@status", SqlDbType.Int)
                    {
                        Value = action.Status
                    };
                    command.Parameters.Add(parameter);
                    command.Prepare();

                    try
                    {
                        await command.ExecuteNonQueryAsync();
                    }
                    catch (SqlException ex)
                    {
                        if (ex == null)
                        {
                            throw;
                        }
                        if (ex.Number == 2601)
                        {
                            var fragment = new TextFragment()
                            {
                                Code = TextCodes.ExistScheduleActionByName,
                                DefaultFormatting = "调度动作中存在相同名称\"{0}\"数据",
                                ReplaceParameters = new List <object>()
                                {
                                    action.Name
                                }
                            };

                            throw new UtilityException((int)Errors.ExistScheduleActionByName, fragment);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    //如果用户未赋值ID则创建成功后返回ID
                    if (action.ID == Guid.Empty)
                    {
                        action.ID = (Guid)command.Parameters["@newid"].Value;
                    }
                    ;
                }
            });
        }
Example #27
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public async Task Update(ScheduleAction action)
        {
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _dbConnectionFactory.CreateAllForSchedule(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                    CommandText = @"UPDATE [dbo].[ScheduleAction]
                                   SET 
                                      [name] = @name,
                                      [triggercondition] = @triggercondition,
                                      [configuration]=@configuration,
                                      [mode] = @mode,
                                      [scheduleactionservicefactorytype] = @scheduleactionservicefactorytype,
                                      [scheduleactionservicefactorytypeusedi] = @scheduleactionservicefactorytypeusedi,
                                      [scheduleactionserviceweburl] = @scheduleactionserviceweburl,
                                      [websignature] = @websignature,
                                      [status] = @status,
                                      [modifytime] = GETUTCDATE()
                                 WHERE id=@id;"
                })
                {
                    var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                    {
                        Value = action.ID
                    };
                    command.Parameters.Add(parameter);
                    parameter = new SqlParameter("@name", SqlDbType.VarChar, 150)
                    {
                        Value = action.Name
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@triggercondition", SqlDbType.VarChar, 200)
                    {
                        Value = action.TriggerCondition
                    };
                    command.Parameters.Add(parameter);


                    parameter = new SqlParameter("@configuration", SqlDbType.NVarChar, action.Configuration.Length)
                    {
                        Value = action.Configuration
                    };
                    command.Parameters.Add(parameter);


                    parameter = new SqlParameter("@mode", SqlDbType.Int)
                    {
                        Value = action.Mode
                    };
                    command.Parameters.Add(parameter);
                    if (action.ScheduleActionServiceFactoryType != null)
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytype", SqlDbType.VarChar, 200)
                        {
                            Value = action.ScheduleActionServiceFactoryType
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytype", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.ScheduleActionServiceFactoryTypeUseDI != null)
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytypeusedi", SqlDbType.Bit)
                        {
                            Value = action.ScheduleActionServiceFactoryTypeUseDI
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionservicefactorytypeusedi", SqlDbType.Bit)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.ScheduleActionServiceWebUrl != null)
                    {
                        parameter = new SqlParameter("@scheduleactionserviceweburl", SqlDbType.VarChar, 200)
                        {
                            Value = action.ScheduleActionServiceWebUrl
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@scheduleactionserviceweburl", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    if (action.WebSignature != null)
                    {
                        parameter = new SqlParameter("@websignature", SqlDbType.VarChar, 200)
                        {
                            Value = action.WebSignature
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        parameter = new SqlParameter("@websignature", SqlDbType.VarChar, 200)
                        {
                            Value = DBNull.Value
                        };
                        command.Parameters.Add(parameter);
                    }
                    parameter = new SqlParameter("@status", SqlDbType.Int)
                    {
                        Value = action.Status
                    };
                    command.Parameters.Add(parameter);

                    command.Prepare();


                    try
                    {
                        await command.ExecuteNonQueryAsync();
                    }
                    catch (SqlException ex)
                    {
                        if (ex == null)
                        {
                            throw;
                        }
                        if (ex.Number == 2601)
                        {
                            var fragment = new TextFragment()
                            {
                                Code = TextCodes.ExistScheduleActionByName,
                                DefaultFormatting = "调度动作中存在相同名称\"{0}\"数据",
                                ReplaceParameters = new List <object>()
                                {
                                    action.Name
                                }
                            };

                            throw new UtilityException((int)Errors.ExistScheduleActionByName, fragment);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            });
        }
Example #28
0
 public SolveQuadEquationJob(Task task, double _a, double _b, double _c)
 {
     CurrentAction = new GetParamsState(this, _a, _b, _c);
 }
Example #29
0
 public FindStringInFileJob(Task task, string _fName, string _Find)
 {
     CurrentAction = new GetSrcStrings(this, _fName, _Find);
 }