//working for relative and absolute private static Response CreateFile(DirectoryNode directory, string filename, bool createLocally) { var response = ResponseFormation.GetResponse(); //query filetree to find out which server has least storage occupied var ipSpacePairs = FileTree.GetIPSpacePairs(); string ipPort = null; if (ipSpacePairs.Count == 0) { ipPort = State.LocalEndPoint.ToString(); } else { ipPort = ipSpacePairs.OrderBy(x => x.Value).First().Key; } if (createLocally || State.LocalEndPoint.ToString().Equals(ipPort)) { FileNode file = new FileNode(filename, FileTree.GetNewImplicitName(), 0); File.WriteAllText(Path.Combine(State.GetRootDirectory().FullName, file.ImplicitName), ""); file.IPAddresses.Add(State.LocalEndPoint.ToString()); FileTree.AddFile(directory, file); FileTreeService.UpdateFileTree(FileTree.GetRootDirectory().SerializeToByteArray()); //FileTree.AddInLocalFiles(file); response.Message = "Successfully Created"; } else { //forward response.Command = Command.forwarded; response.Message = ipPort; } response.IsSuccess = true; return(response); }