public AppSettings(string fileName)
        {
            if (LogsShouldBeEnabled)
            {
                PathForLog = SentinelMethods.PathBuilder(fileName);
                var setLogResult = SetLogs(PathForLog);
                if (setLogResult == "OK")
                {
                    LogIsEnabled = true;
                    NewLog       = new Log(PathForLog);
                }
            }

            WebHook = string.Format(Url, HookPart);
        }
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            var myMessage = "Here is my data: \n\n";

            myMessage += "//=======\n";
            myMessage += "//-------\n";
            var messageForLogs = "Here is my data: ";

            myMessage      += "BaseDir: " + SentinelMethods.GetBaseDir() + "\n";
            myMessage      += "//-------\n";
            messageForLogs += "BaseDir: " + SentinelMethods.GetBaseDir() + " | ";
            myMessage      += "Base EMS Url: " + SentinelMethods.UrlBuilder() + "\n";
            myMessage      += "//-------\n";
            messageForLogs += "Base EMS Url: " + SentinelMethods.UrlBuilder() + " | ";
            myMessage      += "Url for Login by PK: " + SentinelMethods.UrlBuilder(SentinelSettings.actionsList["loginpk"]) + "\n";
            myMessage      += "//-------\n";
            messageForLogs += "Url for Login by PK: " + SentinelMethods.UrlBuilder(SentinelSettings.actionsList["loginpk"]) + " | ";
            myMessage      += "Url for Get Info by PK: " + SentinelMethods.UrlBuilder(SentinelSettings.actionsList["getinfo"], SentinelSettings.testProductKey) + "\n";
            messageForLogs += "Url for Get Info by PK: " + SentinelMethods.UrlBuilder(SentinelSettings.actionsList["getinfo"], SentinelSettings.testProductKey);
            myMessage      += "//-------\n";
            var myAuthData = SentinelSettings.authXmlString;

            myAuthData      = myAuthData.Replace("{PLACEHOLDER_LOGIN}", SentinelSettings.vendorLogin).Replace("{PLACEHOLDER_PASSWORD}", SentinelSettings.vendorPassword);
            myHttpConnector = myHttpConnector.GetRequest("login", HttpMethod.Post, null, new KeyValuePair <string, string>("authenticationDetail", myAuthData)); // TODO vendor login
            XDocument response = XDocument.Parse(myHttpConnector.httpClientResponseStr);

            myMessage      += "Test Login by Vendor - auth response: \n" + response.ToString() + "\n";
            myMessage      += "//-------\n";
            myHttpConnector = myHttpConnector.GetRequest("logout", HttpMethod.Post, null, new KeyValuePair <string, string>("", ""), myHttpConnector); // TODO vendor logout
            myMessage      += "Test Logout status: \n" + myHttpConnector.httpClientResponseStatus.ToString() + " (If \"204\" or \"NoContent\" - this is mean all correct!)\n";
            myMessage      += "//-------\n";
            myMessage      += "//=======\n";

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Try to send response message - " + messageForLogs);
            }
            await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
        }
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            var myMessage      = "";
            var messageForLogs = "";
            var password       = "";

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Try to get Password from message: " + message.Text);
            }
            try
            {
                var tmpMass = message.Text.Split(" ", 1);
                foreach (string el in tmpMass)
                {
                    if (el.Contains("pass:"******"password:"******"p:"))
                    {
                        password = el.Split(":")[1];
                    }
                }
            }
            catch { }
            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Password is: " + password);
            }

            var isMaster = false;

            if (password == AppSettings.MasterPassword)
            {
                isMaster = true;
            }

            if (password == AppSettings.MasterPassword || password == AppSettings.AdminPassword)
            {
                myMessage      = "Here is list of" + (isMaster ? " FULL" : "") + " settings: \n\n";
                messageForLogs = "Here is list of" + (isMaster ? " FULL" : "") + " settings: ";
                myMessage     += "//=======\n";
                myMessage     += "\n";
                myMessage     += "// Bot Settings -------\n";
                //myMessage += "//---\n";
                myMessage      += "BotBuildVersion: " + Startup.myAppSettings.AppVersion + "\n";
                messageForLogs += "BotBuildVersion: " + Startup.myAppSettings.AppVersion + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotProtocol: " + ConfigurationManager.AppSetting["BotNetSettings:BotProtocol"] + "\n";
                messageForLogs += "BotProtocol: " + ConfigurationManager.AppSetting["BotNetSettings:BotProtocol"] + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotAddress: " + ConfigurationManager.AppSetting["BotNetSettings:BotAddress"] + "\n";
                messageForLogs += "BotAddress: " + ConfigurationManager.AppSetting["BotNetSettings:BotAddress"] + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotPort: " + ConfigurationManager.AppSetting["BotNetSettings:BotPort"] + "\n";
                messageForLogs += "BotPort: " + ConfigurationManager.AppSetting["BotNetSettings:BotPort"] + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotlUrl: " + AppSettings.Url + "\n";
                messageForLogs += "BotlUrl: " + AppSettings.Url + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotlHookPart: " + AppSettings.HookPart + "\n";
                messageForLogs += "BotlHookPart: " + AppSettings.HookPart + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotlFullUrl: " + string.Format(AppSettings.Url, AppSettings.HookPart) + "\n";
                messageForLogs += "BotlFullUrl: " + string.Format(AppSettings.Url, AppSettings.HookPart) + " | ";
                //myMessage += "//---\n";
                myMessage      += "BotName: " + AppSettings.Name + "\n";
                messageForLogs += "BotName: " + AppSettings.Name + " | ";
                if (isMaster)
                {
                    //myMessage += "//---\n";
                    myMessage      += "BotKey: " + AppSettings.Key + "\n";
                    messageForLogs += "BotKey: " + AppSettings.Key + " | ";
                }
                //myMessage += "//---\n";
                myMessage += "// End Bot Settings -------\n";
                myMessage += "\n";
                myMessage += "// EMS Settings -------\n";
                //myMessage += "//---\n";
                myMessage      += "IgnoreSSLStatus: " + SentinelSettings.ignoreSslCertStatus.ToString() + "\n";
                messageForLogs += "IgnoreSSLStatus: " + SentinelSettings.ignoreSslCertStatus.ToString() + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsProtocol: " + SentinelSettings.emsProtocol + "\n";
                messageForLogs += "EmsProtocol: " + SentinelSettings.emsProtocol + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsAddress: " + SentinelSettings.emsAddress + "\n";
                messageForLogs += "EmsAddress: " + SentinelSettings.emsAddress + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsPort: " + SentinelSettings.emsPort + "\n";
                messageForLogs += "EmsPort: " + SentinelSettings.emsPort + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsBaseDir: " + SentinelSettings.emsBaseDir + "\n";
                messageForLogs += "EmsBaseDir: " + SentinelSettings.emsBaseDir + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsWebServiceVersion: " + SentinelSettings.webServiceVersion + "\n";
                messageForLogs += "EmsWebServiceVersion: " + SentinelSettings.webServiceVersion + " | ";
                //myMessage += "//---\n";
                myMessage      += "EmsUrl: " + SentinelMethods.UrlBuilder() + "\n";
                messageForLogs += "EmsUrl: " + SentinelMethods.UrlBuilder() + " | ";
                //myMessage += "//---\n";
                myMessage      += "BatchCode: " + SentinelSettings.batchCode + "\n";
                messageForLogs += "BatchCode: " + SentinelSettings.batchCode + " | ";
                //myMessage += "//---\n";
                myMessage      += "VendorId: " + SentinelSettings.vendorId + "\n";
                messageForLogs += "VendorId: " + SentinelSettings.vendorId + " | ";
                if (isMaster)
                {
                    //myMessage += "//---\n";
                    myMessage      += "Vendor account login: "******"\n";
                    messageForLogs += "Vendor account login: "******" | ";
                    myMessage      += "Vendor account password: "******"\n";
                    messageForLogs += "Vendor account password: "******" | ";
                }
                //myMessage += "//---\n";
                myMessage += "// End EMS Settings -------\n";
                myMessage += "\n";
                myMessage += "// Custom logging -------\n";
                //myMessage += "//---\n";
                myMessage      += "LogsIsEnabled: " + Startup.myAppSettings.LogIsEnabled + "\n";
                messageForLogs += "LogsIsEnabled: " + Startup.myAppSettings.LogIsEnabled + " | ";
                //myMessage += "//---\n";
                myMessage      += "LogsAutoClearIsEnabled: " + Startup.myAppSettings.LogsAutoClearIsEnabled.ToString() + "\n";
                messageForLogs += "LogsAutoClearIsEnabled: " + Startup.myAppSettings.LogsAutoClearIsEnabled.ToString() + " | ";
                //myMessage += "//---\n";
                myMessage      += "LogsAutoClearDaysBeforeDelete: " + Startup.myAppSettings.LogsAutoClearDaysBeforeDelete + "\n";
                messageForLogs += "LogsAutoClearDaysBeforeDelete: " + Startup.myAppSettings.LogsAutoClearDaysBeforeDelete + " | ";
                //myMessage += "//---\n";
                myMessage += "// End Custom Logging -------\n";
                myMessage += "\n";
                myMessage += "// Storage Settings -------\n";
                //myMessage += "//---\n";
                myMessage      += "StorageAutoClearIsEnabled: " + Startup.myAppSettings.StorageAutoClearIsEnabled.ToString() + "\n";
                messageForLogs += "StorageAutoClearIsEnabled: " + Startup.myAppSettings.StorageAutoClearIsEnabled.ToString() + " | ";
                //myMessage += "//---\n";
                myMessage      += "StorageAutoClearDaysBeforeDelete: " + Startup.myAppSettings.StorageAutoClearDaysBeforeDelete + "\n";
                messageForLogs += "StorageAutoClearDaysBeforeDelete: " + Startup.myAppSettings.StorageAutoClearDaysBeforeDelete + " | ";
                //myMessage += "//---\n";
                myMessage += "// End Storage Settings -------\n";
                myMessage += "\n";
                myMessage += "// Test data -------\n";
                //myMessage += "//---\n";
                myMessage      += "TestProductKey: " + SentinelSettings.testProductKey + "\n";
                messageForLogs += "TestProductKey: " + SentinelSettings.testProductKey + " | ";
                //myMessage += "//---\n";
                myMessage += "// End Test data -------\n";
                myMessage += "\n";
                myMessage += "//=======\n";
            }
            else
            {
                myMessage      = "Wrong password, access denied!";
                messageForLogs = "Wrong password, access denied!";
            }

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Try to send response message - " + messageForLogs);
            }
            await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
        }
Ejemplo n.º 4
0
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            var myMessage    = "";
            var pKey         = "";
            var savingResult = "";
            var pathForSave  = "";
            var fileName     = "";

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Try to get Product Key from message: " + message.Text);
            }
            try { pKey = message.Text.Split(" ")[1]; } catch { }
            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Product Key is: " + pKey);
            }

            if (!SentinelMethods.ProductKeyAndAidValidator(pKey))
            {
                // Return error message if PK is invalid
                myMessage = "Product Key is invalid (format)! Please check Product key and try again. ";
            }
            else
            {
                // TODO some logics here...
                myHttpConnector = myHttpConnector.GetRequest("loginpk", HttpMethod.Post, null, new KeyValuePair <string, string>("productKey", pKey)); // TODO login first!
                if (myHttpConnector.httpClientResponseStatus == "OK")
                {
                    myHttpConnector.GetRequest(Name, HttpMethod.Get, pKey, new KeyValuePair <string, string>("productKey", pKey), myHttpConnector);

                    if (myHttpConnector.httpClientResponseStatus == "OK")
                    {
                        var tmpXml = SentinelSettings.pkInfoXmlString;
                        tmpXml = tmpXml.Replace("{PLACEHOLDER}", myHttpConnector.httpClientResponseStr);
                        XDocument pkInfoXml = XDocument.Parse(tmpXml);
                        fileName    = SentinelMethods.FileNameBuilder(Name);
                        pathForSave = SentinelMethods.PathBuilder(fileName);
                        if (!String.IsNullOrEmpty(pathForSave))
                        {
                            var tmp = SentinelSettings.pkInfoXmlString;
                            tmp = tmp.Replace("{PLACEHOLDER}", pkInfoXml.ToString());

                            savingResult = SentinelMethods.SaveFile(pathForSave, tmp);

                            if (savingResult == "OK")
                            {
                                myMessage = "File was saved in dir: " + pathForSave + "\n\n";
                            }
                            else
                            {
                                myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                            }
                        }
                    }
                    else
                    {
                        myMessage = "Get Info error: " + myHttpConnector.httpClientResponseStatus;
                    }
                }
                else
                {
                    myMessage = "Login error: " + myHttpConnector.httpClientResponseStatus;
                }
            }

            if (savingResult == "OK")
            {
                using (var fileStream = new FileStream(pathForSave, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await botClient.SendDocumentAsync(
                        chatId : chatId,
                        document : new InputOnlineFile(fileStream, fileName),
                        caption : "Here is info about your Product Key: " + pKey
                        );
                }
            }
            else
            {
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Try to send response message - " + myMessage);
                }
                await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
            }
        }
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            bool goNext = true;

            int maxFileSize = 8 * 1024 * 100; // 100Kb

            string myMessage    = "";
            string savingResult = "";
            string pathForSave  = "";
            string fileName     = "";
            string fileId       = "";
            string fileData     = "";
            string targetXml    = "";
            string haspId       = "";

            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            if (message.Type != Telegram.Bot.Types.Enums.MessageType.Document)
            {
                // Return error message if C2V is not provided
                myMessage = "C2V is missing! Please do not forget add C2V and try again. ";
                goNext    = false;
            }

            if (goNext)
            {
                fileName    = SentinelMethods.FileNameBuilder(Name, true);
                pathForSave = SentinelMethods.PathBuilder(fileName, true);

                if (!String.IsNullOrEmpty(pathForSave))
                {
                    fileId = message.Document.FileId;
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"File ID is: " + fileId);
                    }
                    var fileInfo = await botClient.GetFileAsync(fileId);

                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"File size is: " + fileInfo.FileSize.ToString() + " bits (Max file size is: " + maxFileSize.ToString() + " bit (((8 bit * 1024) byte * 100) Kb = 100Kb))");
                    }

                    if (fileInfo.FileSize < maxFileSize)
                    {
                        using (var saveFileStream = System.IO.File.Open(pathForSave, FileMode.Create))
                        {
                            await botClient.DownloadFileAsync(fileInfo.FilePath, saveFileStream);

                            savingResult = "OK";
                        }

                        if (savingResult == "OK")
                        {
                            fileData = await System.IO.File.ReadAllTextAsync(pathForSave);

                            if (Startup.myAppSettings.LogIsEnabled)
                            {
                                Log.Write("Incomming file(size: " + fileInfo.FileSize.ToString() + " bits) was saved in dir: " + pathForSave);
                            }
                        }
                        else
                        {
                            myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                            if (Startup.myAppSettings.LogIsEnabled)
                            {
                                Log.Write("Problem with saving file on server. Saving result: " + savingResult);
                            }
                            goNext = false;
                        }
                    }
                    else
                    {
                        myMessage = "Incomming file size is to big (more then 2 Mb): " + fileInfo.FileSize.ToString() + " bits\n\n";
                        if (Startup.myAppSettings.LogIsEnabled)
                        {
                            Log.Write(@"File size: " + fileInfo.FileSize.ToString() + " bits more then: " + maxFileSize.ToString());
                        }
                        goNext = false;
                    }
                }
                else
                {
                    goNext = false;
                }
            }

            if (goNext && savingResult == "OK")
            {
                targetXml = fileData;

                myHttpConnector = myHttpConnector.GetRequest(Name, HttpMethod.Post, null, new KeyValuePair <string, string>("targetXml", targetXml)); // TODO get updates!
                if (myHttpConnector.httpClientResponseStatus == "OK")
                {
                    XDocument v2cXml = XDocument.Parse(myHttpConnector.httpClientResponseStr);
                    haspId      = v2cXml.Descendants("hasp").FirstOrDefault().Attributes("id").FirstOrDefault().Value.ToString();
                    fileName    = SentinelMethods.FileNameBuilder(Name, key: haspId);
                    pathForSave = SentinelMethods.PathBuilder(fileName);
                    if (!String.IsNullOrEmpty(pathForSave))
                    {
                        savingResult = SentinelMethods.SaveFile(pathForSave, v2cXml.ToString());

                        if (savingResult == "OK")
                        {
                            using (var fileStream = new FileStream(pathForSave, FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                await botClient.SendDocumentAsync(
                                    chatId : chatId,
                                    document : new InputOnlineFile(fileStream, fileName),
                                    caption : "Here is your updates for Protection Key ID: " + v2cXml.Descendants("hasp").FirstOrDefault().Attributes("id").FirstOrDefault().Value.ToString()
                                    );

                                myMessage = "";
                                if (Startup.myAppSettings.LogIsEnabled)
                                {
                                    Log.Write("Updates for Protection Key ID: " + v2cXml.Descendants("hasp").FirstOrDefault().Attributes("id").FirstOrDefault().Value.ToString());
                                }
                            }
                        }
                        else
                        {
                            myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                            if (Startup.myAppSettings.LogIsEnabled)
                            {
                                Log.Write("Problem with saving file on server. Saving result: " + savingResult);
                            }
                        }
                    }
                }
                else
                {
                    myMessage = "Get Fetch Pending Updates error: " + myHttpConnector.httpClientResponseStatus;
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write("Get Fetch Pending Updates error: " + myHttpConnector.httpClientResponseStatus);
                    }
                }

                if (!String.IsNullOrEmpty(myMessage))
                {
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"Try to send response message - " + myMessage);
                    }
                    await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
                }
            }
            else
            {
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Try to send response message - " + myMessage);
                }
                await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
            }
        }
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            bool goNext = true;

            int maxFileSize = 8 * 1024 * 100; // 100Kb

            string myMessage    = "";
            string pKey         = "";
            string savingResult = "";
            string pathForSave  = "";
            string fileName     = "";
            string fileId       = "";
            string fileData     = "";
            string actXml       = SentinelSettings.activationXmlString;

            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            if (message.Type != Telegram.Bot.Types.Enums.MessageType.Document)
            {
                // Return error message if C2V is not provided
                myMessage = "C2V is missing! Please do not forget add C2V and try again. ";
                goNext    = false;
            }

            if (goNext)
            {
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Try to get Product Key from message: " + message.Caption);
                }
                try { pKey = message.Caption.Split(" ")[1]; } catch { goNext = false; }
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Product Key is: " + pKey);
                }

                if (String.IsNullOrEmpty(pKey) || !SentinelMethods.ProductKeyAndAidValidator(pKey))
                {
                    // Return error message if PK is invalid
                    myMessage = "Product Key is invalid (format)! Please check Product key and try again. ";
                    goNext    = false;
                }
            }

            if (goNext)
            {
                fileName    = SentinelMethods.FileNameBuilder(Name, true, pKey);
                pathForSave = SentinelMethods.PathBuilder(fileName, true);

                if (!String.IsNullOrEmpty(pathForSave))
                {
                    fileId = message.Document.FileId;
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"File ID is: " + fileId);
                    }
                    var fileInfo = await botClient.GetFileAsync(fileId);

                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"File size is: " + fileInfo.FileSize.ToString() + " bits (Max file size is: " + maxFileSize.ToString() + " bit (((8 bit * 1024) byte * 100) Kb = 100Kb))");
                    }

                    if (fileInfo.FileSize < maxFileSize)
                    {
                        using (var saveFileStream = System.IO.File.Open(pathForSave, FileMode.Create))
                        {
                            await botClient.DownloadFileAsync(fileInfo.FilePath, saveFileStream);

                            savingResult = "OK";
                        }

                        if (savingResult == "OK")
                        {
                            fileData = await System.IO.File.ReadAllTextAsync(pathForSave);

                            if (Startup.myAppSettings.LogIsEnabled)
                            {
                                Log.Write("Incomming file(size: " + fileInfo.FileSize.ToString() + " bits) was saved in dir: " + pathForSave);
                            }
                        }
                        else
                        {
                            myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                            if (Startup.myAppSettings.LogIsEnabled)
                            {
                                Log.Write("Problem with saving file on server. Saving result: " + savingResult);
                            }
                            goNext = false;
                        }
                    }
                    else
                    {
                        myMessage = "Incomming file size is to big (more then 2 Mb): " + fileInfo.FileSize.ToString() + " bits\n\n";
                        if (Startup.myAppSettings.LogIsEnabled)
                        {
                            Log.Write(@"File size: " + fileInfo.FileSize.ToString() + " bits more then: " + maxFileSize.ToString());
                        }
                        goNext = false;
                    }
                }
                else
                {
                    goNext = false;
                }
            }

            if (goNext && savingResult == "OK")
            {
                actXml          = actXml.Replace("{PLACEHOLDER}", fileData);
                myHttpConnector = myHttpConnector.GetRequest("loginpk", HttpMethod.Post, null, new KeyValuePair <string, string>("productKey", pKey)); // TODO login first!
                if (myHttpConnector.httpClientResponseStatus == "OK")
                {
                    myHttpConnector = myHttpConnector.GetRequest(Name, HttpMethod.Post, pKey, new KeyValuePair <string, string>("activationXml", actXml), myHttpConnector); // TODO activation!
                    if (myHttpConnector.httpClientResponseStatus == "OK")
                    {
                        XDocument activationResultXml = XDocument.Parse(myHttpConnector.httpClientResponseStr);
                        fileName    = SentinelMethods.FileNameBuilder(Name);
                        pathForSave = SentinelMethods.PathBuilder(fileName);
                        if (!String.IsNullOrEmpty(pathForSave))
                        {
                            XDocument v2cXml = XDocument.Parse(activationResultXml.Descendants("activationString").FirstOrDefault().Value);

                            savingResult = SentinelMethods.SaveFile(pathForSave, v2cXml.ToString());

                            if (savingResult == "OK")
                            {
                                using (var fileStream = new FileStream(pathForSave, FileMode.Open, FileAccess.Read, FileShare.Read))
                                {
                                    await botClient.SendDocumentAsync(
                                        chatId : chatId,
                                        document : new InputOnlineFile(fileStream, fileName),
                                        caption : "Here is your license by Product Key: " + pKey + "\n" + "AID: " + activationResultXml.Descendants("AID").FirstOrDefault().Value
                                        );

                                    myMessage = "";
                                    if (Startup.myAppSettings.LogIsEnabled)
                                    {
                                        Log.Write("License by Product Key: " + pKey + " | AID: " + activationResultXml.Descendants("AID").FirstOrDefault().Value);
                                    }
                                }
                            }
                            else
                            {
                                myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                                if (Startup.myAppSettings.LogIsEnabled)
                                {
                                    Log.Write("Problem with saving file on server. Saving result: " + savingResult);
                                }
                            }
                        }
                    }
                    else
                    {
                        myMessage = "Activation error: " + myHttpConnector.httpClientResponseStatus;
                        if (Startup.myAppSettings.LogIsEnabled)
                        {
                            Log.Write("Activation error: " + myHttpConnector.httpClientResponseStatus);
                        }
                    }
                }
                else
                {
                    myMessage = "Login error: " + myHttpConnector.httpClientResponseStatus;
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write("Login error: " + myHttpConnector.httpClientResponseStatus);
                    }
                }

                if (!String.IsNullOrEmpty(myMessage))
                {
                    if (Startup.myAppSettings.LogIsEnabled)
                    {
                        Log.Write(@"Try to send response message - " + myMessage);
                    }
                    await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
                }
            }
            else
            {
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Try to send response message - " + myMessage);
                }
                await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
            }
        }
        public override async Task Execute(Message message, TelegramBotClient botClient)
        {
            var chatId = message.Chat.Id;

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Get Chat Id for response message: " + chatId);
            }

            var myMessage    = "";
            var pKey         = "";
            var aid          = "";
            var savingResult = "";
            var pathForSave  = "";
            var fileName     = "";

            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"Try to get AID and Product Key from message: " + message.Text);
            }
            try {
                var tmpMass = message.Text.Split(" ");
                foreach (string el in tmpMass)
                {
                    if (el.Contains("AID:") || el.Contains("aid:"))
                    {
                        aid = el.Split(":")[1];
                    }
                    if (el.Contains("PK:") || el.Contains("pk:"))
                    {
                        pKey = el.Split(":")[1];
                    }
                }
            } catch { }
            if (Startup.myAppSettings.LogIsEnabled)
            {
                Log.Write(@"AID is: " + aid + " | Product Key is: " + pKey);
            }

            if (!SentinelMethods.ProductKeyAndAidValidator(aid) || !SentinelMethods.ProductKeyAndAidValidator(pKey))
            {
                // Return error message if AID or Product Key is invalid
                myMessage = "AID or Product Key is invalid (format)! Please check AID and Product Key and try again. ";
            }
            else
            {
                // TODO some logics here...
                myHttpConnector = myHttpConnector.GetRequest("loginpk", HttpMethod.Post, null, new KeyValuePair <string, string>("productKey", pKey)); // TODO login first!
                if (myHttpConnector.httpClientResponseStatus == "OK")
                {
                    myHttpConnector.GetRequest(Name, HttpMethod.Get, aid, new KeyValuePair <string, string>("aid", aid), myHttpConnector); // TODO get license by AID
                    if (myHttpConnector.httpClientResponseStatus == "OK")
                    {
                        XDocument response = XDocument.Parse(myHttpConnector.httpClientResponseStr);

                        fileName    = SentinelMethods.FileNameBuilder(Name);
                        pathForSave = SentinelMethods.PathBuilder(fileName);
                        if (!String.IsNullOrEmpty(pathForSave))
                        {
                            XDocument v2cXml = XDocument.Parse(response.Descendants("activationString").FirstOrDefault().Value);

                            savingResult = SentinelMethods.SaveFile(pathForSave, v2cXml.ToString());

                            if (savingResult == "OK")
                            {
                                myMessage = "File was saved in dir: " + pathForSave + "\n\n";
                            }
                            else
                            {
                                myMessage = "Problem with saving file on server. Saving result: " + savingResult + "\n\n";
                            }
                        }
                    }
                    else
                    {
                        myMessage = "Get license by AID error: " + myHttpConnector.httpClientResponseStatus;
                    }
                }
                else
                {
                    myMessage = "Login error: " + myHttpConnector.httpClientResponseStatus;
                }
            }

            if (savingResult == "OK")
            {
                using (var fileStream = new FileStream(pathForSave, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await botClient.SendDocumentAsync(
                        chatId : chatId,
                        document : new InputOnlineFile(fileStream, fileName),
                        caption : "Here is your license getting by AID: " + aid
                        );
                }
            }
            else
            {
                if (Startup.myAppSettings.LogIsEnabled)
                {
                    Log.Write(@"Try to send response message - " + myMessage);
                }
                await botClient.SendTextMessageAsync(chatId, myMessage, parseMode : Telegram.Bot.Types.Enums.ParseMode.Markdown);
            }
        }