//Creates a file on Google Drive and uses the specified stream to fill it with data. //This should be used for data that is 5MB or less. public async Task <GFile> UploadFile(GFile fileMetadata, Stream fileData, IProgress <int> progress) { //Create the message to send. HttpRequestMessage message = new HttpRequestMessage(); message.Method = HttpMethod.Post; //Use the content upload url. message.RequestUri = new Uri("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart" + "&fields=" + GFile.FileMetadataFields()); //Create JSON that represents the Google Drive file metadata. var jsonText = GFile.ToJObject(fileMetadata).ToString(); //JSON file metadata content part. var metadataContent = new StringContent(jsonText, Encoding.UTF8); metadataContent.Headers.ContentLength = Encoding.UTF8.GetByteCount(jsonText); metadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=UTF-8"); //Streaming file bytes content. var fileContent = new StreamContent(fileData); fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); //Create the content for the HTTP request. This content must be multipart content, where the first //part is the file metadata JSON, split it using the boundary string "content_separator", and then //the next part is the data in the stream. Note I have no idea what the subtype parameter is supposed //to do. generic_subtype is just a random value, and it works, so I'll leave it like that. var mainContent = new MultipartContent("generic_subtype", "content_separator"); //Add the metadata. mainContent.Add(metadataContent); //Add the file data. mainContent.Add(fileContent); //Specify the content type. Notice the boundary specified in the constructor should also be specified //here as well. mainContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/related; boundary=content_separator"); //Add the multipart content to the actual message. message.Content = mainContent; //Attempt to upload the file. var result = await _client.SendAuthorizedRequestMessage(message, progress); if (_client.LastError != OAuthClientResult.Success) { return(null); } try { return(GFile.FromJObject(JObject.Parse(result))); } catch (Exception) { //An exception means parsing failed for some reason. Return null. return(null); } }
//Returns a list of files from the user's Google Drive. public async Task <List <GFile> > ListFiles(string query) { //Create the url that is used for listing files. Note that FileMetadataFieldsParenthesis is used //instead of FileMetadataFields. string url = "https://www.googleapis.com/drive/v3/files?spaces=drive&pageSize=200&trashed=false" + "&fields=" + GFile.FileMetadataFieldsParenthesis() + "&q="; //Url encode the query part of the url. url += HttpUtility.UrlEncode(query); //Make the authorized request for data. var result = await _client.SendAuthorizedRequestMessage(url, HttpMethod.Get); if (_client.LastError != OAuthClientResult.Success) { return(null); } //The result string should be a large JSON document. Use the parser helper methods. try { var rootObj = JObject.Parse(result); //"files" is the object we want here. It is an array of GFile objects. return(GFile.FromJArray((JArray)rootObj["files"])); } catch (Exception) { //Just return null. The only possible explanation for error is parsing failed for some reason. return(null); } }
public void HistoryFuturesIntervalTimeframe(string rootSymbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime = null, string endDateTime = null, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { m_filename = Folders.df_path(GFile.GetDfFuturesFilename(rootSymbol, (int)interval)); m_outfile = null; int addMonthsToEnd = 6; beginDateTime = beginDateTime ?? EARLIEST_DATE; endDateTime = endDateTime ?? DateTime.Now.AddMonths(addMonthsToEnd).ToString("yyyyMMdd"); var mcList = GetMonthCodeList(beginDateTime, endDateTime); string sInterval = ((int)interval).ToString(); foreach (var mYY in mcList) { m_symbol = rootSymbol + mYY; // use mYY and the mYY from 6 months prior to calculate a begin and end date for contract historical data string mYYplus1 = AddMonths(mYY, 1); string mYYminus6 = AddMonths(mYY, -6); string dt1 = GetDateTimeMYY(mYYminus6).ToYYYYMMDD(); string dt2 = GetDateTimeMYY(mYYplus1).ToYYYYMMDD(); HistoryIntervalTimeframe(m_symbol, itype, sInterval, dt1, dt2, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); } if (m_outfile != null) { m_outfile.Close(); Console.WriteLine("\nOutput to file: {0}\n", m_filename); } }
public static List <GFile> FromJArray(JArray arrObj) { //Loop through each object in this array. Each object is a file. var files = new List <GFile>(); foreach (var fileObj in arrObj) { files.Add(GFile.FromJObject((JObject)fileObj)); } return(files); }
//Creates a folder on Google Drive, and returns a GFile representing the folder. //Set parentFolderId to "root" to specify the root folder as the parent. public async Task <GFile> CreateFolder(string name, string description, string parentFolderId) { //Construct a request message to send. HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://www.googleapis.com/drive/v3/files?fields=" + GFile.FileMetadataFields()); //The parameters for the folder must be provided in the message body as JSON. JObject folderData = new JObject(); folderData["name"] = name; folderData["description"] = description; folderData["mimeType"] = "application/vnd.google-apps.folder"; //The following makes JSON that looks like this. [{"id": "parentFolderId"}] JArray parentArr = new JArray(); parentArr.Add(new JObject() { ["id"] = parentFolderId }); folderData["parents"] = parentArr; //Convert the JSON to a string. string json = folderData.ToString(); //Create the content. StringContent content = new StringContent(json, Encoding.UTF8); content.Headers.ContentLength = Encoding.UTF8.GetByteCount(json); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=UTF-8"); message.Content = content; //Send the create folder command. var result = await _client.SendAuthorizedRequestMessage(message); if (_client.LastError != OAuthClientResult.Success) { return(null); } //Try to parse the returned data. try { return(GFile.FromJObject(JObject.Parse(result))); } catch (Exception) { //Just return null. The error at this point is a parsing issue. return(null); } }
// Create the output file (StreamWriter) that will be used. public void CreateOutputFile(string pathname) { m_writer = GFile.CreateOutputFile(pathname, TickerOutput.CsvHeaders); /*//var loc = Assembly.GetExecutingAssembly().Location; * if (pathname != null) * { * m_writer = new StreamWriter(pathname, append: true); * } * else * { * string filename = string.Format("tickers_{0}.DF.csv", DateTime.Now.ToString("yyyy-MM-dd_HHmmss")); * pathname = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename); * m_writer = new StreamWriter(pathname, append: false); * m_writer.WriteLine(TickerOutput.CsvHeaders); * }*/ }
private void RefreshSettings() { string filename = "python.exe"; if (GFile.ExistsOnPath(filename)) { lblPythonIsInstalled.Text = "Python is installed"; lblPythonIsInstalled.ForeColor = Color.Black; lblPythonInstallationPath.Text = GFile.GetFullPath(filename); } else { lblPythonIsInstalled.Text = "Python is NOT installed"; lblPythonIsInstalled.ForeColor = Color.Red; lblPythonInstallationPath.Text = ""; } }
public void GainersTask(bool display = false) { var headers = CoinMarketCapTicker.CsvHeaders + ",Exchanges"; var writer = GFile.CreateOutputFile("sploders_raw", headers); if (display) { Console.WriteLine(headers); } while (true) { var g24 = m_cmc.GetBiggestGainers24h(); var now = DateTime.Now; m_rawGainers24[now] = new Dictionary <string, CoinMarketCapTicker>(); int count = 0; foreach (var t in g24) { m_rawGainers24[now][t.symbol] = t; var mr = CoinMarketCapApi.GetMarkets(t.name); var marketExchanges = mr.Select(m => m.exchange).Distinct(); //var mr = CoinMarketCapApi.GetMarkets(t.name, removeDuplicates: true); //var marketExchanges = mr.Select(x => x.pair); var exchanges = marketExchanges.Intersect(m_workingExchanges); if (exchanges.Count() > 0) { var exchangesString = string.Join('|', exchanges); var output = string.Format("{0},{1}", t.ToCsv(), exchangesString); if (display) { Console.WriteLine(output); } writer.WriteLine(output); ++count; } } writer.FlushAsync(); var timeString = now.ToString("yyyy-MM-dd HH:mm:ss"); Console.WriteLine(" {0} {1} symbols output", timeString, count); Thread.Sleep(40000); } }
public Dictionary <string, EtherDeltaTicker> GetTickerDetails(bool forceUpdate = false) { //string json = @"{""ETH_Polymath"":{""tokenAddr"":""0x9992ec3cf6a55b00978cddf2b27bc6882d88d1ec"",""quoteVolume"":1593128.061,""baseVolume"":2062.115,""last"":0.001268256,""percentChange"":-0.0244,""bid"":0.001262,""ask"":0.00129},""ETH_ABS"":{""tokenAddr"":""0x8ce9411df545d6b51a9bc52a89e0f6d1b54a06dd"",""quoteVolume"":194476798498,""baseVolume"":1195.379,""last"":1e-8,""percentChange"":-0.4737,""bid"":7e-9,""ask"":1e-8}}"; //var d = JsonConvert.DeserializeObject<Dictionary<string, EtherDeltaTicker>>(json); //cout(d["ETH_Polymath"].tokenAddr); Dictionary <string, EtherDeltaTicker> request; if (forceUpdate) { request = GET <Dictionary <string, EtherDeltaTicker> >(string.Format("{0}/returnTicker", BaseUrl)); } else { string json = GFile.ReadTextFile(Folders.misc_path("etherdelta_tickers.json.txt")); request = DeserializeJSON <Dictionary <string, EtherDeltaTicker> >(json); } return(request); }
public void HistoryContractIntervalTimeframe(string symbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime = null, string endDateTime = null, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { m_filename = Folders.df_path(GFile.GetDfContractFilename(symbol, (int)interval)); m_outfile = null; beginDateTime = beginDateTime ?? EARLIEST_DATE; endDateTime = endDateTime ?? DateTime.Now.AddMonths(1).ToString("yyyyMMdd"); string sInterval = ((int)interval).ToString(); m_symbol = symbol; HistoryIntervalTimeframe(m_symbol, itype, sInterval, beginDateTime, endDateTime, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); if (m_outfile != null) { m_outfile.Close(); Console.WriteLine("\nOutput to file: {0}\n", m_filename); } }
public static JObject ToJObject(GFile file) { var rootObj = new JObject(); rootObj["name"] = file.Name; if (!string.IsNullOrEmpty(file.Description)) { rootObj["description"] = file.Description; } if (!string.IsNullOrEmpty(file.ID)) { rootObj["id"] = file.ID; } if (!string.IsNullOrEmpty(file.MimeType)) { rootObj["mimeType"] = file.MimeType; } if (file.Parents != null && file.Parents.Count > 0) { var parentIDs = new JArray(); foreach (var parentID in file.Parents) { parentIDs.Add(new JObject() { ["id"] = parentID }); } rootObj["parents"] = parentIDs; } if (file.Properties != null && file.Properties.Count > 0) { var properties = new JArray(); foreach (var key in file.Properties.Keys) { properties.Add(new JObject() { ["key"] = (string)key, ["value"] = file.Properties[(string)key] }); } rootObj["properties"] = properties; } return(rootObj); }
private void RefreshSettings() { PopulateGeneralSettings(); PopulateEnvironmentVariables(); CheckSelectedTab(); string filename = "python.exe"; if (GFile.ExistsOnPath(filename)) { lblPythonIsInstalled.Text = "Python is installed"; lblPythonIsInstalled.ForeColor = Color.Black; lblPythonInstallationPath.Text = GFile.GetFullPath(filename); } else { lblPythonIsInstalled.Text = "Python is NOT installed"; lblPythonIsInstalled.ForeColor = Color.Red; lblPythonInstallationPath.Text = ""; } }
//Create an empty file on Google Drive, and returns a GFile representing the file. //Note that this does not upload any data, only creates an empty file. public async Task <GFile> CreateFile(GFile fileMetadata) { //Create the message to send. HttpRequestMessage message = new HttpRequestMessage(); //Use the metadata only url. message.RequestUri = new Uri("https://www.googleapis.com/drive/v3/files?fields=" + GFile.FileMetadataFields()); message.Method = HttpMethod.Post; //Create JSON that represents the Google Drive file metadata. var jsonText = GFile.ToJObject(fileMetadata).ToString(); //Create the content using the file metadata, converted to a JSON object. StringContent content = new StringContent(jsonText, Encoding.UTF8); content.Headers.ContentLength = Encoding.UTF8.GetByteCount(jsonText); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=UTF-8"); //Send the create file command. var result = await _client.SendAuthorizedRequestMessage(message); if (_client.LastError != OAuthClientResult.Success) { return(null); } try { return(GFile.FromJObject(JObject.Parse(result))); } catch (Exception) { //Parsing issue. return(null); } }
public IoApi() { ops = new io_ops(); gfile = new GFile(); }
// Download the full IQFeed symbols file (tab-delimited) public static void DownloadSymbolsFile() { string url = "http://www.dtniq.com/product/mktsymbols_v2.zip"; GFile.DownloadFile(url, Folders.raw_path("mktsymbols_v2.zip")); }
public static GFile FromJObject(JObject fileObj) { var file = new GFile(); JToken holderValue = null; if (fileObj.TryGetValue("id", out holderValue)) { file.ID = (string)holderValue; } if (fileObj.TryGetValue("name", out holderValue)) { file.Name = (string)holderValue; } if (fileObj.TryGetValue("mimeType", out holderValue)) { file.MimeType = (string)holderValue; } //If the mime type is "application/vnd.google-apps.folder", this is a folder. file.IsFolder = file.MimeType == "application/vnd.google-apps.folder"; if (fileObj.TryGetValue("createdTime", out holderValue)) { file.CreateTime = (DateTime)holderValue; } if (fileObj.TryGetValue("modifiedTime", out holderValue)) { file.ModifyDate = (DateTime)holderValue; } if (fileObj.TryGetValue("fileExtension", out holderValue)) { file.FileExtension = (string)holderValue; } if (fileObj.TryGetValue("md5Checksum", out holderValue)) { file.Md5Checksum = (string)holderValue; } if (fileObj.TryGetValue("size", out holderValue)) { file.FileSize = (long)holderValue; } if (fileObj.TryGetValue("description", out holderValue)) { file.Description = (string)holderValue; } if (fileObj.TryGetValue("originalFilename", out holderValue)) { file.OriginalFileName = (string)holderValue; } //The parents are really "Parent" types, but the information stored in the "Parent" type is not //necessary. Just loop through the array, and for each object, pull out the ID. if (fileObj.TryGetValue("parents", out holderValue)) { foreach (var parentObj in (JArray)holderValue) { file.Parents.Add((string)parentObj); //Store the ID field. } } //Like parents, the "Property" object is also a type, but some information for the "Property" type //is not necessary. Just loop through the array, and for each object, pull out of the key/value. if (fileObj.TryGetValue("properties", out holderValue)) { //Store each property as a key value pair. foreach (var propertyObj in (JArray)holderValue) { file.Properties.Add((string)propertyObj["key"], (string)propertyObj["value"]); } } return(file); }
// Given a filename within the executable path and a filename // Return a Filepath that combines the path in the pathFilename file and the given filename // where pathFilename like "path.apis.txt" or "path.pw.txt" // where filename like "system.apis.enc" or "system.pw.txt" // If the pathFilename doesn't exist in executable path, default to "C:\cryptomania" public static string GetFilepath(string pathFilename, string filename) { return(Path.Combine(GFile.GetString(pathFilename, "C:\\cryptomania"), filename)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(GFile obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }