Skip to content

Instantly share code, notes, and snippets.

View asapostolov's full-sized avatar

Apostol Apostolov asapostolov

  • bilidpm.com/en
  • Plovdiv, Bulgaria
View GitHub Profile
@asapostolov
asapostolov / Raven-DB-Document-Manager.cs
Created March 3, 2012 16:05
Initalizes and manages RavenDB Document Store and Session. Initalize() method must be called in Application_Start event to initialize the store and optionally - SessionSaveAndClose() on Application_PostRequestHandlerExecute to save the changes.
public class DocumentManager
{
public static readonly string SessionKey = "current.session";
public static IDocumentStore CurrentDocumentStore { get; private set; }
public static IDocumentSession CurrentSession
{
get
# Auto detect text files and perform LF normalization
* text=auto
# These files are text and should be normalized (convert crlf => lf)
*.cs text diff=csharp
*.java text diff=java
*.html text diff=html
*.js text
*.cshtml text
@asapostolov
asapostolov / Raven Conflicts
Created January 30, 2014 10:14
RavenDB index for getting all the conflicted documents from a database.
from doc in docs
where doc["@metadata"]["Raven-Replication-Conflict"]
select new { Id = doc.__document_id }
@asapostolov
asapostolov / RavenConflictsConsole
Created January 30, 2014 10:30
Console application for fixing RavenDB conflicts through
namespace ConsoleApplication {
class Program {
static void Main( string[] args ) {
var store = new DocumentStore() {
Url = "<your-url-here>",
Credentials = new System.Net.NetworkCredential() {
UserName = "<your-username>",
Password = "<your-password>",
@asapostolov
asapostolov / BaseController.cs
Last active August 29, 2015 14:05
RavenDB Session Management
public const string RavenSessionKey = "raven.session";
public IDocumentSession RavenSession { get; set; }
protected override void Initialize( System.Web.Routing.RequestContext requestContext ) {
base.Initialize( requestContext );
RavenSession = (IDocumentSession) HttpContext.Items[ RavenSessionKey ];
}
@asapostolov
asapostolov / config path change
Last active August 29, 2015 14:12
MiniBlog web.config as virtual application
<add key="blog:path" value="myblog"/>
@asapostolov
asapostolov / file.html
Created September 24, 2015 22:03
City of Plovdiv's Center in Polygon
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polygon</title>
<style>
html, body {
height: 100%;
margin: 0;
@asapostolov
asapostolov / RavenDbRqlIssue.cs
Created April 9, 2020 13:27
Failing test for RavenDb 4 RQL and Lucene queries with NOT
using Raven.Client.Documents;
using Raven.TestDriver;
using Xunit;
using System.Linq;
using Raven.Client.Documents.Indexes;
using Raven.Client.Documents.Session;
using System;
namespace RavenDBTestCase {
public class RavenDbRqlIssue : RavenTestDriver {
@asapostolov
asapostolov / RavenDbRqlIssue.cs
Last active April 9, 2020 13:34
Failing test for RavenDb 4 RQL and Lucene queries with NOT
using Raven.Client.Documents;
using Raven.TestDriver;
using Xunit;
using System.Linq;
using Raven.Client.Documents.Indexes;
using Raven.Client.Documents.Session;
using System;
namespace RavenDBTestCase {
public class RavenDbRqlIssue : RavenTestDriver {
Failed to execute mapping function on contracts-8314. Exception: System.InvalidOperationException: The output of the mapping function does not contain all fields that the index is supposed to group by.
Output: { AccountId &#x3D; accounts-994, ContractId &#x3D; contracts-8314, DateCreated &#x3D; 04&#x2F;02&#x2F;2019 15:03:47, DateLastModified &#x3D; 02&#x2F;24&#x2F;2020 09:13:05 }
Group by fields: AccountId,ContractId
Compiled index def:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;