Esempio n. 1
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            string Format = "{0,-30} | {1,-30}";

            IpcClient.Respond(string.Format(Format, "Username", "Groups"));
            foreach (User user in Program.UserManager.Users)
            {
                string Permissions = "";
                foreach (string Group in user.Groups)
                {
                    if (Permissions.Length != 0)
                    {
                        Permissions += ",";
                    }

                    Permissions += Group;
                }

                IpcClient.Respond(string.Format(Format, user.Username, Permissions));
            }

            IpcClient.Respond("");

            Program.SaveSettings();
        }
Esempio n. 2
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            UserGroup ExistingGroup = Program.UserManager.FindGroup(Name);

            if (ExistingGroup != null)
            {
                Program.UserManager.DeleteGroup(ExistingGroup);
                IpcClient.Respond(string.Format("SUCCESS: Removed group '{0}'.", Name));
            }
            else
            {
                IpcClient.Respond(string.Format("FAILED: Group '{0}' does not exist.", Name));
            }
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            User ExistingUser = Program.UserManager.FindUser(Username);

            if (ExistingUser != null)
            {
                Program.UserManager.DeleteUser(ExistingUser);
                IpcClient.Respond(string.Format("SUCCESS: Removed user '{0}'.", Username));
            }
            else
            {
                IpcClient.Respond(string.Format("FAILED: Username '{0}' does not exist.", Username));
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            if (Program.UserManager.FindUser(Username) != null)
            {
                IpcClient.Respond(string.Format("FAILED: Username '{0}' already exists.", Username));
            }
            else
            {
                Program.UserManager.CreateUser(Username);
                IpcClient.Respond(string.Format("SUCCESS: Added user '{0}'.", Username));
            }

            Program.SaveSettings();
        }
Esempio n. 5
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            string Format = "{0,-30}";

            IpcClient.Respond(string.Format(Format, "Name"));
            foreach (UserGroup user in Program.UserManager.UserGroups)
            {
                // TODO: Add more info to this.
                IpcClient.Respond(string.Format(Format, user.Name));
            }

            IpcClient.Respond("");

            Program.SaveSettings();
        }
Esempio n. 6
0
        /// <summary>
        /// </summary>
        private static void PollIpcServer()
        {
            if (!RespondingToIpc)
            {
                string   Command;
                string[] Args;
                if (IPCServer.Recieve(out Command, out Args))
                {
                    RespondingToIpc = true;

                    if (Command == "RunCommand")
                    {
                        Logger.Log(LogLevel.Warning, LogCategory.Main, "Recieved ipc command '{0} {1}'.", Command, string.Join(" ", Args));

                        Parser parser = new Parser(with => with.HelpWriter = new CommandIPCWriter(IPCServer));
                        ParserResult <object> parserResult = parser.ParseArguments <CommandLineAddOptions, CommandLineDeleteOptions, CommandLineListOptions, CommandLineConfigureOptions>(Args);
                        parserResult.WithParsed <CommandLineAddOptions>(opts => { opts.Run(IPCServer); });
                        parserResult.WithParsed <CommandLineDeleteOptions>(opts => { opts.Run(IPCServer); });
                        parserResult.WithParsed <CommandLineListOptions>(opts => { opts.Run(IPCServer); });
                        parserResult.WithParsed <CommandLineConfigureOptions>(opts => { opts.Run(IPCServer); });
                        parserResult.WithNotParsed(errs => { });

                        IPCServer.EndResponse();
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warning, LogCategory.Main, "Recieved unknown ipc command '{0}'.", Command);

                        IPCServer.Respond("Unknown Command");
                    }

                    RespondingToIpc = false;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            License license = License.Load(FilePath);

            if (license == null)
            {
                IpcClient.Respond(string.Format("FAILED: Unable to load valid license from '{0}'.", FilePath));
            }

            if (Program.LicenseMgr.Apply(license))
            {
                IpcClient.Respond(string.Format("SUCCESS: Applied license for '{0}' seats which is licensed to '{1}'.", license.MaxSeats == int.MaxValue ? "Unlimited" : license.MaxSeats.ToString(), license.LicensedTo));
            }
            else
            {
                IpcClient.Respond("FAILED: Unable to apply license, either invalid or expired.");
            }

            Program.SaveSettings();
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            UserPermissionType PermissionType;

            if (!Enum.TryParse(Permission, out PermissionType))
            {
                IpcClient.Respond(string.Format("FAILED: Permission '{0}' is not valid.", Permission));
                return;
            }

            UserGroup group = Program.UserManager.FindGroup(Name);

            if (group == null)
            {
                IpcClient.Respond(string.Format("FAILED: Group '{0}' does not exist.", Name));
            }
            else
            {
                Program.UserManager.GrantPermission(group, PermissionType, Path);
                IpcClient.Respond(string.Format("SUCCESS: Granted group '{0}' permission '{1}' on '{2}'.", Name, Permission, Path));
            }
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            UserGroup group = Program.UserManager.FindGroup(GroupName);

            if (group == null)
            {
                IpcClient.Respond(string.Format("FAILED: Group '{0}' does not exist.", GroupName));
                return;
            }

            User user = Program.UserManager.FindUser(Username);

            if (user == null)
            {
                IpcClient.Respond(string.Format("FAILED: User '{0}' does not exist.", GroupName));
                return;
            }

            Program.UserManager.RemoveUserFromGroup(user, group);
            IpcClient.Respond(string.Format("SUCCESS: Removed user '{0}' from group '{1}'.", Username, GroupName));

            Program.SaveSettings();
        }
Esempio n. 10
0
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            VirtualPath = VirtualFileSystem.Normalize(VirtualPath);

            if (!Program.NetClient.IsConnected)
            {
                IpcClient.Respond("FAILED: No connection to server.");
                return;
            }

            bool GotResults = false;

            BuildsRecievedHandler BuildsRecievedHandler = (RootPath, Builds) =>
            {
                if (GotResults)
                {
                    return;
                }

                if (RootPath == VirtualPath)
                {
                    string Format = "{0,-30} | {1,-40} | {2,-25}";

                    IpcClient.Respond(string.Format(Format, "Path", "Id", "Create Time"));
                    foreach (NetMessage_GetBuildsResponse.BuildInfo Info in Builds)
                    {
                        if (Info.Guid == Guid.Empty)
                        {
                            IpcClient.Respond(string.Format(Format, VirtualFileSystem.GetNodeName(Info.VirtualPath), "", ""));
                        }
                        else
                        {
                            IpcClient.Respond(string.Format(Format, VirtualFileSystem.GetNodeName(Info.VirtualPath), Info.Guid, Info.CreateTime));
                        }
                    }

                    IpcClient.Respond("");

                    GotResults = true;
                }
            };

            Program.NetClient.OnBuildsRecieved += BuildsRecievedHandler;

            if (!Program.NetClient.RequestBuilds(VirtualPath))
            {
                IpcClient.Respond("FAILED: Failed to request builds for unknown reason.");
                return;
            }

            Program.PumpLoop(
                () =>
            {
                if (!Program.NetClient.IsConnected)
                {
                    IpcClient.Respond("FAILED: Lost connection to server.");
                    return(true);
                }

                return(GotResults);
            }
                );

            Program.NetClient.OnBuildsRecieved -= BuildsRecievedHandler;
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            PropertyInfo Property = null;

            foreach (PropertyInfo Potential in Program.Settings.GetType().GetProperties())
            {
                if (Potential.Name.ToLower() == Name.ToLower())
                {
                    Property = Potential;
                    break;
                }
            }

            if (Property == null)
            {
                IpcClient.Respond(string.Format("FAILED: Setting '{0}' does not exist.", Name));
                return;
            }

            // Calcualte correct value to set property to.
            object ValueToSet = null;

            if (Property.PropertyType == typeof(string))
            {
                ValueToSet = Value;
            }
            else if (Property.PropertyType == typeof(int))
            {
                int Result = 0;
                if (!int.TryParse(Value, out Result))
                {
                    IpcClient.Respond(string.Format("FAILED: Value '{0}' is not a valid int.", Value));
                    return;
                }

                ValueToSet = Result;
            }
            else if (Property.PropertyType == typeof(float))
            {
                float Result = 0;
                if (!float.TryParse(Value, out Result))
                {
                    IpcClient.Respond(string.Format("FAILED: Value '{0}' is not a valid float.", Value));
                    return;
                }

                ValueToSet = Result;
            }
            else if (Property.PropertyType == typeof(bool))
            {
                bool Result = false;
                if (Value == "1")
                {
                    Result = true;
                }
                else if (Value == "0")
                {
                    Result = false;
                }
                else
                {
                    if (!bool.TryParse(Value, out Result))
                    {
                        IpcClient.Respond(string.Format("FAILED: Value '{0}' is not a valid bool.", Value));
                        return;
                    }
                }

                ValueToSet = Result;
            }
            else if (Property.PropertyType == typeof(bool))
            {
                bool Result = false;
                if (Value == "1")
                {
                    Result = true;
                }
                else if (Value == "0")
                {
                    Result = false;
                }
                else
                {
                    if (!bool.TryParse(Value, out Result))
                    {
                        IpcClient.Respond(string.Format("FAILED: Value '{0}' is not a valid bool.", Value));
                        return;
                    }
                }

                ValueToSet = Result;
            }
            else
            {
                IpcClient.Respond(string.Format("FAILED: Setting '{0}' cannot be set externally.", Name));
                return;
            }

            // Check if we don't need to modify the setting.
            if (Property.GetValue(Program.Settings).ToString() == ValueToSet.ToString())
            {
                IpcClient.Respond(string.Format("FAILED: Setting '{0}' already set to given value.", Name));
                return;
            }

            // Update the value.
            IpcClient.Respond(string.Format("Applying value '{1}' to '{0}'.", Name, Value));
            Property.SetValue(Program.Settings, ValueToSet);
            Program.SaveSettings();
            Program.ApplySettings();
            IpcClient.Respond(string.Format("SUCCESS: Setting '{0}' was set to '{1}'.", Name, Value));
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            VirtualPath = VirtualFileSystem.Normalize(VirtualPath);

            string ParentPath = VirtualFileSystem.GetParentPath(VirtualPath);
            string NodeName   = VirtualFileSystem.GetNodeName(VirtualPath);

            bool DeleteInProgress = false;
            bool IsComplete       = false;

            if (!Program.NetClient.IsConnected)
            {
                IpcClient.Respond("FAILED: No connection to server.");
                return;
            }

            if (!Program.NetClient.Permissions.HasPermission(UserPermissionType.Write, "", false, true))
            {
                IpcClient.Respond("FAILED: Permission denied to manage builds.");
                return;
            }

            BuildsRecievedHandler BuildsRecievedHandler = (RootPath, Builds) =>
            {
                if (RootPath == ParentPath && !DeleteInProgress)
                {
                    bool Found = false;

                    foreach (NetMessage_GetBuildsResponse.BuildInfo Info in Builds)
                    {
                        if (VirtualFileSystem.GetNodeName(Info.VirtualPath).ToLower() == NodeName.ToLower())
                        {
                            if (Info.Guid == Guid.Empty)
                            {
                                IpcClient.Respond("FAILED: Path is not a build.");
                                IsComplete = true;
                            }
                            else
                            {
                                IpcClient.Respond(string.Format("Deleting manifest with guid: {0}", Info.Guid));
                                Program.NetClient.DeleteManifest(Info.Guid);
                            }

                            Found = true;
                            break;
                        }
                    }

                    if (!Found)
                    {
                        IpcClient.Respond("FAILED: Path is not a build.");
                        IsComplete = true;
                    }

                    DeleteInProgress = true;
                }
            };

            ManifestDeleteResultRecievedHandler ManifestRecieveHandler = Id =>
            {
                IpcClient.Respond("SUCCESS: Deleted manifest.");
                IsComplete = true;
            };

            Program.NetClient.OnBuildsRecieved += BuildsRecievedHandler;
            Program.NetClient.OnManifestDeleteResultRecieved += ManifestRecieveHandler;

            if (!Program.NetClient.RequestBuilds(ParentPath))
            {
                IpcClient.Respond("FAILED: Failed to request builds for unknown reason.");
                return;
            }

            Program.PumpLoop(
                () =>
            {
                if (!Program.NetClient.IsConnected)
                {
                    IpcClient.Respond("FAILED: Lost connection to server.");
                    return(true);
                }

                return(IsComplete);
            }
                );

            Program.NetClient.OnManifestDeleteResultRecieved -= ManifestRecieveHandler;
            Program.NetClient.OnBuildsRecieved -= BuildsRecievedHandler;
        }
        /// <summary>
        ///     Called when the CLI invokes this command.
        /// </summary>
        /// <param name="IpcClient">Interprocess communication pipe to the application that invoked this command.</param>
        internal void Run(CommandIPC IpcClient)
        {
            VirtualPath = VirtualFileSystem.Normalize(VirtualPath);

            if (!Directory.Exists(LocalPath))
            {
                IpcClient.Respond("FAILED: Path does not exists: {0}");
                return;
            }

            if (!Program.NetClient.IsConnected)
            {
                IpcClient.Respond("FAILED: No connection to server.");
                return;
            }

            if (!Program.NetClient.Permissions.HasPermission(UserPermissionType.Write, "", false, true))
            {
                IpcClient.Respond("FAILED: Permission denied to manage builds.");
                return;
            }

            PublishBuildTask     Publisher         = new PublishBuildTask();
            BuildPublishingState OldPublisherState = BuildPublishingState.Unknown;
            int OldPublisherProgress = 0;

            Publisher.Start(VirtualPath, LocalPath);

            Program.PumpLoop(
                () =>
            {
                if (!Program.NetClient.IsConnected)
                {
                    IpcClient.Respond("FAILED: Lost connection to server.");
                    return(true);
                }

                if (Publisher != null && (Publisher.State != OldPublisherState || (int)Publisher.Progress != OldPublisherProgress))
                {
                    OldPublisherState    = Publisher.State;
                    OldPublisherProgress = (int)Publisher.Progress;

                    switch (Publisher.State)
                    {
                    case BuildPublishingState.CopyingFiles:
                        {
                            IpcClient.Respond(string.Format("Copying files to storage: {0}%", OldPublisherProgress));
                            break;
                        }

                    case BuildPublishingState.ScanningFiles:
                        {
                            IpcClient.Respond(string.Format("Scanning local files: {0}%", OldPublisherProgress));
                            break;
                        }

                    case BuildPublishingState.UploadingManifest:
                        {
                            IpcClient.Respond("Uploading manfiest to server.");
                            break;
                        }

                    case BuildPublishingState.FailedVirtualPathAlreadyExists:
                        {
                            IpcClient.Respond(string.Format("FAILED: Build already exists at path '{0}'.", VirtualPath));
                            return(true);
                        }

                    case BuildPublishingState.PermissionDenied:
                        {
                            IpcClient.Respond(string.Format("FAILED: Permission denied to path '{0}'.", VirtualPath));
                            return(true);
                        }

                    case BuildPublishingState.FailedGuidAlreadyExists:
                        {
                            IpcClient.Respond("FAILED: Manifest with same GUID already exists.");
                            return(true);
                        }

                    case BuildPublishingState.Success:
                        {
                            Publisher.Commit();
                            Publisher = null;
                            IpcClient.Respond("SUCCESS: Build added successfully.");
                            return(true);
                        }

                    case BuildPublishingState.Failed:
                    default:
                        {
                            IpcClient.Respond("FAILED: Undefined reason.");
                            return(true);
                        }
                    }
                }

                return(false);
            }
                );
        }