private static void ProcessImages(WriteableBitmap wb, List <string> localUris, List <Rect> map, Action <string> callback, int ind, long userOrChatId, bool isChat) { if (ind >= localUris.Count || ind >= map.Count) { Rectangle rectangle = new Rectangle(); rectangle.Width = (double)ConversationTileImageFormatter.DIMENSION; rectangle.Height = (double)ConversationTileImageFormatter.DIMENSION; rectangle.Fill = (Brush) new SolidColorBrush(Colors.Black); rectangle.Opacity = 0.2; wb.Render((UIElement)rectangle, (Transform)null); wb.Invalidate(); using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { string path = "/Shared/ShellContent/conversationTileImg" + (object)userOrChatId + isChat.ToString() + ".jpg"; if (!storeForApplication.DirectoryExists("/Shared/ShellContent")) { storeForApplication.CreateDirectory("/Shared/ShellContent"); } using (IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, storeForApplication)) { int targetWidth = ConversationTileImageFormatter.DIMENSION; int targetHeight = ConversationTileImageFormatter.DIMENSION; wb.SaveJpeg((Stream)storageFileStream, targetWidth, targetHeight, 0, 80); } callback(path); } } else { string uri = localUris[ind]; Rect rect = map[ind]; double width = rect.Width; rect = map[ind]; double height = rect.Height; Image image1 = ConversationTileImageFormatter.CreateImage(uri, width, height); WriteableBitmap writeableBitmap = wb; Image image2 = image1; TranslateTransform translateTransform = new TranslateTransform(); rect = map[ind]; double x = rect.X; translateTransform.X = x; rect = map[ind]; double y = rect.Y; translateTransform.Y = y; writeableBitmap.Render((UIElement)image2, (Transform)translateTransform); ConversationTileImageFormatter.ProcessImages(wb, localUris, map, callback, ind + 1, userOrChatId, isChat); } }
public static void CreateTileForConversation(long userOrChatId, bool isChat, string name, List <string> imagesUris, Action <bool> completionCallback) { //Action<string> action=null; Execute.ExecuteOnUIThread((Action)(() => { string tileType = "Conversation"; string objId = userOrChatId.ToString() + isChat.ToString() + AppGlobalStateManager.Current.LoggedInUserId.ToString(); imagesUris = imagesUris.Take <string>(8).ToList <string>(); List <WaitHandle> waitHandles = SecondaryTileManager.DownloadImages(imagesUris.Select <string, Tuple <int, string> >((Func <string, Tuple <int, string> >)(i => new Tuple <int, string>(imagesUris.IndexOf(i), i))).ToList <Tuple <int, string> >(), tileType, objId); new Thread((ThreadStart)(() => { if (!WaitHandle.WaitAll(waitHandles.ToArray(), 10000)) { completionCallback(false); } else { List <string> localUris = new List <string>(); for (int ind = 0; ind < imagesUris.Count; ++ind) { if (!string.IsNullOrWhiteSpace(imagesUris[ind])) { localUris.Add("/" + SecondaryTileManager.GetLocalNameFor(ind, tileType, objId)); } } ConversationTileImageFormatter.CreateTileImage(localUris, userOrChatId, isChat, /*action ?? (action = (*/ new Action <string> (uriStr => { if (!string.IsNullOrEmpty(uriStr)) { FlipTileData flipTileData = new FlipTileData(); Uri uri = new Uri("isostore:" + uriStr, UriKind.Absolute); flipTileData.SmallBackgroundImage = uri; flipTileData.BackgroundImage = uri; flipTileData.Title = name; ShellTile.Create(new Uri(string.Format("/VKMessenger;component/Views/ConversationPage.xaml?UserOrChatId={0}&IsChat={1}&FromLookup={2}&NewMessageContents={3}&TileLoggedInUserId={4}&ClearBackStack=True", (object)userOrChatId, (object)isChat, (object)false, (object)false, (object)AppGlobalStateManager.Current.LoggedInUserId), UriKind.Relative), (ShellTileData)flipTileData, false); completionCallback(true); } else { completionCallback(false); } })); } })).Start(); })); }
public static void CreateTileImage(List <string> localUris, long userOrChatId, bool isChat, Action <string> callback) { Execute.ExecuteOnUIThread((Action)(() => { try { WriteableBitmap wb = new WriteableBitmap(ConversationTileImageFormatter.DIMENSION, ConversationTileImageFormatter.DIMENSION); localUris = localUris.Where <string>((Func <string, bool>)(u => !string.IsNullOrWhiteSpace(u))).ToList <string>(); List <Rect> map1 = ConversationTileImageFormatter.CreateMap(localUris.Count, isChat); List <string> localUris1 = localUris; List <Rect> map2 = map1; Action <string> callback1 = callback; int ind = 0; long userOrChatId1 = userOrChatId; int num = isChat ? 1 : 0; ConversationTileImageFormatter.ProcessImages(wb, localUris1, map2, callback1, ind, userOrChatId1, num != 0); } catch (Exception ex) { callback(""); Logger.Instance.Error("CreateTileImage failed. " + (object)ex); } })); }
private static void ProcessImages(WriteableBitmap wb, List <string> localUris, List <Rect> map, Action <string> callback, int ind, long userOrChatId, bool isChat) { if (ind >= localUris.Count || ind >= map.Count) { Rectangle rectangle = new Rectangle(); ((FrameworkElement)rectangle).Width = ((double)ConversationTileImageFormatter.DIMENSION); ((FrameworkElement)rectangle).Height = ((double)ConversationTileImageFormatter.DIMENSION); ((Shape)rectangle).Fill = ((Brush) new SolidColorBrush(Colors.Black)); ((UIElement)rectangle).Opacity = 0.2; wb.Render((UIElement)rectangle, null); wb.Invalidate(); IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication(); try { string str = string.Concat(new object[4] { "/Shared/ShellContent/conversationTileImg", userOrChatId, isChat.ToString(), ".jpg" }); if (!storeForApplication.DirectoryExists("/Shared/ShellContent")) { storeForApplication.CreateDirectory("/Shared/ShellContent"); } IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(str, (FileMode)2, (FileAccess)2, storeForApplication); try { int dimension1 = ConversationTileImageFormatter.DIMENSION; int dimension2 = ConversationTileImageFormatter.DIMENSION; System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, (Stream)storageFileStream, dimension1, dimension2, 0, 80); } finally { if (storageFileStream != null) { ((IDisposable)storageFileStream).Dispose(); } } callback(str); } finally { if (storeForApplication != null) { ((IDisposable)storeForApplication).Dispose(); } } } else { string localUri = localUris[ind]; Rect rect = map[ind]; // ISSUE: explicit reference operation double width = rect.Width; rect = map[ind]; // ISSUE: explicit reference operation double height = rect.Height; Image image1 = ConversationTileImageFormatter.CreateImage(localUri, width, height); WriteableBitmap writeableBitmap = wb; Image image2 = image1; TranslateTransform translateTransform = new TranslateTransform(); rect = map[ind]; // ISSUE: explicit reference operation double x = rect.X; translateTransform.X = x; rect = map[ind]; // ISSUE: explicit reference operation double y = rect.Y; translateTransform.Y = y; writeableBitmap.Render((UIElement)image2, (Transform)translateTransform); ConversationTileImageFormatter.ProcessImages(wb, localUris, map, callback, ind + 1, userOrChatId, isChat); } }