Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some smarter defaults for persistence of data #25

Merged
merged 7 commits into from
Mar 1, 2023

Conversation

MichaelGHSeg
Copy link
Contributor

No description provided.

this.writeKey = writeKey;
this.persistentDataPath = persistentDataPath;
this.persistentDataPath = persistentDataPath ?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work on unity on mobile? since it requires to be Application.persistentDataPath for unity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it worked when I tried it and returned the same value that I got from .Net. I didn't test Unity's Application.persistentDataPath, but from googling it should return the same values. I'm guessing it's a convenience thing?

@@ -75,7 +81,19 @@ public class Configuration
this.apiHost = apiHost;
this.cdnHost = cdnHost;
this.exceptionHandler = exceptionHandler;
this.storageProvider = storageProvider ?? new DefaultStorageProvider();

if (storageProvider != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the more I think the more I feel we probably only need to smart default persist data path. we should always to default to use storage unless the user specifies to use in memory. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm in favor. More consistent behavior, fewer assumptions and surprises.

/// </param>
public Configuration(string writeKey,
string persistentDataPath,
string persistentDataPath = null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we have a way to provide StorageProvider, I think we can move this parameter to where we create a storage provider. since these two things are related, it makes sense to put them at one place.

@@ -33,11 +33,12 @@ public class Configuration
/// </summary>
/// <param name="writeKey">the Segment writeKey</param>
/// <param name="persistentDataPath">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to remove this comment block too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -65,8 +66,9 @@ public class Configuration
ICoroutineExceptionHandler exceptionHandler = null,
IStorageProvider storageProvider = default)
{
var platform = SystemInfo.getPlatform();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this variable is unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks.

@@ -73,6 +73,12 @@ public interface IStorageProvider

public class DefaultStorageProvider : IStorageProvider
{
public string PersistentDataPath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make it a property. public field is discouraged. see here for comparison

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Analytics-CSharp/Segment/Analytics/Configuration.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@wenxi-zeng wenxi-zeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MichaelGHSeg MichaelGHSeg merged commit 72211ba into main Mar 1, 2023
@MichaelGHSeg MichaelGHSeg deleted the MichaelGHSeg/LIBMOBILE-1096 branch March 1, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants