Linked rows, single table SQL - c#

I have a table with parts and different phases. FromID=0 is where the material for the parts is entered. part1 and part2 are processed and then assembled to part3.
ID Partname FromID Parts Process
----------------------------------------------------
1 part1 0 10 process1 part1
2 part1 1 0 process2 part1
3 part2 0 10 process1 part2
4 part2 1 0 process2 part2
5 part3 2 0 Assembly part1
6 part3 4 0 Assembly part2
Is there a way to write a query to get a part and all its subparts that can handle nested subparts as well? I'm using MS Access 2010 and C#.
The result should look like this
PartName = part1
ID Partname FromID Parts Work
-------------------------------------------
1 part1 0 10 work1 part1
2 part1 1 0 work2 part1
PartName = part2
ID Partname FromID Parts Work
-------------------------------------------
3 part2 0 10 work1 part2
4 part2 1 0 work2 part2
PartName = part3
ID Partname FromID Parts Work
-------------------------------------------
1 part1 0 10 work1 part1
2 part1 1 0 work2 part1
5 part3 2 0 Assembly part1
3 part2 0 10 work1 part2
4 part2 1 0 work2 part2
6 part3 4 0 Assembly part2

Use modified pre order tree traversal to mark the rows for quick querying. Check out this write up:
http://iamcam.wordpress.com/2006/03/24/storing-hierarchical-data-in-a-database-part-2a-modified-preorder-tree-traversal/
If you are planning to deploy on SQL server you could consider using common table expressions:
http://msdn.microsoft.com/en-us/library/ms190766(v=sql.105).aspx

Related

how to remove delimiters in C#

Hi I have tried already the code below and it does not remove the delimeters in a dat file:
StreamReader input = new StreamReader(txtFile.Text);
string content = input.ReadToEnd().Trim();
string[] split = System.Text.RegularExpressions.Regex.Split(content, "\\s+", RegexOptions.None);
foreach (string s in split)
{
txtStatus.Text = s + "\r\n" + txtStatus.Text;
}
here is a sample data from the dat file I am working on:
xú !' Date D Time C Millitm N TagIndex N Value C Status C! Marker C" Internal C#
2020032403:25:25829 0 # Bÿÿÿÿ 2020032403:25:25829 1 9# Bÿÿÿÿ 2020032403:25:26844 0 # 2020032403:25:26844 1 9# 2020032403:25:27845 0 # 2020032403:25:27845 1 :# 2020032403:25:28847 0 # 2020032403:25:28847 1 ;# 2020032403:25:29851 0 # 2020032403:25:29851 1 <# 2020032403:25:30857 0 # 2020032403:25:30857 1 =# 2020032403:25:31861 0 #
2020032403:25:31861 1 ># 2020032403:25:32867 0 # 2020032403:25:32867 1 ?#
2020032403:25:33873 0 # 2020032403:25:33873 1 ## 2020032403:25:34877 0 # 2020032403:25:34877 1 €## 2020032403:25:35879 0 # 2020032403:25:35879 1 A# 2020032403:25:36888 0 # 2020032403:25:36888 1 €A# 2020032403:25:37890 0 # 2020032403:25:37890 1 B# 2020032403:25:38838 0 # 2020032403:25:38838 1 €B# 2020032403:25:39841 0 # 2020032403:25:39841 1 C# 2020032403:25:40846 0 # 2020032403:25:40846 1 €C# 2020032403:25:41849 0 # 2020032403:25:41849 1 D# 2020032403:25:42851 0 # 2020032403:25:42851 1 €D# ! 2020032403:25:43852 0 # " 2020032403:25:43852 1 E# # 2020032403:25:44860 0 # $ 2020032403:25:44860 1 €E# % 2020032403:25:45862 0 # & 2020032403:25:45862 1 F# ' 2020032403:25:46869 0 # ( 2020032403:25:46869 1 €F# ) 2020032403:25:47873 0 # * 2020032403:25:47873 1 G# + 2020032403:25:48883 0 # , 2020032403:25:48883 1 €G# - 2020032403:25:49887 0 # . 2020032403:25:49887 1 H# / 2020032403:25:50842 0 # 0 2020032403:25:50842 1 €H# 1 2020032403:25:51844 0 # 2 2020032403:25:51844 1 I# 3 2020032403:25:52866 0 # 4 2020032403:25:52866 1 €I# 5 2020032403:25:53868 0 # 6 2020032403:25:53868 1 J# 7 2020032403:25:54884 0 # 8 2020032403:25:54884 1 €J# 9 2020032403:25:55886 0 # : 2020032403:25:55886 1 K# ; 2020032403:25:56896 0 # < 2020032403:25:56896 1 €K# = 2020032403:25:57860 0 # > 2020032403:25:57860 1 L# ? 2020032403:25:58866 0 # # 2020032403:25:58866 1 €L# A 2020032403:25:59868 0 # B 2020032403:25:59868 1 M# C 2020032403:26:00873
can anyone help me?
It depends on your definition of special characters. To remove all characters except numbers, alphabets, spaces and ":" you can use following pattern [^0-9a-zA-Z:\s]+
s = Regex.Replace(s, "[^0-9a-zA-Z]+", "");
txtStatus.Text = s + "\r\n" + txtStatus.Text;

Error System.BadImageFormatException, Couldn't not load assembly, using C#

Hello i'm having difficulty because i can't load my assembly. I can't because when i join them together and after split the assemblies using a DELIMITER the image of my files are corrupted. The result is well and i can see perfectly the same assembly, however when i do the split, my file will return me System.BadImageFormatException.
Here is the program that i did for joining the files:
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
namespace Crypter
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//No Arguments -> Exit
if (args.Length < 2)
{
Console.WriteLine("Syntax: crypter.exe <Exe/Dll to get Encrypted> <Password> (Optional: output file name)");
Environment.Exit(0);
}
String file = args[0];
String pass = args[1];
String outFile = "Crypted.exe";
//If Output Name is specified -> Set it
if (args.Length == 3)
{
outFile = args[2];
}
//File doesn't exist -> Exit
if (!File.Exists(file))
{
Console.WriteLine("[!] The selected File doesn't exist!");
Environment.Exit(0);
}
//Everything seems fine -> Reading bytes
Console.WriteLine("[*] Reading Data...");
byte[] plainBytes = File.ReadAllBytes(file);
//Yep, got bytes -> Encoding
Console.WriteLine("[*] Encoding Data...");
byte[] encodedBytes = encodeBytes(plainBytes, pass);
Console.WriteLine("[*] Save to Output File... ");
//Leer el stub
Console.WriteLine("[*] Reading Stub...");
byte[] Stub = File.ReadAllBytes("Stub.exe");
//byte separador
string strseperate = "BLAUMOLAMUCHO";
byte[] toBytes = Encoding.ASCII.GetBytes(strseperate);
//byte[] toBytes = new byte[30];
//write bytes
//var stream
//Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("skip.skip.exe");
//Console.WriteLine(stream);
var s = new MemoryStream();
s.Write(Stub, 0, Stub.Length);
s.Write(toBytes, 0, toBytes.Length);
s.Write(encodedBytes, 0, encodedBytes.Length);
var b3 = s.ToArray();
Stream stream = new MemoryStream(b3);
//Stream stream = new MemoryStream(encodedBytes);
FileStream fileStream = new FileStream(#"out.exe", FileMode.Create, FileAccess.Write);
for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
Console.WriteLine("Done!");
Console.WriteLine("\n[*] File successfully encoded!");
}
private static byte[] encodeBytes(byte[] bytes, String pass)
{
byte[] XorBytes = Encoding.Unicode.GetBytes(pass);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] ^= XorBytes[i % XorBytes.Length];
}
return bytes;
}
}
}
And then i open since the first program, stub.. the program is:
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Resources;
using System.Security.Cryptography;
using System.Reflection;
using Microsoft.Win32;
namespace skip
{
static class Program
{
/// <summary>
/// MAIN
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
//leemos el byte array
byte[] file = File.ReadAllBytes(System.Reflection.Assembly.GetExecutingAssembly().Location);
//obtenemos la string
string str = System.Text.Encoding.ASCII.GetString(file);
string[] arr=str.Split(new string[] { "BLAUMOLAMUCHO" }, StringSplitOptions.None);
string a = arr[0];
string b = arr[1];
/*Console.WriteLine(a);
Console.WriteLine("------------------------------");
Console.WriteLine(b);
Console.ReadKey();*/
byte[] encodedBytes = Encoding.ASCII.GetBytes(b);
RunInternal(encodedBytes,"1234");
}
private static void RunInternal(byte[] exeName, String pass)
{
//Read the raw bytes of the file
byte[] resourcesBuffer = exeName;
//Decrypt bytes from payload
byte[] decryptedBuffer = null;
decryptedBuffer = decryptBytes(resourcesBuffer, pass);
//If .NET executable -> Run
if (System.Text.Encoding.ASCII.GetString(decryptedBuffer).Contains("</assembly>")) //Esto devuelve false
{
//Load the bytes as an assembly
Assembly exeAssembly = Assembly.Load(decryptedBuffer);
//Execute the assembly
object[] parameters = new object[1]; //Don't know why but fixes TargetParameterCountException
try{
exeAssembly.EntryPoint.Invoke(null, parameters);
}catch (Exception ex){
Console.WriteLine(ex);
Console.ReadKey();
}
}
else
{
Console.WriteLine(Encoding.ASCII.GetString(decryptedBuffer));
Console.ReadKey();
}
}
/// <summary>
/// Decrypt the Loaded Assembly Bytes
/// </summary>
/// <param name="payload"></param>
/// <returns>Decrypted Bytes</returns>
private static byte[] decryptBytes(byte[] bytes, String pass)
{
byte[] XorBytes = Encoding.Unicode.GetBytes(pass);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] ^= XorBytes[i % XorBytes.Length];
}
return bytes;
}
}
}
I know that it's possible because i did in other languages like autoit. And my binary add perflectly the delimiter that i can see when i convert to string:
MZ? ♥ ♦ ?? ? # ? ♫▼?♫ ? ?!?☺L?!T
his program cannot be run in DOS mode.
$ PE L☺♥ ?4‼Y ? ☻☺♂☺♂ ♫ N, # # ☻ ♦ ♦
? ☻ ♥ #? ► ► ► ► ► ?+ S # ♣
` ♀ ?* ∟ H
.text T♀ ♫ ☻ `.rsrc ♣ # ♠ ►
# #.reloc ♀ ` ☻ ▬ # B 0, H ☻ ♣ ?
! $ ☺ ☺ ♠ ‼0☻ # ☺ ◄ (
↕
▬(‼
(¶
o§
(▬
▼→(↨
♂(↑
♠o↓
(→
(←
&*←0♥ ? ☻ ◄ ☻(∟
‼♣◄♣-♣8? ☻(▬
¶♂♠♥(♥ ♠♂(↑
o↓
r☺ po↔
▬?☺‼♣◄♣-9 (▲
o▼ ☺
¶ o
& ?¶‼♦ ◄♦(!
(←
& ? +↓ (↑
o↓
(→
(←
& *☺► P ↕b ¶▼ ☺‼0♣ B ♥ ◄ ("
♥o#
-?☻♀+* BSJB☺ ☺ ♀ v4.0.30319 ♣ l ?☻ #~ H♥ (♦ #Strings
p ∟ #US ? ► #GUID ? ?☺ #Blob ☻ ☺G§☻ ?%3 ▬ ☺ ☻ ♥
♦ # ☼ ♥ ☺ ☻
☺ ♠ 0 ) ♠ ? h ♠ ? ? ♠ ? ? ♠ ? ? ♠ ♠☺? ♠ ▼☺? ♠ 8☺? ♠ S☺? ♠ n☺? ♠ ?☺?☺♠ ?☺?☺♠
?☺? ♠ ?☺? ♠ ◄☻?☺? %☻ ♠ T☻4☻♠ t☻4☻♠ ?☻)
?☻?☻♠ ?☻? ♠ 0♥&♥♠ B♥) _ N♥ ♠ v♥j♥♠ ?♥) ♠ ?♥) ♠ ?♥) ♠ ?♥? ♠ ?♥? ♠ ♦♦) ♠ #♦)
☺ ☺ ☺ ?☺► ‼ ← ♣ ☺ ☺ P ? 7
☺ ? ? < ♫ ☺ L! ? H ¶ ♥ ☺ U ☻ ] ☺ b ☻ ] ◄ ? ∟ ↓ ? ∟ ! ? ∟ ) ? ∟ 1
? ∟ 9 ? ∟ A ? ∟ I ? ∟ Q ? ∟ Y ? ! a ? ∟ i ? ∟ q ? ∟ y ? & ? ? , ? ? 1 ? ? 1 ? ?
☻
? ?☻: ? ♦♥? ? ↓♥D ? 5♥H ? \♥N ? ⌂♥T ? ?♥Y ? ?♥_ ? ?♥d ? ?♥p ? ?♥u ? ?♥z ? ?♥? ?
?♥? ? ?♥? ? ♫♦T ? →♦? ? 5 . ; ☺. ‼ ? . ← ☺☺. # ☺☺. + ☺☺. 3 ? . ♂ ? . C ☺☺. S
☺☺. [ ▼☺. k I☺. s V☺. { _☺. ? h☺i ? ? ♦? ☺ ← ♦ ☺
♦ ☺ ?☻ <Module> skip.exe Program skip mscorlib System Object M
ain RunInternal decryptBytes exeName pass bytes System.Runtime.Versioning Target
FrameworkAttribute .ctor System.Reflection AssemblyTitleAttribute AssemblyDescri
ptionAttribute AssemblyConfigurationAttribute AssemblyCompanyAttribute AssemblyP
roductAttribute AssemblyCopyrightAttribute AssemblyTrademarkAttribute AssemblyCu
ltureAttribute System.Runtime.InteropServices ComVisibleAttribute GuidAttribute
AssemblyVersionAttribute AssemblyFileVersionAttribute System.Diagnostics Debugga
bleAttribute DebuggingModes System.Runtime.CompilerServices CompilationRelaxatio
nsAttribute RuntimeCompatibilityAttribute STAThreadAttribute System.Windows.Form
s Application EnableVisualStyles SetCompatibleTextRenderingDefault Assembly GetE
xecutingAssembly get_Location System.IO File ReadAllBytes Environment SpecialFol
der GetFolderPath System.Text Encoding get_ASCII GetString Console WriteLine Con
soleKeyInfo ReadKey Exists String Contains Load MethodInfo get_EntryPoint Method
Base Invoke Exception get_Unicode GetBytes Byte ↨< / a s s e m b l y > ????
=??J?▲??R???z\V↓4??♥ ☺♣ ☻☺♫♫ ☻↔♣↔♣♫♦ ☺☺♫♦ ☺☺☻♣ ☺☺◄A♦ ☺♥ ☺♦☺ ♦ ☺☺☻♦ ↕U♥ ♫♣
♠↔♣↔♣↕U↔∟↕}☻♣ ☺↔♦↔♣☻G☺ →.NETFramework,Version=v4.0☺ T♫¶FrameworkDisplayName►.NET
Framework 4 ☺ ♦Stub ♣☺ ↨☺ ↕Copyright ?? 2017 )☺ $0f86beb5-80bf-47f1-89
e1-df778adbda88 ♀☺ 1.0.0.0☺ ☺ ▲☺ ☺ T☻▬WrapNonExceptionThrows☺ ?4‼Y
☻ ∟☺ ?* ?♀ RSDS§2??♦YL?{Q‼????☺ c:\Users\Androide\Desktop\CRYPTER SIN DR
OPEAR\Stub\obj\Debug\skip.pdb
, >,
0, _CorExeMain mscoree.dll ?% #
☻ ► ?↑ 8 ? ☺ ☺ P ?
☺ ☺ h ? ☺ ? ☺ ? ?# ?☻
0C ?☺ ?☻4 V S _ V E R S I O N _ I N F O ?♦?? ☺ ☺ ☺
? ♦ ☺ D ☺ V a r F i l e I n f o $ ♦ T r a n s
l a t i o n ?♦?☺ ☺ S t r i n g F i l e I n f o ?☺ ☺ 0 0 0 0 0 4 b 0
4 ♣ ☺ F i l e D e s c r i p t i o n S t u b ☺ F i l e V e r s i o n
1 . 0 . 0 . 0 4 ☺ I n t e r n a l N a m e s k i p . e x e H ↕ ☺ L
e g a l C o p y r i g h t C o p y r i g h t ? 2 0 1 7 < ☺ O r i
g i n a l F i l e n a m e s k i p . e x e , ♣ ☺ P r o d u c t N a m e
S t u b ☺ P r o d u c t V e r s i o n 1 . 0 . 0 . 0 8 ☺ A s s e m b l
y V e r s i o n 1 . 0 . 0 . 0 ???<?xml version="1.0" encoding="UTF-8" stan
dalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
♀ P<
BLAUMOLAMUCHO|Z? 0 4 5 2 ??4 ? 2 3 4 q 2 3 4 1 2 3 4 1 2 3
94 1 2 3 4 1 2 ? 4 ?▼?♫3?=?►?3L?!`hXs↕pAoSrPm↕cRnZoE Pe‼rAn◄i\ wOg \oVe↔
§ 2 3 4 aE2 ⌂☺7 ??#Y3 4 1 2 ? 6☺:☺☻ 42 3 4 ?'2 3 4 1#2 3 t 1 2 3☻4 5 2 3 4 5 2 3
4 1?2 3☻4 1 2 0 t?1 " 3►4 1 " 3►4 1 2 # 4 1 2 3 4 Q'2 | 4 1#2 ?♣4 1 2 3 4 1 2 3
4 1`2 ? 4 ↓&2 / 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 ; 4 1 2 3 4 9 2 {
4 1 2 3 4 ▼tWxG 4 ?2 3 42 3☻4 1 2 3 4 1 2 ‼ 4`▼rArP 4 ?♣2 3#4 1♠2 3
4 1 2 3 4 1 2 s 4#▼rWl\c4 = 2 3`4 1☻2 3►4 1 2 3 4 1 2 s 4B1 2 3 4 1 2 3 4 ?'2 3
4 y 2 1 1 M 2 ?♣4 2 2 2 4♠1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 O #☺3
D(< 2
3r/ 1p→♫3 > &(= 3
↕*‼☻→►3 > ← 2 qS~B0 3 3 4 = 2 E4→0▼3☻3☻94 1 7 _ 4 ?☺2 ►~4 §☻2 w☻4 ↕SFrZnSs1 2 [♦
4 Q 2 ►Ug ?♦2 # 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 3 5 1 2 ?♥4 ?#2 ♣♥4 1 2
3 4 ♥♠ 3 b b m e q c a z { ⌂ m z z w } 3 4 ?♦??3 5 1 3 ‼W?↑1 3 ‼W?↑♫ 2 3 4 5 2 2
4 1 2 3 4 1 2 w 4 0 d R F w [ _ Q x \ U [ 1 2 ↨ 0 1 f A U _ A _ U E [ \ Z 1 2 3
?♦?☻2 2 g E # Z Z V t Z X T { ] R ^ 2 A☻4 0 ☻ ♥ ♦ ☺ ☻ V ☺ 2 ) 5 0 q \ Y \ W ]
# B 2 3 4 ‼ 3 2 w ^ _ C U _ K } U \ W 3 4 1 2 ♂ < 0 t Z X T v V G R # Z D E [ \
; 0 t Z X T d V F B [ \ Z 1 2 ☻ → ☺ ∟ ♣ ☻
↔ ♠ ♥ ☺ ♥ 1 2 ♂ 8 0 { ] # T # ] U ] | R Y T 2 p [ _ A \ X T ∟ V L T 2 q ; 0 ~
V S P ^ p [ A K A ] V Z G 4 r ] C M C [ T \ E ↕ ☺ ♦ ♣ 3 4 ← 3 2 x T U R X e #
R P T _ R F Z A 3 4 1 2 s 8 0 } A ] V [ ] U ] t Z X T \ R Y T 2 p [ _ A \ X T ∟
V L T 2 ♥ < 0 b A [ U G P # ⌂ S ^ Q 1 2 p [ _ A \ X T 2 q ; 0 b A [ U G P # g W
A G X ] ] 4 ∟ ♥ → ☺ ♀ ▼ ☺ ☺ ♠ 3 4 w = 2 u B A V Y S ^ J ¶ g W A G X ] ]
4 ∟ ♥ → ☺ ♀ ▼ ☺ ☺ ♠ 3 4 ?C2 ?☺4 1 2 3 4 ???<♀xYl◄vWr#i[n♀"♥.♥"¶e_c]dZnS
=‼UfF▲8▬ BtSnWaXo_e☼"JeG"♫>?
>
aBsWmQlM Im^n#=▬uCsPhQmPs▼mZcFoBoTt▲c[m♂aAm↔v♣"◄mSnZfQsEVWr#i[n♀"♥.♥"
8 ‼ ¶ ◄<#eBuQsEeVPAiBi]eUe# Lm]nA=◄uFn♂sQhVmUs∟m[cAoGoWt▼c\m♫aBm∟v "
; ↕ ‼ ¶ ◄<#eBuQsEeVEKeWuEi]n⌂eBe] ^eEeX=‼aAI]v[kTr► FiucReAs♫"Ra]sW"∟>9
◄ ↕ ‼/CeCuVs#eUP#iEiXeVeA>>
><▲aAsVmVlH>2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 ?
4 ?72 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
4 1 2 3 4 1 2 3 4 1 2 3 4
Error return's me:
If you search in the assembly you will see perflectly the DELIMITER, BLAUMOLAMUCHO. I tried including the length's but i must to use streamreader because it's not data.
How i can load two assemblies without using like resource in c#(it's only for educational purposes and learning.)

To Count Occurrences of all sub strings in string C#

Question: I have a long string and I require to find the count of occurrences of all sub strings present under that string and print a list of all sub strings and their count (if count is > 1) in decreasing order of count.
Example:
String = "abcdabcd"
Result:
Substrings Count
abcd 2
abc 2
bcd 2
ab 2
bc 2
cd 2
a 2
b 2
c 2
d 2
Problem: My string can be 5000 character long and I am not able to find a efficient way to achieve this.( Efficiency is very important for application)
Is there any algorithm present or by multi threading it is possible. please help.
Example using: Find a common string within a list of strings
void Main()
{
"abcdabcd".getAllSubstrings()
.AsParallel()
.GroupBy(x => x)
.Select(g => new {g.Key, count=g.Count()})
.Dump();
}
// Define other methods and classes here
public static class Ext
{
public static IEnumerable<string> getAllSubstrings(this string word)
{
return from charIndex1 in Enumerable.Range(0, word.Length)
from charIndex2 in Enumerable.Range(0, word.Length - charIndex1 + 1)
where charIndex2 > 0
select word.Substring(charIndex1, charIndex2);
}
}
Produces:
a 2
dabc 1
abcdabc 1
b 2
abc 2
dabcd 1
bc 2
bcda 1
abcd 2
ab 2
bcdab 1
cdabc 1
abcda 1
d 2
bcdabc 1
dab 1
bcd 2
abcdab 1
c 2
bcdabcd 1
abcdabcd 1
cd 2
da 1
cdab 1
cda 1
cdabcd 1

LINQ generates wrong sql query with system.data.sqlite

I have the following model:
[Table(Name="word")]
public partial class Word
{
[Column(IsPrimaryKey=true, Name="id")]
public int Id { get; set; }
[Column(IsPrimaryKey=true, Name="language_id")]
public int LanguageId { get; set; }
[Column(Name="translation")]
public string Translation { get; set; }
[Column(Name="category")]
public string Category { get; set; }
[Column(Name="order")]
public int Order { get; set; }
}
And the following code:
var connection = new SQLiteConnection(#"Data Source=data.sqlite3");
var context = new DataContext(connection);
context.Log = Console.Out;
var test = from w1 in context.GetTable<Word> ()
join w2 in context.GetTable<Word> () on w1.Id equals w2.Id
select new {w1 = w1.Id, w2 = w2.Id};
foreach (var i in test)
{
Console.WriteLine("Word: {0} {1}", i.w1, i.w2);
}
And the output looks like this:
SELECT w1$.[id], w2$.[id]
FROM [word] AS w1$, [word] AS w2$
WHERE (w1$.[id] = w1$.[id])
-- Context: SqlServer Model: AttributedMetaModel Build: 4.0.0.0
Word: 1 1
Word: 1 1
Word: 1 2
Word: 1 2
Word: 1 3
Word: 1 3
Word: 1 4
Word: 1 4
Word: 1 5
Word: 1 5
What is going on? Why is the join condition different from what I have specified? Is this a bug or am I doing something wrong? For what it's worth, I'm using Mono on Mac and I've compiled system.data.sqlite for Mono as described on their website.
Update:
This work-around fixes the problem:
var test = from w1 in context.GetTable<Word> ()
join w2 in context.GetTable<Word> () on w1.Id equals w2.Id
where w1.Id == w2.Id
select new {w1 = w1.Id, w2 = w2.Id};
Update 2:
Apparently, linq 2 sql works quite bad with sqlite. The recommended solution is to use Entity Framework.
I think the issue is in the SQLite driver not being able to cope with self joins too well. I just tried the same thing in SQLServer
my table looks like this
Id Language_id Translation
1 1 hello
1 2 bonjour
1 3 yo
2 1 bye
2 2 aurevoiur
2 3 laterz
and the output looks like this (i added the translation column to help see whats happening easier)
SELECT [t0].[id] AS [w1], [t0].[translation] AS [word1], [t1].[id] AS [w2],
[t1].[translation] AS [word2]
FROM [word] AS [t0]
INNER JOIN [word] AS [t1] ON [t0].[id] = [t1].[id]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.18408
Word: 1 = hello, 1 = hello
Word: 1 = bonjour, 1 = hello
Word: 1 = yo, 1 = hello
Word: 1 = hello, 1 = bonjour
Word: 1 = bonjour, 1 = bonjour
Word: 1 = yo, 1 = bonjour
Word: 1 = hello, 1 = yo
Word: 1 = bonjour, 1 = yo
Word: 1 = yo, 1 = yo
Word: 2 = bye, 2 = bye
Word: 2 = aurevoiur, 2 = bye
Word: 2 = laterz, 2 = bye
Word: 2 = bye, 2 = aurevoiur
Word: 2 = aurevoiur, 2 = aurevoiur
Word: 2 = laterz, 2 = aurevoiur
Word: 2 = bye, 2 = laterz
Word: 2 = aurevoiur, 2 = laterz
Word: 2 = laterz, 2 = laterz
which still doesn't give you the set of results you are after (its giving every combination) - but at least its doing the join.
I'd advise splitting your data into two tables if possible, have the Word table - with the Id and other single columns, and have a translations table - which contains the actual translations, and foreign keys back to the word table. I suspect the sqlite driver will cope with this better.

Best way to Find which cell of string array contins text

I have a block of text that im taking from a Gedcom (Here and Here) File
The text is flat and basically broken into "nodes"
I am splitting each node on the \r char and thus subdividing it into each of its parts( amount of "lines" can vary)
I know the 0 address will always be the ID but after that everything can be anywhere so i want to test each Cell of the array to see if it contains the correct tag for me to proccess
an example of what two nodes would look like
0 #ind23815# INDI <<<<<<<<<<<<<<<<<<< Start of node 1
1 NAME Lawrence /Hucstepe/
2 DISPLAY Lawrence Hucstepe
2 GIVN Lawrence
2 SURN Hucstepe
1 POSITION -850,-210
2 BOUNDARY_RECT (-887,-177),(-813,-257)
1 SEX M
1 BIRT
2 DATE 1521
1 DEAT Y
2 DATE 1559
1 NOTE * Born: Abt 1521, Kent, England
2 CONT * Marriage: Jane Pope 17 Aug 1546, Kent, England
2 CONT * Died: Bef 1559, Kent, England
2 CONT
1 FAMS #fam08318#
0 #ind23816# INDI <<<<<<<<<<<<<<<<<<<<<<< Start of Node 2
1 NAME Jane /Pope/
2 DISPLAY Jane Pope
2 GIVN Jane
2 SURN Pope
1 POSITION -750,-210
2 BOUNDARY_RECT (-787,-177),(-713,-257)
1 SEX F
1 BIRT
2 DATE 1525
1 DEAT Y
2 DATE 1609
1 NOTE * Born: Abt 1525, Tenterden, Kent, England
2 CONT * Marriage: Lawrence Hucstepe 17 Aug 1546, Kent, England
2 CONT * Died: 23 Oct 1609
2 CONT
1 FAMS #fam08318#
0 #ind23817# INDI <<<<<<<<<<< start of Node 3
So a when im done i have an array that looks like
address , string
0 = "1 NAME Lawrence /Hucstepe/"
1 = "2 DISPLAY Lawrence Hucstepe"
2 = "2 GIVN Lawrence"
3 = "2 SURN Hucstepe"
4 = "1 POSITION -850,-210"
5 = "2 BOUNDARY_RECT (-887,-177),(-813,-257)"
6 = "1 SEX M"
7 = "1 BIRT "
8 = "1 FAMS #fam08318#"
So my question is what is the best way to search the above array to see which Cell has the SEX tag or the NAME Tag or the FAMS Tag
this is the code i have
private int FindIndexinArray(string[] Arr, string search)
{
int Val = -1;
for (int i = 0; i < Arr.Length; i++)
{
if (Arr[i].Contains(search))
{
Val = i;
}
}
return Val;
}
But it seems inefficient because i end up calling it twice to make sure it doesnt return a -1
Like so
if (FindIndexinArray(SubNode, "1 BIRT ") != -1)
{
// add birthday to Struct
I.BirthDay = SubNode[FindIndexinArray(SubNode, "1 BIRT ") + 1].Replace("2 DATE ", "").Trim();
}
sorry this is a longer post but hopefully you guys will have some expert advice
Can use the static method FindAll of the Array class:
It will return the string itself though, if that works..
string[] test = { "Sex", "Love", "Rock and Roll", "Drugs", "Computer"};
Array.FindAll(test, item => item.Contains("Sex") || item.Contains("Drugs") || item.Contains("Computer"));
The => indicates a lamda expression. Basically a method without a concrete implementation.
You can also do this if the lamda gives you the creeps.
//Declare a method
private bool HasTag(string s)
{
return s.Contains("Sex") || s.Contains("Drugs") || s.Contains("Computer");
}
string[] test = { "Sex", "Love", "Rock and Roll", "Drugs", "Computer"};
Array.FindAll(test, HasTag);
What about a simple regular expression?
^(\d)\s=\s\"\d\s(SEX|BIRT|FAMS){1}.*$
First group captures the address, second group the tag.
Also, it might be quicker to dump all array items into a string and do your regex on the whole lot at once.
"But it seems inefficient because i end up calling it twice to make sure it doesnt return a -1"
Copy the returned value to a variable before you test to prevent multiple calls.
IndexResults = FindIndexinArray(SubNode, "1 BIRT ")
if (IndexResults != -1)
{
// add birthday to Struct
I.BirthDay = SubNode[IndexResults].Replace("2 DATE ", "").Trim();
}
The for loop in method FindIndexinArray shd break once you find a match if you are interested in only the first match.

Categories

Resources