Skip to content

Instantly share code, notes, and snippets.

View enkelmedia's full-sized avatar

Markus Johansson enkelmedia

View GitHub Profile
// Use
var parser = new HttpRequestToTextParser();
var res = parser.Parse(Request);
System.IO.File.AppendAllLines(@"c:\\temp\\log_request.txt",res);
// Implementation
public class HttpRequestToTextParser
{
public List<string> Parse(HttpRequestBase request)
{
// ******* Confirmation-dialog **********
var overlay = {
"view": "default",
"title": 'Headline',
"content": 'This is some important text that you need to confirm',
"disableBackdropClick": true,
"disableEscKey": true,
"submitButtonLabel": 'Confirm',
"closeButtonLabel": 'Cancel',
@enkelmedia
enkelmedia / update examine fields.cs
Last active January 20, 2021 17:06
Update field in Lucene / Examine index (Umbraco 8 v8 -specific)
var index = (LuceneIndex)ExamineManager.Instance.Indexes.Where(f => f.Name == "ExternalIndex").FirstOrDefault();
// Get the IndexWriter
var writer = index.GetIndexWriter();
var searcher = (BaseLuceneSearcher)index.GetSearcher();
// perform search to get the doc from the index based on node id
Term term = new Term("id", "1082"); // Term to get node by id
var q = new TermQuery(term);
@enkelmedia
enkelmedia / gist:5e7c242d08d8af6b7b3149af2e952ab2
Last active September 17, 2019 14:15
ModelsBuilderMock.cs
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
using Moq;
using Umbraco.Core.Models;
using Umbraco.ModelsBuilder;
namespace Obviuse.Tests
/// <summary>
/// Just used to record an incomming request to see any headers passed from CloudFront to the Win2012-server.
/// Routes to: /umbraco/surface/contactmesurface/recordrequest
/// </summary>
/// <returns></returns>
public ActionResult RecordRequest()
{
var path = Server.MapPath("~/app_data/logs/") + DateTime.Now.ToString("yyyyMMdd-hhmmss_") + ".txt";
@enkelmedia
enkelmedia / Umbraco Helper Extentions
Created December 18, 2018 09:42
Umbraco Helper Extentions for getting nodes by property value, attribute value and by document type alias
public static class UmbracoHelperExtensions
{
public static IEnumerable<IPublishedContent> TypedContentByPropertyValue(this UmbracoHelper helper, string propertyName, string value, string documentTypeAlias = "")
{
if (string.IsNullOrEmpty(documentTypeAlias))
documentTypeAlias = "*";
// format: var all = Umbraco.TypedContentAtXPath("//jobListing[englishUrlName = 'test']");
return helper.TypedContentAtXPath($"//{documentTypeAlias}[{propertyName} = '{value}']");
}
@enkelmedia
enkelmedia / Umbraco - Empty Recycle Bin.sql
Last active April 11, 2023 12:13
Umbraco - Empty Recycle Bin.sql
/*
2018-12-06
This SQL will remove all content and media that's in the recycle bin
Tested on: Umbraco 7.12.3
NOTE:
You might want to empty the recycle bin in the media-section manually since the files on disk will not be deleted when executing this SQL-query.
PRO-TIP: Execute each line one by one by selecting the row and hit CTRL+E
*/
@enkelmedia
enkelmedia / gist:5d6ee184cc3d404b524b51730537a9ff
Last active April 28, 2021 08:38
Multi Node Tree Picker-convert function.sql
CREATE FUNCTION [dbo].[mntpConvert]
(
-- Add the parameters for the function here
@mntpXml ntext
)
RETURNS nvarchar(MAX)
AS
BEGIN
-- Declare the return variable here
DECLARE @Result nvarchar(MAX)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Web.Routing;
@enkelmedia
enkelmedia / Umbraco - Delete Older Versions.sql
Last active May 16, 2024 19:54
Remove older content versions from the Umbraco database (tested on v7.9.2)
-- set how many versions to keep using @numberOfVersionToKeep, this can be set to anything from 0 and above. 0 will clean all versions except the current of course.
-- actually delete stuff by modifying last line to 'commit tran'
begin tran
go
DECLARE @numberOfVersionToKeep int = 20
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP Table #tmp
create table #tmp (versionid uniqueidentifier)