コード例 #1
0
        //------------------------------------------------------------------------------
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            LoginManager login = new LoginManager();

            login.LoginBehavior = LoginBehavior.Web;
            login.LogOut();
            login.LogInWithReadPermissions(readPermissions.ToArray(), null, delegate(LoginManagerLoginResult result, NSError error)
            {
                if (error != null)
                {
                    UpdateCredentials(string.Empty);
                }
                else if (result.IsCancelled)
                {
                    UpdateCredentials(string.Empty);

                    ((AppDelegate)UIApplication.SharedApplication.Delegate).Continue(new SettingsViewController
                    {
                        AddLoginButton         = true,
                        AddSyncInProgressLabel = false,
                        EnableSettingsReload   = false,
                        AddSyncDatasetButton   = false,
                    });
                }
                else
                {
                    var accessToken = result.Token;
                    UpdateCredentials(accessToken.TokenString);

                    var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
                    appDelegate.SynchronizeSettings();

                    appDelegate.Continue(new SettingsViewController
                    {
                        AddLoginButton         = false,
                        AddLogoutButton        = true,
                        AddSyncInProgressLabel = true,
                        EnableSettingsReload   = true,
                        AddSyncDatasetButton   = true,
                    });

                    // plugins are persistant and next call return the same object
                    var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>();
                    plugin.SynchronizeDataset();
                }
            });
        }
        //------------------------------------------------------------------------------
        public void OnSyncSuccess(object sender, SyncSuccessEventArgs e)
        {
            if (!EnableSettingsReload)
            {
                return;
            }

            Root.Remove(m_syncLabelSection);
            CognitoSyncSettings.LoadSettings();

            m_boolElement.Value         = CognitoSyncSettings.Boolean;
            m_textElement.Value         = CognitoSyncSettings.Text;
            m_enumElement.RadioSelected = (int)CognitoSyncSettings.Enum;
            Root.Reload(m_enumElement, UITableViewRowAnimation.Automatic);
        }
コード例 #3
0
        //------------------------------------------------------------------------------
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Profile.EnableUpdatesOnAccessTokenChange(true);
            Settings.AppId       = Constants.FacebookAppId;
            Settings.DisplayName = Constants.FacebookAppName;

            CognitoSyncSettings.LoadSettings();

            // plugins are persistant per instance (static settings processed by separate, internal instance)
            // and next call will return the same object
            var plugin = CognitoSyncSettings.GetPlugin <ICognitoSyncSettingsPlugin>();

            plugin.OnSyncSuccess += (sender, e) =>
            {
                var el = m_ViewController as ICognitoSyncEventsListerner;
                InvokeOnMainThread(() =>
                {
                    if (el != null)
                    {
                        el.OnSyncSuccess(sender, e);
                    }
                });
            };

            plugin.OnSyncFailure += (sender, e) =>
            {
                var el = m_ViewController as ICognitoSyncEventsListerner;
                InvokeOnMainThread(() =>
                {
                    if (el != null)
                    {
                        el.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);
            };

            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            Continue(new SettingsViewController()
            {
                AddLoginButton = true
            });
            Window.MakeKeyAndVisible();

            // This method verifies if you have been logged into the app before, and keep you logged in after you reopen or kill your app.
            return(ApplicationDelegate.SharedInstance.FinishedLaunching(application, launchOptions));
        }
        //------------------------------------------------------------------------------
        RootElement CreateRoot()
        {
            // IDynamicSettingsPlugin ds = CognitoSyncSettings.GetPlugin<ICognitoSyncSettingsPlugin>() as IDynamicSettingsPlugin;
            // You can use CognitoSync dynamic settings
            // Just cast plugin interface to IDynamicSettingsPlugin

            var info = new MultilineElement("See Sample.CognitoSyncSettings.Android and Sample.CognitoSyncSettings.Windows projects for more details");

            m_boolElement = new BooleanElement("Bool value", CognitoSyncSettings.Boolean);
            m_boolElement.ValueChanged += (object sender, EventArgs e) =>
            {
                CognitoSyncSettings.Boolean = m_boolElement.Value;
                CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Boolean);
            };

            m_textElement = new EntryElement("", "Text",
                                             CognitoSyncSettings.Text);
            m_textElement.AutocorrectionType     = UITextAutocorrectionType.No;
            m_textElement.AutocapitalizationType = UITextAutocapitalizationType.None;
            m_textElement.Changed += (object sender, EventArgs e) =>
            {
                CognitoSyncSettings.Text = m_textElement.Value;
                CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Text);
            };

            Action <RadioElementEx, EventArgs> saveAutoLockDelegate = (sender, e) =>
            {
                CognitoSyncSettings.Enum = (EEnumValues)m_enumElement.RadioSelected;
                CognitoSyncSettings.SaveSetting(s => CognitoSyncSettings.Enum);
            };

            m_enumElement = new RootElement("Enum value", new RadioGroup((int)CognitoSyncSettings.Enum))
            {
                new Section()
                {
                    new RadioElementEx("Zero", saveAutoLockDelegate),
                    new RadioElementEx("One", saveAutoLockDelegate),
                    new RadioElementEx("Two", saveAutoLockDelegate),
                    new RadioElementEx("Three", saveAutoLockDelegate),
                    new RadioElementEx("Four", saveAutoLockDelegate),
                    new RadioElementEx("Five", saveAutoLockDelegate),
                    new RadioElementEx("Six", saveAutoLockDelegate),
                    new RadioElementEx("Seven", saveAutoLockDelegate),
                    new RadioElementEx("Eight", saveAutoLockDelegate),
                    new RadioElementEx("Nine", saveAutoLockDelegate),
                    new RadioElementEx("Ten", saveAutoLockDelegate),
                }
            };

            return(new RootElement("CognitoSync Settings")
            {
                new Section()
                {
                    info
                },
                new Section()
                {
                    m_boolElement,
                    m_textElement,
                    m_enumElement,
                }
            });
        }