コード例 #1
0
 public RequestHandler()
 {
     sessionLocker  = new Object();
     sessions       = new Dictionary <string, SessionData> ();
     pendingSession = null;
 }
コード例 #2
0
        private void HandleSendRequest(HttpListenerContext context)
        {
            //Logger.Debug("RECEIVE: HandleSendRequest called");

            if (pendingSession != null)
            {
                Logger.Debug("RECEIVE: HandleSendRequest: Found a pending Session... closing it");
                pendingSession.context.Response.StatusCode        = (int)HttpStatusCode.Unauthorized;
                pendingSession.context.Response.StatusDescription = Protocol.ResponseDeclined;
                pendingSession.context.Response.OutputStream.Close();
                pendingSession.context.Response.Close();
                pendingSession = null;
            }

            // get the information about what wants to be sent
            SessionData sd = new SessionData();

            sd.count     = Convert.ToInt32(context.Request.Headers[Protocol.Count]);
            sd.name      = context.Request.Headers[Protocol.Name];
            sd.type      = context.Request.Headers[Protocol.Type];
            sd.userName  = context.Request.Headers[Protocol.UserName];
            sd.size      = Convert.ToInt32(context.Request.Headers[Protocol.Size]);
            sd.sessionID = System.Guid.NewGuid().ToString();
            sd.context   = context;

            //Logger.Debug("RECEIVE: Preparing Notification");
            try {
                // place this request into the pending requests and notify the user of the request
                string summary = Services.PlatformService.GetString("{0} wants to give", sd.userName);
                string body;
                if (sd.count == 1)
                {
//				*** TOMBOY HACK **
                    if (sd.type.CompareTo(Protocol.ProtocolTypeTomboy) == 0)
                    {
                        body = Services.PlatformService.GetString("Tomboy Note:\n{0}", sd.name);
                    }
//				*** TASQUE HACK **
                    else if (sd.type.CompareTo(Protocol.ProtocolTypeTasque) == 0)
                    {
                        body = Services.PlatformService.GetString("Task:\n{0}", sd.name);
                    }
                    else
                    {
                        body = Services.PlatformService.GetString("{0}\nSize: {1} bytes", sd.name, sd.size);
                    }
                }
                else
                {
                    body = Services.PlatformService.GetString("{0} files\nSize: {1} bytes", sd.count, sd.size);
                }

                pendingSession = sd;

                //Logger.Debug("RECEIVE: About to do a Gtk.Application.Invoke for the notify dude.");
                Gtk.Application.Invoke(delegate {
                    //Logger.Debug("RECEIVE: Inside the Gtk.Application.Invoke dude");
                    Gdk.Pixbuf pixbuf = null;

//				*** TOMBOY HACK **
                    if (sd.type.CompareTo(Protocol.ProtocolTypeTomboy) == 0)
                    {
                        pixbuf = Gtk.IconTheme.Default.LoadIcon("tomboy", 48, 0);
                    }

//				*** TASQUE HACK **
                    if (sd.type.CompareTo(Protocol.ProtocolTypeTasque) == 0)
                    {
                        pixbuf = Gtk.IconTheme.Default.LoadIcon("tasque", 48, 0);
                    }

                    if (pixbuf == null)
                    {
                        pixbuf = Utilities.GetIcon("giver-48", 48);
                    }

                    Services.PlatformService.AskYesNoQuestion(summary, body, pixbuf,
                                                              Services.PlatformService.GetString("Accept"), Services.PlatformService.GetString("Decline"),
                                                              AcceptReceiveHandler, DeclineReceiveHandler);

                    Services.PlatformService.PlaySoundFile(Path.Combine(Giver.Defines.SoundDir, "notify.wav"));
                });
            } catch (Exception e) {
                Logger.Debug("RECEIVE: Exception attempting to notify {0}", e);

                pendingSession.context.Response.StatusCode        = (int)HttpStatusCode.Unauthorized;
                pendingSession.context.Response.StatusDescription = Protocol.ResponseDeclined;
                pendingSession.context.Response.OutputStream.Close();
                pendingSession.context.Response.Close();
                pendingSession.context = null;
                pendingSession         = null;
            }
        }
コード例 #3
0
ファイル: RequestHandler.cs プロジェクト: tcausby/giver
		private void HandleSendRequest(HttpListenerContext context)
		{
			//Logger.Debug("RECEIVE: HandleSendRequest called");

			if(pendingSession != null) {
				Logger.Debug("RECEIVE: HandleSendRequest: Found a pending Session... closing it");
				pendingSession.context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
				pendingSession.context.Response.StatusDescription = Protocol.ResponseDeclined;
				pendingSession.context.Response.OutputStream.Close();
				pendingSession.context.Response.Close();
				pendingSession = null;
			}

			// get the information about what wants to be sent
			SessionData sd = new SessionData();
			sd.count = Convert.ToInt32(context.Request.Headers[Protocol.Count]);
			sd.name = context.Request.Headers[Protocol.Name];
			sd.type = context.Request.Headers[Protocol.Type];
			sd.userName = context.Request.Headers[Protocol.UserName];
			sd.size = Convert.ToInt32(context.Request.Headers[Protocol.Size]);
			sd.sessionID = System.Guid.NewGuid().ToString();
			sd.context = context;

			//Logger.Debug("RECEIVE: Preparing Notification");
			try {
				// place this request into the pending requests and notify the user of the request
				string summary = Services.PlatformService.GetString("{0} wants to give", sd.userName);
				string body;
				if(sd.count == 1) {
//				*** TOMBOY HACK **
					if(sd.type.CompareTo(Protocol.ProtocolTypeTomboy) == 0) {
						body = Services.PlatformService.GetString("Tomboy Note:\n{0}", sd.name);
					}
//				*** TASQUE HACK **
					else if(sd.type.CompareTo(Protocol.ProtocolTypeTasque) == 0) {
						body = Services.PlatformService.GetString("Task:\n{0}", sd.name);
					}
					else
						body = Services.PlatformService.GetString("{0}\nSize: {1} bytes", sd.name, sd.size);

				}
				else
					body = Services.PlatformService.GetString("{0} files\nSize: {1} bytes", sd.count, sd.size);

				pendingSession = sd;

				//Logger.Debug("RECEIVE: About to do a Gtk.Application.Invoke for the notify dude.");
				Gtk.Application.Invoke( delegate {


					//Logger.Debug("RECEIVE: Inside the Gtk.Application.Invoke dude");
					Gdk.Pixbuf pixbuf = null;
					
//				*** TOMBOY HACK **
					if(sd.type.CompareTo(Protocol.ProtocolTypeTomboy) == 0)
						pixbuf = Gtk.IconTheme.Default.LoadIcon ("tomboy", 48, 0);

//				*** TASQUE HACK **
					if(sd.type.CompareTo(Protocol.ProtocolTypeTasque) == 0)
						pixbuf = Gtk.IconTheme.Default.LoadIcon ("tasque", 48, 0);
					
					if(pixbuf == null)
						pixbuf = Utilities.GetIcon ("giver-48", 48);

					Services.PlatformService.AskYesNoQuestion (summary, body, pixbuf,
						Services.PlatformService.GetString ("Accept"), Services.PlatformService.GetString ("Decline"), 
						AcceptReceiveHandler, DeclineReceiveHandler);

					Services.PlatformService.PlaySoundFile (Path.Combine (Giver.Defines.SoundDir, "notify.wav"));
				} );
			} catch (Exception e) {
				Logger.Debug("RECEIVE: Exception attempting to notify {0}", e);

				pendingSession.context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
				pendingSession.context.Response.StatusDescription = Protocol.ResponseDeclined;
				pendingSession.context.Response.OutputStream.Close();
				pendingSession.context.Response.Close();
				pendingSession.context = null;
				pendingSession = null;
			}			
		}
コード例 #4
0
ファイル: RequestHandler.cs プロジェクト: tcausby/giver
		public RequestHandler()
		{
			sessionLocker = new Object();
			sessions = new Dictionary<string, SessionData> ();
			pendingSession = null;
		}
コード例 #5
0
ファイル: RequestHandler.cs プロジェクト: tcausby/giver
		private void DeclineFile ()
		{
			lock(sessionLocker) {
				if(pendingSession != null) {
					pendingSession.context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
					pendingSession.context.Response.StatusDescription = Protocol.ResponseDeclined;
					pendingSession.context.Response.OutputStream.Close();
					pendingSession.context.Response.Close();
					pendingSession.context = null;
					pendingSession = null;
				}
			}
		}
コード例 #6
0
ファイル: RequestHandler.cs プロジェクト: tcausby/giver
		private void AcceptFile ()
		{
			lock(sessionLocker) {
				if(pendingSession != null) {
					pendingSession.context.Response.Headers.Set(Protocol.SessionID, pendingSession.sessionID);
					sessions.Add(pendingSession.sessionID, pendingSession);
					pendingSession.countReceived = 0;
					pendingSession.bytesReceived = 0;
					pendingSession.context.Response.StatusCode = (int)HttpStatusCode.OK;
					pendingSession.context.Response.StatusDescription = Protocol.ResponseOKToSend;
					pendingSession.context.Response.OutputStream.Close();
					pendingSession.context.Response.Close();
					pendingSession.context = null;
					pendingSession = null;
				}
			}
		}