unit1 summary

13
eleks.com eleks.com Unit 1 Summary

Upload: eleksdev

Post on 13-Apr-2017

1.174 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Unit1 summary

eleks.com eleks.com

Unit 1 Summary

Page 2: Unit1 summary

P/Invoke, Marshalling

Page 3: Unit1 summary

C++ .h fileextern "C"{

struct EndpointData{

char* userName1;char* userName2;

};

struct ResultData{

char* userName;int userId;

};

__declspec(dllexport) int __stdcall findPath(EndpointData* pStructs, int nItems, const char* userName1, const char* userName2);

__declspec(dllexport) int __stdcall returnNumber();__declspec(dllexport) ResultData* __stdcall findPathWithResultData(EndpointData* pStructs, int nItems,

const char* userName1, const char* userName2, int& resultArraySize);}

Page 4: Unit1 summary

C# methods definition[DllImport("ExternalNativeLibrary.dll")]public static extern int returnNumber();

[DllImport("ExternalNativeLibrary.dll")]public static extern int findPath(MyStruct[] pStructs, int nItems, string userNamr1, string userName2);

[DllImport("ExternalNativeLibrary.dll", EntryPoint = "findPathWithResultData")]public static extern IntPtr findPathWithResultData(MyStruct[] pStructs, int nItems, string userNamr1, string userName2, out int resultArrSize);

Page 5: Unit1 summary

C# structures definition [StructLayout(LayoutKind.Sequential)] public struct MyStruct { public string userName1; public string userName2; }

[StructLayout(LayoutKind.Sequential)] public struct Results { public string userName; public int userId; }

Page 6: Unit1 summary

C# Call methodsConsole.WriteLine("Return number:");Console.WriteLine(returnNumber());

int count;var pointer = findPathWithResultData(structArray, structArray.Length, "user1", "user3", out count);

var firstResult = Marshal.PtrToStructure<Results>(pointer);

var pointer2 = pointer + Marshal.SizeOf<Results>();var secondResult = Marshal.PtrToStructure<Results>(pointer2);

Page 7: Unit1 summary

SerializationSerialization is the process of converting an object into a stream of bytes in order to store or transmit it.Deserialization is the opposite process to serialization – converting data to object.

The most used serialization types in .NET Framework:

• Binary serialization (is the serialization process with binary data as a result)• Xml serialization (is the serialization process with XML data as a result)

Page 8: Unit1 summary

Serialization example public static class XmlSerializationService<T> where T : class{ private static XmlSerializer _serializer = new XmlSerializer(typeof(T));

public static T Deserialize(string serializedObject) { using (var sr = new StringReader(serializedObject)) { return (T)_serializer.Deserialize(sr); } }

public static string Serialize(T objectToSerialize) { using (var sw = new StringWriter()) { _serializer.Serialize(sw, objectToSerialize); return sw.ToString(); } } }

Page 9: Unit1 summary

Trello

Page 10: Unit1 summary

Project architecture

Page 11: Unit1 summary

Project requirementsІдея: месенджер, де дружба = надіслане повідомлення.

C++- Пошук спільних друзів.- Пошук спільних речей між людьми.- Пошук відстані між двома людьми.C#- Консольна аплікація.- Додавання користувача.- Збереження, завантаження даних з файлу.- Видалення користувача.- Інтеграція С++ методів.- Збереження ‘метадати’ користувача.- Імпорт\експорт файлу з користувачами. Вхідний файл – csv- Технічні вимоги: exception handling, logs, application menu.

Page 12: Unit1 summary

eleks.com

Inspired by Technology.Driven by Value.