Beispiel #1
0
        //------------------------------------------------------------------------------
        public void SynchronizeSettings()
        {
            AndHUD.Shared.Show(this, "Synchronizing dataset...");

            var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>();

            plugin.SynchronizeDataset();
        }
Beispiel #2
0
        //------------------------------------------------------------------------------
        public static void UpdatePropertiesText()
        {
            CognitoSyncSettings.LoadSettings();

            TextView textView = (TextView)s_TextView.Target;

            String propertiesText = String.Format(
                "Bool value is '{0}'\n" +
                "TextPreference value is '{1}'\n" +
                "EnumPreference value is '{2}'",
                CognitoSyncSettings.Boolean,
                CognitoSyncSettings.Text,
                CognitoSyncSettings.Enum
                );

            textView.Text = propertiesText;
        }
            //------------------------------------------------------------------------------
            public override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                AddPreferencesFromResource(Resource.Xml.preferences);

                var switchPreference = (SwitchPreference)FindPreference("switch");
                var textPrference    = (EditTextPreference)FindPreference("text");
                var enumPreference   = (ListPreference)FindPreference("enum");

                switchPreference.OnPreferenceChangeListener = this;
                textPrference.OnPreferenceChangeListener    = this;
                enumPreference.OnPreferenceChangeListener   = this;

                CognitoSyncSettings.LoadSettings();

                switchPreference.Checked = CognitoSyncSettings.Boolean;
                textPrference.Text       = CognitoSyncSettings.Text;
                enumPreference.Value     = CognitoSyncSettings.Enum.ToString();
            }
            //------------------------------------------------------------------------------
            public bool OnPreferenceChange(Preference preference, Java.Lang.Object newValue)
            {
                switch (preference.Key)
                {
                case "switch":
                    CognitoSyncSettings.Boolean = (bool)newValue;
                    CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Boolean);
                    break;

                case "text":
                    CognitoSyncSettings.Text = (string)newValue;
                    CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Text);
                    break;

                case "enum":
                    CognitoSyncSettings.Enum = (EEnumValues)System.Enum.Parse(typeof(EEnumValues), (string)newValue);
                    CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Enum);
                    break;
                }

                return(true);
            }
            //------------------------------------------------------------------------------
            public override void OnCreate(Bundle savedInstanceState)
            {
                // IDynamicSettingsPlugin ds = CognitoSyncSettings.GetPlugin<ICognitoSyncSettingsPlugin>() as IDynamicSettingsPlugin;
                // You can use CognitoSync dynamic settings
                // Just cast plugin interface to IDynamicSettingsPlugin

                base.OnCreate(savedInstanceState);

                AddPreferencesFromResource(Resource.Xml.preferences);

                var switchPreference = (SwitchPreference)FindPreference("switch");
                var textPrference    = (EditTextPreference)FindPreference("text");
                var enumPreference   = (ListPreference)FindPreference("enum");

                switchPreference.OnPreferenceChangeListener = this;
                textPrference.OnPreferenceChangeListener    = this;
                enumPreference.OnPreferenceChangeListener   = this;

                CognitoSyncSettings.LoadSettings();

                switchPreference.Checked = CognitoSyncSettings.Boolean;
                textPrference.Text       = CognitoSyncSettings.Text;
                enumPreference.Value     = CognitoSyncSettings.Enum.ToString();
            }
        //------------------------------------------------------------------------------
        public override void OnCreate()
        {
            base.OnCreate();

            SettingsConfiguration.KeyStoreFileProtectionPassword = "******";
            SettingsConfiguration.KeyStoreFileName    = "keystore";
            SettingsConfiguration.EncryptionServiceID = "Advexp.Settings.Sample";

            Advexp.SettingsBaseConfiguration.RegisterSettingsPlugin <ICognitoSyncSettingsPlugin, CognitoSyncSettingsPlugin>();

            CognitoSyncSettingsConfiguration.Config = new AmazonCognitoSyncConfig()
            {
                RegionEndpoint = Constants.CognitoSyncRegion,
            };

            CognitoSyncSettingsConfiguration.Credentials = new CognitoAWSCredentials(Constants.CognitoSyncIdentityPoolId,
                                                                                     Constants.CognitoSyncIdentityRegion);

            // plugins are persistant and next call will return the same object
            var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>();

            plugin.OnSyncSuccess += (object sender, SyncSuccessEventArgs e) =>
            {
                ICognitoSyncEventsListerner listerner;
                lock (m_CognitoSyncListerner)
                {
                    listerner = m_CognitoSyncListerner;
                }
                if (listerner != null)
                {
                    listerner.OnSyncSuccess(sender, e);
                }
            };

            plugin.OnSyncFailure += (object sender, SyncFailureEventArgs e) =>
            {
                ICognitoSyncEventsListerner listerner;
                lock (m_CognitoSyncListerner)
                {
                    listerner = m_CognitoSyncListerner;
                }
                if (listerner != null)
                {
                    listerner.OnSyncFailure(sender, e);
                }
            };

            plugin.OnDatasetDeleted = delegate(Dataset ds)
            {
                // Do clean up if necessary
                // returning true informs the corresponding dataset can be purged in the local storage and return false retains the local dataset
                return(true);
            };

            plugin.OnDatasetMerged = delegate(Dataset dataset, List <string> datasetNames)
            {
                // returning true allows the Synchronize to continue and false stops it
                return(true);
            };

            plugin.OnSyncConflict = delegate(Dataset dataset, List <SyncConflict> conflicts)
            {
                var resolvedRecords = new List <Amazon.CognitoSync.SyncManager.Record>();
                foreach (SyncConflict conflictRecord in conflicts)
                {
                    // SyncManager provides the following default conflict resolution methods:
                    //      ResolveWithRemoteRecord - overwrites the local with remote records
                    //      ResolveWithLocalRecord - overwrites the remote with local records
                    //      ResolveWithValue - to implement your own logic
                    resolvedRecords.Add(conflictRecord.ResolveWithRemoteRecord());
                }
                // resolves the conflicts in local storage
                dataset.Resolve(resolvedRecords);

                // on return true the synchronize operation continues where it left,
                // returning false cancels the synchronize operation
                return(true);
            };
        }