Exemplo n.º 1
0
 public void SetCommand(CommandConsole console, string[] args)
 {
     if (args.Length == 0)
         console.Print("=" + Value);
     else
         Value = args[0];
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            CommandConsole console = new CommandConsole();
            LocalNode node = new LocalNode(console);
            HttpNodeConnector connector = new HttpNodeConnector(node, 6681, false);

            #region "Commands"
            console.RegisterCommand("help", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
                {
                    console.Print("List of commands: \n-" + string.Join("\n-", console.GetCommandList()));
                })));
            console.RegisterCommand("quit", new EventCommand(new Action<object, EventCmdArgs>(Quit)));
            console.RegisterCommand("checkin", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
                {
                    node.Checkin();
                })));
            #endregion

            connector.Start();
            Console.WriteLine("Started, Type 'help' for list of commands.");

            while (Running)
            {
                string input = Console.ReadLine();
                console.Call(input, false, true);
            }
            //deregister

        }
Exemplo n.º 3
0
        public CommunicationNode(CommandConsole console)
        {
            CmdConsole = console;
            CmdConsole.RegisterCommand("save_state", new EventCommand(new Action<object, EventCmdArgs>(SaveState)));//, "Usage: save_state\nSaves the state of the node"));
            CmdConsole.RegisterCommand("load_state", new EventCommand(new Action<object, EventCmdArgs>(LoadState)));//, "Usage: load_state\nLoads the state of the node"));

            Client = new WebClient();
        }
Exemplo n.º 4
0
 public void SetCommand(CommandConsole console, string[] args)
 {
     if (args.Length == 0)
         console.Print("=" + Value);
     else
     {
         CmdValueEventArgs eventArg = new CmdValueEventArgs(args[0]);
         if (OnChange != null) OnChange(this, eventArg);
         Value = eventArg.Value;
     }
 }
Exemplo n.º 5
0
        public LocalNode(CommandConsole console)
            : base(console)
        {
            CmdConsole.RegisterCommand("state_dir", new CommandValue() { Value = "./FogState/" });
            CmdConsole.RegisterCommand("register", new EventCommand(new Action<object, EventCmdArgs>(Register)));
            CmdConsole.RegisterCommand("add_store", new EventCommand(new Action<object, EventCmdArgs>(AddStore)));
            CmdConsole.RegisterCommand("poll_list", new EventCommand(new Action<object, EventCmdArgs>(PollList)));
            CmdConsole.RegisterCommand("list_stores", new EventCommand(new Action<object, EventCmdArgs>(ListStores)));
            CmdConsole.RegisterCommand("list_store_entries", new EventCommand(new Action<object, EventCmdArgs>(ListStoreEntries)));
            CmdConsole.RegisterCommand("validate", new EventCommand(new Action<object, EventCmdArgs>(Validate)));

            TicketStore = new Dictionary<Guid, OpTicket>();
            FileStores = new List<FileStore>();
        }
Exemplo n.º 6
0
        public CentralNode(CommandConsole console)
            : base(console)
        {
            CmdConsole.RegisterCommand("allow_register", new CommandValue { Value = "1" });
            CmdConsole.RegisterCommand("access_token", new CommandValue() { Value = Guid.NewGuid().ToHexString() });
            CmdConsole.RegisterCommand("db_path", new CommandValue() { Value = "./FogData.sdf" });
            CmdConsole.RegisterCommand("state_dir", new CommandValue() { Value = "./FogState/" });
            CmdConsole.RegisterCommand("list_nodes", new EventCommand(new Action<object, EventCmdArgs>(ListNodes)));
            CmdConsole.RegisterCommand("list_stores", new EventCommand(new Action<object, EventCmdArgs>(ListStores)));
            CmdConsole.RegisterCommand("list_store_entries", new EventCommand(new Action<object, EventCmdArgs>(ListStoreEntries)));
            CmdConsole.RegisterCommand("list_entries", new EventCommand(new Action<object, EventCmdArgs>(ListEntries)));
            CmdConsole.RegisterCommand("permit_entry", new EventCommand(new Action<object, EventCmdArgs>(PermitEntry)));
            CmdConsole.RegisterCommand("revoke_entry", new EventCommand(new Action<object, EventCmdArgs>(RevokeEntry)));

            Entries = new EntryTree();
            stores = new Dictionary<Guid, FileStore>();
            storeList = new List<FileStore>();
            nodes = new Dictionary<Guid, NodeInfo>();
            nodeList = new List<NodeInfo>();
        }
Exemplo n.º 7
0
 public void SetCommand(CommandConsole console, string[] args)
 {
     if (OnCommand != null) OnCommand(this, new EventCmdArgs(console, args));
 }
Exemplo n.º 8
0
 public EventCmdArgs(CommandConsole console, string[] args)
 {
     ConsoleCaller = console;
     Arguments = args;
 }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            bool running = true;
            CommandConsole console = new CommandConsole() { PrintTimestamp = true, VerboseLevel = VerboseTag.Info };
            CentralNode node = new CentralNode(console);
            HttpNodeConnector connector = new HttpNodeConnector(node, 6680, true);
            FileStore fManager = new FileStore(Guid.Empty, "VirtualStore", ".\\", node.Entries);

            #region "Commands"
            //TODO: Package commands in a more elegant manner
            console.RegisterCommand("help", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                console.Print("List of commands: \n-" + string.Join("\n-", console.GetCommandList()));
            })));
            console.RegisterCommand("exec", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                if (eventArgs.Arguments.Length == 1)
                {
                    string[] lines = File.ReadAllLines(eventArgs.Arguments[0]);
                    foreach (string line in lines)
                        console.Call(line, true, true);
                }
                else
                {
                    console.Print("Usage: exec [file]"); 
                }
            })));
            console.RegisterCommand("quit", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                running = false;
            })));
            console.RegisterCommand("add_file", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                if (eventArgs.Arguments.Length == 2)
                {
                    string virtualPath = eventArgs.Arguments[0];
                    Stream s = File.OpenRead(eventArgs.Arguments[1]);
                    node.Entries.AddFile(fManager.CreateEntry(virtualPath, s, DateTime.Now));
                    s.Close();
                    console.Print("Added: " + virtualPath);
                }
                else
                {
                    console.Print("Usage: add_file [virtual_path] [physical_path]");
                }
            })));
            console.RegisterCommand("add_dir", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                if (eventArgs.Arguments.Length == 2)
                {
                    string virtualDir = eventArgs.Arguments[0];
                    string physicalDir = eventArgs.Arguments[1];
                    foreach (string path in Directory.GetFiles(physicalDir))
                    {
                        string name = Path.GetFileName(path);
                        console.Call("add_file \"" + virtualDir + name + "\" \"" + path + "\"", false, true);
                    }
                }
                else
                {
                    console.Print("Usage: add_dir [virtual_dir] [physical_dir]");
                }
            })));
            console.RegisterCommand("add_entry", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {

            })));
            console.RegisterCommand("permit_dir", new EventCommand(new Action<object, EventCmdArgs>((sender, eventArgs) =>
            {
                if (eventArgs.Arguments.Length == 2)
                {
                    EntryDirectoryNode dirNode = node.Entries.Navigate(eventArgs.Arguments[1], false);
                    if (dirNode == null)
                    {
                        console.Print("directory does not exist");
                        return;
                    }
                    FileStore store = node.FileStores[Convert.ToInt32(eventArgs.Arguments[0])];
                    foreach (FileEntry entry in dirNode.Entries.Values)
                        store.EntryTree.AddFile(entry);
                }
                else
                {
                    console.Print("Usage: permit_dir [store_id] [virtual_path]");
                }
            })));
            #endregion
            
            //DB Testing
            //MySql.Data.MySqlClient.MySqlConnection dbConnector = new MySql.Data.MySqlClient.MySqlConnection("Server=127.0.0.1;Username=FogAdmin;Password=654987");
            //dbConnector.Open();
            //node.connection = dbConnector;
            //Testing entry handling
            //DbAccess.AddEntries(dbConnector, node.Entries.Entries);
            
            //Testing node handling
            //DbAccess.AddNode(dbConnector, node.Nodes[0]);
            //NodeInfo[] nodes = DbAccess.GetNode(dbConnector);

            node.LoadState();
            console.Print(VerboseTag.Info, "Started, Type 'help' for list of commands.", true);



            while (running)
            {
                string input = Console.ReadLine();
                console.Call(input, false, true);
            }
            console.Print("Stopping...");
            //dbConnector.Close();
        }