/// <summary> /// Prüft, ob ein Telefonaktivierungsantwortcode (siehe <see cref="TelephoneActivation">TelephoneActivation</see>) richtig oder falsch ist. /// </summary> /// <param name="pRequestcode">Requestcode, mit dem die Telefonaktivierung durchgeführt wurde</param> /// <param name="pAnswer">Antwortcode, den der Kunde eingegeben hat</param> /// <returns></returns> public static bool IsValidTelephoneCode(string pRequestcode, string pAnswer) { int sum = 0; for (int i = 0; i < pRequestcode.Length; i++) { sum += (int)pRequestcode[i]; } sum = sum ^ 0x240290; // crypten.. int answerCode = 0; try { answerCode = Convert.ToInt32(pAnswer); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("AnswerCode hat ungültiges Format. Antwortcode: " + pAnswer); throw ex; } return(sum == answerCode); }
/// <summary> /// Sollte nur vom Konstruktor aufgerufen werden, versucht übergebenes Objekt in M3S-Datenframe oder Interference zu konvertieren /// </summary> /// <param name="rToStore">m3sDataframe oder Bytestream</param> private void analyseAndStore(object rToStore) { // Differenziere was es ist... logTime = DateTime.Now; dgv = new DataGridView(); if (rToStore.GetType() == typeof(IM3S_Dataframe)) { validFrame = rToStore as IM3S_Dataframe; } else if (rToStore.GetType() == typeof(byte[])) { // Konvertierung war nicht erfolgreich, probiere es in einen Bytestream zu verwandeln byte[] tempStream = rToStore as byte[]; try { int errCode = -555; validFrame = protocol.CreateFrameByBytestream(tempStream, out errCode); if (errCode == 0) // Konvertierung war erfolgreich { isValidFrame = true; interference = null; } else // Konvertierung war nicht erfolgreich { validFrame = null; interference = tempStream; // Ablegen isValidFrame = false; } } catch { // Nothing, war einfach nicht konvertierbar... Muss also Störung sein validFrame = null; interference = tempStream; // Ablegen isValidFrame = false; } } else if (rToStore.GetType() == typeof(byte)) { } else { // War auch kein Bytearray, also Exception TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("Das bei der Instanzierung an M3sLogFrame übergebene hat keinen gültigen Typ (erlaubt: m3sDataframe und byte[])"); throw ex; } if (this.isValidFrame) { if (this.validFrame.Protocol == M3SProtocol.Reset) { resetCounter++; } } }
/// <summary> /// Prüft, ob die Lizenzdatei gültig und aktiviert ist /// </summary> /// <param name="pLicensePath">Pfad zur Lizenzdatei</param> /// <param name="pAppID">ApplikationsID (Valid, muss am Webserver vorhanden sein)</param> /// <returns>true ... aktiviert, false .. nicht aktiviert, falsche Lizenzdatei</returns> /// <exception cref="TBL.Exceptions.ConversionException">ConversionException (Zeilen und Spaltensplit), ';'-csv</exception> public static bool IsLicensed(string pLicensePath, string pAppID) { if (!File.Exists(pLicensePath)) // Wenns nit existiert kanns auch nicht aktiviert sein.. { return(false); } string fileContent = TBL.Crypt.RatsEncryptionManager.DecryptFiletoString(pLicensePath); string[] lines; try { lines = fileContent.Split(Environment.NewLine[0]); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("Dekryptographierter String aus Lizenzdatei kann nicht in mehrere Zeilen aufgelöst werden, hat somit ungültiges Format. Ausgabe des Strings aus Sicherheitsgründen unterbunden"); throw(ex); } if (EDOLL.EDOLLHandler.NoError(TBL.Check.CheckCSVHeader(lines[0], configFileType))) { try { string[] data = lines[1].Split(';'); if (data[0].Trim() != Hardware.HardwareInfo.GetIdentificationString().Trim()) { EDOLL.stdOut.Error("Die Lizenzdatei ist für eine andere Hardware bestimmt. Setzen Sie sich bitte mit der Herstellerfirma in Verbindung..."); return(false); } if (data[2].Trim() == pAppID.Trim()) { return(true); } else { EDOLL.stdOut.Error("Die Lizenzdatei ist für eine andere Software bestimmt. Setzen Sie sich bitte mit der Herstellerfirma in Verbindung..."); return(false); } } catch { TBL.Exceptions.ConversionException ex2 = new TBL.Exceptions.ConversionException("Dekryptographierter String (LizenzID + Key) aus Lizenzdatei kann nicht in mehrere Spalten aufgelöst werden, hat somit ungültiges Format. Ausgabe des Strings aus Sicherheitsgründen unterbunden"); throw(ex2); } } else { EDOLL.stdOut.Error(EDOLL.EDOLLHandler.GetLastError(), "Beim Lesen der Lizenzdatei."); } return(false); }
/// <summary> /// Wandelt einen Hexstring in eine .NET-Farbe (System.Drawing.Color) /// </summary> /// <param name="pHexstring">String im format #xxxxxx oder xxxxxx</param> /// <returns>Gewandelte Farbe</returns> /// <exception cref="Exceptions.ConversionException">Ungültiges Hexfileformat</exception> public static Color HexToColor(String pHexstring) { if (EDOLL.EDOLLHandler.Error(Check.CheckRGBString(pHexstring))) { Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("String " + pHexstring + " kann nicht in System.Drawing.Color gewandelt werden - Syntax Error"); throw(ex); } Color actColor; int r, g, b; r = 0; g = 0; b = 0; if ((pHexstring.StartsWith("#")) && (pHexstring.Length == 7)) { r = Convert.ToInt32(pHexstring.Substring(1, 2), 16); g = Convert.ToInt32(pHexstring.Substring(3, 2), 16); b = Convert.ToInt32(pHexstring.Substring(5, 2), 16); actColor = Color.FromArgb(r, g, b); } else if (pHexstring.Length == 6) { r = Convert.ToInt32(pHexstring.Substring(0, 1), 16); g = Convert.ToInt32(pHexstring.Substring(2, 2), 16); b = Convert.ToInt32(pHexstring.Substring(4, 2), 16); actColor = Color.FromArgb(r, g, b); } else { actColor = Color.White; // Some kind of default value... } return(actColor); }
/// <summary> /// Sollte nur vom Konstruktor aufgerufen werden, versucht übergebenes Objekt in M3S-Datenframe oder Interference zu konvertieren /// </summary> /// <param name="rToStore">m3sDataframe oder Bytestream</param> private void analyseAndStore(object rToStore) { // Differenziere was es ist... logTime = DateTime.Now; dgv = new DataGridView(); if(rToStore.GetType() == typeof(IM3S_Dataframe)) { validFrame = rToStore as IM3S_Dataframe; } else if(rToStore.GetType() == typeof(byte[])) { // Konvertierung war nicht erfolgreich, probiere es in einen Bytestream zu verwandeln byte[] tempStream = rToStore as byte[]; try { int errCode = -555; validFrame = protocol.CreateFrameByBytestream(tempStream, out errCode); if(errCode == 0) // Konvertierung war erfolgreich { isValidFrame = true; interference = null; } else // Konvertierung war nicht erfolgreich { validFrame = null; interference = tempStream; // Ablegen isValidFrame = false; } } catch { // Nothing, war einfach nicht konvertierbar... Muss also Störung sein validFrame = null; interference = tempStream; // Ablegen isValidFrame = false; } } else if(rToStore.GetType() == typeof(byte)) { } else { // War auch kein Bytearray, also Exception TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("Das bei der Instanzierung an M3sLogFrame übergebene hat keinen gültigen Typ (erlaubt: m3sDataframe und byte[])"); throw ex; } if(this.isValidFrame) { if(this.validFrame.Protocol == M3SProtocol.Reset) { resetCounter++; } } }
/// <summary> /// Routine zum Durchführen einer manuellen Konfiguration (Kunde gibt über Telefon Codes durch und erhält Antwortcode) /// </summary> /// <param name="pAddress">URL zum Aktivierungsskript</param> /// <param name="pKey">Key, für den aktiviert werden soll</param> /// <param name="pAppID">ApplikationsID für die aktiviert werden soll</param> /// <param name="pHWID">Hardwarekennung, für die aktiviert werden soll</param> /// <param name="pAnswerCodePrinter">Delgat (siehe <see cref="AnswerCodePrinter">AnswerCodePrinter</see></param> /// <returns>Aktivierungsstatus, Aktivierungscode über Delegate</returns> public static OnlineActivationResponse TelephoneActivation(string pAddress, string pKey, string pAppID, string pHWID, AnswerCodePrinter pAnswerCodePrinter) { string requestUrl = pAddress; string parameters = "?"; parameters += "key=" + pKey; parameters += "&app=" + pAppID; parameters += "&machine=" + pHWID; parameters += "&action=4"; // Fire activation // Parameter prüfen // Mit PC-ID versehen // Request HttpWebRequest requ = (HttpWebRequest)HttpWebRequest.Create(requestUrl + parameters); HttpWebResponse resp = (HttpWebResponse)requ.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); string answer = sr.ReadLine(); sr.Close(); resp.Close(); string[] parts; try { parts = answer.Split(';'); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("In Telefonaktivierungsantwort zurückgelieferter String lässt sich nicht nach Separator ';' zerteilen. Empfangener Wert: " + answer); throw(ex); } int intAnswer = 0; try { intAnswer = Convert.ToInt32(parts[0]); } catch { return(OnlineActivationResponse.InvalidResponseCode); } OnlineActivationResponse response = (OnlineActivationResponse)(intAnswer); if (response == OnlineActivationResponse.Successful) { try { int activationCode = Convert.ToInt32(sr.ReadLine()); pAnswerCodePrinter(parts[1].ToString()); } catch { return(OnlineActivationResponse.InvalidResponseCode); } } //else return(response); }
/// <summary> /// Wandelt einen Hexstring in eine .NET-Farbe (System.Drawing.Color) /// </summary> /// <param name="pHexstring">String im format #xxxxxx oder xxxxxx</param> /// <returns>Gewandelte Farbe</returns> /// <exception cref="Exceptions.ConversionException">Ungültiges Hexfileformat</exception> public static Color HexToColor(String pHexstring) { if(EDOLL.EDOLLHandler.Error(Check.CheckRGBString(pHexstring))) { Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("String " + pHexstring + " kann nicht in System.Drawing.Color gewandelt werden - Syntax Error"); throw(ex); } Color actColor; int r,g,b; r=0; g=0; b=0; if ((pHexstring.StartsWith("#"))&&(pHexstring.Length==7)) { r=Convert.ToInt32(pHexstring.Substring(1,2),16); g=Convert.ToInt32(pHexstring.Substring(3,2),16); b=Convert.ToInt32(pHexstring.Substring(5,2),16); actColor=Color.FromArgb(r,g,b); } else if(pHexstring.Length==6) { r=Convert.ToInt32(pHexstring.Substring(0,1),16); g=Convert.ToInt32(pHexstring.Substring(2,2),16); b=Convert.ToInt32(pHexstring.Substring(4,2),16); actColor=Color.FromArgb(r,g,b); } else { actColor=Color.White; // Some kind of default value... } return actColor; }
/// <summary> /// Erstellt aufgrund von pStatus eine versandfertige byteFolge mit der entsprechenden Kommandorückmeldung (siehe <see cref="m3sExecutionError">m3sExecutionError</see>) im ersten Nutzdatenbyte und zusätzlichen Informationen (nachfolgende Nutzdatenbytes) /// </summary> /// <param name="pStatus">Ausführungsstatus des Kommandos (siehe <see cref="m3sExecutionError">m3sExecutionError</see>)</param> /// <param name="pCommandFrame">Frame, aufgrunddessen das Kommando ausgeführt wurde</param> /// <param name="pInfo">Informationsdatenbytes (max. 255) als byte[], auch null kann übergeben werden.</param> /// <returns> /// <list type="table"> /// <item><term>versandfertiges ByteArray</term><description>bei fehlerfreier Ausführung</description></item> /// <item><term>Exception</term><description>im Fehlerfall</description></item> /// </list> /// </returns> /// <remarks> /// Die Funktion kann zusätzliche als Parameter übergebene Informationsbytes an den Kommandosender zurückliefern. Diese werden als byte[] übergeben und hinten an das ExecutionStatus-Byte angehängt. /// <para> /// <para>Interne <see cref="EDOLL">EDOLL-Behandlung</see> ist implementiert. Das heißt im Fehlerfall (siehe Rückgabewert) kann mit einer Codezeile der Fehler ausgegeben werden:</para> /// <para><c>string EDOLLHandler.GetLastError();</c></para> /// </para> /// Liste möglicherweise auftretenden EDOLL-Fehler: /// <list type="table"> /// <listheader><term><see cref="EDOLLHandler">(interne) Fehlernummer</see></term><description>Beschreibung</description></listheader> /// <item><term>-19</term><description>Ungültiges Datenframe; Länge, Frameaufbau oder Prüfsumme inkorrekt</description></item> /// <item><term>-612</term><description>Es wurden zu viele Informationsbyte (>255) übergeben.</description></item> /// </list> /// (siehe <see cref="EDOLLHandler.GetLastError">EDOLLHANDLER.GetLastError()</see>) /// </remarks> /// <exception cref="TBL.Exceptions.FrameError">Ungültiges Frame versucht zu verarbeiten</exception> public byte[] GetCommandExecutionStateFrame(m3sExecutionError pStatus, byte[] pCommandFrame, byte[] pInfo) { if(pInfo == null) { return(this.GetCommandExecutionStateFrame(pStatus,pCommandFrame)); // Version ohne Info aufrufen.. } if(!this.IsFrame(pCommandFrame)) { EDOLLHandler.Error(-19); // Frameerror Exceptions.FrameError ex = new TBL.Exceptions.FrameError("Ungültiges Frame versucht zu verarbeiten"); throw ex; } if(pInfo.Length > 255) { EDOLLHandler.Error(-612); Exceptions.ConversionException ex2 = new TBL.Exceptions.ConversionException("Es wurden zu viele Informationsbytes (" + pInfo.Length.ToString() + ") übergeben an: TBL.Communication.Protocol.m3sHandler.GetCommandExecutionStateFrame(). max 255 erlaubt!"); throw ex2; } byte[] data = new byte[1 + pInfo.Length]; data[0] = Convert.ToByte(pStatus); // Kommando ins Frame einfügen for(int i=0; i<pInfo.Length; i++) // Informationsbytes einfügen { data[i+1] = pInfo[i]; } IM3S_Dataframe toReturn = this.CreateFrame(Convert.ToInt32(pCommandFrame[1]), M3SProtocol.CommandResponse,this.ExtractMasterAddress(pCommandFrame), data, true, false); return(toReturn.GetDataframe()); }
/// <summary> /// Prüft zwei <see cref="M3S_V2_Dataframe">M3S-Dataframes</see> auf Gleichheit /// </summary> /// <param name="toCompare">Zu vergleichendes Objekt (byte[] oder Objekt vom Typ <see cref="M3S_V2_Dataframe">M3S_V2_Dataframe</see></param> /// <returns> /// true / false</returns> /// <remarks> /// Vergleicht die beiden Datenframes durch ihre resultierenden Streams (Rahmen + Nutzdaten) /// </remarks> public override bool Equals(object toCompare) { byte[] stream; try { // is it a M3s-Dataframe? M3S_V2_Dataframe tmpFrame = toCompare as M3S_V2_Dataframe; stream = tmpFrame.GetDataframe(); } catch { // was no IM3S_Dataframe try { stream = toCompare as byte[]; } catch { TBL.Exceptions.ConversionException e = new TBL.Exceptions.ConversionException("IM3S_Dataframe.CompareTo hat ein Objekt erhalten, das weder ein IM3S_Dataframe noch ein byte-Array ist"); throw e; } } byte[] thisStream = this.GetDataframe(); // wenn hier, hat die Konvertierung hingehaut if(stream.Length != thisStream.Length) { return(false); } for(int i=0; i<stream.Length; i++) { if(stream[i] != thisStream[i]) { return(false); } } return(true); }
/// <summary> /// Routine zum Durchführen einer manuellen Konfiguration (Kunde gibt über Telefon Codes durch und erhält Antwortcode) /// </summary> /// <param name="pAddress">URL zum Aktivierungsskript</param> /// <param name="pKey">Key, für den aktiviert werden soll</param> /// <param name="pAppID">ApplikationsID für die aktiviert werden soll</param> /// <param name="pHWID">Hardwarekennung, für die aktiviert werden soll</param> /// <param name="pAnswerCodePrinter">Delgat (siehe <see cref="AnswerCodePrinter">AnswerCodePrinter</see></param> /// <returns>Aktivierungsstatus, Aktivierungscode über Delegate</returns> public static OnlineActivationResponse TelephoneActivation(string pAddress, string pKey, string pAppID, string pHWID, AnswerCodePrinter pAnswerCodePrinter) { string requestUrl = pAddress; string parameters = "?"; parameters += "key=" + pKey; parameters += "&app=" + pAppID; parameters += "&machine=" + pHWID; parameters += "&action=4"; // Fire activation // Parameter prüfen // Mit PC-ID versehen // Request HttpWebRequest requ = (HttpWebRequest)HttpWebRequest.Create(requestUrl + parameters); HttpWebResponse resp = (HttpWebResponse)requ.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); string answer = sr.ReadLine(); sr.Close(); resp.Close(); string[] parts; try { parts = answer.Split(';'); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("In Telefonaktivierungsantwort zurückgelieferter String lässt sich nicht nach Separator ';' zerteilen. Empfangener Wert: " + answer); throw(ex); } int intAnswer=0; try { intAnswer = Convert.ToInt32(parts[0]); } catch { return(OnlineActivationResponse.InvalidResponseCode); } OnlineActivationResponse response = (OnlineActivationResponse)(intAnswer); if(response == OnlineActivationResponse.Successful) { try { int activationCode = Convert.ToInt32(sr.ReadLine()); pAnswerCodePrinter(parts[1].ToString()); } catch { return(OnlineActivationResponse.InvalidResponseCode); } } //else return(response); }
/// <summary> /// Prüft, ob ein Telefonaktivierungsantwortcode (siehe <see cref="TelephoneActivation">TelephoneActivation</see>) richtig oder falsch ist. /// </summary> /// <param name="pRequestcode">Requestcode, mit dem die Telefonaktivierung durchgeführt wurde</param> /// <param name="pAnswer">Antwortcode, den der Kunde eingegeben hat</param> /// <returns></returns> public static bool IsValidTelephoneCode(string pRequestcode, string pAnswer) { int sum = 0; for(int i=0; i<pRequestcode.Length; i++) { sum += (int)pRequestcode[i]; } sum = sum ^ 0x240290; // crypten.. int answerCode = 0; try { answerCode = Convert.ToInt32(pAnswer); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("AnswerCode hat ungültiges Format. Antwortcode: " + pAnswer); throw ex; } return(sum == answerCode); }
/// <summary> /// Prüft, ob die Lizenzdatei gültig und aktiviert ist /// </summary> /// <param name="pLicensePath">Pfad zur Lizenzdatei</param> /// <param name="pAppID">ApplikationsID (Valid, muss am Webserver vorhanden sein)</param> /// <returns>true ... aktiviert, false .. nicht aktiviert, falsche Lizenzdatei</returns> /// <exception cref="TBL.Exceptions.ConversionException">ConversionException (Zeilen und Spaltensplit), ';'-csv</exception> public static bool IsLicensed(string pLicensePath, string pAppID) { if(!File.Exists(pLicensePath)) // Wenns nit existiert kanns auch nicht aktiviert sein.. { return(false); } string fileContent = TBL.Crypt.RatsEncryptionManager.DecryptFiletoString(pLicensePath); string[] lines; try { lines = fileContent.Split(Environment.NewLine[0]); } catch { TBL.Exceptions.ConversionException ex = new TBL.Exceptions.ConversionException("Dekryptographierter String aus Lizenzdatei kann nicht in mehrere Zeilen aufgelöst werden, hat somit ungültiges Format. Ausgabe des Strings aus Sicherheitsgründen unterbunden"); throw(ex); } if(EDOLL.EDOLLHandler.NoError(TBL.Check.CheckCSVHeader(lines[0], configFileType))) { try { string[] data = lines[1].Split(';'); if(data[0].Trim() != Hardware.HardwareInfo.GetIdentificationString().Trim()) { EDOLL.stdOut.Error("Die Lizenzdatei ist für eine andere Hardware bestimmt. Setzen Sie sich bitte mit der Herstellerfirma in Verbindung..."); return(false); } if(data[2].Trim() == pAppID.Trim()) { return(true); } else { EDOLL.stdOut.Error("Die Lizenzdatei ist für eine andere Software bestimmt. Setzen Sie sich bitte mit der Herstellerfirma in Verbindung..."); return(false); } } catch { TBL.Exceptions.ConversionException ex2 = new TBL.Exceptions.ConversionException("Dekryptographierter String (LizenzID + Key) aus Lizenzdatei kann nicht in mehrere Spalten aufgelöst werden, hat somit ungültiges Format. Ausgabe des Strings aus Sicherheitsgründen unterbunden"); throw(ex2); } } else { EDOLL.stdOut.Error(EDOLL.EDOLLHandler.GetLastError(), "Beim Lesen der Lizenzdatei."); } return(false); }