Пример #1
0
        public SynchronizationModule(IFilesProvider filesProvider, IDocumentApiProvider documentApiProvider, IClientAuthorizationProvider authorizationProvider)
        {
            this.filesProvider = filesProvider;
            this.documentApiProvider = documentApiProvider;
            this.authorizationProvider = authorizationProvider;

            authorizationProvider.LoggedIn += AuthorizationProvider_LoggedIn;
            authorizationProvider.LoggedOut += AuthorizationProvider_LoggedOut;
            filesProvider.FileAdded += FilesProvider_FileAdded;
            filesProvider.FileRemoved += FilesProvider_FileRemoved;

            this.metadata = filesProvider.Metadata;
        }
Пример #2
0
        private void InitializeMetaData()
        {
            bool loaded = false;

            if (File.Exists(this.metadataPath))
            {
                using (FileStream fs = new FileStream(this.metadataPath, FileMode.Open))
                {
                    try
                    {
                        this.metadata = (Metadata)this.binaryFormatter.Deserialize(fs);
                        loaded = true;
                    }
                    catch (SerializationException)
                    {
                        loaded = false;
                    }
                }
            }

            if (!loaded)
            {
                this.metadata = new Metadata();
            }
        }
Пример #3
0
        private void AuthorizationProvider_LoggedIn()
        {
            lock (this.metadata)
            {
                if (this.metadata.Username == null)
                {
                    this.metadata.Username = this.authorizationProvider.Username;
                }
                else if (this.authorizationProvider.Username != this.metadata.Username)
                {
                    this.metadata = this.filesProvider.CleanLocalData();
                    this.metadata.Username = this.authorizationProvider.Username;
                }
            }

            this.StartSynchronization();
        }