예제 #1
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "block")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "availability" &&
                args.Current != "avail")
            {
                return(CommandResultCode.SyntaxError);
            }

            try {
                Random r = new Random();
                BlockMapProcess(networkContext, new BlockMapProcessImpl(this, networkContext, r));
            } catch (Exception e) {
                Error.WriteLine("unable to fix block availability: " + e.Message);
                return(CommandResultCode.ExecutionFailed);
            }

            return(CommandResultCode.Success);
        }
예제 #2
0
파일: FixCommand.cs 프로젝트: ikvm/cloudb
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext) context;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "block")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "availability" &&
                args.Current != "avail")
                return CommandResultCode.SyntaxError;

            try {
                Random r = new Random();
                BlockMapProcess(networkContext, new BlockMapProcessImpl(this, networkContext, r));

            } catch(Exception e) {
                Error.WriteLine("unable to fix block availability: " + e.Message);
                return CommandResultCode.ExecutionFailed;
            }

            return CommandResultCode.Success;
        }
예제 #3
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (!args.Current.Equals("path"))
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string pathName = args.Current;

            NetworkContext networkContext = (NetworkContext) context;
            PathInfo pathInfo = networkContext.Network.GetPathInfo(pathName);
            if (pathInfo == null) {
                Out.WriteLine("The path '" + pathName + "' was not found.");
                return CommandResultCode.ExecutionFailed;
            }

            IServiceAddress address = pathInfo.RootLeader;

            Out.Write("Root " + address);
            Out.WriteLine(" is managing path " + pathName);
            Out.Flush();
            return CommandResultCode.Success;
        }
예제 #4
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.Current.Equals("path"))
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string pathName = args.Current;

            NetworkContext networkContext = (NetworkContext)context;
            PathInfo       pathInfo       = networkContext.Network.GetPathInfo(pathName);

            if (pathInfo == null)
            {
                Out.WriteLine("The path '" + pathName + "' was not found.");
                return(CommandResultCode.ExecutionFailed);
            }

            IServiceAddress address = pathInfo.RootLeader;

            Out.Write("Root " + address);
            Out.WriteLine(" is managing path " + pathName);
            Out.Flush();
            return(CommandResultCode.Success);
        }
예제 #5
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string alias = args.Current;
            // no quoted aliases..
            if (alias.StartsWith("\"") || alias.StartsWith("'"))
                return CommandResultCode.SyntaxError;

            // unless we override an alias, moan, if this command already
            // exists.
            if (!Application.Commands.Aliases.HasAlias(alias) &&
                Application.Commands.ContainsCommand(alias)) {
                Error.WriteLine("cannot alias built-in command!");
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            String value = StripQuotes(args.Current); // rest of values.
            Application.Commands.Aliases.AddAlias(alias, value);
            return CommandResultCode.Success;
        }
예제 #6
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "path")
            {
                return(CommandResultCode.SyntaxError);
            }

            string pathName    = args.Current;
            string rootAddress = null;

            if (args.MoveNext())
            {
                if (args.Current != "from")
                {
                    return(CommandResultCode.SyntaxError);
                }

                if (!args.MoveNext())
                {
                    return(CommandResultCode.SyntaxError);
                }

                rootAddress = args.Current;
            }

            return(RemovePath(networkContext, pathName, rootAddress));
        }
예제 #7
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = context as NetworkContext;

            if (networkContext == null)
            {
                return(CommandResultCode.ExecutionFailed);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string role = args.Current;

            IServiceAddress address = null;

            if (args.MoveNext())
            {
                if (args.Current != "on")
                {
                    return(CommandResultCode.SyntaxError);
                }

                if (!args.MoveNext())
                {
                    return(CommandResultCode.SyntaxError);
                }

                try {
                    address = ServiceAddresses.ParseString(args.Current);
                } catch (Exception) {
                    Error.WriteLine("Invalid service address");
                    return(CommandResultCode.ExecutionFailed);
                }
            }
            else
            {
                IServiceAddress[] addresses = networkContext.Network.Configuration.NetworkNodes;
                if (addresses != null && addresses.Length == 1)
                {
                    address = addresses[0];
                }
            }

            if (address == null)
            {
                Error.WriteLine("cannot determine the address of the service to stop.");
                return(CommandResultCode.ExecutionFailed);
            }

            return(StopRole(networkContext, role, address));
        }
예제 #8
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "path")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string pathName = args.Current;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "to")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string time = args.Current;

            bool hours = false;

            if (args.MoveNext())
            {
                if (args.Current != "hours")
                {
                    return(CommandResultCode.SyntaxError);
                }

                hours = true;
            }

            try {
                return(Rollback(networkContext, pathName, time, hours));
            } catch (Exception) {
                Error.WriteLine("unable to rollback the path to the given date.");
                Error.WriteLine();
                return(CommandResultCode.ExecutionFailed);
            }
        }
예제 #9
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string varname = args.Current;
            string[] newArgs = new string[args.Count-1];
            while (args.MoveNext()) {
                newArgs[args.CurrentIndex - 1] = args.Current;
            }

            string param = String.Join(" ", newArgs);
            int pos = 0;
            int paramLength = param.Length;
            // skip whitespace after 'set'
            while (pos < paramLength
                   && Char.IsWhiteSpace(param[pos])) {
                ++pos;
            }
            // skip non-whitespace after 'set  ': variable name
            while (pos < paramLength
                   && !Char.IsWhiteSpace(param[pos])) {
                ++pos;
            }
            // skip whitespace before vlue..
            while (pos < paramLength
                   && Char.IsWhiteSpace(param[pos])) {
                ++pos;
            }
            String value = param.Substring(pos);
            if (value.StartsWith("\"") && value.EndsWith("\"")) {
                value = value.Substring(1, value.Length - 2);
            } else if (value.StartsWith("\'") && value.EndsWith("\'")) {
                value = value.Substring(1, value.Length - 2);
            }

            try {
                PropertyRegistry properties = Properties;
                if (properties == null)
                    throw new Exception("The current context doesn't support properties.");

                properties.SetProperty(varname, value);
            } catch (Exception e) {
                Application.Error.WriteLine(e.Message);
                return CommandResultCode.ExecutionFailed;
            }
            return CommandResultCode.Success;
        }
예제 #10
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            ISettingsHandler handler = Application as ISettingsHandler;
            if (handler == null) {
                Error.WriteLine("The application doesn't support settings.");
                return CommandResultCode.ExecutionFailed;
            }

            if (args.MoveNext())
                return CommandResultCode.SyntaxError;

            VarColumns[0].ResetWidth();
            VarColumns[1].ResetWidth();

            TableRenderer table = new TableRenderer(VarColumns, Out);
            table.EnableHeader = true;
            table.EnableFooter = true;
            foreach(KeyValuePair<string, string> setting in handler.Settings) {
                if (setting.Key == ApplicationSettings.SpecialLastCommand)
                    continue;

                ColumnValue[] row = new ColumnValue[4];
                row[0] = new ColumnValue(setting.Key);
                row[1] = new ColumnValue(setting.Value);
                table.AddRow(row);
            }

            table.CloseTable();
            Error.WriteLine();

            return CommandResultCode.Success;
        }
예제 #11
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (args.MoveNext())
                return CommandResultCode.SyntaxError;

            NetworkContext networkContext = context as NetworkContext;
            if (networkContext == null)
                return CommandResultCode.ExecutionFailed;

            Out.WriteLine();
            Out.WriteLine("refreshing...");
            Out.Flush();

            networkContext.Network.Refresh();

            try {
                //TODO:
                // networkContext.Network.Configuration.Reload();
            } catch (IOException e) {
                Error.WriteLine("Unable to refresh network config due to IO error");
                Error.WriteLine(e.Message);
                Error.WriteLine(e.StackTrace);
            }

            Out.WriteLine("done.");
            Out.WriteLine();

            return CommandResultCode.Success;
        }
예제 #12
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
            {
                ProductInfo  product = ProductInfo.Current;
                StringWriter writer  = new StringWriter();
                writer.WriteLine("---------------------------------------------------------------------------");
                writer.WriteLine(" {0} {1} {2}", product.Title, product.Version, product.Copyright);
                writer.WriteLine();
                writer.WriteLine(" CloudB Admin is provided AS IS and comes with ABSOLUTELY NO WARRANTY");
                writer.WriteLine(" This is free software, and you are welcome to redistribute it under the");
                writer.WriteLine(" conditions of the Lesser GNU Public License.");
                writer.WriteLine("---------------------------------------------------------------------------");
                Out.Write(writer.ToString());
                return(CommandResultCode.Success);
            }

            if (args.Current == "version")
            {
                //TODO:
            }
            else if (args.Current == "license")
            {
                Out.WriteLine("Lesser GNU Public License <http://www.gnu.org/licenses/lgpl.txt>");
                return(CommandResultCode.Success);
            }

            return(CommandResultCode.SyntaxError);
        }
예제 #13
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (args.Count != 1)
                return CommandResultCode.SyntaxError;

            PropertyRegistry properties = Properties;
            if (properties == null) {
                Application.Error.WriteLine("the current context does not support properties.");
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            String name = args.Current;
            PropertyHolder holder = properties.GetProperty(name);
            if (holder == null)
                return CommandResultCode.ExecutionFailed;

            string defaultValue = holder.DefaultValue;

            try {
                properties.SetProperty(name, defaultValue);
            } catch (Exception) {
                Application.Error.WriteLine("setting to default '" + defaultValue + "' failed.");
                return CommandResultCode.ExecutionFailed;
            }
            return CommandResultCode.Success;
        }
예제 #14
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            NetworkContext networkContext = context as NetworkContext;

            if (networkContext == null)
            {
                return(CommandResultCode.ExecutionFailed);
            }

            Out.WriteLine();
            Out.WriteLine("refreshing...");
            Out.Flush();

            networkContext.Network.Refresh();

            try {
                //TODO:
                // networkContext.Network.Configuration.Reload();
            } catch (IOException e) {
                Error.WriteLine("Unable to refresh network config due to IO error");
                Error.WriteLine(e.Message);
                Error.WriteLine(e.StackTrace);
            }

            Out.WriteLine("done.");
            Out.WriteLine();

            return(CommandResultCode.Success);
        }
예제 #15
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            PropertyRegistry properties = Properties;
            if (properties == null) {
                Application.Error.WriteLine("the current context does not support properties.");
                return CommandResultCode.ExecutionFailed;
            }

            if (args.MoveNext()) {
                string name = args.Current;
                PropertyHolder holder = properties.GetProperty(name);
                if (holder == null)
                    return CommandResultCode.ExecutionFailed;

                PrintDescription(name, holder, Application.Error);
                return CommandResultCode.Success;
            }

            ProperiesColumns[0].ResetWidth();
            ProperiesColumns[1].ResetWidth();
            TableRenderer table = new TableRenderer(ProperiesColumns, Application.Out);
            foreach(KeyValuePair<string, PropertyHolder> entry in properties) {
                ColumnValue[] row = new ColumnValue[3];
                PropertyHolder holder = entry.Value;
                row[0] = new ColumnValue(entry.Key);
                row[1] = new ColumnValue(holder.Value);
                row[2] = new ColumnValue(holder.ShortDescription);
                table.AddRow(row);
            }
            table.CloseTable();
            return CommandResultCode.Success;
        }
예제 #16
0
파일: ShowCommand.cs 프로젝트: ikvm/cloudb
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (context == null)
                return CommandResultCode.ExecutionFailed;

            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (args.Current == "analytics") {

            } else if (args.Current == "free") {

            } else if (args.Current == "network") {
                ShowNetwork(networkContext);
                return CommandResultCode.Success;
            } else if (args.Current == "paths") {
                return ShowPaths(networkContext);
            } else if (args.Current == "status") {
                ShowStatus(networkContext);
                return CommandResultCode.Success;
            } else {
                return CommandResultCode.SyntaxError;
            }

            return CommandResultCode.ExecutionFailed;
        }
예제 #17
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext()) {
                ProductInfo product = ProductInfo.Current;
                StringWriter writer = new StringWriter();
                writer.WriteLine("---------------------------------------------------------------------------");
                writer.WriteLine(" {0} {1} {2}", product.Title, product.Version, product.Copyright);
                writer.WriteLine();
                writer.WriteLine(" CloudB Admin is provided AS IS and comes with ABSOLUTELY NO WARRANTY");
                writer.WriteLine(" This is free software, and you are welcome to redistribute it under the");
                writer.WriteLine(" conditions of the Lesser GNU Public License.");
                writer.WriteLine("---------------------------------------------------------------------------");
                Out.Write(writer.ToString());
                return CommandResultCode.Success;
            }

            if (args.Current == "version") {
                //TODO:
            } else if (args.Current == "license") {
                Out.WriteLine("Lesser GNU Public License <http://www.gnu.org/licenses/lgpl.txt>");
                return CommandResultCode.Success;
            }

            return CommandResultCode.SyntaxError;
        }
예제 #18
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            ISettingsHandler handler = Application as ISettingsHandler;
            if (handler == null) {
                Error.WriteLine("The application doesn't support settings.");
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string varName = args.Current;
            bool success = UnsetVariable(varName, handler.Settings);

            while (args.MoveNext()) {
                success |= UnsetVariable(args.Current, handler.Settings);
            }

            return success ? CommandResultCode.Success : CommandResultCode.ExecutionFailed;
        }
예제 #19
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext) context;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "path")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string pathName = args.Current;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "to")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string time = args.Current;

            bool hours = false;

            if (args.MoveNext()) {
                if (args.Current != "hours")
                    return CommandResultCode.SyntaxError;

                hours = true;
            }

            try {
                Rollback(networkContext, pathName, time, hours);
            } catch(Exception) {
                Error.WriteLine("unable to rollback the path to the given date.");
                Error.WriteLine();
                return CommandResultCode.ExecutionFailed;
            }

            return CommandResultCode.Success;
        }
예제 #20
0
            public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
            {
                if (args.MoveNext())
                {
                    ((TestApplication)Application).appDir = args.Current;
                }

                TestApplication app = (TestApplication)Application;

                app.Configure();
                return(CommandResultCode.Success);
            }
예제 #21
0
파일: StartCommand.cs 프로젝트: ikvm/cloudb
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = context as NetworkContext;
            if (networkContext == null)
                return CommandResultCode.ExecutionFailed;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string role = args.Current;

            IServiceAddress address = null;

            if (args.MoveNext()) {
                if (args.Current != "on")
                    return CommandResultCode.SyntaxError;

                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;

                try {
                    address = ServiceAddresses.ParseString(args.Current);
                } catch(Exception) {
                    Error.WriteLine("The address specified is invalid.");
                    return CommandResultCode.ExecutionFailed;
                }
            } else {
                IServiceAddress[] addresses = networkContext.Network.Configuration.NetworkNodes;
                if (addresses != null && addresses.Length == 1)
                    address = addresses[0];
            }

            if (address == null) {
                Error.WriteLine("unable to determine the address of the service to start.");
                return CommandResultCode.ExecutionFailed;
            }

            return StartRole(networkContext, role, address);
        }
예제 #22
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (context == null)
                return CommandResultCode.ExecutionFailed;

            if (args.MoveNext())
                return CommandResultCode.SyntaxError;

            ((CloudAdmin)Application).SetNetworkContext(null);

            Out.WriteLine("successfully disconnected...");
            Out.WriteLine();
            return CommandResultCode.Success;
        }
예제 #23
0
파일: SetCommand.cs 프로젝트: deveel/dshell
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!(Application is ISettingsHandler)) {
                Error.WriteLine("The application doesn't support settings.");
                return CommandResultCode.ExecutionFailed;
            }

            ApplicationSettings settings = ((ISettingsHandler) Application).Settings;

            int argc = args.Count;
            if (argc < 2)
                return CommandResultCode.SyntaxError;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string varname = args.Current;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string value = args.Current;

            if (value.StartsWith("\"") && value.EndsWith("\"")) {
                value = value.Substring(1, value.Length - 2);
            } else if (value.StartsWith("\'") && value.EndsWith("\'")) {
                value = value.Substring(1, value.Length - 2);
            }

            settings.SetVariable(varname, value);

            Out.WriteLine();
            Out.WriteLine("variable {0} set to {1}", varname, value);
            Out.WriteLine();

            return CommandResultCode.Success;
        }
예제 #24
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "path")
                return CommandResultCode.SyntaxError;

            string pathName = args.Current;
            string rootAddress = null;

            if (args.MoveNext()) {
                if (args.Current != "from")
                    return CommandResultCode.SyntaxError;

                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;

                rootAddress = args.Current;
            }

            return RemovePath(networkContext, pathName, rootAddress);
        }
예제 #25
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (!(Application is IPluginHandler)) {
                Error.WriteLine("The application doesn't support plug-ins.");
                return CommandResultCode.ExecutionFailed;
            }

            ApplicationPlugins plugins = ((IPluginHandler) Application).Plugins;
            string pluginType = args.Current;
            if (plugins.HasPlugin(pluginType)) {
                Application.Error.WriteLine("plugin '" + pluginType + "' already loaded");
                return CommandResultCode.ExecutionFailed;
            }

            Command plugin;
            try {
                plugin = plugins.LoadPlugin(pluginType);
            } catch (Exception e) {
                Application.Error.WriteLine("couldn't load plugin: " + e.Message);
                return CommandResultCode.ExecutionFailed;
            }
            if (plugin != null) {
                plugins.Add(pluginType, plugin);
                Out.Write("adding command: ");
                Out.Write(plugin.Name);
                string[] aliases = plugin.Aliases;
                if (aliases.Length > 0) {
                    Out.Write(" (");
                    for (int i = 0; i < aliases.Length; ++i) {
                        Out.Write(aliases[i]);

                        if (i < aliases.Length - 1)
                            Out.Write(", ");
                    }

                    Out.Write(")");
                }

                Out.WriteLine();
            }

            return CommandResultCode.Success;
        }
예제 #26
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (context == null)
            {
                return(CommandResultCode.ExecutionFailed);
            }

            if (args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            ((CloudAdmin)Application).SetNetworkContext(null);

            Out.WriteLine("successfully disconnected...");
            Out.WriteLine();
            return(CommandResultCode.Success);
        }
예제 #27
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            try {
                string arg = args.Current;
                if (arg.ToLower().Equals("off")) {
                    CloseSpool();
                } else if (arg.Length > 0) {
                    OpenSpool(arg);
                } else {
                    return CommandResultCode.SyntaxError;
                }
            } catch (Exception e) {
                System.Console.Error.Write(e.StackTrace);
                return CommandResultCode.ExecutionFailed;
            }
            return CommandResultCode.Success;
        }
예제 #28
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (!(Application is IPluginHandler)) {
                Error.WriteLine("The application doesn't support plug-ins.");
                return CommandResultCode.ExecutionFailed;
            }

            ApplicationPlugins plugins = ((IPluginHandler) Application).Plugins;

            string pluginType = args.Current;
            if (!plugins.HasPlugin(pluginType)) {
                Application.Error.WriteLine("unknown plugin '" + pluginType + "'");
                return CommandResultCode.ExecutionFailed;
            }
            if (!plugins.Unregister(pluginType))
                return CommandResultCode.ExecutionFailed;
            return CommandResultCode.Success;
        }
예제 #29
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (context == null)
            {
                return(CommandResultCode.ExecutionFailed);
            }

            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            if (args.Current == "analytics")
            {
                return(ShowAnalytics(networkContext));
            }
            if (args.Current == "free")
            {
                ShowFree(networkContext);
                return(CommandResultCode.Success);
            }
            if (args.Current == "network")
            {
                ShowNetwork(networkContext);
                return(CommandResultCode.Success);
            }
            if (args.Current == "paths")
            {
                return(ShowPaths(networkContext));
            }
            if (args.Current == "status")
            {
                ShowStatus(networkContext);
                return(CommandResultCode.Success);
            }

            return(CommandResultCode.SyntaxError);
        }
예제 #30
0
파일: AddCommand.cs 프로젝트: ikvm/cloudb
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string pathType;

            if (args.Current == "path") {
                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;

                pathType = args.Current;
            } else if (args.Current == "base") {
                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;
                if (args.Current != "path")
                    return CommandResultCode.SyntaxError;

                pathType = "Deveel.Data.BasePath, cloudbase";
            } else if (args.Current == "value") {
                return AddValue(networkContext, args);
            } else {
                return CommandResultCode.SyntaxError;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string pathName = args.Current;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (args.Current != "to")
                return CommandResultCode.SyntaxError;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string rootAddress = args.Current;

            return AddPath(networkContext, pathType, pathName, rootAddress);
        }
예제 #31
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            IInformationProvider provider = Application as IInformationProvider;
            if (provider == null) {
                Error.WriteLine("The current context does not support information.");
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string infoName = args.Current;
            if (!provider.IsInfoSupported(infoName)) {
                Error.WriteLine("Information " + infoName + " is not supported by the current context.");
                return CommandResultCode.ExecutionFailed;
            }

            ColumnDesign[] columns = provider.GetColumns(infoName);
            for (int i = 0; i < columns.Length; i++)
                columns[i].ResetWidth();

            TableRenderer renderer = new TableRenderer(columns, Out);
            // TODO: make it configurable ...
            renderer.EnableHeader = true;
            renderer.EnableFooter = true;

            IList<ColumnValue[]> values = provider.GetValues(infoName);
            for (int i = 0; i < values.Count; i++) {
                ColumnValue[] rowValues = values[i];
                renderer.AddRow(rowValues);
            }

            renderer.Flush();
            renderer.CloseTable();
            return CommandResultCode.Success;
        }
예제 #32
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (args.Count > 1)
                return CommandResultCode.SyntaxError;

            string commandName = null;
            if (args.MoveNext())
                commandName = args.Current;

            // nothing given: provide generic help.

            Application.Error.WriteLine();

            int maxPad = 0;
            if (commandName == null) {
                ICollection<Command> commands = Application.Commands.RegisteredCommands;

                // process the command groups first...
                Dictionary<string, List<CommandHelp>> groups = new Dictionary<string, List<CommandHelp>>();
                foreach (Command command in commands) {
                    string groupName = command.GroupName;
                    if (groupName == null || groupName.Length == 0)
                        groupName = "commands";

                    List<CommandHelp> list;
                    if (!groups.TryGetValue(groupName, out list)) {
                        list = new List<CommandHelp>();
                        groups[groupName] = list;
                    }

                    CommandHelp commandHelp = new CommandHelp();

                    StringBuilder cmdPrint = new StringBuilder(" ");
                    string[] aliases = command.Aliases;

                    cmdPrint.Append(command.Name);

                    if (aliases != null && aliases.Length > 0) {
                        cmdPrint.Append(" | ");
                        for (int i = 0; i < aliases.Length; i++) {
                            if (i != 0)
                                cmdPrint.Append(" | ");
                            cmdPrint.Append(aliases[i]);
                        }
                    }

                    commandHelp.Name = cmdPrint.ToString();

                    string description = command.ShortDescription;
                    if (description == null) {
                        // no description ... try to get the groups description...
                    }

                    commandHelp.Description = description;

                    maxPad = Math.Max(maxPad, cmdPrint.Length);

                    list.Add(commandHelp);
                }

                foreach (KeyValuePair<string, List<CommandHelp>> entry in groups) {
                    string groupName = entry.Key;
                    Application.Error.Write(groupName);
                    Application.Error.Write(":");
                    Application.Error.WriteLine();

                    List<CommandHelp> commandList = entry.Value;
                    foreach (CommandHelp command in commandList) {
                        Application.Error.Write("  ");
                        Application.Error.Write(command.Name);

                        if (command.Description != null) {
                            for (int i = 0; i < maxPad - command.Name.Length; ++i)
                                Application.Error.Write(" ");

                            Application.Error.Write(" : ");
                            Application.Error.Write(command.Description);
                        }

                        Application.Error.WriteLine();
                    }
                }
            } else {
                CommandDispatcher disp = Application.Commands;

                string cmdString = disp.CompleteCommandName(commandName);
                Command c = disp.GetCommand(cmdString);
                if (c == null) {
                    Application.Error.WriteLine("Help: unknown command '" + cmdString + "'");
                    Application.Error.WriteLine();
                    return CommandResultCode.ExecutionFailed;
                }

                WriteDescription(c);
            }

            Application.Error.WriteLine();
            return CommandResultCode.Success;
        }
예제 #33
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            NetworkContext networkContext = (NetworkContext)context;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string pathType;

            if (args.Current == "path")
            {
                if (!args.MoveNext())
                {
                    return(CommandResultCode.SyntaxError);
                }

                pathType = args.Current;
            }
            else if (args.Current == "base")
            {
                if (!args.MoveNext())
                {
                    return(CommandResultCode.SyntaxError);
                }
                if (args.Current != "path")
                {
                    return(CommandResultCode.SyntaxError);
                }

                pathType = "Deveel.Data.BasePath, cloudbase";
            }
            else if (args.Current == "value")
            {
                return(AddValue(networkContext, args));
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string pathName = args.Current;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            if (args.Current != "to")
            {
                return(CommandResultCode.SyntaxError);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string rootAddress = args.Current;

            return(AddPath(networkContext, pathType, pathName, rootAddress));
        }
예제 #34
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated)
            {
                Error.WriteLine("a context is already opened: try to disconnect first");
                Error.WriteLine();
                return(CommandResultCode.ExecutionFailed);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            if (args.Current != "to")
            {
                return(CommandResultCode.SyntaxError);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string          address = args.Current;
            IServiceAddress serviceAddress;

            try {
                serviceAddress = ServiceAddresses.ParseString(address);
            } catch (Exception) {
                Error.WriteLine("Invalid service address specified: {0}", address);
                return(CommandResultCode.ExecutionFailed);
            }

            NetworkConfigSource configSource = new NetworkConfigSource();

            try {
                configSource.AddNetworkNode(serviceAddress);
            } catch (Exception e) {
                Error.WriteLine("The address '" + address + "' is invalid: " + e.Message);
                return(CommandResultCode.ExecutionFailed);
            }

            string protocol    = "tcp";
            string credentials = String.Empty;
            string format      = "binary";

            if (args.MoveNext())
            {
                if (args.Current == "identified")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (args.Current != "by")
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    credentials = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "on")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        protocol = args.Current;

                        if (args.MoveNext())
                        {
                            if (args.Current != "with")
                            {
                                return(CommandResultCode.SyntaxError);
                            }

                            format = args.Current;
                        }
                    }
                }
                else if (args.Current == "on")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    protocol = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "with")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        format = args.Current;
                    }
                }
                else if (args.Current == "with")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    format = args.Current;
                }
                else
                {
                    return(CommandResultCode.SyntaxError);
                }
            }

            IServiceConnector connector;

            if (protocol == "tcp")
            {
                if (String.IsNullOrEmpty(credentials))
                {
                    while (String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }
                    Out.WriteLine();
                }
                connector = new TcpServiceConnector(credentials);
            }
            else if (protocol == "http")
            {
                string userName = credentials;
                string password = null;
                int    index    = credentials.IndexOf(':');
                if (index != -1)
                {
                    password = credentials.Substring(index + 1);
                    userName = credentials.Substring(0, index);
                }

                if (String.IsNullOrEmpty(password))
                {
                    while (String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }

                    Out.WriteLine();
                }

                // TODO: connector = new HttpServiceConnector(userName, password);
                Out.WriteLine("Not supported yet.");
                return(CommandResultCode.ExecutionFailed);
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            IMessageSerializer serializer;

            if (format == "binary")
            {
                serializer = new BinaryRpcMessageSerializer();
            }
            else if (format == "xml")
            {
                //TODO: serializer = new XmlRpcMessageSerializer();
                return(CommandResultCode.ExecutionFailed);
            }
            else if (format == "json")
            {
                if (JsonRpcMessageSerializer == null)
                {
                    Error.WriteLine("JSON serializer was not installed.");
                    Error.WriteLine();
                    return(CommandResultCode.ExecutionFailed);
                }
                serializer = JsonRpcMessageSerializer;
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            connector.MessageSerializer = serializer;

            NetworkProfile networkProfile = new NetworkProfile(connector);

            networkProfile.Configuration = configSource;

            //TODO: test the connection is correct ...

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));

            Out.WriteLine("connected successfully to {0}", address);
            Out.WriteLine();

            return(CommandResultCode.Success);
        }
예제 #35
0
파일: AddCommand.cs 프로젝트: ikvm/cloudb
        private CommandResultCode AddValue(NetworkContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string value = args.Current;

            if (String.IsNullOrEmpty(value))
                return CommandResultCode.ExecutionFailed;

            if (value[0] == '\'') {
                bool endFound = false;
                StringBuilder sb = new StringBuilder();
                while (!endFound) {
                    for (int i = 0; !String.IsNullOrEmpty(value) && i < value.Length; i++) {
                        char c = value[i];
                        if (c == '\'' && i > 0) {
                            endFound = true;
                            break;
                        }

                        sb.Append(c);
                    }

                    if (!endFound && args.MoveNext()) {
                        sb.Append(' ');
                        value = args.Current;
                    }
                }

                value = sb.ToString();
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "into")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string tableName = args.Current;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "with")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "key")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string key = args.Current;

            string pathName = null;

            if (args.MoveNext()) {
                if (args.Current != "to")
                    return CommandResultCode.SyntaxError;
                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;

                pathName = args.Current;
            }

            try {
                context.AddValueToPath(pathName, tableName, key, value);
            } catch(Exception e) {
                Error.WriteLine("error while adding the value: " + e.Message);
                Error.WriteLine();
                return CommandResultCode.ExecutionFailed;
            }

            return CommandResultCode.Success;
        }
예제 #36
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated) {
                Error.WriteLine("a context is already opened: try to disconnect first");
                Error.WriteLine();
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (args.Current != "to")
                return CommandResultCode.SyntaxError;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string address = args.Current;
            IServiceAddress serviceAddress;

            try {
                serviceAddress = ServiceAddresses.ParseString(address);
            } catch(Exception) {
                Error.WriteLine("Invalid service address specified: {0}", address);
                return CommandResultCode.ExecutionFailed;
            }

            NetworkConfigSource configSource = new NetworkConfigSource();

            try {
                configSource.AddNetworkNode(serviceAddress);
            } catch(Exception e) {
                Error.WriteLine("The address '" + address + "' is invalid: " + e.Message);
                return CommandResultCode.ExecutionFailed;
            }

            string protocol = "tcp";
            string credentials = String.Empty;
            string format = "binary";

            if (args.MoveNext()) {
                if (args.Current == "identified") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;
                    if (args.Current != "by")
                        return CommandResultCode.SyntaxError;
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    credentials = args.Current;

                    if (args.MoveNext()) {
                        if (args.Current != "on")
                            return CommandResultCode.SyntaxError;

                        protocol = args.Current;

                        if (args.MoveNext()) {
                            if (args.Current != "with")
                                return CommandResultCode.SyntaxError;

                            format = args.Current;
                        }
                    }
                } else if (args.Current == "on") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    protocol = args.Current;

                    if (args.MoveNext()) {
                        if (args.Current != "with")
                            return CommandResultCode.SyntaxError;

                        format = args.Current;
                    }
                } else if (args.Current == "with") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    format = args.Current;
                } else {
                    return CommandResultCode.SyntaxError;
                }
            }

            IServiceConnector connector;
            if (protocol == "tcp") {
                if (String.IsNullOrEmpty(credentials)) {
                    while(String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }
                    Out.WriteLine();
                }
                connector = new TcpServiceConnector(credentials);
            } else if (protocol == "http") {
                string userName = credentials;
                string password = null;
                int index = credentials.IndexOf(':');
                if (index != -1) {
                    password = credentials.Substring(index + 1);
                    userName = credentials.Substring(0, index);
                }

                if (String.IsNullOrEmpty(password)) {
                    while(String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }

                    Out.WriteLine();
                }

                connector = new HttpServiceConnector(userName, password);
            } else {
                return CommandResultCode.SyntaxError;
            }

            IMessageSerializer serializer;

            if (format == "binary") {
                serializer = new BinaryRpcMessageSerializer();
            } else if (format == "xml") {
                serializer = new XmlRpcMessageSerializer();
            } else if (format == "json") {
                if (JsonRpcMessageSerializer == null) {
                    Error.WriteLine("JSON serializer was not installed.");
                    Error.WriteLine();
                    return CommandResultCode.ExecutionFailed;
                }
                serializer = JsonRpcMessageSerializer;
            } else {
                return CommandResultCode.SyntaxError;
            }

            connector.MessageSerializer = serializer;

            NetworkProfile networkProfile = new NetworkProfile(connector);
            networkProfile.Configuration = configSource;

            //TODO: test the connection is correct ...

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));

            Out.WriteLine("connected successfully to {0}" , address);
            Out.WriteLine();

            return CommandResultCode.Success;
        }
예제 #37
0
파일: Program.cs 프로젝트: deveel/dshell
            public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
            {
                if (args.MoveNext())
                    ((TestApplication)Application).appDir = args.Current;

                TestApplication app = (TestApplication)Application;
                app.Configure();
                return CommandResultCode.Success;
            }
예제 #38
0
        private CommandResultCode AddValue(NetworkContext context, CommandArguments args)
        {
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string value = args.Current;

            if (String.IsNullOrEmpty(value))
            {
                return(CommandResultCode.ExecutionFailed);
            }

            if (value[0] == '\'')
            {
                bool          endFound = false;
                StringBuilder sb       = new StringBuilder();
                while (!endFound)
                {
                    for (int i = 0; !String.IsNullOrEmpty(value) && i < value.Length; i++)
                    {
                        char c = value[i];
                        if (c == '\'' && i > 0)
                        {
                            endFound = true;
                            break;
                        }

                        sb.Append(c);
                    }

                    if (!endFound && args.MoveNext())
                    {
                        sb.Append(' ');
                        value = args.Current;
                    }
                }

                value = sb.ToString();
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "into")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string tableName = args.Current;

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "with")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }
            if (args.Current != "key")
            {
                return(CommandResultCode.SyntaxError);
            }
            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string key = args.Current;

            string pathName = null;

            if (args.MoveNext())
            {
                if (args.Current != "to")
                {
                    return(CommandResultCode.SyntaxError);
                }
                if (!args.MoveNext())
                {
                    return(CommandResultCode.SyntaxError);
                }

                pathName = args.Current;
            }

            try {
                context.AddValueToPath(pathName, tableName, key, value);
            } catch (Exception e) {
                Error.WriteLine("error while adding the value: " + e.Message);
                Error.WriteLine();
                return(CommandResultCode.ExecutionFailed);
            }

            return(CommandResultCode.Success);
        }