示例#1
0
        /// <summary>
        /// Save the serialized value of content into message section of a <see cref="ISharpBatchTracking"/>,
        /// </summary>
        /// <param name="data">The content to save</param>
        /// <param name="serializer">The <see cref="IModelSerializer"/> to use to serialize data.</param>
        /// <returns></returns>
        public Task ToTracking(object data, IModelSerializer serializer)
        {
            ISharpBatchTrackingFactory trackingFactory = (ISharpBatchTrackingFactory)BatchContext.RequestServices.GetService(typeof(ISharpBatchTrackingFactory));
            var responseToTracking = new ResponseToTrackingManager(trackingFactory, SessionId);

            return(responseToTracking.ToTracking(data, serializer));
        }
        public DefaultBatchInvoker(IPropertyInvoker propertyInvoker, MethodActivator activator, ISharpBatchTrackingFactory trakingFactory, IModelSerializer modelserializer)
        {
            if (propertyInvoker == null)
            {
                throw new ArgumentNullException(nameof(propertyInvoker));
            }

            if (activator == null)
            {
                throw new ArgumentNullException(nameof(activator));
            }

            if (trakingFactory == null)
            {
                throw new ArgumentNullException(nameof(trakingFactory));
            }

            if (modelserializer == null)
            {
                throw new ArgumentNullException(nameof(modelserializer));
            }

            _propertyInvoker   = propertyInvoker;
            _activator         = activator;
            _sharpBatchTraking = trakingFactory.getTrakingProvider();
            _modelSerializer   = modelserializer;
        }
 public static AnalyzeRequest Deserialize(this IModelSerializer serializer, byte[] bytes)
 {
     using (var ms = new MemoryStream(bytes))
     {
         return(serializer.Deserialize(ms));
     }
 }
示例#4
0
        public DataService(IModelSerializer serializer, FSO.Content.Content content)
        {
            this.Serializer     = serializer;
            this.DataDefinition = content.DataDefinition;

            //Build Struct => Field[] maps for quicker serialization
            foreach (var derived in DataDefinition.DerivedStructs)
            {
                var type = MaskedStructUtils.FromID(derived.ID);
                List <StructField> fields = new List <StructField>();
                var parent = DataDefinition.Structs.First(x => x.ID == derived.Parent);

                foreach (var field in parent.Fields)
                {
                    var mask = derived.FieldMasks.FirstOrDefault(x => x.ID == field.ID);
                    if (mask == null)
                    {
                        continue;
                    }

                    /*
                     * var action = DerivedStructFieldMaskType.KEEP;
                     * if (mask != null){
                     *  action = mask.Type;
                     * }
                     * if (action == DerivedStructFieldMaskType.REMOVE){
                     *  //These seems wrong, ServerMyAvatar and MyAvatar both exclude bookmarks by this logic
                     *  //continue;
                     * }
                     */
                    fields.Add(field);
                }
                MaskedStructToActualFields.Add(type, fields.ToArray());
            }

            foreach (var _struct in DataDefinition.Structs)
            {
                StructToActualFields.Add(_struct.ID, _struct.Fields.ToArray());
            }

            var assembly = Assembly.GetAssembly(typeof(DataService));

            foreach (Type type in assembly.GetTypes())
            {
                System.Attribute[] attributes = System.Attribute.GetCustomAttributes(type);

                foreach (Attribute attribute in attributes)
                {
                    if (attribute is DataServiceModel)
                    {
                        var _struct = DataDefinition.GetStruct(type.Name);
                        if (_struct != null)
                        {
                            ModelTypeById.Add(_struct.ID, type);
                            ModelIdByType.Add(type, _struct.ID);
                        }
                    }
                }
            }
        }
示例#5
0
 public static void Serialize(this IModelSerializer serializer, IModelElement element, string path, Uri uri)
 {
     using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
     {
         serializer.Serialize(element, fs, uri);
     }
 }
示例#6
0
 /// <summary>
 /// Creates a new model repository with a given parent
 /// </summary>
 /// <param name="parent">The parent repository</param>
 /// <param name="serializer">A serializer object or null to use the default</param>
 /// <param name="locators">A set of model locators</param>
 /// <remarks>If no parent repository is provided, the meta repository is used as parent repository</remarks>
 public ModelRepository(IModelRepository parent, IModelSerializer serializer, params IModelLocator[] locators)
 {
     models                = new ModelRepositoryModelCollection(this);
     Locators              = new List <IModelLocator>(locators);
     Parent                = parent ?? MetaRepository.Instance;
     Serializer            = serializer ?? MetaRepository.Instance.Serializer;
     Parent.BubbledChange += Parent_BubbledChange;
 }
        public static byte[] Serialize(this IModelSerializer serializer, AnalyzeRequest request)
        {
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(request, ms);

                return(ms.ToArray());
            }
        }
示例#8
0
        /// <summary>
        /// Associates an IModelSerializer with a specific ModelRoot type.
        /// </summary>
        /// <typeparam name="T">The specific ModelRoot type.</typeparam>
        /// <param name="serializer">The serializer to use for serializing and deserializing the specific ModelRoot type.</param>
        protected static void RegisterSerializer <T>(IModelSerializer serializer) where T : ModelRoot
        {
            Type type = typeof(T);

            if (ModelRoot.serializers.ContainsKey(type))
            {
                throw new Exception(string.Format("A serializer for type {0} is already registered", type.Name));
            }
            ModelRoot.serializers[type] = serializer;
        }
        public static string Create(IModelSerializer serializer, string modelPropertyName, object model)
        {
            string serializedModel = serializer.Serialize(model);

            var modelBuilder = new StringBuilder();
            modelBuilder.AppendLine("<script type=\"text/javascript\">");
            modelBuilder.Append("window.").Append(modelPropertyName).Append(" = ").Append(serializedModel).AppendLine(";");
            modelBuilder.Append("</script>");

            return modelBuilder.ToString();
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelAsset"/> class.
 /// <para>
 /// This constructor is called by <see cref="ModelAssetLoader"/> when loading a model asset.
 /// </para>
 /// </summary>
 /// <param name="modelSerializer">
 ///     The model serializer service.
 /// </param>
 /// <param name="name">
 ///     The name of the model asset.
 /// </param>
 /// <param name="rawData">
 ///     The raw, serialized model data.
 /// </param>
 /// <param name="rawAdditionalAnimations">
 ///     The source raw data that contains additional animations, mapping byte arrays to animation names.
 /// </param>
 /// <param name="data">
 ///     The platform specific data.
 /// </param>
 /// <param name="sourcedFromRaw">
 ///     Whether or not this asset was sourced from a purely raw asset file (such as a PNG).
 /// </param>
 /// <param name="extension">
 ///     The appropriate file extension for this model.
 /// </param>
 /// <param name="importOptions"></param>
 public ModelAsset(IModelSerializer modelSerializer, string name, byte[] rawData, Dictionary <string, byte[]> rawAdditionalAnimations, PlatformData data, bool sourcedFromRaw, string extension, string[] importOptions)
 {
     _modelSerializer        = modelSerializer;
     Name                    = name;
     RawData                 = rawData;
     RawAdditionalAnimations = rawAdditionalAnimations;
     PlatformData            = data;
     SourcedFromRaw          = sourcedFromRaw;
     Extension               = extension;
     ImportOptions           = importOptions;
 }
示例#11
0
        private Plugin(IGeneratorSettings generatorSettings, IModelSerializer <TCodeModel> serializer, ITransformer <TCodeModel> transformer,
                       CodeGenerator generator, CodeNamer namer)
        {
            _generatorSettings = generatorSettings;
            _serializer        = serializer;
            _transformer       = transformer;
            _generator         = generator;
            _namer             = namer;

            // apply custom settings to the GeneratorSettings
            Core.Settings.PopulateSettings(_generatorSettings, Core.Settings.Instance.CustomSettings);
        }
示例#12
0
        public ServerDataService(IModelSerializer serializer,
                                 Content.GameContent content,
                                 IKernel kernel) : base(serializer, content)
        {
            AddProvider(kernel.Get <ServerAvatarProvider>());
            var lots = kernel.Get <ServerLotProvider>();

            AddProvider(lots);
            var city = kernel.Get <ServerCityProvider>();

            AddProvider(city);
            city.BindLots(lots);
        }
 public FileConversionOrchestrator(
     IFileHandler fileHandlerService,
     IModelSerializer <TSourceModel> sourceModelSerializerService,
     IModelConverter <TSourceModel, TIntermediateModel> sourceModelConverterService,
     IModelConverter <TTargetModel, TIntermediateModel> targetModelConverterService,
     IModelSerializer <TTargetModel> targetModelSerializerService)
 {
     _fileHandlerService           = fileHandlerService;
     _sourceModelSerializerService = sourceModelSerializerService;
     _sourceModelConverterService  = sourceModelConverterService;
     _targetModelConverterService  = targetModelConverterService;
     _targetModelSerializerService = targetModelSerializerService;
 }
示例#14
0
        public SystemActionProvider(ISharpBatchTrackingFactory trakingFactory, IModelSerializer modelSerializer)
        {
            if (trakingFactory == null)
            {
                throw new ArgumentNullException(nameof(trakingFactory));
            }

            if (modelSerializer == null)
            {
                throw new ArgumentNullException(nameof(modelSerializer));
            }

            _trakingProvider = trakingFactory.getTrakingProvider();
            _modelSerializer = modelSerializer;
        }
示例#15
0
        public ClientDataService(IModelSerializer serializer,
                                 FSO.Content.Content content,
                                 IKernel kernel) : base(serializer, content)
        {
            AddProvider(kernel.Get <ClientAvatarProvider>());
            AddProvider(kernel.Get <ClientLotProvider>());
            AddProvider(kernel.Get <ClientCityProvider>());
            CityClient = kernel.Get <AriesClient>("City");
            CityClient.AddSubscriber(this);

            //When a new object is made, this data will be requested automatically
            SetDefaultDataStruct(typeof(Avatar), MaskedStruct.SimPage_Main);

            PollInterval = GameThread.SetInterval(PollTopics, 5000);
        }
示例#16
0
        public static void Serialize(this IModelSerializer serializer, IModelElement element, string path)
        {
            Uri   uri;
            Model model = element.Model;

            if (model == null || model.ModelUri == null)
            {
                if (!Uri.TryCreate(path, UriKind.Absolute, out uri))
                {
                    uri = new Uri(Path.GetFullPath(path));
                }
            }
            else
            {
                uri = model.ModelUri;
            }
            serializer.Serialize(element, path, uri);
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HtmlViewEngine"/> class.
        /// </summary>
        /// <param name="cacheExpiration">
        /// Sets the HTML cache expiration interval. Set this parameter to
        /// <see cref="TimeSpan.Zero"/> to disable the HTML cache.
        /// </param>
        public HtmlViewEngine(TimeSpan cacheExpiration)
        {
            if (cacheExpiration > TimeSpan.Zero)
            {
                if (HttpRuntime.Cache == null)
                {
                    throw new InvalidOperationException(Resources.UnavailableAspCache);
                }

                _cacheExpiration = DateTime.Now.Add(cacheExpiration);
            }

            _serializer = new DefaultModelSerializer();

            ViewLocationFormats = new[] { "~/views/{1}/{0}.html", "~/views/shared/{0}.html" };
            PartialViewLocationFormats = new[] { "~/views/{1}/{0}.partial.html", "~/views/shared/{0}.partial.html" };
            FileExtensions = new[] { "html" };
        }
示例#18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HtmlView"/> class.
        /// </summary>
        /// <param name="serializer">The model serializer.</param>
        /// <param name="filePath">The local view file path.</param>
        /// <param name="version">An optional application version.</param>
        /// <param name="antiForgeryTokenSupport">
        /// A value indicating whether anti-forgery tokens are supported.
        /// </param>
        /// <param name="cacheExpiration">An optional HTML cache expiration time.</param>
        /// <param name="modelPropertyName">
        /// An optional model property name returned from the controller.
        /// </param>
        /// <param name="minificationOptions">
        /// A value indicating whether the output HTML should be minified.
        /// </param>
        /// <param name="cdnUrl">An optional CDN URL.</param>
        public HtmlView(IModelSerializer serializer,
                        string filePath,
                        string version,
                        bool antiForgeryTokenSupport,
                        DateTime? cacheExpiration,
                        string modelPropertyName,
                        MinificationOptions minificationOptions,
                        Uri cdnUrl)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            _serializer = serializer;
            _filePath = filePath;
            _version = version;
            _antiForgeryTokenSupport = antiForgeryTokenSupport;
            _cacheExpiration = cacheExpiration;
            _minificationOptions = minificationOptions;

            if (!IsNullOrWhiteSpace(modelPropertyName))
            {
                _modelPropertyName = modelPropertyName.Trim();
            }

            if (cdnUrl == null)
            {
                return;
            }

            if (!cdnUrl.IsAbsoluteUri)
            {
                throw new ArgumentException(Resources.InvalidCdnUrl, nameof(cdnUrl));
            }

            _cdnUrl = cdnUrl;
        }
示例#19
0
        public static void Serialize(this IModelSerializer serializer, IModelElement element, Stream target, Uri uri)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            var model = element.Model;

            if (model == null)
            {
                model = new Model();
                model.RootElements.Add(element);
            }
            model.ModelUri = uri;

            serializer.Serialize(model, target);
        }
        public ServerDataService(IModelSerializer serializer,
                                 FSO.Content.Content content,
                                 IKernel kernel) : base(serializer, content)
        {
            AddProvider(kernel.Get <ServerAvatarProvider>());
            var lots = kernel.Get <ServerLotProvider>();

            AddProvider(lots);
            var city = kernel.Get <ServerCityProvider>();

            AddProvider(city);
            var nhood = kernel.Get <ServerNeighborhoodProvider>();

            nhood.BindCityRep(lots);
            AddProvider(nhood);

            var ratings = kernel.Get <ServerMayorRatingProvider>();

            AddProvider(ratings);

            city.BindLots(lots);
        }
示例#21
0
        public static IContentModelBinder GetContentModelBinder(IServiceProvider serviceProvider,
                                                                HttpMethod httpMethod,
                                                                ContentType contentType)
        {
            IModelSerializer modelSerializer = null;

            if (contentType == ContentType.Xml)
            {
                modelSerializer = serviceProvider.GetService <IModelXmlSerializer>();
            }
            else
            {
                modelSerializer = serviceProvider.GetService <IModelJsonSerializer>();
            }

            if (httpMethod == HttpMethod.Get)
            {
                return(new HttpGetContentBinder(httpMethod));
            }

            if (httpMethod == HttpMethod.Post)
            {
                return(new HttpPostContentBinder(httpMethod, modelSerializer));
            }

            if (httpMethod == HttpMethod.Put)
            {
                return(new HttpPutContentBinder(httpMethod, modelSerializer));
            }

            if (httpMethod == HttpMethod.Delete)
            {
                return(new HttpDeleteContentBinder(httpMethod));
            }

            throw new NotImplementedException($"{httpMethod.Method} is not supported or not implemented yet.");
        }
示例#22
0
 public BodyContentBinder(HttpMethod httpMethod, IModelSerializer modelSerializer)
     : base(httpMethod)
 {
     ModelSerializer = modelSerializer;
 }
示例#23
0
 public RabbitMqConsumer(IModel model, IModelSerializer serializer, IRequestProcessor requestProcessor)
 {
     _model            = model;
     _serializer       = serializer;
     _requestProcessor = requestProcessor;
 }
示例#24
0
 public SerializationContext(IKernel Kernel, IModelSerializer ModelSerializer)
 {
     this.Kernel          = Kernel;
     this.ModelSerializer = ModelSerializer;
 }
示例#25
0
 /// <summary>
 /// Save the serialized value of content into message section of a <see cref="ISharpBatchTracking"/>,
 /// </summary>
 /// <param name="data">The content to save</param>
 /// <param name="serializer">The <see cref="IModelSerializer"/> to use to serialize data.</param>
 /// <returns></returns>
 public Task ToTracking(object data, IModelSerializer serializer)
 {
     return(ToTracking(serializer.Serialize(data)));
 }
示例#26
0
 public ResponseToTrackingManager(ISharpBatchTrackingFactory sharpBatchTrackingFactory, IModelSerializer modelSerializer, Guid sessionId)
 {
     _sharpBatchTrackingFactory = sharpBatchTrackingFactory;
     _modelSerializer           = modelSerializer;
     _sessionId = sessionId;
 }
示例#27
0
 public ModelAsset(IModelSerializer modelSerializer, string name, byte[] data)
 {
     _modelSerializer = modelSerializer;
     Name             = name;
     _data            = data;
 }
示例#28
0
 public HttpPutContentBinder(HttpMethod httpMethod, IModelSerializer modelSerializer)
     : base(httpMethod, modelSerializer)
 {
 }
示例#29
0
 public RabbitMqQueue(IModel model, IModelSerializer serializer)
 {
     _model      = model;
     _serializer = serializer;
 }
示例#30
0
 public NullDataService(IModelSerializer serializer,
                        FSO.Content.Content content,
                        IKernel kernel) : base(serializer, content)
 {
 }
示例#31
0
 public ModelAssetCompiler(IModelRenderConfiguration[] modelRenderConfigurations, IRenderBatcher renderBatcher, IModelSerializer modelSerializer)
 {
     _modelRenderConfigurations = modelRenderConfigurations;
     _renderBatcher             = renderBatcher;
     _modelSerializer           = modelSerializer;
 }
示例#32
0
 public ModelAssetLoader(IModelSerializer modelSerializer)
 {
     _modelSerializer = modelSerializer;
 }
示例#33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelAssetLoader"/> class.
 /// </summary>
 /// <param name="modelSerializer">
 /// The model serializer service.
 /// </param>
 /// <param name="assetContentManager">
 /// The asset content manager.
 /// </param>
 public ModelAssetLoader(IModelSerializer modelSerializer, IAssetContentManager assetContentManager)
 {
     _modelSerializer           = modelSerializer;
     this.m_AssetContentManager = assetContentManager;
 }
示例#34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelAssetLoader"/> class.
 /// </summary>
 /// <param name="modelSerializer">
 /// The model serializer service.
 /// </param>
 /// <param name="assetContentManager">
 /// The asset content manager.
 /// </param>
 public ModelAssetLoader(IModelSerializer modelSerializer, IAssetContentManager assetContentManager)
 {
     _modelSerializer = modelSerializer;
     this.m_AssetContentManager = assetContentManager;
 }