static void session_OnBuddyMoved(AccSession session, IAccUser user, IAccGroup fromGroup, int fromPosition, IAccGroup toGroup, int toPosition, AccResult hr) { throw new NotImplementedException(); }
static void session_OnBuddyAdded(AccSession session, IAccGroup group, IAccUser user, int position, AccResult hr) { throw new NotImplementedException(); }
static void session_OnGroupRemoved(AccSession session, IAccGroup group, AccResult hr) { throw new NotImplementedException(); }
static void session_OnGroupMoved(AccSession session, IAccGroup group, int fromPosition, int toPosition, AccResult hr) { throw new NotImplementedException(); }
static void session_OnDeliverStoredImsResult(AccSession session, int transId, AccResult hr) { throw new NotImplementedException(); }
static void session_OnImSendResult(AccSession session, IAccImSession imSession, IAccParticipant recipient, IAccIm im, AccResult hr) { throw new NotImplementedException(); }
private static void accSess_OnUserRequestPropertyResult(AccSession session, IAccUser user, AccUserProp Property, int transId, AccResult hr, object propertyValue) { //if its the idle time, raise the event if necessary if (Property == AccUserProp.AccUserProp_IdleTime) { //if the user's idle time is > 0 then raise idle event if ((int)propertyValue > 0) { BuddyWentIdle(user.Name, GetUsersGroupsNames(user)); } } else if (Property == AccUserProp.AccUserProp_Profile) { //profile is actually an IM object IAccIm im = (IAccIm)propertyValue; //dequeue the request Actions.QueueOfRequests.Dequeue(); //check that this is the last queued request if (Actions.QueueOfRequests.Count < 1) { //add the profile to the return var strReturnRequest += im.GetConvertedText(MIME_TYPE); //invoke info received event if (InfoReceived != null) { InfoReceived.Invoke(user.Name, strReturnRequest); } } else { //add the profile to the return strReturnRequest = im.GetConvertedText(MIME_TYPE); } } else if (Property == AccUserProp.AccUserProp_AwayMessage) { //away message is actually an IM object IAccIm im = (IAccIm)propertyValue; //dequeue the request Actions.QueueOfRequests.Dequeue(); //check the request count if (Actions.QueueOfRequests.Count < 1) { //put this text at the beginning of the request strReturnRequest = im.GetConvertedText(MIME_TYPE) + strReturnRequest; //invoke away message reveived event if (AwayMessageReceived != null) { AwayMessageReceived.Invoke(user.Name, strReturnRequest); } } else { //set the return request var as the decoded string strReturnRequest = im.GetConvertedText(MIME_TYPE); } } }
private static void accSess_OnStateChange(AccSession session, AccSessionState State, AccResult hr) { #region State switch (State) { case AccSessionState.AccSessionState_Offline: break; case AccSessionState.AccSessionState_Online: if (SuccessfulLogin != null) { SuccessfulLogin.Invoke(); LoadBuddyListGroups(); LoadBuddyListNames(); } break; default: break; } #endregion #region Errors switch (hr) { case AccResult.ACC_E_CONNECT_ERROR: case AccResult.ACC_E_INVALID_CLIENT_INFO: break; case AccResult.ACC_E_EXPIRED_KEY: case AccResult.ACC_E_RATE_LIMITED_KEY: case AccResult.ACC_E_SUSPENDED_KEY: case AccResult.ACC_E_INVALID_DATA: case AccResult.ACC_E_INVALID_KEY: case AccResult.ACC_E_INVALID_FINGERPRINT: if (UnknownSignonError != null) { UnknownSignonError.Invoke(); } break; //invalid SN or suspended SN case AccResult.ACC_E_SUSPENDED_IDENTITY: case AccResult.ACC_E_INVALID_IDENTITY: if (InvalidScreenName != null) { InvalidScreenName.Invoke(); } break; //invalid Password case AccResult.ACC_E_INVALID_PASSWORD: if (InvalidPassword != null) { InvalidPassword.Invoke(); } break; case AccResult.ACC_S: case AccResult.ACC_E: case AccResult.ACC_S_NO_CHANGE: case 0: break; default: System.Windows.Forms.MessageBox.Show(hr.ToString()); break; } #endregion }
private static void accSess_OnUserChange(AccSession session, IAccUser oldUser, IAccUser newUser, AccUserProp Property, AccResult hr) { //get states AccUserState oldState = (AccUserState)oldUser.get_Property(AccUserProp.AccUserProp_State); AccUserState newState = (AccUserState)newUser.get_Property(AccUserProp.AccUserProp_State); //compare old state to the new state to figure out what happened to the buddy switch (oldState) { case AccUserState.AccUserState_Away: switch (newState) { case AccUserState.AccUserState_Idle: //buddy went from just Away to Away and Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Away to Offline BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Away to just Online (aka took away down) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Idle: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from just Idle to Away and Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Idle to Offline BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Idle to Online (aka no longer Idle) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from Offline to Away (aka Signed On then Went Away) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Idle: //buddy went from Offline to Idle (aka Signed On then Went Idle) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Offline/Unknown to Offline/Unknown BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Offline to Online BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Online: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from Online to Away BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Idle: //buddy went from Online to Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Online to Offline/Unknown BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; } break; } }
public void Unions_AccResult__HasValues() { var x = default(AccResult <int, string>); Assert.False(x.HasValue); Assert.False(x.IsSuccess); Assert.False(x.IsFailure); x = 0; Assert.True(x.HasValue); Assert.True(x.IsSuccess); Assert.False(x.IsFailure); Assert.Equal(x.AsSuccess, (0)); x = 7; Assert.True(x.HasValue); Assert.True(x.IsSuccess); Assert.False(x.IsFailure); Assert.Equal(x.AsSuccess, (7)); x = "seven"; Assert.True(x.HasValue); Assert.False(x.IsSuccess); Assert.True(x.IsFailure); Assert.Equal(x.AsFailure, ((new List <string>() { "seven" }))); var isEven = new AccResult <Func <int, bool>, string>(_ => _ % 2 == 0); var ret = isEven.Apply(x); Assert.True(ret.HasValue); Assert.False(ret.IsSuccess); Assert.True(ret.IsFailure); Assert.Equal(ret.AsFailure, ((new List <string>() { "seven" }))); x = 8; ret = isEven.Apply(x); Assert.True(ret.HasValue); Assert.True(ret.IsSuccess); Assert.False(ret.IsFailure); Assert.Equal(ret.AsSuccess, (true)); var hasFailure = new AccResult <Func <int, bool>, string>("failure"); ret = hasFailure.Apply(x); Assert.True(ret.HasValue); Assert.False(ret.IsSuccess); Assert.True(ret.IsFailure); Assert.Equal(ret.AsFailure, ((new List <string>() { "failure" }))); x = "bothfailure"; ret = hasFailure.Apply(x); Assert.True(ret.HasValue); Assert.False(ret.IsSuccess); Assert.True(ret.IsFailure); Assert.Equal(ret.AsFailure, ((new List <string>() { "failure", "bothfailure" }))); var ret2 = hasFailure.Apply(x); Assert.Equal(ret.AsFailure, (ret2.AsFailure)); // apply (success) var a = new AccResult <int, string>(3); var b = new AccResult <int, string>(4); var c = new AccResult <int, string>(5); var applyResult = AccResultOps.LiftA3(Tuple.Create, a, b, c); var expected = Tuple.Create(3, 4, 5); Assert.Equal(applyResult.AsSuccess, (expected)); // apply (failure) var a2 = new AccResult <int, string>(3); var b2 = new AccResult <int, string>("failure 1"); var c2 = new AccResult <int, string>("failure 2"); var applyResult2 = AccResultOps.LiftA3(Tuple.Create, a2, b2, c2); var expected2 = new List <string>() { "failure 1", "failure 2" }; Assert.Equal(applyResult2.AsFailure, (expected2)); // sequence (success) var accList = new AccResult <int, string>[] { 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; var sequenceResult = accList.SequenceA(); var successExpected = new int[] { 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; Assert.Equal(sequenceResult.AsSuccess, (successExpected)); // sequence (fail) var accList2 = new AccResult <int, string>[] { 4, 5, 1, 1, 1, 13, "fail 1", 3, 1, "fail 2", 4, 5, 1, 5, "fail 3" }; var sequenceResult2 = accList2.SequenceA(); var failExpected2 = new string[] { "fail 1", "fail 2", "fail 3" }; Assert.Equal(sequenceResult2.AsFailure, (failExpected2)); // traverse (success) var tList = new int[] { 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; var tResult = AccResultOps.Traverse <int, int, string>(p1 => p1, tList); Assert.Equal(tResult.AsSuccess, (tList)); // traverse (fail) var t2List = new int[] { 3, 4, 5, 1, 1, 1, 1, 1, 1, 3, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; var t2Result = AccResultOps.Traverse <int, int, string>(p1 => { if (p1 % 2 == 1) { return(p1); } else { return("n" + p1.ToString()); }; }, t2List); Assert.Equal(t2Result.AsFailure, (new string[] { "n4", "n6" })); }
void s_OnFileXferComplete(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer, AccResult hr) { try { string user = fileXferSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); Console.WriteLine("File transfer complete! (from user: {0})", user); long size = Int64.Parse(fileXferSession.get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_TotalBytes).ToString()); if (!uploadSize.ContainsKey(user)) { uploadSize.Add(user, size); } else { uploadSize[user] += size; } // move the file to where we want it string localPath = fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath).ToString(); string fileName = user + "\\" + localPath.Substring(DEFAULT_DOWNLOAD_PATH.Length); // we need to create all the necessary directories string[] parts = fileName.Split('\\'); string dir = ""; for (int i = 0; i < parts.Length - 1; i++) { string currentDir = BASE_PATH + dir + parts[i]; if (!Directory.Exists(currentDir)) { Directory.CreateDirectory(currentDir); } dir += parts[i] + "\\"; } // check if it already existed, if so delete it if (File.Exists(BASE_PATH + fileName)) { File.Delete(BASE_PATH + fileName); } File.Move(localPath, BASE_PATH + fileName); // add it to uploads db // if it already existed remove it beforehand if (uploads.ContainsKey(fileName)) { uploads.Remove(fileName); } uploads.Add(fileName, new Upload(fileName, DateTime.Now)); // now remove the old directory, if any if (parts.Length > 2 && Directory.Exists(DEFAULT_DOWNLOAD_PATH + parts[1])) { Directory.Delete(DEFAULT_DOWNLOAD_PATH + parts[1], true); } } catch (Exception e) { Console.WriteLine("exception occurred when completing transfer: " + e.Message + e.StackTrace); } }
private void s_OnStateChange(AccSession session, AccSessionState state, AccResult hr) { Console.WriteLine("STATE CHANGE: {0} {1}", state, hr); if (state == AccSessionState.AccSessionState_Online) { Console.WriteLine("...Welcome to AOL Instant Messenger (SM)..."); WaitForCommand(); } else if (state == AccSessionState.AccSessionState_Offline) { Thread.Sleep(5000); // automatic reconnection s.Identity = m_userName; s.SignOn(m_passWord); /* if (killProcessesThread != null) { killProcessesThread.Abort(); } Application.Exit(); */ } }
private void s_OnSecondarySessionStateChange(AccSession session, IAccSecondarySession piSecSession, AccSecondarySessionState State, AccResult hr) { try { // accept all incoming IMs even if the user is not on the buddy list if ((AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId) == AccSecondarySessionServiceId.AccSecondarySessionServiceId_Im) { if (State == AccSecondarySessionState.AccSecondarySessionState_ReceivedProposal) { Console.WriteLine("** acshbuddy has received an IM from {0}.", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); piSecSession.Accept(); } } else if ((AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId) == AccSecondarySessionServiceId.AccSecondarySessionServiceId_FileXfer) { if (State == AccSecondarySessionState.AccSecondarySessionState_ReceivedProposal) { Console.WriteLine("** acshbuddy has received an file xfer request from {0}.", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); string fileName = ((IAccFileXferSession)piSecSession). get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_Name).ToString(); string isDir = ((IAccFileXferSession)piSecSession).get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_IsDirectory).ToString(); string size = ((IAccFileXferSession)piSecSession).get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_TotalBytes).ToString(); string user = piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); // check the size if (Int64.Parse(size) > MAX_UPLOAD_SIZE) { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); IAccImSession imSess = session. CreateImSession(user, AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("Rejected transfer because file size was bigger than 200 Kilobytes.", "text/plain")); Console.WriteLine("Rejected transfer because file size was too large: " + size); return; } else if (uploadSize.ContainsKey(user) && uploadSize[user] + Int64.Parse(size) > MAX_TOTAL_UPLOAD_SIZE) { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); IAccImSession imSess = session. CreateImSession(user, AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("You have uploaded more than 1MB already. Wait until 15min are up and you may upload more.", "text/plain")); Console.WriteLine("Rejected transfer because user uploaded more than 1MB"); return; } // check extension - must be one of php, cs, java, cpp, h, hpp, py, pl - only check extension for files if (isDir.Equals("False")) { string ext = fileName.LastIndexOf(".") != -1 ? fileName.Substring(fileName.LastIndexOf(".") + 1) : ""; if (ext.ToLower().Equals("php") || ext.ToLower().Equals("cs") || ext.ToLower().Equals("java") || ext.ToLower().Equals("cpp") || ext.ToLower().Equals("h") || ext.ToLower().Equals("hpp") || ext.ToLower().Equals("java") || ext.ToLower().Equals("py") || ext.ToLower().Equals("pl")) { piSecSession.Accept(); } else { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); Console.WriteLine("Rejected transfer because extension was invalid: " + ext + " (" + fileName + ")"); IAccImSession imSess = session. CreateImSession(piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(), AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("Rejected transfer because file did not have any of the specified extensions.", "text/plain")); } } else { piSecSession.Accept(); } } else if (State == AccSecondarySessionState.AccSecondarySessionState_Offline) { Console.WriteLine("** file xfer with {0} now complete!", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); //piSecSession.EndSession(); } } else { Console.WriteLine("service id: {0}, state: {1}", (AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId), State); } } catch (Exception e) { Console.WriteLine("exception occurred during secondary session state change: {0}", e.Message + e.StackTrace); } }