Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
        public Task AddAsync(AnalyzeRequest request)
        {
            var bytes = _serializer.Serialize(request);

            _model.BasicPublish(Constants.Exchange, Constants.Routing, null, bytes);

            return(Task.CompletedTask);
        }
Exemplo n.º 3
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>
        /// <returns></returns>
        /// <remarks>The <see cref="IModelSerializer"/> used is returned from registered service </remarks>
        public Task ToTracking(object data)
        {
            if (_modelSerializer == null)
            {
                throw new ArgumentNullException(nameof(_modelSerializer));
            }

            return(ToTracking(_modelSerializer.Serialize(data)));
        }
        public static byte[] Serialize(this IModelSerializer serializer, AnalyzeRequest request)
        {
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(request, ms);

                return(ms.ToArray());
            }
        }
        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();
        }
Exemplo n.º 6
0
        public async Task <string> InvokeAsync(IBatchUrlManager urlManager, ContextInvoker context)
        {
            switch (urlManager.RequestCommand)
            {
            case BatchUrlManagerCommand.Status:
                var batchStaus = await _trakingProvider.GetStatusAsync(new Guid(context.Parameters["sessionid"].ToString()));

                var result = _modelSerializer.Serialize(batchStaus);
                return(result);

            default:
                throw new InvalidCastException($"Command {urlManager.RequestCommand.ToString()} not found");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The compile.
        /// </summary>
        /// <param name="asset">
        /// The asset.
        /// </param>
        /// <param name="platform">
        /// The platform.
        /// </param>
        public void Compile(ModelAsset asset, TargetPlatform platform)
        {
            if (asset.RawData == null)
            {
                return;
            }

            var reader = new AssimpReader(_modelRenderConfigurations, _renderBatcher);
            var model  = reader.Load(asset.RawData, asset.Name, asset.Extension, asset.RawAdditionalAnimations, asset.ImportOptions);
            var data   = _modelSerializer.Serialize(model);

            asset.PlatformData = new PlatformData {
                Data = data, Platform = platform
            };
        }
Exemplo n.º 8
0
        public async Task <ProgrammingTask> Create(ProgrammingTask task)
        {
            var taskId = Guid.NewGuid();

            task.Identifier = new GuidIdentifier(taskId);
            var serialized = _serializer.Serialize(task);

            var newFilePath = Path.Combine(_directoryPath, $"{taskId}.pt");

            using (var writer = new StreamWriter(File.Create(newFilePath)))
            {
                await writer.WriteAsync(serialized);
            }

            return(task);
        }
Exemplo n.º 9
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);
        }
        public void ConvertFile(string inputFilePath, string targetFilePath, string language)
        {
            // read input file
            var fileContent = _fileHandlerService.ReadFileAsString(inputFilePath);

            // parse file
            var sourceModel = _sourceModelSerializerService.Deserialize(fileContent);

            // convert source to intermediate model
            var intermediateModel = _sourceModelConverterService.ConvertToIntermediate(sourceModel, language);

            // convert intermediate to target model
            var targetModel = _targetModelConverterService.ConvertFromIntermediate(intermediateModel);

            // serialize model
            var serializedTargetModel = _targetModelSerializerService.Serialize(targetModel);

            // save output
            _fileHandlerService.WriteFileAsString(targetFilePath, serializedTargetModel);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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)));
 }
Exemplo n.º 13
0
        public async Task <object> InvokeAsync(ContextInvoker context)
        {
            var actionToExecute   = context.ActionDescriptor;
            var executor          = MethodExecutor.Create(actionToExecute.ActionInfo, actionToExecute.BatchTypeInfo);
            var activatorInstance = _activator.CreateInstance <object>(context.RequestServices, actionToExecute.BatchTypeInfo.AsType());

            //Check Propertyes to activate
            if (actionToExecute.PropertyInfo != null)
            {
                await _propertyInvoker.invokeAsync(activatorInstance, context);
            }

            var batchExecutionContext = BatchExecutionContext.Create(context);

            //Execute attribute onExecuting

            foreach (var executionAttribute in  actionToExecute.ExecutionAttribute)
            {
                executionAttribute.onExecuting(batchExecutionContext);
            }

            var parameterBinding = new DefaultBatchInvokerParameterBinding(context.Parameters, actionToExecute.ActionInfo, _modelSerializer);
            var parameters       = parameterBinding.Bind();

            object result   = null;
            object response = null;

            try
            {
                result = executor.Execute(activatorInstance, parameters);

                if (actionToExecute.IsAsync)
                {
                    var   task = result as Task;
                    await task;

                    var responseType   = result.GetType();
                    var taskTType      = responseType.GetGenericArguments()[0];
                    var resultProperty = typeof(Task <>).MakeGenericType(taskTType).GetProperty("Result");
                    response = resultProperty.GetValue(task);
                }
                else
                {
                    response = result;
                }

                //Save response in ShareMessage
                IResponseObject responseObject = new ResponseObject(response, context.SessionId);
                context.ShareMessage.Set <IResponseObject>(responseObject);
            }catch (Exception ex)
            {
                IResponseObject responseObject = new ResponseObject(ex, context.SessionId);
                context.ShareMessage.Set <IResponseObject>(responseObject);
                await _sharpBatchTraking.AddExAsync(context.SessionId, ex);

                foreach (var item in actionToExecute.ExceptionAttribute)
                {
                    item.onExecuted(batchExecutionContext, ex);
                }
            }

            foreach (var executionAttribute in actionToExecute.ExecutionAttribute)
            {
                executionAttribute.onExecuted(batchExecutionContext);
            }

            var serializedResult = "";

            //If result not null i serialize it
            if (result != null)
            {
                serializedResult = _modelSerializer.Serialize(response);
            }
            return(serializedResult);
        }
Exemplo n.º 14
0
        public async Task CompileAsync(IAssetFsFile assetFile, IAssetDependencies assetDependencies, TargetPlatform platform, IWritableSerializedAsset output)
        {
            var otherAnimations = new Dictionary <string, byte[]>();

            if (assetFile.Extension != "x")
            {
                var otherFiles = (await assetDependencies.GetAvailableCompileTimeFiles())
                                 .Where(x => x.Name.StartsWith(assetFile.Name + "-"))
                                 .ToArray();
                foreach (var otherAnim in otherFiles)
                {
                    using (var otherStream = await otherAnim.GetContentStream().ConfigureAwait(false))
                    {
                        var b = new byte[otherStream.Length];
                        await otherStream.ReadAsync(b, 0, b.Length).ConfigureAwait(false);

                        otherAnimations[otherAnim.Name.Substring((assetFile.Name + "-").Length)] = b;
                    }
                }
            }

            var nameComponents = assetFile.Name.Split('.');

            nameComponents[nameComponents.Length - 1] = "_FolderOptions";
            var folderOptionsFile = await assetDependencies.GetOptionalCompileTimeFileDependency(string.Join(".", nameComponents)).ConfigureAwait(false);

            string[] importFolderOptions = null;
            if (folderOptionsFile != null)
            {
                using (var optionsReader = new StreamReader(await folderOptionsFile.GetContentStream().ConfigureAwait(false)))
                {
                    importFolderOptions = optionsReader.ReadToEnd()
                                          .Trim()
                                          .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                          .Select(x => x.Trim())
                                          .Where(x => !x.StartsWith("#"))
                                          .ToArray();
                }
            }

            var optionsFile = await assetDependencies.GetOptionalCompileTimeFileDependency(assetFile.Name + ".Options").ConfigureAwait(false);

            string[] importOptions = null;
            if (optionsFile != null)
            {
                using (var optionsReader = new StreamReader(await optionsFile.GetContentStream().ConfigureAwait(false)))
                {
                    importOptions = optionsReader.ReadToEnd()
                                    .Trim()
                                    .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Select(x => x.Trim())
                                    .Where(x => !x.StartsWith("#"))
                                    .ToArray();
                }
            }

            if (importOptions == null)
            {
                importOptions = importFolderOptions;
            }

            byte[] modelData;
            using (var stream = await assetFile.GetContentStream().ConfigureAwait(false))
            {
                modelData = new byte[stream.Length];
                await stream.ReadAsync(modelData, 0, modelData.Length).ConfigureAwait(false);
            }

            var reader = new AssimpReader(_modelRenderConfigurations, _renderBatcher);
            var model  = reader.Load(modelData, assetFile.Name, assetFile.Extension, otherAnimations, importOptions);
            var data   = _modelSerializer.Serialize(model);

            output.SetLoader <IAssetLoader <ModelAsset> >();
            output.SetByteArray("Data", data);
        }