コード例 #1
0
        public void doesnt_reload_data_from_local_when_changed_not_fired()
        {
            ILocalDataSource <IEnumerable <Address> > localDataSource = Substitute.For <ILocalDataSource <IEnumerable <Address> > >();

            Address[] expected = { TestItem.AddressA };
            localDataSource.Data.Returns(expected);
            TestCase <Address> testCase    = BuildTestCase(localDataSource, false);
            BlockHeader        blockHeader = Build.A.BlockHeader.WithNumber(1).TestObject;

            localDataSource.Data.Returns(new[] { TestItem.AddressA, TestItem.AddressB });
            testCase.ContractDataStore.GetItemsFromContractAtBlock(blockHeader).Should().BeEquivalentTo(expected.Cast <object>());
        }
コード例 #2
0
 public ContractDataStoreWithLocalData(
     IContractDataStoreCollection <T> collection,
     IDataContract <T> dataContract,
     IBlockTree blockTree,
     IReceiptFinder receiptFinder,
     ILogManager logManager,
     ILocalDataSource <IEnumerable <T> > localDataSource)
     : base(collection, dataContract ?? new EmptyDataContract <T>(), blockTree, receiptFinder, logManager)
 {
     _localDataSource          = localDataSource ?? throw new ArgumentNullException(nameof(localDataSource));
     _localDataSource.Changed += OnChanged;
     LoadLocalData();
 }
コード例 #3
0
 protected internal ContractDataStoreWithLocalData(
     TCollection collection,
     IDataContract <T> dataContract,
     IBlockTree blockTree,
     IReceiptFinder receiptFinder,
     ILogManager logManager,
     ILocalDataSource <IEnumerable <T> > localDataSource)
     : base(collection, dataContract, blockTree, receiptFinder, logManager)
 {
     _localDataSource          = localDataSource ?? throw new ArgumentNullException(nameof(localDataSource));
     _localDataSource.Changed += OnChanged;
     LoadLocalData();
 }
コード例 #4
0
 private static ContractDataStoreWithLocalData <T, TCollection> CreateContractDataStoreWithLocalData(
     TCollection collection,
     IDataContract <T> dataContract,
     IBlockTree blockTree,
     IReceiptFinder receiptFinder,
     ILogManager logManager,
     ILocalDataSource <IEnumerable <T> > localDataSource) =>
 new ContractDataStoreWithLocalData <T, TCollection>(
     collection,
     dataContract ?? new EmptyDataContract <T>(),
     blockTree,
     receiptFinder,
     logManager,
     localDataSource);
コード例 #5
0
        private TestCase <T> BuildTestCase <T>(ILocalDataSource <IEnumerable <T> > localDataSource, bool withContractSource = true, IComparer <T> keyComparer = null, IComparer <T> valueComparer = null)
        {
            IDataContract <T> dataContract = null;

            if (withContractSource)
            {
                dataContract = Substitute.For <IDataContract <T> >();
                dataContract.IncrementalChanges.Returns(true);
            }

            var blockProcessor = Substitute.For <IBlockProcessor>();

            return(new TestCase <T>()
            {
                DataContract = dataContract,
                BlockProcessor = blockProcessor,
                ContractDataStore = keyComparer == null
                    ? (IContractDataStore <T>) new ContractDataStoreWithLocalData <T>(new HashSetContractDataStoreCollection <T>(), dataContract, blockProcessor, LimboLogs.Instance, localDataSource)
                    : new DictionaryContractDataStore <T>(new SortedListContractDataStoreCollection <T>(keyComparer, valueComparer), dataContract, blockProcessor, LimboLogs.Instance, localDataSource)
            });
        }
コード例 #6
0
        /// <summary>
        /// Create an instance of ILocalDataSource through reflection on the LocalDataSourceAssembly.
        /// Or return an external ILocalDataSource object given by a client.
        /// </summary>
        /// <returns></returns>
        private ILocalDataSource CreateLocalDataSource()
        {
            Type localDataSourceType = null;

            if (!String.IsNullOrEmpty(syncItem.LocalDataSourceAssembly))
            {
                localDataSourceType = FindLocalDataSourceTypeInAssembly();

                if (localDataSourceType == null)
                {
                    return(null);
                }
            }


            try
            {
                object filter = syncItem.GetFilter();
                object handle;
                if (filter == null)
                {
                    handle = Activator.CreateInstance(localDataSourceType, new object[] { syncItem.DataFormat });
                }
                else
                {
                    handle = Activator.CreateInstance(localDataSourceType, new object[] { syncItem.DataFormat, filter });
                }
                ILocalDataSource source = (ILocalDataSource)handle;
                //  source.ExchangeType = syncItem.DataFormat;
                return(source);
            }
            catch (TargetInvocationException e)
            {
                Trace.TraceInformation("When LoadLocalDataSource: " + e.Message);
                return(null);
            }
        }
コード例 #7
0
        private SyncMLFacade CreateFacadeForSyncSession()
        {
            SyncMLFacade facade;

            try
            {
                localDataSource = LoadLocalDataSource();
            }
            catch (NullReferenceException e)
            {
                MessageBox.Show(this, e.Message, "Warning");
                UpdateStatusLogText(e.Message);
                return(null);
            }

            if (localDataSource == null)
            {
                return(null);
            }

            facade = new SyncMLFacade(localDataSource);

            facade.User = Settings.Default.User;
            //    facade.ContactMediumType = ContactExchangeType.Vcard21;
            string password = ObtainPassword();

            if (String.IsNullOrEmpty(password))
            {
                return(null);
            }
            else
            {
                facade.Password = password;
            }
            facade.BasicUriText = Settings.Default.BasicURI;

            facade.DeviceAddress = Settings.Default.DeviceAddress;

            facade.LastAnchorTime            = Settings.Default.LastAnchorTime;
            facade.LastAnchor                = Settings.Default.LastAnchor; // Next anchor is generated so before alert
            facade.VendorName                = Settings.Default.VendorName;
            facade.ModelName                 = Settings.Default.ModelName;
            facade.ModelVersion              = Settings.Default.ModelVersion;
            facade.ContactDataSourceAtServer = Settings.Default.ServerContactSource;

            facade.LastAnchorChangedEvent += HandleLastAnchorChanged;


            #region Wire event handlings to Facade's events regarding to visual effects
            facade.StartOperationEvent   += HandleStartOperation;
            facade.EndOperationEvent     += HandleEndOperation;
            facade.OperationStatusEvent  += HandleOperationMessage;
            facade.ServerDeviceInfoEvent += HandleServerDeviceInfo;

            facade.InitProgressBarEvent      += HandleInitProgressBar;
            facade.IncrementProgressBarEvent += HandleIncrementProgressBar;
            facade.StageMessageEvent         += new EventHandler <StatusEventArgs>(HandleStageMessageEvent);

            facade.InitProgressBarReceivingEvent      += HandleInitProgressBarReceiving;
            facade.IncrementProgressBarReceivingEvent += HandleIncrementProgressBarReceiving;
            facade.StageMessageReceivingEvent         += HandleStageMessageReceivingEvent;
            facade.GracefulStopEvent += new EventHandler <EventArgs>(facade_GracefulStopEvent);
            #endregion


            System.Net.WebProxy proxy;
            if (Settings.Default.UseProxy)
            {
                proxy = new System.Net.WebProxy(Settings.Default.Proxy);
                proxy.UseDefaultCredentials = true;
            }
            else
            {
                proxy = null;
            }

            facade.Proxy = proxy;


            return(facade);
        }
コード例 #8
0
 /// <summary>
 /// Create a mainform as a component of client codes.
 /// Client codes will create ILocalDataSource object.
 /// </summary>
 /// <param name="syncDataSource"></param>
 public SyncMLForm(ILocalDataSource syncDataSource, AboutInfo aboutInfo)
     : this()
 {
     localDataSource = syncDataSource;
     this.aboutInfo  = aboutInfo;
 }
コード例 #9
0
 /// <summary>
 /// construct the facade and wire with platformProvider
 /// </summary>
 /// <param name="platformProvider"></param>
 public SyncFacadeBase(ILocalDataSource platformProvider)
 {
     this.localDataSource = platformProvider;
 }
コード例 #10
0
 public Repository(IDataSource dataSource, ILocalDataSource localData)
 {
     _dataSource = dataSource;
     _localData  = localData;
 }