示例#1
0
        protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context)
        {
            var files = Files.Get <string[]>(context);
            var t     = new OpenRPA.Workitem();

            t.wiqid       = wiqid.Get <string>(context);
            t.wiq         = wiq.Get <string>(context);
            t.name        = Name.Get <string>(context);
            t.priority    = Priority.Get <int>(context);
            t.nextrun     = NextRun.Get <DateTime?>(context);
            t.success_wiq = Success_wiq.Get <string>(context);
            t.failed_wiq  = Failed_wiq.Get <string>(context);
            if (t.payload == null)
            {
                t.payload = new Dictionary <string, object>();
            }
            foreach (var item in Payload)
            {
                t.payload.Add(item.Key, item.Value.Get(context));
            }
            Workitem result = null;

            if (string.IsNullOrEmpty(Config.local.wsurl))
            {
                await t.Save(false);
            }
            else
            {
                result = await global.webSocketClient.AddWorkitem <Workitem>(t, files);
            }
            return(result);
        }
示例#2
0
        protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context)
        {
            var files = Files.Get <string[]>(context);
            var t     = new Workitem();

            t.wiqid       = wiqid.Get <string>(context);
            t.wiq         = wiq.Get <string>(context);
            t.name        = Name.Get <string>(context);
            t.priority    = Priority.Get <int>(context);
            t.nextrun     = NextRun.Get <DateTime?>(context);
            t.success_wiq = Success_wiq.Get <string>(context);
            t.failed_wiq  = Failed_wiq.Get <string>(context);
            if (t.payload == null)
            {
                t.payload = new Dictionary <string, object>();
            }
            foreach (var item in Payload)
            {
                t.payload.Add(item.Key, item.Value.Get(context));
            }
            Workitem result = null;
            await RobotInstance.instance.WaitForSignedIn(TimeSpan.FromSeconds(10));

            result = await global.webSocketClient.AddWorkitem <Workitem>(t, files);

            return(result);
        }
示例#3
0
        public NextRun Create(NextRun nextRunToCreate)
        {
            _db.NextRuns.Add(nextRunToCreate);
            _db.SaveChanges();

            return(nextRunToCreate);
        }
示例#4
0
        public void RunApp()
        {
            NextRun mostRecentNextRun = _nextRunRepository.GetMostRecent();

            if (mostRecentNextRun == null)
            {
                return;
            }

            var currentNextRun = new NextRun {
                RunComplete = DateTime.Now
            };

            List <QueueItem> nextBatchToProcess = _sapphireService.ListNextBatch(mostRecentNextRun.RunComplete);

            if (nextBatchToProcess == null)
            {
                return;
            }

            _queueRepository.Create(nextBatchToProcess);

            //currentNextRun.Status = NextRunStatusType.Processed;
            //_nextRunRepository.Create(currentNextRun);
        }
示例#5
0
            public int CompareTo(object obj)
            {
                if (obj == null || !(obj is CronJob))
                {
                    return(1);
                }
                var cron = (CronJob)obj;

                return(NextRun.CompareTo(cron.NextRun));
            }
示例#6
0
        public void CalculateNextRunDate()
        {
            switch (Interval)
            {
            case Interval.Day:
                NextRun = NextRun.AddDays(1);
                break;

            case Interval.Week:
                NextRun = NextRun.AddDays(7);
                break;

            case Interval.Month:
                NextRun = NextRun.AddMonths(1);
                break;
            }
        }
示例#7
0
        public void IncNextRun()
        {
            if (ExtraRun)
            {
                return;
            }

            if (Intervall == -1)
            {
                NextRun = DateTime.MaxValue;
                return;
            }

            while (NextRun < DateTime.Now)
            {
                NextRun = NextRun.AddMinutes(Intervall);
            }
        }
示例#8
0
        private void ApplyAvailableSegmentedBackground(Brush[] brushes)
        {
            // However, it should have at least 2 brushes.
            if (brushes.Length < 2)
            {
                throw new Exception("BrushList contains only " + brushes.Length + " brush.");
            }

            // If prev is null, just check with the next one.
            if (PreviousRun == null)
            {
                SegmentedBackground = (NextRun == null || NextRun.SegmentedBackground != brushes[0]) ? brushes[0] : brushes[1];
                //UpdateBackground();
                return;
            }

            // If next is null, just check with the prev one. [But now we know that prev is not null.]
            if (NextRun == null)
            {
                SegmentedBackground = (PreviousRun.SegmentedBackground != brushes[0]) ? brushes[0] : brushes[1];
                //UpdateBackground();
                return;
            }

            // Check every brush in brushes, find one that doesn't share color with prev or next.
            foreach (Brush brush in brushes)
            {
                if (PreviousRun.SegmentedBackground == brush || NextRun.SegmentedBackground == brush)
                {
                    continue;
                }
                SegmentedBackground = brush;
                //UpdateBackground();
                return;
            }

            // If there is no consistent brush, choose one that is different from prev, repeat the algo with the next one.
            SegmentedBackground = (PreviousRun.SegmentedBackground != brushes[0]) ? brushes[0] : brushes[1];
            //UpdateBackground();
            NextRun.ApplyAvailableSegmentedBackground(brushes);
        }
示例#9
0
        public static void SaveConfig()
        {
            ConfigNode cfgnode = new ConfigNode();
            ConfigNode KSPAVC  = cfgnode.AddNode("MINI-AVC");

            ConfigNode Interval = KSPAVC.AddNode("UPDATE_FREQUENCY");

            {
                Interval.AddValue("MinTimeBetweenAvcRuns", AvcInterval.ToString() + " //Timespan between AVC runs in hours (-1 = Disable MiniAVC, 0 = Run on each game start)");

                if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0)
                {
                    Interval.AddValue("AvcRunsNext", DateTime.Now.AddHours(AvcInterval).ToString());
                }
                else
                {
                    Interval.AddValue("AvcRunsNext", NextRun.ToString());
                }
            }
            cfgnode.Save(configPath);
            Logger.Log("Config saved!");
        }
        public void Next()
        {
            switch (Type)
            {
            case ScheduleType.ByInterval:
                NextRun += Time;
                if (ShouldRun())
                {
                    NextRun = DateTime.UtcNow;
                }
                break;

            case ScheduleType.Daily:
                do
                {
                    NextRun = NextRun.AddDays(1);
                } while (ShouldRun());
                break;

            default:
                break;
            }
        }
        public ScheduleInfo(ScheduleType type, TimeSpan time, IRegularAsync action)
        {
            Type   = type;
            Time   = time;
            Action = action;
            switch (Type)
            {
            case ScheduleType.ByInterval:
                NextRun = DateTime.UtcNow;
                break;

            case ScheduleType.Daily:
                NextRun = DateTime.UtcNow.Date + time;
                if (ShouldRun())
                {
                    NextRun = NextRun.AddDays(1);
                }
                break;

            default:
                throw new ArgumentException("类型不对", nameof(type));
            }
        }
示例#12
0
        public static void SaveCfg()
        {
            Logger.Log("SaveCfg");
            CfgUpdated = false;

            if (!File.Exists(AvcConfigFile) || !Directory.Exists(AvcConfigFilePath))
            {
                Directory.CreateDirectory(AvcConfigFilePath);
                var ConfigFileStream = File.Create(AvcConfigFile);
                ConfigFileStream.Close(); //avoid System.IO access violation
                //Some default values so this method can create a config file
                //modsIgnoreOverride.Add("Kopernicus"); //Unfortunately, the name of Kopernicus is actually "<b><color=#CA7B3C>Kopernicus</color></b>" which may irritates some users
                OverrideIsDisabledGlobal = true;
                ShowDefaultValues        = true;
                AvcInterval = 0;
                //UseKspSkin = true;
                CfgUpdated = true;
                //For some reason, if a config file is missing, it will just create an empty config.
                //By setting the bool CfgUpdated = true, this method will run again on destroy of the starter, which creates the empty config nodes within the file.
            }

            ConfigNode cfgnode = new ConfigNode();
            ConfigNode KSPAVC  = cfgnode.AddNode("KSP-AVC");

            //KSPAVC.AddValue("KSP_SKIN", UseKspSkin);
            KSPAVC.AddValue("OVERRIDE_PRIORITY", OverridePriority);
            KSPAVC.AddValue("SIMPLE_PRIORITY", SimplePriority);
            KSPAVC.AddValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE", OverrideIsDisabledGlobal);
            KSPAVC.AddValue("SHOW_DEFAULT_VALUES", ShowDefaultValues);
#if STRICT
            KSPAVC.AddValue("STRICT_VERSION", StrictVersion);
#endif

            ConfigNode OverrideName = KSPAVC.AddNode("OVERRIDE_NAME");
            foreach (string ModName in OverrideCompatibilityByName)
            {
                OverrideName.AddValue("OverrideEnabled", ModName);
            }

            ConfigNode OverrideVersion = KSPAVC.AddNode("OVERRIDE_VERSION");
            foreach (KeyValuePair <string, CompatVersions> kvp in CompatibleVersions)
            {
                string temp = kvp.Key.Replace("-1", "*");
                for (int i = 0; i < kvp.Value.compatibleWithVersion.Count; i++)
                {
                    temp = temp + $", {kvp.Value.compatibleWithVersion[i]}";
                }
                OverrideVersion.AddValue("OverrideEnabled", temp);
            }

            ConfigNode OverrideIgnore = KSPAVC.AddNode("OVERRIDE_IGNORE");
            foreach (string ModName in modsIgnoreOverride)
            {
                OverrideIgnore.AddValue("IgnoreOverride", ModName);
            }

            ConfigNode Interval = KSPAVC.AddNode("INTERVAL");
            {
                Interval.AddValue("MinTimeBetweenAvcRuns", AvcInterval.ToString() + " //Timespan between AVC runs in hours");

                if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0)
                {
                    Interval.AddValue("AvcRunsNext", DateTime.Now.AddHours(AvcInterval).ToString());
                    CfgUpdated = true;
                }
                else
                {
                    Interval.AddValue("AvcRunsNext", NextRun.ToString());
                }
            }
            cfgnode.Save(AvcConfigFile);
        }
示例#13
0
        protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context)
        {
            var _wiqid   = wiqid.Get(context);
            var _wiq     = wiq.Get(context);
            var dt       = DataTable.Get(context);
            var priority = Priority.Get <int>(context);
            var bulksize = BulkSize.Get <int>(context);

            if (bulksize < 1)
            {
                bulksize = 50;
            }
            var nextrun    = NextRun.Get <DateTime?>(context);
            var items      = new List <OpenRPA.Interfaces.AddWorkitem>();
            var filefields = Filefields.Get <string[]>(context);

            if (filefields == null)
            {
                filefields = new string[] { }
            }
            ;
            for (var i = 0; i < filefields.Length; i++)
            {
                filefields[i] = filefields[i].ToLower();
            }
            var counter     = 0;
            var bulkcounter = 0;

            if (dt == null)
            {
                Log.Warning("BulkAddWorkitems: Datatable is null");
                return(null);
            }
            if (dt.Rows == null)
            {
                Log.Warning("BulkAddWorkitems: Datatable contains no rows");
                return(null);
            }
            foreach (DataRow row in dt.Rows)
            {
                counter++;
                bulkcounter++;
                var wi = new Interfaces.AddWorkitem();
                wi.name     = "Bulk added item " + counter.ToString();
                wi.priority = priority;
                wi.nextrun  = nextrun;
                wi.payload  = new Dictionary <string, object>();
                var _files = new List <MessageWorkitemFile>();
                foreach (DataColumn field in dt.Columns)
                {
                    if (string.IsNullOrEmpty(field.ColumnName))
                    {
                        continue;
                    }
                    var columnname = field.ColumnName.ToLower();
                    wi.payload.Add(columnname, row[field.ColumnName]);
                    if (columnname == "name")
                    {
                        wi.name = row[field.ColumnName].ToString();
                    }
                    if (filefields.Contains(columnname))
                    {
                        if (field.DataType == typeof(string))
                        {
                            _files.Add(new MessageWorkitemFile()
                            {
                                filename = row[field.ColumnName].ToString()
                            });
                        }
                    }
                }
                wi.files = _files.ToArray();
                items.Add(wi);
                if (bulkcounter >= bulksize)
                {
                    await global.webSocketClient.AddWorkitems(_wiqid, _wiq, items.ToArray());

                    items.Clear();
                }
            }
            if (items.Count > 0)
            {
                await global.webSocketClient.AddWorkitems(_wiqid, _wiq, items.ToArray(),
                                                          Success_wiq.Get <string>(context), null, Failed_wiq.Get <string>(context), null);
            }
            return(null);
        }