Ejemplo n.º 1
0
        public void Parse(char separator)
        {
            string[]       cols          = RawLine.Split(separator);
            DateTimeOffset lineTimestamp = DateTimeOffset.Parse(cols.ElementAtOrDefault(0));

            Timestamp     = new DateTime(FileDate.Year, FileDate.Month, FileDate.Day, lineTimestamp.Hour, lineTimestamp.Minute, 0);
            TimestampUnix = (Timestamp - unixMin).TotalSeconds;
            Power1        = decimal.TryParse(cols.ElementAtOrDefault(1), out decimal tmp1) ? tmp1 : default(decimal);
            Power2        = decimal.TryParse(cols.ElementAtOrDefault(2), out decimal tmp2) ? tmp2 : default(decimal);
        }
Ejemplo n.º 2
0
        //Decript the Licence File

        #region         private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)

        private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)
        {
            /* File Schema:
             * File Format: spsproparts_[ProductID]_productVersion].lic
             *
             * spsProParts                          --> Always
             * http://www.spsproparts.net           --> Always
             * ProductName: productAAA              --> Product Name, doesn't have any meaning
             * ProductVersion: 1.0.0.0              --> Needs to be the same as in the name of the lic file (used internally without dots)
             * ProductID: 123456789ABCDEF           --> Needs to be the same as in the name of the lic file
             * LicenseID: 987654321QWERTY           --> IMPORTANT: needed als public key to decrypt the raw data
             * RXpTjTdBl7RP1oQqfqScDlYXQxgAYPg+m    --> Raw data
             *
             * Raw data format:
             * EngineVersion|LicenseDate|TypeLicense|EvaluationDate|EvaluationDays|MAC|IP|Domain|Client|Other
             * 1.0|20071125|mac|||112233445566|||ClientAAA||
             * EngineVersion                        --> The version of this Class. In the future, the class can change
             * LicenseDate                          --> Date of issuance of the License - yyyymmdd
             * TypeLicense                          --> can be: mac - ip - days - date - domain
             * EvaluationDate                       --> If the expiration evaluation periode is absolute - yyyymmdd
             * EvaluationDays                       --> If the expiration evaluation periode is relative - number of days
             * MAC                                  --> MAC Address to check, if TypeLicense is "mac"
             * IP                                   --> IP Address to check, if TypeLicense is "ip"
             * Domain                               --> Domain name to check, if TypeLicense is "domain"
             *  Host
             * Client                               --> Client name and other information
             * Other                                --> Reserved for other information
             * Host
             */

            bool   blnReturn   = false;
            string OneLine     = string.Empty;
            int    LineCounter = 1;

            string[] TempString = new string[2];

            try
            {
                //Read each line of the File, inclusive the raw data (last line), and set it in the object
                while ((OneLine = myTextReader.ReadLine()) != null)
                {
                    //Console.WriteLine(OneLine);

                    switch (LineCounter)
                    {
                    case (1):
                        //Nothing to do --> "spsProParts"
                        break;

                    case (2):
                        //Nothing to do --> "http://www.spsrproparts.net"
                        break;

                    case (3):
                        TempString             = OneLine.Split(':');
                        myFileData.ProductName = TempString[1].Trim();
                        break;

                    case (4):
                        TempString = OneLine.Split(':');
                        myFileData.ProductVersion = TempString[1].Trim().Replace(".", string.Empty);
                        break;

                    case (5):
                        TempString           = OneLine.Split(':');
                        myFileData.ProductID = TempString[1].Trim();
                        break;

                    case (6):
                        TempString           = OneLine.Split(':');
                        myFileData.LicenseID = TempString[1].Trim();
                        break;

                    case (7):
                        myFileData.RawData = OneLine;
                        break;

                    default:
                        break;
                    }
                    LineCounter++;
                }
                myTextReader.Close();

                string RawLine;
                //Read the values of the encrypted last line, and set it in the object
                using (CryptoString myCryptoString = new CryptoString())
                {
                    RawLine = myCryptoString.Decrypt(myFileData.RawData, myFileData.LicenseID);
                    //string RawLine = myCryptoString.Encrypt("1.0|20071125|days||1|11223344556677|||clientAA||", myFileData.LicenseID);
                    //Console.WriteLine(RawLine);
                }
                TempString = RawLine.Split('|');
                myFileData.LicenseEngineVersion = TempString[0].Trim();
                myFileData.LicenseDate          = TempString[1].Trim();
                //Type Licenses can be: mac - ip - days - date - domain
                switch (TempString[2].Trim().ToLower())
                {
                case ("mac"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.MAC;
                    break;

                case ("ip"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.IP;
                    break;

                case ("days"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDays;
                    break;

                case ("date"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDate;
                    break;

                case ("domain"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Domain;
                    break;

                case ("host"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Host;
                    break;

                default:
                    break;
                }
                myFileData.DateExpiration   = TempString[3].Trim();
                myFileData.DaysToExpiration = TempString[4].Trim();
                myFileData.MacAddress       = TempString[5].Trim();
                myFileData.IpAddress        = TempString[6].Trim();
                myFileData.DomainName       = TempString[7].Trim();
                myFileData.HostName         = TempString[8].Trim();
                myFileData.ClientName       = TempString[9].Trim();
                myFileData.OtherInformation = TempString[10].Trim();

                blnReturn = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.LeerFile - " + ex);
            }

            return(blnReturn);
        }