Exemplo n.º 1
0
        public static void startSendSMS()
        {
            listOfRecipients = ReadJSON.getListProgramming(FileUtil.filePathJSONProgramming);

            if (listOfRecipients != null)
            {
                if (listOfRecipients != null && listOfRecipients.Count != 0)
                {
                    foreach (VideoproiectiePojo currentRecipient in listOfRecipients)
                    {
                        String serviceResponse = SendSmsAPI.SendSMSToRecipient(currentRecipient);
                        //mesaje in eventViewer de succes respectiv eroare.
                        if (serviceResponse.Contains("\"status\":\"success\""))
                        {
                            String notification = "SMS trimis cu succes catre " + currentRecipient.Username + " la nr tel " + currentRecipient.PhoneNumber + " " + " In data de " + DateTime.Now;
                            LogMessage.PrintEventMessage(notification);
                            EmailUtil.SendEmailToAdministrator(notification, "Notification sending SMS");
                        }
                        else
                        {
                            HandlerErrorsUtil.handlerErrorFromService(serviceResponse);
                        }
                    }
                }
                else
                {
                    HandlerErrorsUtil.handlerWarningFromFileJSON(1);
                }
            }
            else
            {
                HandlerErrorsUtil.handlerWarningFromFileJSON(2);
            }
        }
        public void startApp()
        {
            listWithAllDataFromJSON = FileUtil.GetListFromJSONFile();

            if (listWithAllDataFromJSON != null)
            {
                listOfRecipients = ContentParserUtil.GetListOfRecipients(listWithAllDataFromJSON);
                if (listOfRecipients != null && listOfRecipients.Count != 0)
                {
                    foreach (ProgramareVideoproiectiePojo currentRecipient in listOfRecipients)
                    {
                        String serviceResponse = SendSMSUtil.SendSMSToRecipient(currentRecipient);
                        //mesaje in eventViewer de succes respectiv eroare.
                        if (serviceResponse.Contains("\"status\":\"success\""))
                        {
                            LogMessage.PrintEventMessage("Mesaj trimis cu succes catre " + currentRecipient.Username + " in data de " + DateTime.Now);
                        }
                        else
                        {
                            HandlerErrorsUtil.handlerErrorFromService(serviceResponse);
                        }
                    }
                }
                else
                {
                    HandlerErrorsUtil.handlerWarningFromFileJSON(1);
                }

                Console.ReadLine();
            }
            else
            {
                HandlerErrorsUtil.handlerWarningFromFileJSON(2);
            }
        }
Exemplo n.º 3
0
        public static List <UserDateProgrammingPojo> getDataFromGoogleSheetAPI()
        {
            List <UserDateProgrammingPojo> extractedData = null;

            try
            {
                // If modifying these scopes, delete your previously saved credentials
                // at ~/.credentials/sheets.googleapis.com-dotnet-quickstart.json
                string[]       Scopes          = { SheetsService.Scope.SpreadsheetsReadonly };
                string         ApplicationName = "Google Sheets API .NET Quickstart";
                UserCredential credential;

                using (var stream =
                           new FileStream(FileUtil.credentialsJSONPath, FileMode.Open, FileAccess.Read))
                {
                    string credPath = FileUtil.credPathForGoogleSheetApi;

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Google Sheets API service.
                var service = new SheetsService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                // Define request parameters.
                String spreadsheetId = "1CXbZGgYEiUqolQgACSFocOqWoC1kGn_0FadAE35r4Q4";


                StringBuilder range = new StringBuilder();
                range.Append(getSheetName());
                range.Append("!B4:K7");


                SpreadsheetsResource.ValuesResource.GetRequest request =
                    service.Spreadsheets.Values.Get(spreadsheetId, range.ToString());


                // Prints the names and majors of students in a sample spreadsheet:
                // https://docs.google.com/spreadsheets/d/1CXbZGgYEiUqolQgACSFocOqWoC1kGn_0FadAE35r4Q4/edit
                ValueRange response            = request.Execute();
                IList <IList <Object> > values = response.Values;

                if (values != null && values.Count > 0)
                {
                    int count = 0;
                    extractedData = new List <UserDateProgrammingPojo>();
                    foreach (var row in values)
                    {
                        count = 0;
                        UserDateProgrammingPojo currentUser = new UserDateProgrammingPojo();
                        foreach (var currentValue in row)
                        {
                            count++;
                            if (count % 2 == 0)
                            {
                                Console.WriteLine("User="******"Data=" + currentValue);
                                currentUser.Date = currentValue.ToString();
                            }
                        }
                    }
                }
                return(extractedData);
            }
            catch (Exception ex)
            {
                HandlerErrorsUtil.handlerErrorFromGoogleAPI(ex.Message);
                return(null);
            }
        }