コード例 #1
0
 public TaskItem(TaskFlag flag, Playground hive = null, PlaygroundHost host = null, string depotKey = null, string appId = null)
 {
     this.Flag = flag;
     this.Hive = hive;
     this.Host = host;
     this.DepotKey = depotKey;
     this.AppId = appId;
 }
コード例 #2
0
        /// <summary>
        /// Create a new hive on a host
        /// </summary>
        /// <remarks>
        /// The hive name is the current signed in user username.
        /// </remarks>
        /// <param name="host"></param>
        /// <param name="completionCallback"></param>
        /// <param name="progressCallback"></param>
        /// <param name="errorCallback"></param>
        public static void CreateHive(PlaygroundHost host, Action<Playground> completionCallback = null, Action<string, double> progressCallback = null, Action<ErrorResponse> errorCallback = null)
        {
            if (host == null) throw new ArgumentNullException("host");

            ConcurrentQueue<TaskItem> tasks = new ConcurrentQueue<TaskItem>();      // FIFO
            ConcurrentStack<TaskItem> revertList = new ConcurrentStack<TaskItem>(); // LIFO

            SystemUser user = SystemUser.GetCurrentSystemUser();
            if (user == null) {
                Utils.CallBack(errorCallback, Utils.GenerateError("Anonymous user can not create a hive"));
                return;
            }

            Playground hive = null;
            Db.Transact(() => {
                hive = new Playground();
                hive.PlaygroundHost = host;
                hive.Owner = user;
                hive.Created = hive.Updated = DateTime.UtcNow;
            });

            // Add tasks
            tasks.Enqueue(new TaskItem(TaskFlag.AllocatedPort, hive, host));
            tasks.Enqueue(new TaskItem(TaskFlag.CreateDatabase, hive, host));
            tasks.Enqueue(new TaskItem(TaskFlag.AddReverseProxy, hive, host));

            if (!string.IsNullOrEmpty(host.EntryPoint)) {
                tasks.Enqueue(new TaskItem(TaskFlag.AddUriAlias, hive, host));
            }

            // Install default apps
            QueryResultRows<DefaultApp> defaultApps = Db.SQL<DefaultApp>("SELECT o FROM PlaygroundKeeper.DefaultApp o WHERE o.PlaygroundHost=?", host);
            foreach (DefaultApp defaultApp in defaultApps) {
                tasks.Enqueue(new TaskItem(TaskFlag.InstallSoftware, hive, host, defaultApp.DepotKey, defaultApp.ID));
            }

            ProcessTasks(tasks, revertList, () => {

                try {
                    // Find created hive
                    foreach (TaskItem item in revertList) {
                        if (item.Hive != null) {
                            if (completionCallback != null) {
                                try {
                                    completionCallback(item.Hive);
                                }
                                catch (Exception e) {
                                    Program.PlaygroundKeeperLogSource.LogError(string.Format("UnhandledException, {0}", e.ToString()));
                                }
                            }
                            return;
                        }
                    }

                    Utils.CallBack(errorCallback, Utils.GenerateError("Failed to find the created hive."));
                }
                catch (Exception e) {
                    Utils.CallBack(errorCallback, Utils.GenerateError(e));
                }
            }, progressCallback, errorCallback);
        }
コード例 #3
0
        /// <summary>
        /// Install software in a hive
        /// </summary>
        /// <param name="depotKey"></param>
        /// <param name="appId"></param>
        /// <param name="hive"></param>
        /// <param name="completionCallback"></param>
        /// <param name="progressCallback"></param>
        /// <param name="errorCallback"></param>
        public static void InstallSoftware(string depotKey, string appId, Playground hive, Action<Playground> completionCallback = null, Action<string, double> progressCallback = null, Action<ErrorResponse> errorCallback = null)
        {
            if (string.IsNullOrEmpty(depotKey)) throw new ArgumentNullException("depotKey");
            if (string.IsNullOrEmpty(appId)) throw new ArgumentNullException("appId");
            if (hive == null) throw new ArgumentNullException("hive");
            if (hive.PlaygroundHost == null) throw new InvalidOperationException("hive.PlaygroundHost");

            ConcurrentQueue<TaskItem> tasks = new ConcurrentQueue<TaskItem>();      // FIFO
            ConcurrentStack<TaskItem> revertList = new ConcurrentStack<TaskItem>(); // LIFO

            // Add tasks
            tasks.Enqueue(new TaskItem(TaskFlag.InstallSoftware, hive, hive.PlaygroundHost, depotKey, appId));
            tasks.Enqueue(new TaskItem(TaskFlag.StartDatabase, hive, hive.PlaygroundHost));
            tasks.Enqueue(new TaskItem(TaskFlag.StartAllapplications, hive, hive.PlaygroundHost));

            ProcessTasks(tasks, revertList, () => {

                if (completionCallback != null) {
                    try {
                        completionCallback(hive);
                    }
                    catch (Exception e) {
                        Program.PlaygroundKeeperLogSource.LogError(string.Format("UnhandledException, {0}", e.ToString()));
                    }
                }
            }, progressCallback, errorCallback);
        }
コード例 #4
0
        private static void SyncHive(Playground hive, Action completionCallback, Action<ErrorResponse> errorCallback)
        {
            // TODO:

            if (completionCallback != null) {
                completionCallback();
            }
            //PlaygroundHost host;

            //Starcounter.RemoteAccess.API.GetDatabases(host.ApiIP, host.ApiPort, host.Username, host.Password, (databasesJson) => {

            //    foreach (DatabaseJson databaseJson in databasesJson.Items) {

            //        if (databaseJson.UserHttpPort == beginPortRange) {
            //            bExist = true;
            //            break;
            //        }
            //    }

            //    if (completionCallback != null) {
            //        completionCallback();
            //    }

            //}, (errorResponse) => {
            //    // Error
            //    if (errorCallback != null) {
            //        string errorMessage = string.Format("Failed to connect to the host ({0}:{1}) to allocated a free port number, {2}", this.ApiIP, this.ApiPort, errorResponse.Text);
            //        errorCallback(Utils.GenerateError(errorMessage));
            //    }
            //});
        }
コード例 #5
0
        /// <summary>
        /// Delete a hive
        /// </summary>
        /// <param name="host"></param>
        /// <param name="completionCallback"></param>
        /// <param name="progressCallback"></param>
        /// <param name="errorCallback"></param>
        public static void DeleteHive(Playground hive, Action completionCallback = null, Action<string, double> progressCallback = null, Action<ErrorResponse> errorCallback = null)
        {
            if (hive == null) throw new ArgumentNullException("hive");
            if (hive.PlaygroundHost == null) throw new InvalidOperationException("hive.PlaygroundHost");

            ConcurrentQueue<TaskItem> tasks = new ConcurrentQueue<TaskItem>();      // FIFO
            ConcurrentStack<TaskItem> revertList = new ConcurrentStack<TaskItem>(); // LIFO

            // Add tasks
            tasks.Enqueue(new TaskItem(TaskFlag.RemoveUriAlias, hive, hive.PlaygroundHost));
            tasks.Enqueue(new TaskItem(TaskFlag.RemoveReverseProxy, hive, hive.PlaygroundHost));
            tasks.Enqueue(new TaskItem(TaskFlag.DeleteDatabase, hive, hive.PlaygroundHost));
            tasks.Enqueue(new TaskItem(TaskFlag.UnAllocatedPort, hive, hive.PlaygroundHost));

            ProcessTasks(tasks, revertList, () => {

                Db.Transact(() => {
                    hive.Delete();
                });

                Utils.CallBack(completionCallback);

            }, progressCallback, errorCallback);
        }