/// <summary> /// Get journals a user has community access to. /// </summary> /// <param name="username">The user's username.</param> /// <param name="password">The user's password.</param> /// <param name="serverURL">The server's URL.</param> /// <returns></returns> static public string[] GetUseJournals(string username, string password, string serverURL) { ILJServer iLJ; XMLStructs.GetChallengeResponse gcr; string auth_response; XMLStructs.LoginParams lp; XMLStructs.LoginResponse lr; try { iLJ = LJServerFactory.Create(serverURL); gcr = iLJ.GetChallenge(); auth_response = MD5Hasher.Compute(gcr.challenge + MD5Hasher.Compute(password)); lp = new XMLStructs.LoginParams(username, "challenge", gcr.challenge, auth_response, 1, clientVersion, 0, 0, 1, 1); lr = iLJ.Login(lp); } catch (CookComputing.XmlRpc.XmlRpcFaultException xfe) { throw new ExpectedSyncException(ExpectedError.InvalidPassword, xfe); } catch (System.Net.WebException we) { throw new ExpectedSyncException(ExpectedError.ServerNotResponding, we); } catch (CookComputing.XmlRpc.XmlRpcServerException xse) { throw new ExpectedSyncException(ExpectedError.ServerNotResponding, xse); } return(lr.usejournals); }
static private void ThreadStart() { // The main threaded execution body for performing a sync. // This method is chopped up into smaller methods for clarity and structure. ILJServer iLJ; Journal.OptionsRow or = null; SyncItemCollection sic = null, deletedsic = null; EventCollection ec = null; CommentCollection ccbody = null, ccmeta = null; UserMapCollection umc = null; LoginResponse lr = new LoginResponse(); string communityPicURL = null; DateTime lastSync = DateTime.MinValue; SessionGenerateResponse sgr; int serverMaxID, localMaxID; try { // STEP 1: Initialize socb(new SyncOperationEventArgs(SyncOperation.Initialize, 0, 0)); syncException = null; or = j.Options; iLJ = LJServerFactory.Create(or.ServerURL); sic = new SyncItemCollection(); deletedsic = new SyncItemCollection(); ec = new EventCollection(); ccmeta = new CommentCollection(); ccbody = new CommentCollection(); umc = new UserMapCollection(); // STEP 2: Login socb(new SyncOperationEventArgs(SyncOperation.Login, 0, 0)); lr = new LoginResponse(); Login(or, iLJ, ref lr, ref communityPicURL); // STEP 3: SyncItems socb(new SyncOperationEventArgs(SyncOperation.SyncItems, 0, 0)); lastSync = DateTime.MinValue; SyncItems(or, iLJ, ref sic, ref deletedsic, ref lastSync); // STEP 4: GetEvents socb(new SyncOperationEventArgs(SyncOperation.GetEvents, 0, 0)); GetEvents(or, iLJ, ref sic, ref deletedsic, ref ec); if (or.GetComments) { // STEP 5: SessionGenerate socb(new SyncOperationEventArgs(SyncOperation.SessionGenerate, 0, 0)); sgr = new SessionGenerateResponse(); SessionGenerate(or, iLJ, ref sgr); // STEP 6: ExportCommentsMeta socb(new SyncOperationEventArgs(SyncOperation.ExportCommentsMeta, 0, 0)); localMaxID = serverMaxID = j.GetMaxCommentID(); ExportCommentsMeta(or, iLJ, sgr, ref serverMaxID, localMaxID, umc, ccmeta); // STEP 7: ExportCommentsBody socb(new SyncOperationEventArgs(SyncOperation.ExportCommentsBody, 0, 0)); ExportCommentsBody(or, iLJ, sgr, serverMaxID, localMaxID, ccbody); } } catch (Exception ex) { ParseException(ex, ref syncException); if (ex.GetType() == typeof(ThreadAbortException)) { socb(new SyncOperationEventArgs(SyncOperation.Failure, 0, 0)); // do this before thread terminates return; } } // STEP 8: Merge try { if (syncException == null) { socb(new SyncOperationEventArgs(SyncOperation.Merge, 0, 0)); Merge(j, ec, ccmeta, ccbody, umc, deletedsic, lr, communityPicURL, lastSync); socb(new SyncOperationEventArgs(SyncOperation.Success, ec.Count, ccbody.Count)); } else if (syncException.GetType() == typeof(ExpectedSyncException) && (((ExpectedSyncException)syncException).ExpectedError == ExpectedError.ServerNotResponding || ((ExpectedSyncException)syncException).ExpectedError == ExpectedError.ExportCommentsNotSupported || ((ExpectedSyncException)syncException).ExpectedError == ExpectedError.CommunityAccessDenied) && lr.moods != null) { socb(new SyncOperationEventArgs(SyncOperation.Merge, 0, 0)); if (sic.Count > 0) { lastSync = DateTime.Parse(sic.GetOldest().time, CultureInfo.InvariantCulture).AddSeconds(-1); } Merge(j, ec, ccmeta, ccbody, umc, deletedsic, lr, communityPicURL, lastSync); socb(new SyncOperationEventArgs(SyncOperation.PartialSync, ec.Count, ccbody.Count)); } else { socb(new SyncOperationEventArgs(SyncOperation.Failure, 0, 0)); } } catch (Exception ex) { syncException = ex; socb(new SyncOperationEventArgs(SyncOperation.Failure, 0, 0)); } }