ok, im having some syntax issues that keep evading me. :(
one is at the very end with Type or namespace definition, or end-of-file expected
and the other is about half way at private static void OnTimedEvent1(object source, ElapsedEventArgs e)
with { expected
thanks
and the actual CODE: ( i put where the errors are in here too)
namespace Gmail_final_prep
{
public class Gmail_FP
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
gTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent1);
gTimer.Interval = 2000;
gTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(gTimer);
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sAscii);
return System.Convert.T开发者_JS百科oBase64String(bytes, 0, bytes.Length);
}
public static string CheckMail()
{
string result = "0";
try
{
var url = @"https://gmail.google.com/gmail/feed/atom";
var USER = "usr";
var PASS = "pss";
var encoded = TextToBase64(USER + ":" + PASS);
var myWebRequest = HttpWebRequest.Create(url);
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add("Authorization", "Basic " + encoded);
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
System.Text.StringBuilder gml = new System.Text.StringBuilder();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
if (reader.Name == "fullcount")
{
gml.Append(reader.ReadElementContentAsString()).Append(",");
//result = reader.ReadElementContentAsString();
//return result;
}
}
Console.WriteLine(gml.ToString());
}
catch (Exception ee) { Console.WriteLine(ee.Message); }
return result;
}
}
}
} // Type or namespace definition, or end-of-file expected here
You have a method within another method.
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
This may be what you're trying to do -- you want to call CheckMail()
from within your event handler.
using System;
using System.Net;
using System.Timers;
using System.Xml;
namespace Gmail_final_prep
{
public class Gmail_FP
{
private static System.Timers.Timer gTimer;
public static void GMain()
{
gTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
gTimer.Elapsed += OnTimedEvent1;
gTimer.Interval = 2000;
gTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(gTimer);
}
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
CheckMail();
}
public static string TextToBase64(string sAscii)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sAscii);
return System.Convert.ToBase64String(bytes, 0, bytes.Length);
}
public static string CheckMail()
{
string result = "0";
try
{
var url = @"https://gmail.google.com/gmail/feed/atom";
var USER = "usr";
var PASS = "pss";
var encoded = TextToBase64(USER + ":" + PASS);
var myWebRequest = HttpWebRequest.Create(url);
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add("Authorization", "Basic " + encoded);
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
System.Text.StringBuilder gml = new System.Text.StringBuilder();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
if (reader.Name == "fullcount")
{
gml.Append(reader.ReadElementContentAsString()).Append(",");
//result = reader.ReadElementContentAsString();
//return result;
}
}
Console.WriteLine(gml.ToString());
}
catch (Exception ee) { Console.WriteLine(ee.Message); }
return result;
}
}
} // Type or namespace definition, or end-of-file expected here
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
{
This isn't legal -- you can't embed one method inside another.
I am wondering what this part is doing:
private static void OnTimedEvent1(object source, ElapsedEventArgs e)
{ // { expected here
public static string TextToBase64(string sAscii)
Your problem might be right here.
精彩评论