Example #1
0
        public async Task <bool> GetFile()
        {
            try
            {
                var    doc     = this.update.Message.Document;
                string docName = this.botPath + String.Format("{0}, {1} - {2} Route Sheet.pdf", this.branch, this.name, this.update.Message.Date.ToString("MMM d, yyyy"));
                var    file    = await Bot.GetFileAsync(doc.FileId, System.IO.File.Create(docName));

                string log = "\r\nNEW DOCUMENT FROM " + this.name + " AT " + docName + "\r\n";
                foreach (var prop in doc.GetType().GetProperties())
                {
                    log += String.Format("{0} = {1}\r\n", prop.Name, prop.GetValue(doc, null));
                }
                System.IO.File.AppendAllText(botPath + "DocLog.txt", log);
                return(true);
            }
            catch (Exception err)
            {
                if (err.GetType() != new NullReferenceException().GetType())
                {
                    string log = "\r\nNEW EXCEPTION OF TYPE " + err.ToString() + "\r\n";
                    Console.WriteLine(log + "Check error log.");
                    foreach (var prop in err.GetType().GetProperties())
                    {
                        log += String.Format("{0} = {1}\r\n", prop.Name, prop.GetValue(err, null));
                    }
                    System.IO.File.AppendAllText(botPath + "ErrorLog.txt", log);
                }
            }
            return(false);
        }