Inheritance: IScheduledTaskStatus
Esempio n. 1
0
 public static ScheduledTaskStatusLive FromScheduledTaskStatus(ScheduledTaskStatus Status, string[] ChangedProperties)
 {
     return new ScheduledTaskStatusLive()
     {
         TaskName = Status.TaskName,
         SessionId = Status.SessionId,
         Progress = Status.Progress,
         CurrentProcess = Status.CurrentProcess,
         CurrentDescription = Status.CurrentDescription,
         CancelSupported = Status.CancelSupported,
         TaskExceptionMessage = (Status.TaskException == null ? null : Status.TaskException.Message),
         IsCancelling = Status.IsCanceling,
         IsRunning = Status.IsRunning,
         StartedTimestamp = Status.StartedTimestamp,
         FinishedTimestamp = Status.FinishedTimestamp,
         NextScheduledTimestamp = Status.NextScheduledTimestamp,
         FinishedMessage = Status.FinishedMessage,
         FinishedUrl = Status.FinishedUrl,
         StatusVersion = Status.StatusVersion,
         ChangedProperties = ChangedProperties
     };
 }
Esempio n. 2
0
        public static ScheduledTaskStatus RegisterTask(ScheduledTask Task, TriggerBuilder TaskBuilder)
        {
            var sessionId = Guid.NewGuid().ToString("D");
            var triggerKey = GenerateTriggerKey();
            var taskType = Task.GetType();

            var taskStatus = new ScheduledTaskStatus(Task, sessionId, triggerKey.Name);

            lock (_RunningTasksLock)
            {
                if (Task.SingleInstanceTask)
                {
                    var existingGuid = _RunningTasks.Where(t => t.IsRunning && t.TaskType == taskType).Select(t => t.SessionId).FirstOrDefault();
                    if (existingGuid != null)
                        throw new InvalidOperationException(string.Format("This Single-Instance Task is already running, SessionId: {0}", existingGuid));
                }
                _RunningTasks.Add(taskStatus);
            }

            if (TaskBuilder != null)
            {
                ITrigger trigger = TaskBuilder.WithIdentity(triggerKey).Build();
                IJobDetail jobDetails = new JobDetailImpl(sessionId, taskType)
                {
                    Description = Task.TaskName,
                    JobDataMap = trigger.JobDataMap
                };

                _TaskScheduler.ScheduleJob(jobDetails, trigger);

                var nextTriggerTime = trigger.GetNextFireTimeUtc();
                if (nextTriggerTime.HasValue)
                    taskStatus.SetNextScheduledTimestamp(nextTriggerTime.Value.LocalDateTime);
            }

            return taskStatus;
        }
Esempio n. 3
0
 public virtual void Uninstall(DiscoDataContext Database, bool UninstallData, ScheduledTaskStatus Status) { return; }
Esempio n. 4
0
 // Events/Triggers for Custom Plugin Initialization (Optional)
 public virtual void Install(DiscoDataContext Database, ScheduledTaskStatus Status) { return; }
Esempio n. 5
0
        internal bool InstallPlugin(DiscoDataContext Database, ScheduledTaskStatus Status)
        {
            // Initialize Plugin
            InitializePluginEnvironment(Database);

            using (var pluginInstance = this.CreateInstance())
            {
                pluginInstance.Install(Database, Status);
            }

            return true;
        }
Esempio n. 6
0
        internal static void ExecuteTaskInternal(ScheduledTaskStatus Status, string pluginPackagesLocation, List<Tuple<PluginManifest, string, PluginLibraryItemV2, PluginLibraryItemReleaseV2>> UpdatePlugins)
        {
            while (UpdatePlugins.Count > 0)
            {
                var updatePlugin = UpdatePlugins[0];
                var existingManifest = updatePlugin.Item1;
                var packageTempFilePath = updatePlugin.Item2;
                var libraryItem = updatePlugin.Item3;
                var libraryItemRelease = updatePlugin.Item4;
                UpdatePlugins.Remove(updatePlugin);

                var pluginId = existingManifest != null ? existingManifest.Id : libraryItemRelease.PluginId;
                var pluginName = existingManifest != null ? existingManifest.Name : libraryItem.Name;

                if (string.IsNullOrEmpty(packageTempFilePath))
                {
                    // Download Update
                    Status.UpdateStatus(0, string.Format("Downloading Plugin Package: {0}", pluginName), "Connecting...");
                    packageTempFilePath = Path.Combine(pluginPackagesLocation, string.Format("{0}.discoPlugin", pluginId));

                    if (File.Exists(packageTempFilePath))
                        File.Delete(packageTempFilePath);

                    if (!Directory.Exists(Path.GetDirectoryName(packageTempFilePath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(packageTempFilePath));

                    // Need to Download the Package
                    using (HttpClient httpClient = new HttpClient())
                    {
                        Status.UpdateStatus(0, "Downloading...");

                        using (var httpResponse = httpClient.GetAsync(libraryItemRelease.DownloadUrl).Result)
                        {
                            httpResponse.EnsureSuccessStatusCode();

                            using (FileStream fsOut = new FileStream(packageTempFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                httpResponse.Content.ReadAsStreamAsync().Result.CopyTo(fsOut);
                            }
                        }
                    }
                }

                Status.UpdateStatus(10, "Opening Plugin Package", Path.GetFileName(packageTempFilePath));

                PluginManifest updateManifest;

                using (var packageStream = File.OpenRead(packageTempFilePath))
                {
                    using (ZipArchive packageArchive = new ZipArchive(packageStream, ZipArchiveMode.Read, false))
                    {

                        ZipArchiveEntry packageManifestEntry = packageArchive.GetEntry("manifest.json");
                        if (packageManifestEntry == null)
                            throw new InvalidDataException("The plugin package does not contain the 'manifest.json' entry");

                        using (Stream packageManifestStream = packageManifestEntry.Open())
                        {
                            updateManifest = PluginManifest.FromPluginManifestFile(packageManifestStream);
                        }
                    }
                }

                // Ensure not already installed
                if (existingManifest != null)
                    if (updateManifest.Version < existingManifest.Version)
                        throw new InvalidOperationException("Older versions cannot update existing plugins");

                Status.UpdateStatus(20, string.Format("{0} [{1} v{2}] by {3}", updateManifest.Name, updateManifest.Id, updateManifest.Version.ToString(4), updateManifest.Author), "Initializing Update Environment");

                using (DiscoDataContext database = new DiscoDataContext())
                {
                    // Check for Compatibility
                    var incompatibilityLibrary = PluginLibrary.LoadManifest(database).LoadIncompatibilityData();
                    PluginIncompatibility incompatibility;
                    if (!incompatibilityLibrary.IsCompatible(updateManifest.Id, updateManifest.Version, out incompatibility))
                        throw new InvalidOperationException(string.Format("The plugin [{0} v{1}] is not compatible: {2}", updateManifest.Id, updateManifest.VersionFormatted, incompatibility.Reason));

                    var updatePluginPath = Path.Combine(database.DiscoConfiguration.PluginsLocation, string.Format("{0}.discoPlugin", updateManifest.Id));
                    File.Move(packageTempFilePath, updatePluginPath);

                    if (existingManifest != null)
                    {
                        PluginsLog.LogBeforeUpdate(existingManifest, updateManifest);
                    }
                }
            }
        }
Esempio n. 7
0
        internal static void UpdateOffline(ScheduledTaskStatus Status)
        {
            PluginLibraryManifestV2 libraryManifest = null;
            PluginLibraryIncompatibility libraryIncompatibility = null;
            List<PluginManifest> installedPluginManifests;
            string pluginPackagesLocation;
            List<Tuple<PluginManifest, string, PluginLibraryItemV2, PluginLibraryItemReleaseV2>> updatePlugins =
                new List<Tuple<PluginManifest, string, PluginLibraryItemV2, PluginLibraryItemReleaseV2>>();


            using (DiscoDataContext database = new DiscoDataContext())
            {
                pluginPackagesLocation = database.DiscoConfiguration.PluginPackagesLocation;
                installedPluginManifests = OfflineInstalledPlugins(database);

                if (installedPluginManifests.Count > 0){
                    libraryManifest = PluginLibrary.LoadManifest(database);
                    libraryIncompatibility = libraryManifest.LoadIncompatibilityData();
                }
            }

            if (libraryManifest != null && installedPluginManifests.Count > 0)
            {
                foreach (var pluginManifest in installedPluginManifests)
                {
                    // Check for Update
                    var libraryItem = libraryManifest.Plugins.FirstOrDefault(i => i.Id == pluginManifest.Id);

                    if (libraryItem != null)
                    {
                        var libraryItemRelease = libraryItem.LatestCompatibleRelease(libraryIncompatibility);

                        if (libraryItemRelease != null && Version.Parse(libraryItemRelease.Version) > pluginManifest.Version)
                        { // Update Available
                            updatePlugins.Add(Tuple.Create(pluginManifest, (string)null, libraryItem, libraryItemRelease));
                        }
                    }
                }
            }

            if (updatePlugins.Count > 0)
            {
                ExecuteTaskInternal(Status, pluginPackagesLocation, updatePlugins);
            }
        }