public static XmlDocument CreateTileNotification(string title, IList <ITask> tasks, IAbstractFolder folder = null) { string content = string.Empty; try { var xmlDocument = new XmlDocument(); const string templateXml = @" <tile> <visual branding=""nameAndLogo"" displayName=""{0}""> <binding template=""TileSmall"" hint-textStacking=""center"" branding=""none""> <image placement=""peek"" src=""{3}""/> <text hint-align=""center"" hint-style=""title"">{1}</text> </binding> <binding template=""TileMedium""> {2} </binding> <binding template=""TileWide"" hint-lockDetailedStatus1=""{4}"" hint-lockDetailedStatus2=""{5}"" hint-lockDetailedStatus3=""{6}""> <group> <subgroup hint-weight=""20"" hint-textStacking=""center""> <image src=""{3}""/> </subgroup> <subgroup hint-weight=""80"" hint-textStacking=""center""> {2} </subgroup> </group> </binding> <binding template=""TileLarge""> {2} </binding> </visual> </tile> "; var builder = new StringBuilder(); bool hasTask = false; string task1 = string.Empty; string task2 = string.Empty; string task3 = string.Empty; for (int i = 0; i < 10; i++) { string taskName = TryGetTaskAt(tasks, i); if (!string.IsNullOrWhiteSpace(taskName)) { var safeEscapeTaskName = SafeEscape(taskName); builder.AppendLine(string.Format("<text>{0}</text>", safeEscapeTaskName)); hasTask = true; if (i == 0) { task1 = safeEscapeTaskName; } else if (i == 1) { task2 = safeEscapeTaskName; } else if (i == 2) { task3 = safeEscapeTaskName; } } } if (!hasTask) { if (folder != null) { builder.AppendLine(string.Format("<text hint-style='captionsubtle' hint-wrap='true'>{0}</text>", SafeEscape(folder.EmptyHeader))); } else { builder.AppendLine(string.Format("<text hint-style='captionsubtle' hint-wrap='true'>{0}</text>", SafeEscape(StringResources.SystemView_Today_EmptyHeader))); } } string displayName = SafeEscape(title); string counter = tasks.Count.ToString(CultureInfo.InvariantCulture); string text = builder.ToString(); string picture = folder != null?ResourcesLocator.GetFolderIconPng(folder) : ResourcesLocator.GetAppIconPng(); content = string.Format( templateXml, displayName, // 0 counter, // 1 text, // 2 picture, // 3 task1, // 4 task2, // 5 task3 // 6 ); xmlDocument.LoadXml(content); return(xmlDocument); } catch (Exception ex) { TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTileNotification: {0}", content)); return(null); } }
public static XmlDocument CreateTileNotificationForTask(ITask task) { string content = string.Empty; try { var xmlDocument = new XmlDocument(); const string templateXml = @" <tile> <visual branding=""nameAndLogo""> <binding template=""TileSmall"" hint-textStacking=""center""> <text hint-style=""subtitle"" hint-align=""center"">{0}</text> </binding> <binding template=""TileMedium"" displayName=""{3}""> <text hint-style=""base"">{0}</text> <text hint-style=""caption"">{1}</text> <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text> </binding> <binding template=""TileWide"" displayName=""{4}""> <group> <subgroup hint-weight=""33""> <image src=""{5}"" /> </subgroup> <subgroup> <text hint-style=""base"">{0}</text> <text hint-style=""caption"">{1}</text> <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text> </subgroup> </group> </binding> <binding template=""TileLarge"" displayName=""{4}""> <group> <subgroup> <text hint-style=""base"">{0}</text> <text hint-style=""caption"">{1}</text> <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text> <image hint-align=""center"" src=""{5}"" /> </subgroup> </group> </binding> </visual> </tile> "; string picture = ResourcesLocator.GetFolderIconPng(task.Folder); content = string.Format( templateXml, SafeEscape(task.Title), // 0 title SafeEscape(task.Folder.Name), // 1 folder SafeEscape(task.Note ?? string.Empty), // 2 notes (max: 65 characters) task.Due.HasValue ? task.Due.Value.ToString("M") : string.Empty, // 3 short due (Aug. 22) task.Due.HasValue ? RelativeDateConverter.ConvertRelative(task.Due) : string.Empty, // 4 long due (Today Aug. 22) picture // 5 image ); xmlDocument.LoadXml(content); return(xmlDocument); } catch (Exception ex) { TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTileNotification: {0}", content)); return(null); } }