diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-15 22:17:20 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-15 22:17:20 -0800 |
commit | e12782c1a6727390b2107ff2e39d4ac6173d86fc (patch) | |
tree | 3be0ccda0a9425927263f5b6b9616ef8ba11ac08 /samples/ProviderCustomStore/CustomStore.cs | |
parent | 078b1f350eb40ceee7423c25b1d833dd1f242da4 (diff) | |
parent | a545f7be2693596fa14540c359e43150a6a7cf88 (diff) | |
download | DotNetOpenAuth-origin/mono.zip DotNetOpenAuth-origin/mono.tar.gz DotNetOpenAuth-origin/mono.tar.bz2 |
Merge branch 'v2.5' into monoorigin/mono
Conflicts:
src/DotNetOpenId/Properties/AssemblyInfo.cs
src/DotNetOpenId/RelyingParty/AuthenticationResponse.cs
Diffstat (limited to 'samples/ProviderCustomStore/CustomStore.cs')
-rw-r--r-- | samples/ProviderCustomStore/CustomStore.cs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/samples/ProviderCustomStore/CustomStore.cs b/samples/ProviderCustomStore/CustomStore.cs deleted file mode 100644 index 5b25ba4..0000000 --- a/samples/ProviderCustomStore/CustomStore.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System;
-using System.Data;
-using System.Globalization;
-using System.Security.Cryptography;
-using DotNetOpenId;
-using DotNetOpenId.RelyingParty;
-using IProviderAssociationStore = DotNetOpenId.IAssociationStore<DotNetOpenId.AssociationRelyingPartyType>;
-
-namespace ProviderCustomStore {
- /// <summary>
- /// This custom store serializes all elements to demonstrate peristent and/or shared storage.
- /// This is common in a web farm, for example.
- /// </summary>
- /// <remarks>
- /// This doesn't actually serialize anything to a persistent store, so restarting the web server
- /// will still clear everything this store is supposed to remember.
- /// But we "persist" all associations and nonces into a DataTable to demonstrate
- /// that using a database is possible.
- /// </remarks>
- public class CustomStore : IProviderAssociationStore {
- public static CustomStore Instance = new CustomStore();
- public CustomStoreDataSet dataSet = new CustomStoreDataSet();
-
- #region IAssociationStore<AssociationRelyingPartyType> Members
-
- public void StoreAssociation(AssociationRelyingPartyType distinguishingFactor, Association assoc) {
- var assocRow = dataSet.Association.NewAssociationRow();
- assocRow.DistinguishingFactor = distinguishingFactor.ToString();
- assocRow.Handle = assoc.Handle;
- assocRow.Expires = assoc.Expires.ToLocalTime();
- assocRow.PrivateData = assoc.SerializePrivateData();
- dataSet.Association.AddAssociationRow(assocRow);
- }
-
- public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor) {
- // properly escape the URL to prevent injection attacks.
- string value = distinguishingFactor.ToString();
- string filter = string.Format(CultureInfo.InvariantCulture, "{0} = '{1}'",
- dataSet.Association.DistinguishingFactorColumn.ColumnName, value);
- string sort = dataSet.Association.ExpiresColumn.ColumnName + " DESC";
- DataView view = new DataView(dataSet.Association, filter, sort, DataViewRowState.CurrentRows);
- if (view.Count == 0) return null;
- var row = (CustomStoreDataSet.AssociationRow)view[0].Row;
- return Association.Deserialize(row.Handle, row.Expires.ToUniversalTime(), row.PrivateData);
- }
-
- public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) {
- var assocRow = dataSet.Association.FindByDistinguishingFactorHandle(distinguishingFactor.ToString(), handle);
- return Association.Deserialize(assocRow.Handle, assocRow.Expires, assocRow.PrivateData);
- }
-
- public bool RemoveAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) {
- var row = dataSet.Association.FindByDistinguishingFactorHandle(distinguishingFactor.ToString(), handle);
- if (row != null) {
- dataSet.Association.RemoveAssociationRow(row);
- return true;
- } else {
- return false;
- }
- }
-
- public void ClearExpiredAssociations() {
- removeExpiredRows(dataSet.Association, dataSet.Association.ExpiresColumn.ColumnName);
- }
-
- #endregion
-
- void removeExpiredRows(DataTable table, string expiredColumnName) {
- string filter = string.Format(CultureInfo.InvariantCulture, "{0} < #{1}#",
- expiredColumnName, DateTime.Now);
- DataView view = new DataView(table, filter, null, DataViewRowState.CurrentRows);
- for (int i = view.Count - 1; i >= 0; i--)
- view.Delete(i);
- }
-
- }
-}
|