public void Delete(object id) { WebsiteFile websiteFile = Find(id); websiteFile.IsDeleted = true; InsertOrUpdate(websiteFile); }
private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { FileBasedFunctionProvider <UserControlBasedFunction> provider; FileBasedFunction <UserControlBasedFunction> function; GetProviderAndFunction((FileBasedFunctionEntityToken)this.EntityToken, out provider, out function); string title = Path.GetFileName(function.VirtualPath); this.Bindings.Add("Title", title); string[] files = GetFiles(function); // Binding all the files for (int i = 0; i < files.Length; i++) { var websiteFile = new WebsiteFile(files[i]); string bindingPrefix = GetBindingPrefix(i); this.Bindings.Add(bindingPrefix + "Content", websiteFile.ReadAllText()); this.Bindings.Add(bindingPrefix + "Name", websiteFile.FileName); this.Bindings.Add(bindingPrefix + "MimeType", websiteFile.MimeType); } }
public HttpResponseMessage Post() { Stream reqStream = Request.Content.ReadAsStreamAsync().Result; MemoryStream tempStream = new MemoryStream(); reqStream.CopyTo(tempStream); tempStream.Seek(0, SeekOrigin.End); StreamWriter writer = new StreamWriter(tempStream); writer.WriteLine(); writer.Flush(); tempStream.Position = 0; StreamContent streamContent = new StreamContent(tempStream); foreach (var header in Request.Content.Headers) { streamContent.Headers.Add(header.Key, header.Value); } var result = new HttpResponseMessage(HttpStatusCode.OK); if (Request.Content.IsMimeMultipartContent()) { var task = streamContent.ReadAsMultipartAsync <MultipartMemoryStreamProvider>(new MultipartMemoryStreamProvider()); task.Wait(); MultipartMemoryStreamProvider provider = task.Result; using (var _repo = new WebsiteFileRepository(UnitOfWork)) { foreach (HttpContent content in provider.Contents) { WebsiteFile newFile = new WebsiteFile(); newFile.Id = Guid.NewGuid(); Stream stream = content.ReadAsStreamAsync().Result; string filePath = HostingEnvironment.MapPath("~/Images/"); string fileName = content.Headers.ContentDisposition.FileName.Replace("\"", ""); string fullPath = Path.Combine(filePath, fileName); using (var fileStream = File.Create(fullPath)) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(fileStream); } //Add To DB newFile.Filename = fileName; _repo.InsertOrUpdate(newFile); } UnitOfWork.Save(); } return(result); } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } }
private IEnumerable <Element> GetSharedCodeElements(SearchToken searchToken) { var result = new List <Element>(); foreach (SharedFile sharedFile in PageTemplateFacade.GetSharedFiles()) { string relativeFilePath = sharedFile.RelativeFilePath; string fullPath = relativeFilePath.StartsWith("~") ? PathUtil.Resolve(relativeFilePath) : relativeFilePath; var websiteFile = new WebsiteFile(fullPath); Element element = new Element(_context.CreateElementHandle(new SharedCodeFileEntityToken(relativeFilePath))) { VisualData = new ElementVisualizedData() { Label = websiteFile.FileName, ToolTip = websiteFile.FileName, HasChildren = false, Icon = FileElementProvider.WebsiteFileIcon(websiteFile.MimeType), OpenedIcon = FileElementProvider.WebsiteFileIcon(websiteFile.MimeType) } }; element.PropertyBag.Add("Uri", PathUtil.GetWebsitePath(websiteFile.FullPath)); element.PropertyBag.Add("ElementType", websiteFile.MimeType); // Adding "Edit" action for text-editable files if (sharedFile.DefaultEditAction && MimeTypeInfo.IsTextFile(websiteFile.MimeType)) { element.AddWorkflowAction( "Composite.Plugins.Elements.ElementProviders.PageTemplateElementProvider.EditSharedCodeFileWorkflow", new[] { PermissionType.Edit }, new ActionVisualizedData { Label = GetResourceString("EditSharedCodeFile.Label"), ToolTip = GetResourceString("EditSharedCodeFile.ToolTip"), Icon = CommonCommandIcons.Edit, Disabled = websiteFile.IsReadOnly, ActionLocation = new ActionLocation { ActionType = ActionType.Edit, IsInFolder = false, IsInToolbar = true, ActionGroup = EditCodeFileActionGroup } }); } var customActions = sharedFile.GetActions(); foreach (var action in customActions) { element.AddAction(action); } result.Add(element); } return(result); }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { string[] files = GetFiles(); var fileContent = new List <string>(); for (int i = 0; i < files.Length; i++) { string bindingPrefix = GetBindingPrefix(i); fileContent.Add(this.GetBinding <string>(bindingPrefix + "Content")); } // Fixing html specific escape sequences in .master file string fixedMaster = PageTemplateHelper.FixHtmlEscapeSequences(fileContent[0]); bool viewNeedsUpdating = fileContent[0] != fixedMaster; fileContent[0] = fixedMaster; EntityToken newEntityToken; if (!CompileAndValidate(files, fileContent, out newEntityToken)) { SetSaveStatus(false); return; } for (int i = 0; i < files.Length; i++) { var websiteFile = new WebsiteFile(files[i]); websiteFile.WriteAllText(fileContent[i]); } PageTemplateProviderRegistry.FlushTemplates(); if (newEntityToken != null) { SetSaveStatus(true, newEntityToken); SerializedEntityToken = EntityTokenSerializer.Serialize(newEntityToken); } else { SetSaveStatus(true); } if (viewNeedsUpdating) { UpdateBinding(GetBindingPrefix(0) + "Content", fixedMaster); RerenderView(); } this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken); }
private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { string filePath = GetFilePath(); WebsiteFile websiteFile = new WebsiteFile(filePath); this.Bindings.Add("FileContent", websiteFile.ReadAllText()); this.Bindings.Add("FileName", websiteFile.FileName); this.Bindings.Add("FileMimeType", websiteFile.MimeType); }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { string filePath = GetFilePath(); WebsiteFile websiteFile = new WebsiteFile(filePath); string content = this.GetBinding <string>("FileContent"); websiteFile.WriteAllText(content); SetSaveStatus(true); }
public void InsertOrUpdate(WebsiteFile websiteFile) { if (Find(websiteFile.Id) == null) { // New Entity _context.Entry(websiteFile).State = EntityState.Added; } else { // Existing User _context.Entry(websiteFile).State = EntityState.Modified; } }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { var functionEntityToken = (FileBasedFunctionEntityToken)this.EntityToken; FileBasedFunctionProvider <UserControlBasedFunction> provider; FileBasedFunction <UserControlBasedFunction> function; GetProviderAndFunction(functionEntityToken, out provider, out function); string[] files = GetFiles(function); var fileContent = new List <string>(); for (int i = 0; i < files.Length; i++) { string bindingPrefix = GetBindingPrefix(i); fileContent.Add(this.GetBinding <string>(bindingPrefix + "Content")); } string fixedMarkup = PageTemplateHelper.FixHtmlEscapeSequences(fileContent[0]); bool viewShouldBeUpdated = fixedMarkup != fileContent[0]; fileContent[0] = fixedMarkup; if (!CompileAndValidate(files, fileContent)) { SetSaveStatus(false); return; } for (int i = 0; i < files.Length; i++) { var websiteFile = new WebsiteFile(files[i]); websiteFile.WriteAllText(fileContent[i]); } provider.ReloadFunctions(); this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken); SetSaveStatus(true); if (viewShouldBeUpdated) { UpdateBinding(GetBindingPrefix(0) + "Content", fileContent[0]); RerenderView(); } }
public void InsertOrUpdateGraph(WebsiteFile websiteFileGraph) { if (websiteFileGraph.Id == default(Guid)) { // New Entity _context.WebsiteFiles.Add(websiteFileGraph); } else { // Existing File websiteFileGraph.State = State.Modified; _context.WebsiteFiles.Add(websiteFileGraph); _context.ApplyStateChanges(); } }
private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { FileBasedFunctionProvider <RazorBasedFunction> provider; FileBasedFunction <RazorBasedFunction> function; GetProviderAndFunction((FileBasedFunctionEntityToken)this.EntityToken, out provider, out function); string title = Path.GetFileName(function.VirtualPath); this.Bindings.Add("Title", title); string file = GetFile(function); var websiteFile = new WebsiteFile(file); this.Bindings.Add("FileContent", websiteFile.ReadAllText()); this.Bindings.Add("FileName", websiteFile.FileName); this.Bindings.Add("FileMimeType", websiteFile.MimeType); }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { string virtualPath = GetFileVirtualPath(); string filePath = PathUtil.Resolve(virtualPath); WebsiteFile websiteFile = new WebsiteFile(filePath); string content = this.GetBinding <string>("FileContent"); string fixedSource = PageTemplateHelper.FixHtmlEscapeSequences(content); EntityToken newEntityToken; bool isValid = ValidateMarkup(virtualPath, fixedSource, out newEntityToken); if (isValid) { websiteFile.WriteAllText(fixedSource); PageTemplateProviderRegistry.FlushTemplates(); this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken); } if (isValid && newEntityToken != null) { SetSaveStatus(true, newEntityToken); SerializedEntityToken = EntityTokenSerializer.Serialize(newEntityToken); } else { SetSaveStatus(isValid); } if (isValid && fixedSource != content) { UpdateBinding("FileContent", fixedSource); RerenderView(); } }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { var functionEntityToken = (FileBasedFunctionEntityToken)this.EntityToken; FileBasedFunctionProvider <RazorBasedFunction> provider; FileBasedFunction <RazorBasedFunction> function; GetProviderAndFunction(functionEntityToken, out provider, out function); string file = GetFile(function); string fileContent = this.GetBinding <string>("FileContent"); string fixedFileContent = PageTemplateHelper.FixHtmlEscapeSequences(fileContent); if (!CompileAndValidate(file, fixedFileContent)) { SetSaveStatus(false); return; } var websiteFile = new WebsiteFile(file); websiteFile.WriteAllText(fixedFileContent); provider.ReloadFunctions(); this.CreateParentTreeRefresher().PostRefreshMesseges(this.EntityToken); SetSaveStatus(true); if (fixedFileContent != fileContent) { UpdateBinding("FileContent", fixedFileContent); RerenderView(); } }
private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { var entityToken = this.EntityToken; string title; if (entityToken is PageTemplateEntityToken) { title = GetPageTemplate().Title; } else { var sharedFileEntityToken = (SharedCodeFileEntityToken)entityToken; title = Path.GetFileName(sharedFileEntityToken.VirtualPath); } this.Bindings.Add("TemplateTitle", title); string[] files = GetFiles(); // Binding all the files for (int i = 0; i < files.Length; i++) { var websiteFile = new WebsiteFile(files[i]); string bindingPrefix = GetBindingPrefix(i); this.Bindings.Add(bindingPrefix + "Content", websiteFile.ReadAllText()); this.Bindings.Add(bindingPrefix + "Name", websiteFile.FileName); // Assigning "text/html" mimetype so CodeMirror will show it correctly // this.Bindings.Add(bindingPrefix + "MimeType", i == 0 ? HtmlMimeType : websiteFile.MimeType); this.Bindings.Add(bindingPrefix + "MimeType", websiteFile.MimeType); } }