コード例 #1
0
 private void wcf_ClientUpdateUserSettingsCompleted(IAsyncResult ar)
 {
     try
     {
         WCF.UpdateUserSettingsResponse rsWCF = ((WCF.SettingsContractClient)ar.AsyncState).EndUpdateUserSettings(ar);
         Merge(rsWCF.UserSettingsCD, false, MissingSchemaAction.Ignore);
         PrepareDataAfterUpdate();
         ClientUpdateUserSettingsCompleted(this, new EventArgs());
     }
     catch { }
 }
コード例 #2
0
        /// <summary>
        /// Client callable code to update UserSettings.
        /// </summary>
        /// <param name="async">Do the update async.</param>
        /// <returns>True if update is successful. If False, check for RowErrors.</returns>
        public bool ClientUpdateUserSettings(bool async)
        {
            if (string.IsNullOrEmpty(_userName))
            {
                throw new Exception("The UserName and/or FormName is null or empty.");
            }

            PrepareDataBeforeUpdate();

            if (UserSettings.Select("", "", DataViewRowState.Deleted).Length > 0 ||
                UserSettings.Select("", "", DataViewRowState.Added).Length > 0 ||
                UserSettings.Select("", "", DataViewRowState.ModifiedCurrent).Length > 0)
            {
                var ds = new UserSettingsCD();
                foreach (UserSettingsRow deletedRow in UserSettings.Select("", "", DataViewRowState.Deleted))
                {
                    ds.UserSettings.ImportRow(deletedRow);
                }
                foreach (UserSettingsRow addedRow in UserSettings.Select("", "", DataViewRowState.Added))
                {
                    ds.UserSettings.ImportRow(addedRow);
                }
                foreach (UserSettingsRow modifiedCurrentRow in UserSettings.Select("", "", DataViewRowState.ModifiedCurrent))
                {
                    ds.UserSettings.ImportRow(modifiedCurrentRow);
                }

                if (UseWcfService)
                {
                    try
                    {
                        var svWCF = new WCF.SettingsContractClient();
                        var rqWCF = new WCF.UpdateUserSettingsRequest {
                            UserSettingsCD = new WCF.UserSettingsCD()
                        };
                        rqWCF.UserSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore);

                        if (async)
                        {
                            if (String.IsNullOrEmpty(svWCF.Ping()))
                            {
                                throw new Exception("WCF is offline.");
                            }

                            svWCF.BeginUpdateUserSettings(rqWCF, wcf_ClientUpdateUserSettingsCompleted, svWCF);
                            return(true);
                        }

                        WCF.UpdateUserSettingsResponse rsWCF = svWCF.UpdateUserSettings(rqWCF);
                        Merge(rsWCF.UserSettingsCD, false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseWcfService = false; }                     // ignore if not responding
                }
                if (UseAsmxService)
                {
                    try
                    {
                        var svASMX = new ASMX.SettingsServiceASMX();
                        var rqASMX = new ASMX.UpdateUserSettingsRequest {
                            UserSettingsCD = new ASMX.UserSettingsCD()
                        };
                        rqASMX.UserSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore);

                        if (async)
                        {
                            svASMX.UpdateUserSettingsCompleted += asmx_ClientUpdateUserSettingsCompleted;
                            svASMX.UpdateUserSettingsAsync(rqASMX);
                            return(true);
                        }

                        ASMX.UpdateUserSettingsResponse rsASMX = svASMX.UpdateUserSettings(rqASMX);
                        Merge(rsASMX.UserSettingsCD, false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseAsmxService = false; }                     // ignore if not responding
                }
                if (UseClientServer)
                {
                    try
                    {
                        Merge(UpdateUserSettings(ds), false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseClientServer = false; }                     // ignore if not responding
                }
            }
            return(false);
        }