public RenderResultModel RenderMatch(INamedItem @object, CodeGenerationConfigBuilder builder) { Models.RenderModels.Object renderModel = RenderModel.FromNamedItem(builder, @object); var serialRenderModel = JSON.Convert(renderModel); _logger.LogError(new LogModel { Message = serialRenderModel, Title = renderModel?.ToString(), AdditionalKey = $"{renderModel?.ToString()}_{DateTime.Now:yyyy-MM-dd-HH-mm-ss}", Scopes = LogScope.Objects }); TemplateContext templateContext = new TemplateContext(); ScriptObject scriptObject = new ScriptObject(); scriptObject.Import(typeof(StringFunctions)); scriptObject.Import(renderModel); templateContext.PushGlobal(scriptObject); string templateContent = TemplateHelper.FindTemplateFile(builder.Input.Template); if (!string.IsNullOrEmpty(templateContent)) { Template template = Template.Parse(templateContent); List <Template> fileNameTemplates = new List <Template>(); if (builder.Output.OutputPathTemplates != null && builder.Output.OutputPathTemplates.Any()) { fileNameTemplates.AddRange(builder.Output.OutputPathTemplates.Select(t => Template.Parse(t))); } else { fileNameTemplates.Add(Template.Parse(builder.Output.OutputPathTemplate)); } string result = template.Render(templateContext); List <string> outputFilePaths = new List <string>(fileNameTemplates.Select(r => r.Render(templateContext))); RenderResultModel renderResult = new RenderResultModel { Result = result, BuilderConfig = builder, OutputPaths = outputFilePaths }; return(renderResult); } else { _logger.LogError("Error finding template", "Could not find the following template: " + builder.Input.Template); return(null); } }
object UnmarshalResult(TextReader reader, Type expectedType = null) { var result = JSON.Parse <MarshaledValue> (reader); switch (result.ScriptType) { case ScriptType.Exception: throw new ScriptException((IDictionary <string, object>)result.Value); case ScriptType.MarshalByVal: return(JSON.Convert(result.Value, expectedType)); case ScriptType.MarshalByRef: return(new ScriptObject(host, result.RefScript, result.DisposeScript)); } throw new Exception(string.Format("Invalid ScriptType: {0}", result.ScriptType)); }
public void SyncToBackDB <T1, T2>(Action <T2, T2> callback) where T1 : Item, new() where T2 : class, new() { //{ // var qName = $"MODIFY:{typeof(T1).FullName}".Replace(".", ":"); // var listName = $"LIST:{typeof(T1).FullName}".Replace(".", ":"); // var resCount = REDIS.Current.GetQueueLength(qName); // var count = Convert.ToInt32(resCount.DATA); // while (resCount.SUCCESS && 0 < count) // { // var popRes = REDIS.Current.Dequeue<Item>(qName); // if (popRes.SUCCESS && null != popRes.DATA && popRes.DATA is Item) // { // var qItem = JSON.Convert<Item, T1>(popRes.DATA as Item); // var val = RedisDB.Current.QueryItem<T1>(qItem); // var newVal = JSON.ToObject<T2>(val.DATA.ToString()); // BackDB.Current.Save<T2>(newVal, callback, new object[] { qItem.ItemID }); // } // resCount = REDIS.Current.GetQueueLength(qName); // count = Convert.ToInt32(resCount.DATA); // } //} { var qName = $"DELETE:{typeof(T1).FullName}".Replace(".", ":"); var listName = $"LIST:{typeof(T1).FullName}".Replace(".", ":"); var resCount = REDIS.Current.GetQueueLength(qName); var count = Convert.ToInt32(resCount.DATA); while (resCount.SUCCESS && 0 < count) { var popRes = REDIS.Current.Dequeue <Item>(qName); if (popRes.SUCCESS && null != popRes.DATA && popRes.DATA is Item) { var qItem = JSON.Convert <Item, T1>(popRes.DATA as Item); var val = RedisDB.Current.QueryItem <T1>(qItem); var newVal = JSON.ToObject <T2>(val.DATA.ToString()); BackDB.Current.Remove <T2>(new object[] { qItem.ItemID }); } resCount = REDIS.Current.GetQueueLength(qName); count = Convert.ToInt32(resCount.DATA); } } }