Пример #1
0
        /// <inheritdoc />
        public object?ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
        {
            SpriteFont font = ContentSerializer.Read <SpriteFont>(parameters.Stream);

            if (font.ImageData.Length <= 0)
            {
                return(null);
            }

            IGraphicsDevice graphicsDevice =
                contentManager.ServiceRegistry.GetService <IGraphicsDevice>();

            try
            {
                using (MemoryStream ms = new MemoryStream(font.ImageData)
                {
                    Position = 0
                })
                {
                    font.Texture = Texture.Load(graphicsDevice.Device, ms) ??
                                   throw new NullReferenceException($"{nameof(font.Texture)}");
                }
            }
            catch { return(null); }

            return(font);
        }
        public override Stream Serialize(ExtendBucketWormRequest request)
        {
            var model = new ExtendBucketWormModel();

            model.Days = request.RetentionPeriodInDays;
            return(ContentSerializer.Serialize(model));
        }
Пример #3
0
        public override Stream Serialize(CreateSelectObjectMetaRequest request)
        {
            var model = new CsvMetaRequestModel();

            var inputFormat = (CreateSelectObjectMetaCSVInputFormat)request.InputFormat;

            model.InputFormat = new CreateSelectObjectMetaInputFormatModel();
            model.InputFormat.CompressionTypeInfo = request.InputFormat.CompressionType;

            model.InputFormat.CSV = new CreateSelectObjectMetaInputFormatModel.CSVModel();

            if (!string.IsNullOrEmpty(inputFormat.RecordDelimiter))
            {
                model.InputFormat.CSV.RecordDelimiter = Convert.ToBase64String(Encoding.UTF8.GetBytes(inputFormat.RecordDelimiter));
            }

            if (!string.IsNullOrEmpty(inputFormat.FieldDelimiter))
            {
                model.InputFormat.CSV.FieldDelimiter = Convert.ToBase64String(Encoding.UTF8.GetBytes(inputFormat.FieldDelimiter));
            }

            if (!string.IsNullOrEmpty(inputFormat.QuoteCharacter))
            {
                model.InputFormat.CSV.QuoteCharacter = Convert.ToBase64String(Encoding.UTF8.GetBytes(inputFormat.QuoteCharacter));
            }

            model.OverwriteIfExists = request.OverwriteIfExists;

            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(SetBucketRequestPaymentRequest request)
        {
            var model = new RequestPaymentConfiguration();

            model.Payer = request.Payer;
            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(CreateLiveChannelRequest request)
        {
            var model = new LiveChannelConfiguration
            {
                Description = request.Description,
                Status      = request.Status,
            };

            if (!string.IsNullOrEmpty(request.Type))
            {
                model.Target = new LiveChannelConfiguration.TargetModel()
                {
                    Type         = request.Type,
                    FragDuration = request.FragDuration,
                    FragCount    = request.FragCount,
                    PlaylistName = request.PlaylistName
                };
            }

            if (!string.IsNullOrEmpty(request.DestBucket))
            {
                model.Snapshot = new LiveChannelConfiguration.SnapshotModel()
                {
                    RoleName    = request.RoleName,
                    DestBucket  = request.DestBucket,
                    NotifyTopic = request.NotifyTopic,
                    Interval    = request.Interval
                };
            }

            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(SetBucketLifecycleRequest request)
        {
            var rules = request.LifecycleRules;

            var lcc = new LifecycleConfiguration
            {
                LifecycleRules = new Model.LifecycleRule[rules.Count]
            };

            for (var i = 0; i < rules.Count; i++)
            {
                lcc.LifecycleRules[i] = new Model.LifecycleRule
                {
                    ID = rules[i].ID,
                    Prefix = rules[i].Prefix
                };

                switch (rules[i].Status)
                {
                    case RuleStatus.Enabled:
                        lcc.LifecycleRules[i].Status = RuleStatus.Enabled.ToString();
                        break;
                    case RuleStatus.Disabled:
                        lcc.LifecycleRules[i].Status = RuleStatus.Disabled.ToString();
                        break;
                }

                lcc.LifecycleRules[i].Expiration = new Expiration();

                if (rules[i].CreatedBeforeDate.HasValue)
                {
                    lcc.LifecycleRules[i].Expiration.CreatedBeforeDate = DateUtils.FormatIso8601Date(rules[i].CreatedBeforeDate.Value);
                }
                else if (rules[i].ExpriationDays.HasValue)
                {
                    lcc.LifecycleRules[i].Expiration.Days = rules[i].ExpriationDays.Value;
                }
                else if (rules[i].ExpirationTime.HasValue)
                {
                    lcc.LifecycleRules[i].Expiration.Date = DateUtils.FormatIso8601Date(rules[i].ExpirationTime.Value);
                }

                if (rules[i].Transitions != null)
                {
                    lcc.LifecycleRules[i].Transition = new LifecycleRuleTransition[rules[i].Transitions.Length];

                    for (int j = 0; j < lcc.LifecycleRules[i].Transition.Length; j++)
                    {
                        lcc.LifecycleRules[i].Transition[j] = ConvertTransition(rules[i].Transitions[j]);
                    }
                }

                if (rules[i].AbortMultipartUpload != null)
                {
                    lcc.LifecycleRules[i].AbortMultipartUpload = ConvertExpiration(rules[i].AbortMultipartUpload);
                }
            }

            return ContentSerializer.Serialize(lcc);
        }
Пример #7
0
        /// <summary>
        /// Executes given IHttpRequest and returns deserialized response body.
        /// </summary>
        /// <typeparam name="TResponse">Type response body will be deserialized to.</typeparam>
        /// <param name="request">Request to be executed.</param>
        /// <returns>Response body deserialized to type TResponse.</returns>
        /// <exception cref="DreamFactoryException">Thrown when there was an error executing request.</exception>
        internal async Task <TResponse> ExecuteRequest <TResponse>(IHttpRequest request)
            where TResponse : class, new()
        {
            string body = await ExecuteRequest(request);

            return(ContentSerializer.Deserialize <TResponse>(body));
        }
Пример #8
0
        public override Stream Serialize(SetBucketVersioningRequest request)
        {
            var model = new VersioningConfiguration();

            model.Status = request.Status;
            return(ContentSerializer.Serialize(model));
        }
Пример #9
0
        public object Convert(ContentSerializer serializer, ContentArea obj, object owner, string locale)
        {
            if (obj == null)
            {
                return(null);
            }

            return(GetContent(serializer, obj.Items.Select(s => s.ContentLink), locale).ToArray());
        }
Пример #10
0
        private object ReadMessage(HorseMessage message, Type type)
        {
            if (ContentSerializer == null)
            {
                ContentSerializer = new NewtonsoftContentSerializer();
            }

            return(ContentSerializer.Deserialize(message, type));
        }
        public override Stream Serialize(StorageClass request)
        {
            var model = new CreateBucketRequestModel
            {
                StorageClass = request
            };

            return(ContentSerializer.Serialize(model));
        }
Пример #12
0
        public override Stream Serialize(RestoreObjectRequest request)
        {
            var model = new RestoreRequestModel();

            model.Days              = request.Days;
            model.JobParameter      = new RestoreRequestModel.JobParameters();
            model.JobParameter.Tier = request.Tier;
            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(SetBucketStorageCapacityRequest request)
        {
            var model = new BucketStorageCapacityModel
            {
                StorageCapacity = request.StorageCapacity,
            };

            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(CreateBucketRequest request)
        {
            var model = new CreateBucketRequestModel
            {
                StorageClass       = request.StorageClass,
                DataRedundancyType = request.DataRedundancyType
            };

            return(ContentSerializer.Serialize(model));
        }
        public void CanSerialisePresentation()
        {
            var contentSerializer = new ContentSerializer <PresentationPublishedDataModel>();

            var presentation = ModelHelper.GetPublishedPresentationModel();

            var json = contentSerializer.Serialize(presentation);

            Assert.IsTrue(!string.IsNullOrEmpty(json));
        }
        public void CanSerialisePage()
        {
            var contentSerializer = new ContentSerializer <PagePublishedDataModel>();

            var page = ModelHelper.GetPublishedPageModel();

            var json = contentSerializer.Serialize(page);

            Assert.IsTrue(!string.IsNullOrEmpty(json));
        }
        public override Stream Serialize(SetBucketEncryptionRequest request)
        {
            var model = new ServerSideEncryptionRule()
            {
                ApplyServerSideEncryptionByDefault = new ServerSideEncryptionRule.ApplyServerSideEncryptionByDefaultModel()
            };

            model.ApplyServerSideEncryptionByDefault.SSEAlgorithm   = request.SSEAlgorithm;
            model.ApplyServerSideEncryptionByDefault.KMSMasterKeyID = request.KMSMasterKeyID;
            return(ContentSerializer.Serialize(model));
        }
        public override Stream Serialize(SetBucketCorsRequest request)
        {
            var model = new SetBucketCorsRequestModel
            {
                CORSRuleModels = new SetBucketCorsRequestModel.CORSRuleModel[request.CORSRules.Count]
            };

            for (var i = 0; i < request.CORSRules.Count; i++)
            {
                var corsRuleModel = new SetBucketCorsRequestModel.CORSRuleModel();

                if (request.CORSRules[i].AllowedHeaders != null)
                {
                    corsRuleModel.AllowedHeaders = new string[request.CORSRules[i].AllowedHeaders.Count];
                    for (var j = 0; j < request.CORSRules[i].AllowedHeaders.Count; j++)
                    {
                        corsRuleModel.AllowedHeaders[j] = request.CORSRules[i].AllowedHeaders[j];
                    }
                }

                if (request.CORSRules[i].AllowedMethods != null)
                {
                    corsRuleModel.AllowedMethods = new string[request.CORSRules[i].AllowedMethods.Count];
                    for (var j = 0; j < request.CORSRules[i].AllowedMethods.Count; j++)
                    {
                        corsRuleModel.AllowedMethods[j] = request.CORSRules[i].AllowedMethods[j];
                    }
                }

                if (request.CORSRules[i].AllowedOrigins != null)
                {
                    corsRuleModel.AllowedOrigins = new string[request.CORSRules[i].AllowedOrigins.Count];
                    for (var j = 0; j < request.CORSRules[i].AllowedOrigins.Count; j++)
                    {
                        corsRuleModel.AllowedOrigins[j] = request.CORSRules[i].AllowedOrigins[j];
                    }
                }

                if (request.CORSRules[i].ExposeHeaders != null)
                {
                    corsRuleModel.ExposeHeaders = new string[request.CORSRules[i].ExposeHeaders.Count];
                    for (var j = 0; j < request.CORSRules[i].ExposeHeaders.Count; j++)
                    {
                        corsRuleModel.ExposeHeaders[j] = request.CORSRules[i].ExposeHeaders[j];
                    }
                }

                corsRuleModel.MaxAgeSeconds = request.CORSRules[i].MaxAgeSeconds;

                model.CORSRuleModels[i] = corsRuleModel;
            }

            return(ContentSerializer.Serialize(model));
        }
    /// <summary>
    /// Called to create an error object from an unhandled HTTP response.
    /// </summary>
    protected virtual async Task <ServiceErrorDto> CreateErrorFromHttpResponseAsync(HttpResponseMessage response, CancellationToken cancellationToken)
    {
        var result = await ContentSerializer.ReadHttpContentAsync <ServiceErrorDto>(response.Content, cancellationToken).ConfigureAwait(false);

        if (result.IsFailure || string.IsNullOrWhiteSpace(result.Value.Code))
        {
            return(HttpServiceErrors.CreateErrorForStatusCode(response.StatusCode, response.ReasonPhrase));
        }

        return(result.Value);
    }
        void LoadListOfGamesIntoListView(ContentSerializer <Game> serializer, ListView listView)
        {
            Game[] games = serializer.Load();

            foreach (Game game in games)
            {
                ListViewItem gameItem = new ListViewItem(game.Name);
                gameItem.Tag = game;

                listView.Items.Add(gameItem);
            }
        }
Пример #21
0
        /// <inheritdoc />
        public async Task <IEnumerable <Resource> > GetResourcesAsync(string serviceName)
        {
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.WithResource(serviceName).Build(), BaseHeaders);

            IHttpResponse response = await HttpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, ContentSerializer);

            var resources = new { resource = new List <Resource>() };

            return(ContentSerializer.Deserialize(response.Body, resources).resource);
        }
        public override Stream Serialize(DeleteObjectsRequest request)
        {
            var model = new DeleteObjectsRequestModel
            {
                Quiet = request.Quiet,
                Keys  = request.Keys.Select(key => new DeleteObjectsRequestModel.ObjectToDel {
                    Key = key
                }).ToArray()
            };

            return(ContentSerializer.Serialize(model));
        }
Пример #23
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: BuildBlockSprite <SpritePath> <DestinationPath>");
                return;
            }

            var spritePath      = args[0];
            var destinationPath = args[1];

            BlockSprite blockSprite;

            using (var stream = new FileStream(spritePath, FileMode.Open))
            {
                var bitmap = new Bitmap(stream);
                var w      = bitmap.Width;
                var h      = bitmap.Height;

                if (w != 16 || h != 16)
                {
                    throw new InvalidOperationException("The size of a sprite is invalid.");
                }

                blockSprite = new BlockSprite(w, h);

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        var c = bitmap.GetPixel(x, y);
                        blockSprite.SetPixel(x, y, new XnaColor(c.R, c.G, c.B, c.A));
                    }
                }
            }

            var processor = new BlockSpriteProcessor();
            var block     = processor.Process(blockSprite);

            var destinationDir = Path.GetDirectoryName(destinationPath);

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

            var serializer = new ContentSerializer <Block>();

            using (var stream = new FileStream(destinationPath, FileMode.Create))
            {
                serializer.Serialize(stream, block);
            }
        }
Пример #24
0
        /// <inheritdoc />
        public async Task <IEnumerable <Service> > GetServicesAsync()
        {
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), BaseHeaders);

            IHttpResponse response = await HttpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, ContentSerializer);

            var services = new { service = new List <Service>() };

            return(ContentSerializer.Deserialize(response.Body, services).service);
        }
Пример #25
0
        public override Stream Serialize(SetBucketWebsiteRequest request)
        {
            var model = new SetBucketWebsiteRequestModel
            {
                ErrorDocument = new SetBucketWebsiteRequestModel.ErrorDocumentModel(),
                IndexDocument = new SetBucketWebsiteRequestModel.IndexDocumentModel {
                    Suffix = request.IndexDocument
                }
            };

            model.ErrorDocument.Key = request.ErrorDocument;

            return(ContentSerializer.Serialize(model));
        }
Пример #26
0
        public override Stream Serialize(SetBucketLoggingRequest request)
        {
            var model = new SetBucketLoggingRequestModel();

            var setBucketLoggingEnabled = new SetBucketLoggingRequestModel.SetBucketLoggingEnabled
            {
                TargetBucket = request.TargetBucket,
                TargetPrefix = request.TargetPrefix
            };

            model.LoggingEnabled = setBucketLoggingEnabled;

            return(ContentSerializer.Serialize(model));
        }
Пример #27
0
        /// <inheritdoc />
        public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo)
        {
            if (string.IsNullOrEmpty(dimensionInfo))
            {
                throw new CSReaderException(
                          $"ERROR: NO DIMENSION INFO FOUND EXPECTED: DICTIONARY<GENERIC_TYPE_INFO1, GENERIC_TYPE_INFO2>(count) -> DICTIONARY{genericTypeInfo}{dimensionInfo}");
            }
            if (string.IsNullOrEmpty(genericTypeInfo))
            {
                throw new CSReaderException(
                          "ERROR: NO GENERIC TYPE INFO DEFINED -> DICTIONARY<GENERIC_TYPE_INFO1, GENERIC_TYPE_INFO2>");
            }

            genericTypeInfo.GetKeyValueInnerType(out string kbti, out string vbti, out string vgti);

            if (!ContentSerializer.s_types.TryGetValue(kbti, out IType itk) || !itk.IsPrimitive)
            {
                throw new NotSupportedException($"ERROR: INVALID KEY TYPE FOUND IN -> '{genericTypeInfo}'");
            }

            Type valueType;
            Func <CSStreamReader, string, object> readCallback;

            if (ContentSerializer.s_types.TryGetValue(vbti, out IType it))
            {
                valueType    = it.CreateType(vgti);
                readCallback = (s, d) =>
                {
                    return(it.Read(stream, string.Empty, vgti, d));
                };
            }
            else
            {
                valueType    = vbti.CreateType();
                readCallback = (s, d) =>
                {
                    return(ContentSerializer.Read(stream, valueType, string.Empty));
                };
            }

            int count = GetDictionaryCount(dimensionInfo);

            Type   dic = BaseType.MakeGenericType(itk.CreateType(string.Empty), valueType);
            object obj = System.Activator.CreateInstance(dic, count);

            AddDictionaryContent(stream, readCallback, (dynamic)obj, count);
            stream.ReadTag($"/{key}");
            return(obj);
        }
        public void CanRoundtripSerialisePresentation()
        {
            var contentSerializer = new ContentSerializer <PresentationPublishedDataModel>();

            var presentation = ModelHelper.GetPublishedPresentationModel();

            var json = contentSerializer.Serialize(presentation);

            var presentationRoundtrip = contentSerializer.Deserialize(json);

            var jsonRoundtrip = contentSerializer.Serialize(presentationRoundtrip);

            // Ensure the JSON matches the original serialisation
            Assert.IsTrue(json.Equals(jsonRoundtrip, StringComparison.Ordinal));
        }
        public object Convert(IPublishedProperty property, IPublishedContent owner, ContentSerializer serializer, UmbracoHelper umbraco)
        {
            if (property.Value is IPublishedContent)
            {
                return(serializer.Serialize(property.Value as IPublishedContent));
            }

            IPublishedContent content = umbraco.TypedContent(property.Value);

            if (content == null)
            {
                return(null);
            }

            return(serializer.Serialize(content));
        }
        public object Convert(ContentSerializer serializer, ContentReference obj, object owner, string locale)
        {
            if (obj == null)
            {
                return(null);
            }

            var content = ServiceLocator.Current.GetInstance <IContentRepository>().Get <IContent>(obj, new LanguageSelector(locale));
            var media   = content as MediaData;

            if (media != null)
            {
                return(new { media.Name, media.Thumbnail, media.MimeType, Url = UrlResolver.Current.GetUrl(media) });
            }

            return(obj.GetContentApiUrl(locale));
        }
Пример #31
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: BuildBlockSprite <SpritePath> <DestinationPath>");
                return;
            }

            var spritePath = args[0];
            var destinationPath = args[1];

            BlockSprite blockSprite;

            using (var stream = new FileStream(spritePath, FileMode.Open))
            {
                var bitmap = new Bitmap(stream);
                var w = bitmap.Width;
                var h = bitmap.Height;

                if (w != 16 || h != 16)
                    throw new InvalidOperationException("The size of a sprite is invalid.");

                blockSprite = new BlockSprite(w, h);

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        var c = bitmap.GetPixel(x, y);
                        blockSprite.SetPixel(x, y, new XnaColor(c.R, c.G, c.B, c.A));
                    }
                }
            }

            var processor = new BlockSpriteProcessor();
            var block = processor.Process(blockSprite);

            var destinationDir = Path.GetDirectoryName(destinationPath);
            if (!Directory.Exists(destinationDir)) Directory.CreateDirectory(destinationDir);

            var serializer = new ContentSerializer<Block>();
            using (var stream = new FileStream(destinationPath, FileMode.Create))
            {
                serializer.Serialize(stream, block);
            }
        }
Пример #32
0
        public void Init()
        {
            Configuration = new uSyncCoreConfig();

            ContentTypeSerializer = new ContentTypeSerializer(Constants.Packaging.DocumentTypeNodeName);
            MediaTypeSerializer = new MediaTypeSerializer("MediaType");

            MemberTypeSerializer = new MemberTypeSerializer("MemberType");

            TemplateSerializer = new TemplateSerializer(Constants.Packaging.TemplateNodeName);

            LanguageSerializer = new LanguageSerializer("Language");
            DictionarySerializer = new DictionarySerializer(Constants.Packaging.DictionaryItemNodeName);

            MacroSerializer = new MacroSerializer(Constants.Packaging.MacroNodeName);

            DataTypeSerializer = new DataTypeSerializer(Constants.Packaging.DataTypeNodeName);

            ContentSerializer = new ContentSerializer();
            MediaSerializer = new MediaSerializer();

            MediaFileMover = new uSyncMediaFileMover();
        }