コード例 #1
0
        public void Init(ScheduleConfig parent)
        {
            SetType();
            switch (this.Type)
            {
            case ConditionType.DateTime:
                this.Valid = SetupDateTime();
                break;

            case ConditionType.Interval:
                this.Valid = SetupInterval();
                break;

            case ConditionType.Function:
                this.Valid = SetupFunction(parent);
                break;

            case ConditionType.TimeRange:
                this.Valid = SetupRange();
                break;

            case ConditionType.Unknown:
            default:
                this.Valid = false;
                break;
            }
        }
コード例 #2
0
        public void Init(ScheduleConfig parent)
        {
            SetType();
            switch (this.Type)
            {
            case ProcessType.SendMessage:
                SetSendTo();
                this.Values = this.Values.Where(v => v.Length > 0).ToArray();
                this.Valid  = this.Values.Length > 0;
                break;

            case ProcessType.Talk:
                this.Values = this.Values.Where(v => v.Length > 0).ToArray();
                this.Valid  = this.Values.Length > 0;
                break;

            case ProcessType.Function:
                this.Valid = SetFunction(parent);
                break;

            case ProcessType.Unknown:
            default:
                this.Valid = false;
                break;
            }
        }
コード例 #3
0
        private bool SetupFunction(ScheduleConfig parent)
        {
            var file = Config.LoadFile(this.FunctionFile, parent.ConfigFileDir);

            if (file.Length > 0)
            {
                this.FunctionStr = file;
            }
            if (this.FunctionName.Length == 0 || this.FunctionStr.Length == 0)
            {
                return(false);
            }
            JSWrapper.Instance.SetFunction(this.FunctionName, this.FunctionStr);
            this.Function = (JSScheduleArgument arg) => {
                try {
                    var r = JSWrapper.Instance.ExecuteFunction(FunctionName, arg);
                    if (r == null)
                    {
                        return(false);
                    }
                    if (r.GetType() == typeof(bool))
                    {
                        return((bool)r);
                    }
                    return(false);
                } catch (System.Exception e) {
                    // TRANSLATORS: Log message. UserDefinedScheduler plugin.
                    Logger.Log(T._("Could not get JS result."));
                    Logger.DebugLog(e.ToString());
                    return(false);
                }
            };
            return(true);
        }
コード例 #4
0
        private bool SetFunction(ScheduleConfig parent)
        {
            var file = Config.LoadFile(this.FunctionFile, parent.ConfigFileDir);

            if (file.Length > 0)
            {
                this.FunctionStr = file;
            }
            if (this.FunctionName.Length == 0 || this.FunctionStr.Length == 0)
            {
                return(false);
            }
            JSWrapper.Instance.SetFunction(this.FunctionName, this.FunctionStr);
            this.Function = (JSScheduleArgument arg) => {
                try {
                    var r = JSWrapper.Instance.ExecuteFunction(FunctionName, arg);
                    if (r == null)
                    {
                        return(null);
                    }
                    var ret = new List <ScheduledMessage>();
                    if (r.GetType().IsArray)
                    {
                        var arr = (object[])r;
                        foreach (var item in arr)
                        {
                            if (item.GetType() == typeof(ScheduledMessage))
                            {
                                ret.Add((ScheduledMessage)item);
                            }
                        }
                        return(ret.ToArray());
                    }
                    return(null);
                } catch (System.Exception e) {
                    // TRANSLATORS: Log message. UserDefinedScheduler plugin.
                    Logger.Log(T._("Could not get JS result."));
                    Logger.DebugLog(e.ToString());
                    return(null);
                }
            };
            return(true);
        }