~ubuntu-branches/ubuntu/lucid/mono/lucid

« back to all changes in this revision

Viewing changes to mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

  • Committer: Bazaar Package Importer
  • Author(s): Mirco Bauer
  • Date: 2009-07-30 19:35:10 UTC
  • mto: (5.2.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090730193510-cdttfvqokq2kmdvh
Tags: upstream-2.4.2.3+dfsg
ImportĀ upstreamĀ versionĀ 2.4.2.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
using System.Security.Permissions;
38
38
using System.Security.Policy;
39
39
using System.Text;
 
40
using System.Threading;
40
41
 
41
42
using Mono.Security.Cryptography;
42
43
 
56
57
                private bool _resolved;
57
58
                private ulong _maxSize;
58
59
                private Evidence _fullEvidences;
 
60
                private static Mutex mutex = new Mutex ();
59
61
 
60
62
                public static IEnumerator GetEnumerator (IsolatedStorageScope scope)
61
63
                {
392
394
                        // identities have been selected
393
395
                        directory = new DirectoryInfo (root);
394
396
                        if (!directory.Exists) {
395
 
                                directory.Create ();
396
 
                                SaveIdentities (root);
 
397
                                try {
 
398
                                        directory.Create ();
 
399
                                        SaveIdentities (root);
 
400
                                }
 
401
                                catch (IOException) {
 
402
                                }
397
403
                        }
398
404
                }
399
405
 
646
652
                        if (!File.Exists (root + ".storage"))
647
653
                                throw new IsolatedStorageException (Locale.GetText ("Missing identities."));
648
654
 
 
655
                        BinaryFormatter deformatter = new BinaryFormatter ();
649
656
                        using (FileStream fs = File.OpenRead (root + ".storage")) {
650
 
                                BinaryFormatter deformatter = new BinaryFormatter ();
651
657
                                Identities identities = (Identities) deformatter.Deserialize (fs);
652
 
                                fs.Close ();
653
658
 
654
659
                                _applicationIdentity = identities.Application;
655
660
                                _assemblyIdentity = identities.Assembly;
661
666
                private void SaveIdentities (string root)
662
667
                {
663
668
                        Identities identities = new Identities (_applicationIdentity, _assemblyIdentity, _domainIdentity);
664
 
                        using (FileStream fs = File.OpenWrite (root + ".storage")) {
665
 
                                BinaryFormatter formatter = new BinaryFormatter ();
666
 
                                formatter.Serialize (fs, identities);
667
 
                                fs.Close ();
 
669
                        BinaryFormatter formatter = new BinaryFormatter ();
 
670
                        mutex.WaitOne ();
 
671
                        try {
 
672
                                using (FileStream fs = File.Create (root + ".storage")) {
 
673
                                        formatter.Serialize (fs, identities);
 
674
                                }
 
675
                        }
 
676
                        finally {
 
677
                                mutex.ReleaseMutex ();
668
678
                        }
669
679
                }
670
680
        }