private static void EnsureAppIdInited() { if (s_appId == null) { IApplicationIdentifier service = null; IServiceProvider host = ObjectCache.Host; if (host != null) { service = host.GetService(typeof(IApplicationIdentifier)) as IApplicationIdentifier; } string fileNameWithoutExtension = (service != null) ? service.GetApplicationId() : null; if (string.IsNullOrEmpty(fileNameWithoutExtension)) { StringBuilder filename = new StringBuilder(0x200); if (System.Runtime.Caching.UnsafeNativeMethods.GetModuleFileName(IntPtr.Zero, filename, 0x200) != 0) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename.ToString()); } } if (string.IsNullOrEmpty(fileNameWithoutExtension)) { fileNameWithoutExtension = AppDomain.CurrentDomain.FriendlyName; } Interlocked.CompareExchange <string>(ref s_appId, fileNameWithoutExtension, null); } }
private static void EnsureAppIdInited() { if (s_appId == null) { IApplicationIdentifier ai = null; IServiceProvider host = ObjectCache.Host; if (host != null) { ai = host.GetService(typeof(IApplicationIdentifier)) as IApplicationIdentifier; } // if the host has an identifier, use it string appId = (ai != null) ? ai.GetApplicationId() : null; // otherwise, use the process name wihtout file extension if (String.IsNullOrEmpty(appId)) { StringBuilder sb = new StringBuilder(512); if (UnsafeNativeMethods.GetModuleFileName(IntPtr.Zero, sb, 512) != 0) { appId = Path.GetFileNameWithoutExtension(sb.ToString()); } } // if all else fails, use AppDomain.FriendlyName if (String.IsNullOrEmpty(appId)) { appId = AppDomain.CurrentDomain.FriendlyName; } Interlocked.CompareExchange(ref s_appId, appId, null); } }
public Task SaveAsync(IApplicationIdentifier application, IEnumerable <DataMap> dataMaps, CancellationToken cancellationToken = default(CancellationToken)) { // This method is intended to insert data maps // downloaded during synchronization, so we'll // not run the pipeline here. return(Task .Factory .StartNew(() => SaveAsyncImpl(application, dataMaps), cancellationToken)); }
private static StringContent CreatePostContent(IApplicationIdentifier applicationSchemaDefinition) { //TODO: the server API now allows multiple applications // to be retrieved with a single call. var applications = new object[] { new { AppName = applicationSchemaDefinition.ApplicationName } }; var json = JsonConvert.SerializeObject(new { applications = applications }); return(new StringContent(json, Encoding.UTF8, HttpCall.JsonMediaType.MediaType)); }
private async Task <IList <DataMap> > DownloadApplicationChanges(IApplicationIdentifier applicationSchemaDefinition, CancellationToken cancellationToken = default(CancellationToken)) { var uri = User.Settings.Routes.Sync(); var postContent = CreatePostContent(applicationSchemaDefinition); using (var reader = await HttpCall.PostStreamAsync(uri, postContent, cancellationToken)) { var dataMaps = ReadDataMapsFromServer(reader); await new DataRepository().SaveAsync(applicationSchemaDefinition, dataMaps, cancellationToken); return(dataMaps); } }
private static void SaveAsyncImpl(IApplicationIdentifier application, IEnumerable <DataMap> dataMaps) { var connection = Database.GetConnection(); connection.RunInTransaction(() => { // Bounced datamaps are (hopefully) stashed // elsewhere, so we can safely obliterate all. connection.Execute("delete from DataMap where application = ?", new object[] { application.ApplicationName }); foreach (var dataMap in dataMaps) { // This method is intended to be used by data // sync routines, so we set the dirty flag as // false, as they are fresh off the server. var persistableDataMap = new PersistableDataMap(application, dataMap, false, DateTime.Now); connection.Insert(persistableDataMap); } }); connection.Close(); }
public PersistableDataMap(IApplicationIdentifier application, DataMap dataMap, bool isDirty, DateTime localRowStamp) { Application = application.ApplicationName; Id = dataMap.Id(application); IsDirty = isDirty; Fields = dataMap.Fields.ToJson(); LocalRowStamp = localRowStamp; LocalId = dataMap.LocalState.LocalId; ParentId = dataMap.LocalState.ParentId; IsLocal = dataMap.LocalState.IsLocal; IsBouncing = dataMap.LocalState.IsBouncing; BounceReason = dataMap.LocalState.BounceReason; Flags = dataMap.LocalState.Flags; // If the custom fields is empty we'll explicitly // serialize it as a null. This comes in handy as // we can now easily identify through SQL queries // those data maps that do have custom fields, as // they generally require special behavior during // synchronization. CustomFields = dataMap.CustomFields.Any() ? dataMap.CustomFields.ToJson() : null; }
public static string Id(this DataMap dataMap, IApplicationIdentifier application) { return(dataMap.Value(application.IdFieldName)); }
public static T Id <T>(this DataMap dataMap, IApplicationIdentifier application) { return(dataMap.Value <T>(application.IdFieldName)); }