void UsageDataUploaded(IAsyncResult result, UdcProxy.UDCUploadServiceClient client, string commaSeparatedSessionIDList) { bool success = false; try { client.EndUploadUsageData(result); success = true; } catch (CommunicationException) { // ignore error (maybe currently not connected to network) } catch (TimeoutException) { // ignore error (network connection trouble?) } client.Close(); if (success) { RemoveUploadedData(commaSeparatedSessionIDList); } }
/// <summary> /// Starts the upload of the usage data. /// </summary> /// <exception cref="IncompatibleDatabaseException">The database version is not compatible with this /// version of the AnalyticsSessionWriter.</exception> public void StartUpload(Binding binding, EndpointAddress endpoint) { UsageDataMessage message; bool addDummySession = false; using (SQLiteConnection connection = OpenConnection()) { using (SQLiteTransaction transaction = connection.BeginTransaction()) { CheckDatabaseVersion(connection); HasUploadedTodayStatus status = HasAlreadyUploadedToday(connection); if (status == HasUploadedTodayStatus.Yes) { message = null; } else { message = FetchDataForUpload(connection, false); if (status == HasUploadedTodayStatus.NeverUploaded) addDummySession = true; } transaction.Commit(); } } if (message != null) { string commaSeparatedSessionIDList = GetCommaSeparatedIDList(message.Sessions); if (addDummySession) { // A dummy session is used for the first upload to notify the server of the user's environment. // Without this, we couldn't tell the version of a user who tries SharpDevelop once but doesn't use it long // enough for an actual session to be uploaded. UsageDataSession dummySession = new UsageDataSession(); dummySession.SessionID = 0; dummySession.StartTime = DateTime.UtcNow; dummySession.EnvironmentProperties.AddRange(UsageDataSessionWriter.GetDefaultEnvironmentData()); if (this.EnvironmentDataForDummySession != null) dummySession.EnvironmentProperties.AddRange(this.EnvironmentDataForDummySession); message.Sessions.Add(dummySession); } DataContractSerializer serializer = new DataContractSerializer(typeof(UsageDataMessage)); byte[] data; using (MemoryStream ms = new MemoryStream()) { using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress)) { serializer.WriteObject(zip, message); } data = ms.ToArray(); } UdcProxy.UDCUploadServiceClient client = new UdcProxy.UDCUploadServiceClient(binding, endpoint); try { client.BeginUploadUsageData(productName, new MemoryStream(data), ar => UsageDataUploaded(ar, client, commaSeparatedSessionIDList), null); } catch (CommunicationException) { // ignore error (maybe currently not connected to network) } catch (TimeoutException) { // ignore error (network connection trouble?) } } }
/// <summary> /// Starts the upload of the usage data. /// </summary> /// <exception cref="IncompatibleDatabaseException">The database version is not compatible with this /// version of the AnalyticsSessionWriter.</exception> public void StartUpload(Binding binding, EndpointAddress endpoint) { UsageDataMessage message; bool addDummySession = false; using (SQLiteConnection connection = OpenConnection()) { using (SQLiteTransaction transaction = connection.BeginTransaction()) { CheckDatabaseVersion(connection); HasUploadedTodayStatus status = HasAlreadyUploadedToday(connection); if (status == HasUploadedTodayStatus.Yes) { message = null; } else { message = FetchDataForUpload(connection, false); if (status == HasUploadedTodayStatus.NeverUploaded) { addDummySession = true; } } transaction.Commit(); } } if (message != null) { string commaSeparatedSessionIDList = GetCommaSeparatedIDList(message.Sessions); if (addDummySession) { // A dummy session is used for the first upload to notify the server of the user's environment. // Without this, we couldn't tell the version of a user who tries SharpDevelop once but doesn't use it long // enough for an actual session to be uploaded. UsageDataSession dummySession = new UsageDataSession(); dummySession.SessionID = 0; dummySession.StartTime = DateTime.UtcNow; dummySession.EnvironmentProperties.AddRange(UsageDataSessionWriter.GetDefaultEnvironmentData()); if (this.EnvironmentDataForDummySession != null) { dummySession.EnvironmentProperties.AddRange(this.EnvironmentDataForDummySession); } message.Sessions.Add(dummySession); } DataContractSerializer serializer = new DataContractSerializer(typeof(UsageDataMessage)); byte[] data; using (MemoryStream ms = new MemoryStream()) { using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress)) { serializer.WriteObject(zip, message); } data = ms.ToArray(); } UdcProxy.UDCUploadServiceClient client = new UdcProxy.UDCUploadServiceClient(binding, endpoint); try { client.BeginUploadUsageData(productName, new MemoryStream(data), ar => UsageDataUploaded(ar, client, commaSeparatedSessionIDList), null); } catch (CommunicationException) { // ignore error (maybe currently not connected to network) } catch (TimeoutException) { // ignore error (network connection trouble?) } } }