/// <summary> /// Updates the specified field values /// </summary> /// <param name="repository">The repository.</param> /// <param name="schema">The schema.</param> /// <param name="uuid">The UUID.</param> /// <param name="fieldValues">The field values.</param> /// <param name="userName">Name of the user.</param> public virtual void UpdateSpecifiedFields(Repository repository, Schema schema, string uuid, NameValueCollection fieldValues, string userName = "", bool enableVersion = true) { var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (content != null) { foreach (var name in fieldValues.AllKeys) { content[name] = Binder.ConvertToColumnType(schema, name, fieldValues[name]); } if (!string.IsNullOrEmpty(userName)) { content.UserId = userName; } content.___EnableVersion___ = enableVersion; content.UtcLastModificationDate = DateTime.UtcNow; EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, content); TextContentProvider.Update(content, content); EventBus.Content.ContentEvent.Fire(ContentAction.Update, content); } }
public virtual void Update(TextFolder textFolder, string uuid, IEnumerable <string> fieldNames, IEnumerable <object> fieldValues, string userName = "", bool enableVersion = true) { var content = textFolder.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (content.IntegrateId != null) { var names = fieldNames.ToArray(); var values = fieldValues.ToArray(); for (int i = 0; i < names.Length; i++) { content[names[i]] = values[i]; } if (!string.IsNullOrEmpty(userName)) { content.UserId = userName; } content.___EnableVersion___ = enableVersion; content.UtcLastModificationDate = DateTime.UtcNow; EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, content); TextContentProvider.Update(content, content); EventBus.Content.ContentEvent.Fire(ContentAction.Update, content); } }
public virtual void RevertTo(Repository repository, string folder, string schemaName, string uuid, int version, string user) { var textContent = new TextFolder(repository, folder).CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (textContent != null) { var versionInfo = Versioning.VersionManager.GetVersion(textContent, version); var @new = new TextContent(versionInfo.TextContent); @new.Repository = repository.Name; @new.UserId = user; @new.UtcLastModificationDate = DateTime.Now; TextContentProvider.Update(@new, textContent); ClearCategories(repository, textContent); if (versionInfo.Categories != null) { AddCategories(repository, textContent, versionInfo.Categories .Where(it => it.Contents != null) .SelectMany(it => it.Contents.Select(c => new TextContent(repository.Name, "", it.FolderName) { UUID = c.UUID })) .ToArray()); } if (string.IsNullOrEmpty(textContent.OriginalUUID)) { EventBus.Content.ContentEvent.Fire(ContentAction.Update, @new); } } }
private SourceUnitTree MakeParseTree(TextContentProvider /*!*/ content, ErrorSink /*!*/ errorSink) { var source = new SourceUnit(HostingHelpers.GetLanguageContext(_engine), content, null, SourceCodeKind.File); var options = new RubyCompilerOptions(); var parser = new Parser(); try { int attempts = 10; while (true) { try { return(parser.Parse(source, options, errorSink)); } catch (IOException) { // file being copied, try again... if (attempts > 0) { Thread.Sleep(100); attempts--; } else { throw; } } } } catch (Exception e) { Debug.Assert(false, String.Format("Failure in IronRuby parser: {0}", e.ToString())); return(null); } }
public virtual ContentBase Add(Repository repository, TextFolder folder, string parentFolder, string parentUUID, NameValueCollection values , HttpFileCollectionBase files, IEnumerable <TextContent> categories, string userid = "") { var textFolder = (TextFolder)folder.AsActual(); var schema = new Schema(repository, textFolder.SchemaName); var textContent = new TextContent(repository.Name, schema.Name, textFolder.FullName); textContent = Binder.Bind(schema, textContent, values); textContent.ParentFolder = parentFolder; textContent.ParentUUID = parentUUID; textContent.UserId = userid; textContent.UtcLastModificationDate = textContent.UtcCreationDate = DateTime.Now; textContent.ContentFiles = GetPostFiles(files); EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); if (categories != null) { AddCategories(repository, textContent, categories.ToArray()); } EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); }
public SourceUnit CreateSourceUnit(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, "contentProvider"); ContractUtils.Requires(kind.IsValid(), "kind"); ContractUtils.Requires(CanCreateSourceCode); return(new SourceUnit(this, contentProvider, path, kind)); }
public virtual void AddCategories(TEntity entity, params TextContent[] categories) { TextContentProvider.AddCategories(entity, categories.Select(it => new Category() { CategoryFolder = it.FolderName, CategoryUUID = it.UUID, ContentUUID = entity.UUID }).ToArray()); }
public virtual void Delete(Repository repository, Schema schema, string uuid) { var textContent = schema.CreateQuery().WhereEquals("UUID", uuid).First(); EventBus.Content.ContentEvent.Fire(ContentAction.PreDelete, textContent); TextContentProvider.Delete(textContent); EventBus.Content.ContentEvent.Fire(ContentAction.Delete, textContent); }
public SourceUnit CreateSourceUnit(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, "contentProvider"); ContractUtils.Requires(path == null || path.Length > 0, "path", Strings.EmptyStringIsInvalidPath); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); ContractUtils.Requires(CanCreateSourceCode); return(new SourceUnit(this, contentProvider, path, kind)); }
public virtual TEntity Update(TEntity entity, TextFolder folder) { entity.Repository = Repository.Name; entity.FolderName = folder.FullName; entity.SchemaName = folder.SchemaName; ContentEvent.Fire(ContentAction.PreUpdate, entity); TextContentProvider.Update(entity, entity); ContentEvent.Fire(ContentAction.Update, entity); return(entity); }
/// <summary> /// This method returns a ScriptSource with the content provider supplied with the current engine as the language binding. /// /// This helper lets you own the content provider so that you can implement a stream over internal host data structures, such as an editor's text representation. /// </summary> public ScriptSource CreateScriptSource(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, "contentProvider"); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); if (!_language.CanCreateSourceCode) { throw new NotSupportedException("Invariant engine cannot create scripts"); } return(new ScriptSource(this, _language.CreateSourceUnit(contentProvider, path, kind))); }
/// <summary> /// This method returns a ScriptSource with the content provider supplied with the current engine as the language binding. /// /// This helper lets you own the content provider so that you can implement a stream over internal host data structures, such as an editor's text representation. /// </summary> public ScriptSource CreateScriptSource(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, nameof(contentProvider)); ContractUtils.Requires(kind.IsValid(), nameof(kind)); if (!LanguageContext.CanCreateSourceCode) { throw new NotSupportedException("Invariant engine cannot create scripts"); } return(new ScriptSource(this, LanguageContext.CreateSourceUnit(contentProvider, path, kind))); }
public virtual void RemoveCategories(Repository repository, TextContent textContent, params TextContent[] categories) { var relations = categories.Select(it => new Category() { ContentUUID = textContent.UUID, CategoryFolder = it.FolderName, CategoryUUID = it.UUID }); TextContentProvider.DeleteCategories(textContent, relations.ToArray()); }
public void Parse(TextContentProvider /*!*/ content) { var errorSink = new CollectingErrorSink(); SourceUnitTree ast = MakeParseTree(content, errorSink); ISnapshotTextContentProvider snapshotContent = content as ISnapshotTextContentProvider; if (snapshotContent != null) { // queue analysis of the parsed tree at High Pri so the active buffer is quickly re-analyzed var snapshot = snapshotContent.Snapshot; var analysis = AnalysisItem.GetAnalysis(snapshot.TextBuffer); // only update the AST when we're error free, this way we don't remove // a useful analysis with an incomplete and useless analysis. if (errorSink.Errors.Count == 0) { analysis.UpdateTree(ast, new SnapshotCookie(snapshot)); _analysisQueue.Enqueue(analysis, AnalysisPriority.High); } SimpleTagger <ErrorTag> squiggles = _squiggleProvider.GetErrorTagger(snapshot.TextBuffer); squiggles.RemoveTagSpans(x => true); // update squiggles for the live buffer foreach (ErrorResult warning in errorSink.Warnings) { var span = warning.Span; var tspan = CreateSpan(snapshot, span); squiggles.CreateTagSpan(tspan, new ErrorTag("Warning", warning.Message)); } foreach (ErrorResult error in errorSink.Errors) { var span = error.Span; var tspan = CreateSpan(snapshot, span); squiggles.CreateTagSpan(tspan, new ErrorTag("Error", error.Message)); } } else { FileTextContentProvider fileContent = content as FileTextContentProvider; AnalysisItem analysis; if (fileContent != null && _projectFiles.TryGetValue(fileContent.Path, out analysis)) { analysis.UpdateTree(ast, new FileCookie(fileContent.Path)); _analysisQueue.Enqueue(analysis, AnalysisPriority.Normal); } } }
public virtual TEntity AddSubContent(TEntity entity, TextFolder folder, string parentFolderName, string parentUUID) { entity.Repository = Repository.Name; entity.FolderName = folder.FullName; entity.SchemaName = folder.SchemaName; entity.ParentFolder = parentFolderName; entity.ParentUUID = parentUUID; ContentEvent.Fire(ContentAction.PreAdd, entity); TextContentProvider.Add(entity); ContentEvent.Fire(ContentAction.Add, entity); return(entity); }
public virtual ContentBase Update(Repository repository, TextFolder folder, string uuid, NameValueCollection values, HttpFileCollectionBase files, DateTime modificationDate, IEnumerable <TextContent> addedCateogries, IEnumerable <TextContent> removedCategories, string userid = "", bool enableVersion = true) { var textFolder = (TextFolder)folder.AsActual(); var schema = new Schema(repository, textFolder.SchemaName); var textContent = textFolder.CreateQuery().WhereEquals("UUID", uuid).First(); var old = new TextContent(textContent); textContent = Binder.Update(schema, textContent, values); textContent.Repository = repository.Name; textContent.UserId = userid; textContent.UtcLastModificationDate = modificationDate; var parentFolder = values["ParentFolder"]; if (!string.IsNullOrEmpty(parentFolder)) { textContent.ParentFolder = parentFolder; } var parentUUID = values["ParentUUID"]; if (!string.IsNullOrEmpty(parentUUID)) { textContent.ParentUUID = parentUUID; } if (files != null) { textContent.ContentFiles = GetPostFiles(files); } textContent.___EnableVersion___ = enableVersion; //SaveFiles(textContent, schema, files); EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, textContent); TextContentProvider.Update(textContent, old); if (addedCateogries != null) { AddCategories(repository, textContent, addedCateogries.ToArray()); } if (removedCategories != null) { RemoveCategories(repository, textContent, removedCategories.ToArray()); } EventBus.Content.ContentEvent.Fire(ContentAction.Update, textContent); return(textContent); }
public virtual void Delete(Repository repository, Folder folder, string uuid) { var textFolder = (TextFolder)folder; textFolder = textFolder.AsActual(); var textContent = textFolder.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (textContent != null) { EventBus.Content.ContentEvent.Fire(ContentAction.PreDelete, textContent); TextContentProvider.Delete(textContent); EventBus.Content.ContentEvent.Fire(ContentAction.Delete, textContent); } }
public void Parse(TextContentProvider content) { ISnapshotTextContentProvider snapshotContent = content as ISnapshotTextContentProvider; if (snapshotContent != null) { ParseSnapshot(snapshotContent); } else { FileTextContentProvider fileContent = content as FileTextContentProvider; if (fileContent != null) { ParseFile(fileContent); } } }
public void TestClearCategory() { var contentProvider = new TextContentProvider(); dynamic category1 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.Name); category1.UserKey = "TestClearCategory-category1"; category1.Title = "TestClearCategory-category1"; contentProvider.Add(category1); dynamic content1 = new TextContent(repository.Name, newsSchema.Name, newsFolder.Name); content1.UserKey = "TestClearCategory-news1"; content1.Title = "TestClearCategory-news1"; contentProvider.Add(content1); contentProvider.AddCategories(content1, new Category() { ContentUUID = content1.uuid, CategoryFolder = categoryFolder.Name, CategoryUUID = category1.UUID }); contentProvider.ClearCategories(content1); }
static void Main(string[] args) { #region " Configuration settings " var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile($"appsettings.json"); var configuration = builder.Build(); var parameters = GetExecutionParams(args); if (parameters == null) { return; } #endregion #region " Verbose section" Console.WriteLine("Stone Test - WebCrowler says: \"-Hello world\"!"); Console.WriteLine("Let's Go!!!"); #endregion #region " Initialyzing essentials components " var chromeDriverPath = configuration.GetSection("Selenium:DriverChromeFilePath").Value.ToString(); ITextContentProvider textProvider = new TextContentProvider(parameters.HeadLessModeActivated); { }; ITextContentAnalyzer textAnalyzer = new TextContentAnalyze(parameters.HeadLessModeActivated) { }; IFileManager fileManager = new FileManagerIO(parameters.DestinyFilePath) { }; #endregion #region " Execution section " Console.WriteLine($"Starting execution with {parameters.BufferLimit}MB of buffer limit and {parameters.FileSizeLimit}MB of file size limit. The file is at {parameters.DestinyFilePath}"); (new CrawlerExecution(textProvider, textAnalyzer, fileManager, parameters.BufferLimit, parameters.FileSizeLimit)) .StartExecution(); #endregion Console.ReadKey(); }
private void ParsePythonCode(TextContentProvider content, out PythonAst ast, out CollectingErrorSink errorSink) { ast = null; errorSink = new CollectingErrorSink(); // parse the tree var source = _engine.CreateScriptSource(content, "", SourceCodeKind.File); var compOptions = (PythonCompilerOptions)HostingHelpers.GetLanguageContext(_engine).GetCompilerOptions(); var context = new CompilerContext(HostingHelpers.GetSourceUnit(source), compOptions, errorSink); //compOptions.Verbatim = true; using (var parser = MakeParser(context)) { if (parser != null) { try { ast = parser.ParseFile(false); } catch (Exception e) { Debug.Assert(false, String.Format("Failure in IronPython parser: {0}", e.ToString())); } } } }
public virtual TextContent Update(Repository repository, Schema schema, string uuid, NameValueCollection values, HttpFileCollectionBase files, string userid = "") { var textContent = schema.CreateQuery().WhereEquals("UUID", uuid).First(); var old = new TextContent(textContent); textContent = Binder.Update(schema, textContent, values); textContent.UtcLastModificationDate = DateTime.Now.ToUniversalTime(); textContent.UserId = userid; if (files != null) { textContent.ContentFiles = GetPostFiles(files); } EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, textContent); TextContentProvider.Update(textContent, old); EventBus.Content.ContentEvent.Fire(ContentAction.Update, textContent); return(textContent); }
public virtual TextContent Add(Repository repository, Schema schema, string parentUUID, NameValueCollection values, HttpFileCollectionBase files, string userid = "") { var textContent = new TextContent(repository.Name, schema.Name, null); textContent.ParentUUID = parentUUID; textContent = Binder.Bind(schema, textContent, values); textContent.UtcLastModificationDate = textContent.UtcCreationDate = DateTime.Now.ToUniversalTime(); textContent.UserId = userid; if (files != null) { textContent.ContentFiles = GetPostFiles(files); } EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); }
public virtual TextContent Copy(Schema schema, string uuid) { var repository = schema.Repository; var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (content != null) { var textContent = new TextContent(content); textContent.Id = ""; textContent.UUID = ""; textContent.UtcCreationDate = DateTime.Now; textContent.UtcLastModificationDate = DateTime.Now; textContent.Published = null; textContent.Sequence = 0; textContent.UserKey = null; var titleField = schema.AsActual().GetSummarizeColumn(); if (titleField != null) { textContent[titleField.Name] = (content[titleField.Name] ?? "") + " - Copy".Localize(); } EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); var categories = this.QueryCategories(repository, content.FolderName, uuid); this.AddCategories(repository, textContent, categories.SelectMany(it => it.Contents).ToArray()); EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); } return(null); }
public virtual void ClearCategories(Repository repository, TextContent textContent) { TextContentProvider.ClearCategories(textContent); }
public void TestClearCategory() { var contentProvider = new TextContentProvider(); dynamic category1 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.Name); category1.UserKey = "TestClearCategory-category1"; category1.Title = "TestClearCategory-category1"; contentProvider.Add(category1); dynamic content1 = new TextContent(repository.Name, newsSchema.Name, newsFolder.Name); content1.UserKey = "TestClearCategory-news1"; content1.Title = "TestClearCategory-news1"; contentProvider.Add(content1); contentProvider.AddCategories(content1, new Category() { ContentUUID = content1.uuid, CategoryFolder = categoryFolder.Name, CategoryUUID = category1.UUID }); contentProvider.ClearCategories(content1); }
public virtual ContentBase Copy(TextContent originalContent, TextFolder textFolder, bool keepStatus, bool keepUUID, NameValueCollection values) { textFolder = textFolder.AsActual(); var repository = textFolder.Repository; var schema = new Schema(repository, textFolder.SchemaName); var copyedContent = new TextContent(originalContent); copyedContent.Id = ""; copyedContent.UUID = ""; if (keepUUID) { copyedContent.UUID = originalContent.UUID; } copyedContent.UtcCreationDate = DateTime.Now.ToUniversalTime(); copyedContent.Repository = textFolder.Repository.Name; copyedContent.FolderName = textFolder.FullName; copyedContent.SchemaName = textFolder.SchemaName; copyedContent.OriginalUUID = originalContent.UUID; copyedContent.OriginalRepository = originalContent.Repository; copyedContent.OriginalFolder = originalContent.FolderName; copyedContent.IsLocalized = false; copyedContent.Sequence = 0; copyedContent.UserId = originalContent.UserId; var versions = Kooboo.CMS.Content.Versioning.VersionManager.AllVersionInfos(originalContent); if (versions.Count() > 0) { copyedContent.OriginalLastestVisitedVersionId = versions.Max(it => it.Version); } if (values != null) { originalContent = Binder.Bind(schema, copyedContent, values); } if (!keepStatus) { copyedContent.Published = false; } //如果没有Content event,那么在发送设置的“转发”功能就会失效。 EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, copyedContent); TextContentProvider.Add(copyedContent); if (textFolder.Categories != null && textFolder.Categories.Count > 0) { var originalRepository = originalContent.GetRepository(); var originalFolder = originalContent.GetFolder().AsActual(); var originalCategories = QueryCategories(originalRepository, originalFolder.FullName, originalContent.UUID); List <TextContent> categories = new List <TextContent>(); foreach (var category in originalCategories) { foreach (var originalCategoryContent in category.Contents) { foreach (var categoryFolder in textFolder.Categories) { var categoryContent = (new TextFolder(textFolder.Repository, categoryFolder.FolderName)).CreateQuery() .WhereEquals("UUID", originalCategoryContent.UUID).FirstOrDefault(); if (categoryContent != null) { categories.Add(categoryContent); break; } } } } AddCategories(repository, copyedContent, categories.ToArray()); } EventBus.Content.ContentEvent.Fire(ContentAction.Add, copyedContent); return(copyedContent); }