コード例 #1
0
        protected override void InitializeViewModel()
        {
            ResourceLoader resource = ResourceLoader.GetForCurrentView();

            ThemeSource.Add(new KeyName((int)ElementTheme.Light, resource.GetString("Theme/Light/Text")));
            ThemeSource.Add(new KeyName((int)ElementTheme.Dark, resource.GetString("Theme/Dark/Text")));

            string fmt = resource.GetString("Thumbnail/Retention/Days/Content");

            ThumbnailRetentionPeriodSource.Add(new KeyName(7, string.Format(fmt, 7)));
            ThumbnailRetentionPeriodSource.Add(new KeyName(15, string.Format(fmt, 15)));
            ThumbnailRetentionPeriodSource.Add(new KeyName(30, string.Format(fmt, 30)));

            var st = Settings.Thumbnail;

            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedLocalFolder, "LocalFolder"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedLocalFile, "LocalFile"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedDLNAFolder, "DLNAFolder"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedDLNAFile, "DLNAFile"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedWebDAVFolder, "WebDAVFolder"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedWebDAVFile, "WebDAVFile"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedFTPFolder, "FTPFolder"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedFTPFile, "FTPFile"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedOneDriveFolder, "OneDriveFolder"));
            UnsupportedThumbnailSource.Add(CreateKeyname(st.UseUnsupportedOneDriveFile, "OneDriveFile"));
        }
コード例 #2
0
        public async Task <ThemeReference> UploadTheme()
        {
            UserTheme         t                      = null;
            int               maxSizeKb              = 1024;
            ThemeReference    ret                    = null;
            string            root                   = string.Empty;
            MultipartFileData file                   = null;
            string            fileName               = string.Empty;
            string            targetFileName         = string.Empty;
            string            originalPhysicalPath   = string.Empty;
            MultipartFormDataStreamProvider provider = null;
            User currentUser = ApplicationContext.Current.User;

            if (currentUser != null && currentUser.Subscription != null && currentUser.Subscription.Type != SubscriptionType.Basic)
            {
                if (!this.Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                root = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/App_Data/Themes/{0}", currentUser.Id));

                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory(root);
                }

                provider = new MultipartFormDataStreamProvider(root);

                await this.Request.Content.ReadAsMultipartAsync(provider);

                file = provider.FileData.FirstOrDefault();

                if (file != null)
                {
                    originalPhysicalPath = file.LocalFileName;

                    if (File.Exists(originalPhysicalPath))
                    {
                        if ((new FileInfo(originalPhysicalPath).Length / maxSizeKb) > maxSizeKb)
                        {
                            File.Delete(originalPhysicalPath);
                        }
                        else
                        {
                            if (file.Headers != null && file.Headers.ContentDisposition != null)
                            {
                                fileName = Path.GetFileNameWithoutExtension((file.Headers.ContentDisposition.FileName ??
                                                                             file.Headers.ContentDisposition.Name ?? string.Empty).Trim('"', '\\', '\'').Trim());
                            }

                            if (string.IsNullOrEmpty(fileName))
                            {
                                fileName = string.Format("Theme {0}", System.DateTime.UtcNow.Ticks);
                            }

                            fileName       = string.Format("{0}.css", fileName);
                            targetFileName = Path.Combine(Path.GetDirectoryName(originalPhysicalPath), fileName);

                            if (File.Exists(targetFileName))
                            {
                                File.Delete(targetFileName);
                            }

                            File.Move(originalPhysicalPath, targetFileName);

                            t = ThemeSource.CreateThemeInstance <UserTheme>(targetFileName, null, true);

                            ret = CreateReferenceFromTheme(t, fileName);
                        }
                    }
                }
            }

            return(ret);
        }