Exemplo n.º 1
0
        void UploadPrivateCallback()
        {
            ReadSentItems();

            var             local  = new FileSystemProvider(_context.LocalStorage, Provider.PrivateDirectory);
            IRemoteProvider remote = CreateRemote(Provider.PrivateDirectory);

            // push
            var localItems = new List <Item>(local.Items);

            foreach (Item l in localItems)
            {
                if (!_sentItems.Contains(l.RelativePath))
                {
                    if (!remote.FileExists(l.RelativePath) ||
                        remote.FindFile(l.RelativePath).Time < l.Time ||
                        remote.FindFile(l.RelativePath).Size < l.Size)    // для поддержки докачки
                    {
                        using (Stream stream = local.GetStream(l.RelativePath))
                            remote.SaveFile(l.RelativePath, stream);

                        _sentItems.Add(l.RelativePath);
                    }
                }
            }

            WriteSentItems();
        }
Exemplo n.º 2
0
        void SyncSharedCallback()
        {
            var             local  = new FileSystemProvider(_context.LocalStorage, Provider.SharedDirectory);
            IRemoteProvider remote = CreateRemote(Provider.SharedDirectory);

            // download
            var remoteItems = new List <Item>(remote.Items);

            foreach (Item r in remoteItems)
            {
                if (!local.FileExists(r.RelativePath) || local.FindFile(r.RelativePath).Time < r.Time)
                {
                    Item item = r;
                    remote.LoadFile(r.RelativePath, stream => local.SaveFile(item.RelativePath, stream));
                }
            }

            // remove deleted
            var localItems = new List <Item>(local.Items);

            foreach (Item l in localItems)
            {
                if (!remote.Items.Exists(val => val.RelativePath == l.RelativePath))
                {
                    local.DeleteFile(l.RelativePath);
                }
            }
        }
Exemplo n.º 3
0
 public static void ReleaseObj(bool ResetPRP = true, bool ResetAP = true)
 {
     if (ResetPRP)
     {
         RP = null;
     }
     if (ResetAP)
     {
         Interaction = null;
     }
 }
Exemplo n.º 4
0
        private void SyncSharedCallback()
        {
            var report = LogManager.Reporter.CreateFileSystemReport("shared");

            try
            {
                var             local  = IOContext.Current.CreateLocalProvider(IOContext.Current.SharedDirectory);
                IRemoteProvider remote = IOContext.Current.CreateRemoteProvider(IOContext.Current.SharedDirectory);

                // download
                var remoteItems = new List <IFile>(remote.Files);
                foreach (IFile r in remoteItems)
                {
                    if (!local.FileExists(r.RelativePath) || local.FindFile(r.RelativePath).Time < r.Time)
                    {
                        IFile item = r;
                        remote.LoadFile(r.RelativePath, stream => local.SaveFile(item.RelativePath, stream));

                        report.LoadedCount++;
                        report.LoadedSize += item.Size;
                    }
                }


                // remove deleted
                var localItems = new List <IFile>(local.Files);
                foreach (IFile l in localItems)
                {
                    if (!remote.Files.Exists(val => val.RelativePath == l.RelativePath))
                    {
                        local.DeleteFile(l.RelativePath);
                        report.DeletedCount++;
                        report.DeletedSize += l.Size;
                    }
                }

                report.Send();
            }
            catch (Exception e)
            {
                report.Send(e);
                throw;
            }
        }
Exemplo n.º 5
0
 public bool SendDatabase()
 {
     try
     {
         using (Stream stream = DbContext.Current.GetDatabaseStream())
             using (Stream zippedStream = GZip.ZipStream(stream))
             {
                 IRemoteProvider provider = IOContext.Current.CreateWebDavProvider(IOContext.Current.LogDirectory);
                 string          fileName = string.Format("{0}.db.zip", DateTime.UtcNow.ToString("yyyyMMddHHmmss"));
                 provider.SaveFile(fileName, zippedStream);
                 return(true);
             }
     }
     catch (WebException e)
     {
         _context.HandleException(new ConnectionException("Error during SendDatabase operation", e));
         return(false);
     }
 }
Exemplo n.º 6
0
        private void UploadPrivateCallback()
        {
            var report = LogManager.Reporter.CreateFileSystemReport("private");

            try
            {
                DateTime syncTime = ReadSyncTime();

                var             local  = IOContext.Current.CreateLocalProvider(IOContext.Current.PrivateDirectory);
                IRemoteProvider remote = IOContext.Current.CreateRemoteProvider(IOContext.Current.PrivateDirectory);

                // push
                var localItems = new List <IFile>(local.Files);
                foreach (IFile l in localItems)
                {
                    if (l.Time > syncTime)
                    {
                        if (!remote.FileExists(l.RelativePath) ||
                            remote.FindFile(l.RelativePath).Time < l.Time ||
                            remote.FindFile(l.RelativePath).Size < l.Size)    // to finish downloading after disconnect
                        {
                            using (Stream stream = local.GetStream(l.RelativePath))
                                remote.SaveFile(l.RelativePath, stream);

                            report.LoadedCount++;
                            report.LoadedSize += l.Size;
                        }
                    }
                }
                WriteSyncTime();

                report.Send();
            }
            catch (Exception e)
            {
                report.Send(e);
                throw;
            }
        }
Exemplo n.º 7
0
        public static void ReloadObj(ICatchError Er, bool ResetPRP = true, bool ResetAP = true)
        {
            try
            {
                ReleaseObj(ResetPRP, ResetAP);

                if (ResetPRP)
                {
                    RP = (IRemoteProvider)Activator.CreateInstance(
                        Type.GetTypeFromProgID("PresentRemoteProvider.RemoteProvider"));
                }
                if (ResetAP)
                {
                    Interaction = (IAPInteractionMng)Activator.CreateInstance(
                        Type.GetTypeFromProgID("APInterMng.APInteractionMng"));
                }
            }
            catch (Exception ex)
            {
                Er.Error(ex);
                ReleaseObj();
            }
        }