public static FileReturn GetFileInfo(string path) { string[] lines = File.ReadAllLines(path); FileReturn fr = new FileReturn(); fr.circumference = Double.Parse(lines[0]); fr.height = Double.Parse(lines[1]); return(fr); }
// If given a valid channel ID, the ID will either be added or removed from the channel blacklist. public static void ToggleBlacklistEntry(ulong id) { string path = Constants.LogBlacklist; FileReturn status = ToggleStorageEntry(path, id.ToString()); if (status == FileReturn.FileDoesNotExist) { return; } else if (status == FileReturn.EntryAdded) { RemoveLogIfExists(id); } // Gets the modified log from storage and sets it to the variable. List <ulong> blacklist = GetListFromStorage(path); _blacklist = blacklist; }
// If given a valid user ID, the ID will either be added or removed from the user message blacklist. public static void ToggleUserBlacklistEntry(ulong id) { string path = Constants.UserBlacklist; FileReturn status = ToggleStorageEntry(path, id.ToString()); if (status == FileReturn.FileDoesNotExist) { return; } else if (status == FileReturn.EntryAdded) { // TODO: Remove all instances of user in condensed log } // Gets the modified log from storage and sets it to the variable. List <ulong> userBlacklist = GetListFromStorage(path); _userBlacklist = userBlacklist; }
private void ListCurrentFiles(HttpContext context) { var bucket = ConfigurationManager.AppSettings["Assets_Amazon_Bucket"]; var prefix = GetPrefix(context); var doctype = context.Request["doctype"]; var files = new List <AmazonFilesStatus>(); var client = AmazonHelper.GetS3Client(); var request = new ListObjectsRequest().WithBucketName(bucket).WithDelimiter("/").WithPrefix(prefix); var l = client.ListObjects(request); foreach (var fl in l.S3Objects) { if (fl.Size > 0) { if (String.IsNullOrWhiteSpace(doctype) || (doctype == getDocType(fl.Key))) { var fs = new AmazonFilesStatus(fl, bucket, prefix); files.Add(fs); } } } var typeObj = new Dictionary <String, String>(); typeObj.Add("doc", AmazonHelper.DocExtensions()); typeObj.Add("image", AmazonHelper.ImgExtensions()); typeObj.Add("media", AmazonHelper.MediaExtensions()); var retObj = new FileReturn() { Files = files, AssetTypes = typeObj }; string jsonObj = js.Serialize(retObj); context.Response.AddHeader("Content-Disposition", "inline, filename=\"files.json\""); context.Response.Write(jsonObj); context.Response.ContentType = "application/json"; }
/// <summary> /// Adds or removes an entry in a given storage file and returns true if the entry is toggled on /// </summary> /// <param name="entry">The line to add or remove from storage</param> /// <returns>Returns true if added to storage, false if removed from storage</returns> public static FileReturn ToggleStorageEntry(string path, string entry) { if (!File.Exists(path)) { return(FileReturn.FileDoesNotExist); } List <string> storageList = File.ReadAllLines(path).ToList(); if (storageList.Count == 0) { File.WriteAllText(path, entry); return(FileReturn.EntryAdded); } int i = 0; FileReturn listStatus = FileReturn.EntryAdded; // Go through all entries and remove the ones that match, if any. foreach (string storageEntry in storageList) { // If the entry is already in storage, delete it. if (storageEntry == entry) { storageList.RemoveAt(i); listStatus = FileReturn.EntryRemoved; } i += 1; } // Adds the entry to the list if it does not exist. if (listStatus == FileReturn.EntryAdded) { storageList.Add(entry); } // Write the changes to storage. File.WriteAllLines(path, storageList); return(listStatus); }
public async Task <NodeEntry> Return([FromRoute] FileReturn input) { return(await _fileService.Return(input.NodeId)); }
private void ListCurrentFiles(HttpContext context) { var bucket = ConfigurationManager.AppSettings["Assets_Amazon_Bucket"]; var prefix = GetPrefix(context); var doctype = context.Request["doctype"]; var files = new List<AmazonFilesStatus>(); var client = AmazonHelper.GetS3Client(); var request = new ListObjectsRequest().WithBucketName(bucket).WithDelimiter("/").WithPrefix(prefix); var l = client.ListObjects(request); foreach (var fl in l.S3Objects) { if(fl.Size > 0) { if(String.IsNullOrWhiteSpace(doctype) || (doctype == getDocType(fl.Key))) { var fs = new AmazonFilesStatus(fl,bucket,prefix); files.Add(fs); } } } var typeObj = new Dictionary<String,String>(); typeObj.Add("doc",AmazonHelper.DocExtensions()); typeObj.Add("image",AmazonHelper.ImgExtensions()); typeObj.Add("media",AmazonHelper.MediaExtensions()); var retObj = new FileReturn(){Files = files,AssetTypes = typeObj}; string jsonObj = js.Serialize(retObj); context.Response.AddHeader("Content-Disposition", "inline, filename=\"files.json\""); context.Response.Write(jsonObj); context.Response.ContentType = "application/json"; }