Ejemplo n.º 1
0
        /// <summary>
        /// Copies the file to the Application Storage and Sets the Image
        /// </summary>
        /// <param name="path">The Full Path to an Image File within the Computers File System</param>
        /// <returns>If the Image was successfully Set</returns>
        public virtual async Task <bool> SetImageFromFileSystem(string path)
        {
            if (!IsSetupComplete)
            {
                return(false);
            }

            if (ClearImagesFolderEveryXImages != 0)
            {
                int fileCount = await StorageTask.Instance.FileCount(ImagesFolder);

                if (fileCount > ClearImagesFolderEveryXImages)
                {
                    await DeleteFilesInFoldersAsync();
                }
            }

            var tmpFile = await StorageFile.GetFileFromPathAsync(path);

            if (tmpFile == null)
            {
                return(false);
            }

            var copiedFile = await tmpFile.CopyAsync(ImagesFolder, tmpFile.Name, NameCollisionOption.ReplaceExisting);

            var localStorageUri  = StorageTask.CreateUri(StorageLocationPrefix.LocalFolder, $"{ImagesFolderName}/{copiedFile.Name}");
            var localStorageFile = await StorageFile.GetFileFromApplicationUriAsync(localStorageUri);

            return(await SetImage(localStorageFile));
        }
Ejemplo n.º 2
0
        public async Task <SecondaryTile> CreateTile(string tileID, string displayName, string activationArguments, TileImages tileImages, bool roamingEnabled = false)
        {
            Uri tileImage = null;

            if (tileImages.Square310x310.OriginalString.Contains("http://") ||
                tileImages.Square310x310.OriginalString.Contains("https://"))
            {
                StorageFolder folder = await StorageTask.Instance.CreateFolder(RootFolder, TileManager.TileImagesFolderName, CreationCollisionOption.OpenIfExists);

                if (folder != null)
                {
                    string fileName = tileID + ".jpg";
                    if (await StorageTask.Instance.SaveFileFromServer(folder, fileName, tileImages.Square310x310))
                    {
                        tileImage = StorageTask.CreateUri(StorageLocationPrefix.LocalFolder, TileImagesFolderName + "/" + fileName);
                    }
                }
            }
            if (tileImage == null)
            {
                tileImage = tileImages.Square310x310;
            }

            SecondaryTile secondaryTile = new SecondaryTile(tileID, displayName, activationArguments, tileImage, TileSize.Square150x150);

            secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;

            // Images
            //secondaryTile.VisualElements.Square30x30Logo = tileImage; // Deprecated in Windows 10
            //secondaryTile.VisualElements.Square70x70Logo = tileImage; // Deprecated in Windows 10
            secondaryTile.VisualElements.Square44x44Logo   = tileImage;
            secondaryTile.VisualElements.Square71x71Logo   = tileImage;
            secondaryTile.VisualElements.Square310x310Logo = tileImage;
            secondaryTile.VisualElements.Wide310x150Logo   = tileImage;

            // Names
            secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
            secondaryTile.VisualElements.ShowNameOnWide310x150Logo   = true;
            secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = true;

            // Roaming
            secondaryTile.RoamingEnabled = roamingEnabled;

            return(secondaryTile);
        }