public OpTicket PollList(FileStore store) { //Get Ticket OpTicket ticket = GetList(store.ID); string printout = "Ticket ID: " + ticket.OpID + "\nFile Entries:\n"; foreach (FileEntry file in ticket.Files) { //TODO: log ticket data //TODO: update list store.EntryTree.ReplaceFile(file); } return ticket; }
//tmp: FileStore Serialization private string StoreToString(FileStore store) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); builder.AppendLine(store.ID.ToHexString() + "\t" + store.Name + "\t" + store.StorePath); foreach (FileEntry entry in store.EntryTree.Entries) builder.AppendLine(entry.ToLine()); return builder.ToString(); }
private FileStore StringToStore(string[] lines) { string[] data = lines[0].Split('\t'); FileStore store = new FileStore(data[0].HexStringToGuid(), data[1], data[2], new EntryTree()); for (int i = 1; i < lines.Length; i++) { store.EntryTree.AddFile(new FileEntry(lines[i])); } return store; }
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(); }
private void RepairFile(FileStore store, FileEntry entry) { //CmdConsole.Print("Sending repair request: " + entry.VirtualPath); string link = RepairRequest(ID, store.ID, entry.VirtualPath); System.Threading.Thread.Sleep(1000); //CmdConsole.Print("Downloading file link: " + link); Directory.CreateDirectory(store.StorePath + entry.VirtualPath.Substring(0, entry.VirtualPath.LastIndexOf("/"))); Client.DownloadFile(link, store.StorePath + entry.VirtualPath); CmdConsole.Print("Downloaded"); }
public override Guid AddStore(Guid token, string name) { //TODO: checks FileStore newStore = new FileStore(Guid.NewGuid(), name, ""); AddStore(newStore); nodes[token].FileStores.Add(newStore.ID, newStore); return newStore.ID; }
/// <summary> /// Revokes services for the specified Node on the specified file entry /// </summary> /// <param name="node">The node losing access</param> /// <param name="entry">File entry path</param> public bool RevokeEntry(FileStore store, string entry) { //Find Node FileEntry fileNode = store.EntryTree.GetFile(entry); if (fileNode == null) { CmdConsole.Print(VerboseTag.Warning, "RevokeEntry: entry '" + entry + "' does not exist in node", true); return false; } //Remove Node store.EntryTree.DeleteEntry(fileNode); //TODO: Log action return true; }
/// <summary> /// Gives specified node access to services to file entry /// </summary> /// <param name="node">Node being given access</param> /// <param name="entry">File entry path</param> /// <returns>If the entry is added</returns> public bool PermitEntry(FileStore store, string entry) { FileEntry fileNode = Entries.GetFile(entry); if (fileNode == null) { CmdConsole.Print(VerboseTag.Warning, "PermitEntry: entry '" + entry + "' does not exist", true); return false; } store.EntryTree.AddFile(fileNode); //TODO: Log action return true; }
public AvailableStore(NodeInfo node, FileStore store) : this() { Node = node; Store = store; }
public void AddStore(FileStore store) { stores.Add(store.ID, store); storeList.Add(store); }