private static void SaveODataItem(ODataItem currentDataItem, Dictionary<string, List<string>> dictExistingFiles, Dictionary<string, uint> dictDirectoryEntries, string lang, Action<string> LogError)
 {
     if (dictExistingFiles.ContainsKey(currentDataItem.Subject))
     //File.Exists(Properties.Settings.Default.WorkDir + Path.DirectorySeparatorChar + Properties.Settings.Default.DataDir + Path.DirectorySeparatorChar + RemoveEvilCharactersForFile(currentDataItem.Subject)))
     {
         try
         {
             StreamWriter fs = File.AppendText(dictExistingFiles[currentDataItem.Subject][0]);
             //Properties.Settings.Default.WorkDir + Path.DirectorySeparatorChar + Properties.Settings.Default.DataDir + Path.DirectorySeparatorChar + RemoveEvilCharactersForFile(currentDataItem.Subject));
             fs.WriteLine("Name_" + lang + "=" + currentDataItem.Subject);
             foreach (String key in currentDataItem.updateProperties.Keys)
             {
                 foreach (String listItem in currentDataItem.updateProperties[key])
                 {
                     // fs.WriteLine(GqlStringExtension.RemoveEvilCharacters(key) + "_" +lang + "=" + listItem);
                     fs.WriteLine(key + "_" + lang + "=" + listItem);
                 }
             }
             fs.Flush();
             fs.Close();
         }
         catch (Exception a)
         {
         }
     }
     else
         LogError("missing file: " + RemoveEvilCharactersForFile(currentDataItem.Subject));
 }
        private static void EvaluateMappingbasedProperties(String filename, String lang, Dictionary<string, List<string>> dictExistingNodes, Dictionary<string, uint> dictDirectoryEntries, Ontology thisOntology, Action<string> LogMessage, Action<string> LogError)
        {
            LogMessage("Begin EvaluateMappingbasedProperties(" + filename + ", " + lang + ")");
            try
            {
                using (StreamReader srNodes = new StreamReader(filename))
                {
                    #region if input stream is empty --> do error handling
                    if (srNodes == null)
                    {
                        LogError("Error reading Nodes file: '" + filename + "'");
                        return;
                    }
                    #endregion

                    #region init local vars
                    ODataItem currentDataItem = null;
                    String strCurrentTriple;
                    Triple currentTriple;
                    uint lineCount = 0;
                    uint updateCount = 0;
                    #endregion

                    #region for each triple (line)
                    while ((strCurrentTriple = srNodes.ReadLine()) != null)
                    {

                        #region some debug info
                        /*
                        if (lineCount % 1000 == 0)
                        {
                            Console.Write(".");
                        }*/
                        if (lineCount % 100000 == 0)
                        {
                            LogMessage("EvaluateMappingbasedProperties('" + lang + "'): lineCount=" + lineCount + " updateCount=" + updateCount);
                            GC.Collect();
                            GC.Collect();
                        }
                        lineCount++;
                        #endregion

                        currentTriple = NTripleParser.Split(strCurrentTriple, LogError);

                        #region some sample data for help
                        /* currentTriple.Subject               currentTriple.Predicate                           currentTriple.TripleObject
                    <http://dbpedia.org/resource/Alabama> <http://xmlns.com/foaf/0.1/name> "State of Alabama"@en .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/demonym> "Alabamian or Alabaman"@en .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/capital> <http://dbpedia.org/resource/Montgomery%2C_Alabama> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/largestCity> <http://dbpedia.org/resource/Birmingham%2C_Alabama> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaTotal> "1.35765E11"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaLand> "1.31426E11"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaWater> "4.338E9"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/maximumElevation> "734.0"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/minimumElevation> "0.0"^^<http://www.w3.org/2001/XMLSchema#double> .                        
                        */
                        #endregion

                        #region clarify __coord> etc. handling
                        if (currentTriple.Subject.Contains("__"))
                        {
                            // TODO find better handling 
                            continue;
                        }
                        #endregion

                        if (currentDataItem == null)
                        {
                            #region create new ODataItem
                            if (CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes))
                            // if (!dictInstances.ContainsKey(currentTriple.Subject))
                            {
                                // Console.WriteLine("What's wrong here?");
                                // ignore uninserted data
                                currentDataItem = new ODataItem(new OClass("0815"));
                            }
                            else
                            {
                                // string instanceType = dictInstances[currentTriple.Subject];
                                string instanceType = GetVertexType(currentTriple.Subject, dictExistingNodes, LogError); // qr.FirstOrDefault().GetProperty<long>("TypeID"));
                                OClass instanceOClass = thisOntology.GetOClass(instanceType);
                                currentDataItem = instanceOClass.CreateODataItem();
                                currentDataItem.bToInsert = true;
                            }
                            currentDataItem.Subject = currentTriple.Subject;
                            #endregion
                        }
                        else
                        {
                            #region multiple rows can be aggregated to a single update statement (as long the currentSubject didn't change)
                            if (!currentTriple.Subject.Equals(currentDataItem.Subject))
                            {
                                #region save previous Instance - EXECUTE QUERY
                                if (CheckExistenceOfVertex(currentDataItem.Subject, dictExistingNodes)
                                    && !currentDataItem.IsEmpty())
                                {
                                    SaveODataItem(currentDataItem, dictExistingNodes, dictDirectoryEntries, lang, LogError);
                                    updateCount++;
                                }
                                #endregion

                                #region re-init all vars for next UPDATE ...  #region create new ODataItem
                                if (!CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes))
                                // !dictInstances.ContainsKey(currentTriple.Subject))
                                {
                                    // Console.WriteLine("What's wrong here?");
                                    // ignore uninserted data
                                    currentDataItem = new ODataItem(new OClass("0815"));
                                }
                                else
                                {

                                    string instanceType = GetVertexType(currentTriple.Subject, dictExistingNodes, LogError); //dictInstances[currentTriple.Subject];
                                    OClass instanceOClass = thisOntology.GetOClass(instanceType);
                                    currentDataItem = instanceOClass.CreateODataItem();
                                    currentDataItem.bToInsert = true;
                                }
                                currentDataItem.Subject = currentTriple.Subject;
                                #endregion
                            }
                            #endregion
                        }

                        #region temporary workaround - don't insert, when data had not been created before
                        if (!CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes)) // !dictInstances.ContainsKey(currentTriple.Subject))
                        {
                            continue;
                        }
                        #endregion

                        #region add current line to dictionary (or previously gql-string)
                        currentDataItem.Add(currentTriple.Predicate, currentTriple.TripleObject);

                        #endregion
                    }

                    #endregion

                    #region save last line
                    if (!currentDataItem.IsEmpty())
                    {
                        SaveODataItem(currentDataItem, dictExistingNodes, dictDirectoryEntries, lang, LogError);
                        updateCount++;
                    }
                    #endregion
                }  // using (StreamReader srNodes = new StreamReader(filename))
            }  // try
            catch (Exception e)
            {
                LogError("Error evaluating " + filename);
                LogError(e.Message);
                LogError(e.StackTrace);
            }
            LogMessage("End EvaluateMappingbasedProperties(" + filename + ", " + lang + ")");
        }