public AppBookmarkInfoStoreProvider(IJetConnectionProvider jetConnectionProvider, IAppBookmarkSerializer serializer, SdataContext context)
 {
     _jetConnectionProvider = jetConnectionProvider;
     _serializer            = serializer;
     _context = context;
     StoreEnvironment.Initialize(jetConnectionProvider, context);
 }
        public Int32tickProvider(IJetConnectionProvider jetConnectionProvider, SdataContext context)
        {
            _jetConnectionProvider = jetConnectionProvider;
            _context = context;

            StoreEnvironment.Initialize(jetConnectionProvider, context);
        }
        public SyncResultsInfoStoreProvider(IJetConnectionProvider jetConnectionProvider, SdataContext context)
        {
            _jetConnectionProvider = jetConnectionProvider;
            _context = context;

            StoreEnvironment.Initialize(jetConnectionProvider, context);
        }
            public static string GetConnectionString(SdataContext context)
            {
                NorthwindConfig config = new NorthwindConfig(context.DataSet);

                config.CurrencyCode = "EUR";
                config.Path         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Northwind");
                return(config.ConnectionString);
            }
Exemple #5
0
        public void DoWork(IRequest request)
        {
            string       resourceKind = _requestContext.ResourceKind.ToString();
            string       endpoint     = _requestContext.DatasetLink + resourceKind;
            SdataContext sdataContext = _requestContext.SdataContext;

            ISyncSyncDigestInfoStore syncDigestStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetSyncDigestStore(sdataContext);

            SyncDigestInfo syncDigestInfo = syncDigestStore.Get(resourceKind);

            SyncDigestPayload syncDigestPayload = new SyncDigestPayload();

            syncDigestPayload.Digest.Origin = endpoint;
            // create a new initial syncDigest and store it.
            if ((null == syncDigestInfo) || (syncDigestInfo.Count == 0))
            {
                SyncFeedDigestEntry entry = new SyncFeedDigestEntry();
                entry.ConflictPriority = 0;
                entry.Endpoint         = endpoint;
                entry.Stamp            = DateTime.Now;
                entry.Tick             = -1;
                syncDigestPayload.Digest.Entries.Add(entry);
            }
            else
            {
                foreach (SyncDigestEntryInfo digestEntry in syncDigestInfo)
                {
                    SyncFeedDigestEntry entry = new SyncFeedDigestEntry();
                    entry.ConflictPriority = digestEntry.ConflictPriority;
                    entry.Endpoint         = digestEntry.Endpoint;
                    //entry.Stamp = digestEntry.;
                    entry.Tick = digestEntry.Tick;
                    syncDigestPayload.Digest.Entries.Add(entry);
                }
            }
            SyncFeed feed = new SyncFeed();
            string   url  = endpoint + "/$syncDigest";
            FeedLink link = new FeedLink(url, LinkType.Self, MediaType.AtomEntry);

            feed.Links = new FeedLinkCollection();
            feed.Links.Add(link);
            feed.Id       = url;
            feed.FeedType = FeedType.ResourceEntry;
            SyncFeedEntry syncFeedEntry = new SyncFeedEntry();

            syncFeedEntry.Payload = syncDigestPayload;
            syncFeedEntry.Title   = "Synchronization digest";
            syncFeedEntry.Id      = url;

            syncFeedEntry.Links.Add(link);
            feed.Entries.Add(syncFeedEntry);

            feed.Id = url;

            request.Response.Serializer  = new SyncFeedSerializer();
            request.Response.Feed        = feed;
            request.Response.ContentType = MediaType.AtomEntry;
        }
Exemple #6
0
            public static string GetConnectionString(SdataContext context)
            {
                string connString;
                string currentDir = Directory.GetCurrentDirectory();

                string mdbFilePath = Path.Combine(currentDir, string.Format(@"SyncStores\{0}\{1}\{2}\syncStore.mdb", context.Application, context.Contract, context.DataSet));

                // TODO: Create an empty mdb file..

                connString = @"PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=" + mdbFilePath;

                return(connString);
            }
Exemple #7
0
        public static T Resolve <T>(SdataContext context)
        {
            StoreEnvironmentItem item = null;

            lock (lockObj)
            {
                if (!stat_EnvironmentItems.TryGetValue(context, out item))
                {
                    throw new InvalidOperationException(string.Format("No StoreEnvironment initialized for the given context {0}", context.ToString()));
                }
            }

            return(item.Resolve <T>());
        }
Exemple #8
0
        public static void Remove(SdataContext context)
        {
            StoreEnvironmentItem item = null;

            lock (lockObj)
            {
                if (!stat_EnvironmentItems.TryGetValue(context, out item))
                {
                    return;
                }

                stat_EnvironmentItems.Remove(context);
            }
        }
        public ISynctickProvider GettickProvider(SdataContext context)
        {
            ISynctickProvider tickProvider;

            string connectionString = ConnStringFactory.GetConnectionString(context);

            if (!ContextStoreResolver.TryResolve <ISynctickProvider>(context, out tickProvider))
            {
                IJetConnectionProvider connectionProvider = new SimpleJetConnectionProvider(connectionString);

                tickProvider = new tickProvider(connectionProvider, context);

                ContextStoreResolver.Register <ISynctickProvider>(context, tickProvider);
            }

            return(tickProvider);
        }
Exemple #10
0
        public static IAppBookmarkInfoStore GetAppBookmarkStore(SdataContext context)
        {
            IAppBookmarkInfoStore store;

            string connectionString = ConnStringFactory.GetConnectionString(context);

            if (!ContextStoreResolver.TryResolve <IAppBookmarkInfoStore>(connectionString, out store))
            {
                IJetConnectionProvider        connectionProvider = new SimpleJetConnectionProvider(connectionString);
                IAppBookmarkInfoStoreProvider provider           = new AppBookmarkInfoStoreProvider(connectionProvider, context);

                store = new AppBookmarkInfoStoreClient(provider);
                ContextStoreResolver.Register <IAppBookmarkInfoStore>(connectionString, store);
            }

            return(store);
        }
        public ISyncResultInfoStore GetSyncResultStore(SdataContext context)
        {
            ISyncResultInfoStore store;

            string connectionString = ConnStringFactory.GetConnectionString(context);

            if (!ContextStoreResolver.TryResolve <ISyncResultInfoStore>(context, out store))
            {
                IJetConnectionProvider connectionProvider = new SimpleJetConnectionProvider(connectionString);

                store = new SyncResultInfoStore(connectionProvider, context);

                ContextStoreResolver.Register <ISyncResultInfoStore>(context, store);
            }

            return(store);
        }
        public ICorrelatedResSyncInfoStore GetCorrelatedResSyncStore(SdataContext context)
        {
            ICorrelatedResSyncInfoStore store;

            string connectionString = ConnStringFactory.GetConnectionString(context);

            if (!ContextStoreResolver.TryResolve <ICorrelatedResSyncInfoStore>(context, out store))
            {
                IJetConnectionProvider connectionProvider    = new SimpleJetConnectionProvider(connectionString);
                ICorrelatedResSyncInfoStoreProvider provider = new CorrelatedResSyncStoreProvider(connectionProvider, context);

                store = new CorrelatedResSyncInfoStore(provider);
                ContextStoreResolver.Register <ICorrelatedResSyncInfoStore>(context, store);
            }

            return(store);
        }
Exemple #13
0
        internal static void Set <T>(SdataContext context, object obj)
        {
            if (obj is T == false)
            {
                throw new InvalidOperationException(string.Format("The supplied instance does not implement {0}", typeof(T).FullName));
            }

            StoreEnvironmentItem item = null;

            lock (stat_EnvironmentItems)
            {
                if (!stat_EnvironmentItems.TryGetValue(context, out item))
                {
                    throw new InvalidOperationException(string.Format("No StoreEnvironment initialized for the given context {0}", context.ToString()));
                }

                item.Set <T>(obj);
            }
        }
        public void GetTrackingState(IRequest request)
        {
            lock (_asyncStateObj)
            {
                if (null == _asyncStateObj.Tracking)
                {
                    throw new InvalidOperationException("Performer has not been started.");
                }


                if (_asyncStateObj.Tracking.Phase == TrackingPhase.FINISH)
                {
                    request.Response.ContentType = MediaType.Atom;
                    int          startindex   = Convert.ToInt32(request.Uri.StartIndex);
                    int          count        = Convert.ToInt32(request.Uri.Count);
                    SdataContext sdataContext = _requestContext.SdataContext;
                    ICorrelatedResSyncInfoStore correlatedResSyncInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(sdataContext);

                    request.Response.Serializer = new SyncFeedSerializer();
                    SyncFeed syncFeed = _asyncPerformer.GetFeed(_requestContext.Config, startindex, count);
                    syncFeed.FeedType     = FeedType.SyncSource;
                    request.Response.Feed = syncFeed;
                }
                else if (_asyncStateObj.Tracking.Phase == TrackingPhase.ERROR)
                {
                    request.Response.Xml         = XmlSerializationHelpers.SerializeObjectToXml(_asyncStateObj.Tracking);
                    request.Response.ContentType = MediaType.Xml;
                    request.Response.StatusCode  = HttpStatusCode.InternalServerError;
                    request.Response.Serializer  = new XmlSerializer();
                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
                else
                {
                    request.Response.Xml         = XmlSerializationHelpers.SerializeObjectToXml(_asyncStateObj.Tracking);
                    request.Response.ContentType = MediaType.Xml;
                    request.Response.StatusCode  = HttpStatusCode.Accepted;
                    request.Response.Serializer  = new XmlSerializer();
                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
            }
        }
            public static bool TryResolve <T>(SdataContext context, out T obj)
            {
                obj = default(T);
                Dictionary <Type, object> entry;

                if (!stat_types.TryGetValue(context, out entry))
                {
                    return(false);
                }


                Type   type = typeof(T);
                object value;

                if (entry.TryGetValue(type, out value))
                {
                    obj = (T)value;
                    return(true);
                }
                return(false);
            }
            public static void Register <T>(SdataContext context, object obj)
            {
                Type type = (typeof(T));

                if (obj is T == false)
                {
                    throw new InvalidOperationException(string.Format("The supplied instance does not implement {0}", type.FullName));
                }


                if (stat_types.ContainsKey(context))
                {
                    stat_types[context].Add(type, obj);
                }
                else
                {
                    Dictionary <Type, object> newEntry = new Dictionary <Type, object>();
                    newEntry.Add(type, obj);
                    stat_types.Add(context, newEntry);
                }
            }
        public void GetTrackingState(IRequest request)
        {
            lock (_asyncStateObj)
            {
                if (null == _asyncStateObj.Tracking)
                {
                    throw new InvalidOperationException("Performer has not been started.");
                }


                if (_asyncStateObj.Tracking.Phase == TrackingPhase.FINISH)
                {
                    PageInfo     normalizedPageInfo = PagingHelpers.Normalize(request.Uri.StartIndex, request.Uri.Count, _asyncStateObj.CorrelatedResSyncInfos.Count);
                    SdataContext sdataContext       = _requestContext.SdataContext;
                    request.Response.ContentType = MediaType.Atom;
                    //request.Response.Serializer  = FeedComponentFactory.GetSerializer<ISyncSourceFeed>();
                    request.Response.Feed = _asyncPerformer.GetFeed(_requestContext.Config, normalizedPageInfo);
                }
                else if (_asyncStateObj.Tracking.Phase == TrackingPhase.ERROR)
                {
                    //request.Response.Xml = NorthwindFeedSerializer.GetXml(_asyncStateObj.Tracking);
                    //request.Response.ContentType = MediaType.Xml;
                    //request.Response.Serializer  = new Sage.Common.Syndication.XmlSerializer();
                    request.Response.Tracking   = _asyncStateObj.Tracking;
                    request.Response.StatusCode = HttpStatusCode.InternalServerError;

                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
                else
                {
                    //request.Response.Xml = NorthwindFeedSerializer.GetXml(_asyncStateObj.Tracking);
                    //request.Response.ContentType = MediaType.Xml;
                    //request.Response.Serializer  = new Sage.Common.Syndication.XmlSerializer();
                    request.Response.Tracking   = _asyncStateObj.Tracking;
                    request.Response.StatusCode = HttpStatusCode.Accepted;
                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
            }
        }
Exemple #18
0
        public static void Initialize(IJetConnectionProvider connProvider, SdataContext context)
        {
            StoreEnvironmentItem item = null;

            lock (lockObj)
            {
                if (stat_EnvironmentItems.TryGetValue(context, out item))
                {
                    return;
                }

                item = new StoreEnvironmentItem();

                item.Register <IJetConnectionProvider>(connProvider);

                TableAdapterFactory       tableAdapterFactory      = new TableAdapterFactory(context, connProvider);
                IResourceKindTableAdapter resourceKindTableAdapter = tableAdapterFactory.CreateResourceKindTableAdapter();
                item.Register <IResourceKindTableAdapter>(resourceKindTableAdapter);

                IEndpointTableAdapter endpointTableAdapter = tableAdapterFactory.CreateEndpointTableAdapter();
                item.Register <IEndpointTableAdapter>(endpointTableAdapter);

                item.Register <ISyncDigestTableAdapter>(tableAdapterFactory.CreateSyncDigestTableAdapter(resourceKindTableAdapter, endpointTableAdapter));
                item.Register <IAppBookmarkTableAdapter>(tableAdapterFactory.CreateAppBookmarkTableAdapter(resourceKindTableAdapter));
                item.Register <ITickTableAdapter>(tableAdapterFactory.CreateTickTableAdapter(resourceKindTableAdapter));


                Dictionary <string, ICorrelatedResSyncTableAdapter> correlatedResSyncTableAdapters = new Dictionary <string, ICorrelatedResSyncTableAdapter>();
                item.Register <Dictionary <string, ICorrelatedResSyncTableAdapter> >(correlatedResSyncTableAdapters);

                Dictionary <string, ISyncResultsTableAdapter> syncResultsTableAdapters = new Dictionary <string, ISyncResultsTableAdapter>();
                item.Register <Dictionary <string, ISyncResultsTableAdapter> >(syncResultsTableAdapters);
                //item.Register<ISyncResultsTableAdapter>(tableAdapterFactory.CreateSyncResultsTableAdapter(resourceKindTableAdapter));



                stat_EnvironmentItems.Add(context, item);
            }
        }
Exemple #19
0
 public AppBookmarkTableAdapter(IAppBookmarkTable appBookmarkTable, SdataContext context)
 {
     _appBookmarkTable = appBookmarkTable;
     this.Context      = context;
 }
 public static void Reset(SdataContext context)
 {
     StoreEnvironment.Remove(context);
 }
Exemple #21
0
 public CorrelatedResSyncTableAdapter(ICorrelatedResSyncTable correlatedResSyncTable, SdataContext context)
 {
     _correlatedResSyncTable = correlatedResSyncTable;
     this.Context            = context;
 }
Exemple #22
0
 public SyncResultInfoStore(IJetConnectionProvider jetConnectionProvider, SdataContext context)
 {
     _provider = new SyncResultsInfoStoreProvider(jetConnectionProvider, context);
 }
Exemple #23
0
 public SyncDigestTableAdapter(ISyncDigestTable syncDigestTable, SdataContext context)
 {
     _syncDigestTable = syncDigestTable;
     this.Context     = context;
 }
Exemple #24
0
 public SyncResultsTableAdapter(ISyncResultsTable syncResultsTable, SdataContext context)
 {
     _syncResultsTable = syncResultsTable;
     this.Context      = context;
 }
Exemple #25
0
 public CorrelatedResSyncStoreProvider(IJetConnectionProvider jetConnectionProvider, SdataContext context)
 {
     _jetConnectionProvider = jetConnectionProvider;
     _context = context;
     StoreEnvironment.Initialize(jetConnectionProvider, context);
 }
Exemple #26
0
 public EndPointTableAdapter(IEndPointTable EndPointTable, SdataContext context)
 {
     _EndPointTable = EndPointTable;
     this.Context   = context;
 }
Exemple #27
0
 public tickTableAdapter(ItickTable tickTable, SdataContext context)
 {
     _tickTable   = tickTable;
     this.Context = context;
 }
 public TableAdapterFactory(SdataContext context, IJetConnectionProvider connProvider)
 {
     _context      = context;
     _connProvider = connProvider;
 }
 public ResourceKindTableAdapter(IResourceKindTable resourceKindTable, SdataContext context)
 {
     _resourceKindTable = resourceKindTable;
     this.Context       = context;
 }
 public EndpointTableAdapter(IEndpointTable endpointTable, SdataContext context)
 {
     _endpointTable = endpointTable;
     this.Context   = context;
 }