Пример #1
0
        static void UpdateSenderExample(Configuration configuration)
        {
            // For more details on senders please check https://docs.transferzero.com/docs/transaction-flow/#sender

            SendersApi sendersApi = new SendersApi(configuration);

            Sender sender = new Sender();

            sender.City = "London";

            SenderRequest senderRequest = new SenderRequest(sender: sender);

            try
            {
                SenderResponse response = sendersApi.PatchSender(Guid.Parse("73f382d0-ffff-ffff-ffff-e78d1a133b8a"), senderRequest);
                System.Console.WriteLine(response);
            }
            catch (ApiException e)
            {
                if (e.IsValidationError)
                {
                    SenderResponse response = e.ParseObject <SenderResponse>();
                    System.Console.WriteLine("Validation Error when trying to update sender!");
                    System.Console.WriteLine(response);
                    System.Console.WriteLine(response.Object.Errors);
                }
                else
                {
                    throw e;
                }
            }
        }
Пример #2
0
        private void ZabbixSender()
        {
            string connectionString = new SqlConnectionStringBuilder()
            {
                DataSource     = sqlServer,
                InitialCatalog = sqlBaseName,
                UserID         = sqlUser,
                Password       = sqlPass
            }.ConnectionString;

            Sender sender = new Sender(zabbixServer, zabbixPort);

            while (!serviceStop)
            {
                try
                {
                    using (SqlConnection oConnection = new SqlConnection(connectionString))
                    {
                        oConnection.Open();
                        SqlCommand command = new SqlCommand(
                            @"SELECT [Basename],[Param], AVG([Value]) as 'Value' FROM[Statistics]
                          GROUP BY[Basename],[Param]
                          TRUNCATE TABLE[Statistics]
                          ", oConnection);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                string send = String.Format("1C.Statistics[{0},{1}]", reader["BaseName"].ToString().Trim(), reader["Param"].ToString().Trim());
                                try
                                {
                                    SenderResponse response = sender.Send(zabbixNodeName, send, reader["Value"].ToString());
                                    logger.Debug(send);
                                    logger.Debug(response.Response);
                                    logger.Debug(response.Info);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex, "Ошибка отправки статистики в zabbix");
                                }
                            }
                        }
                        oConnection.Close();
                    }
                }
                catch (Exception ex) {
                    logger.Error(ex, "Ошибка запроса данных из SQL");
                }
                #region Задержка
                for (int i = 1; i < serviceThreadSleep; i++)
                {
                    if (serviceStop)
                    {
                        return;
                    }
                    Thread.Sleep(1000);
                }
                #endregion
            }
        }
Пример #3
0
        static Guid?CreateSenderExample(Configuration configuration)
        {
            // For more details on senders please check https://docs.transferzero.com/docs/transaction-flow/#sender

            SendersApi sendersApi = new SendersApi(configuration);
            Sender     sender     = new Sender(
                country: "UG",
                phoneCountry: "UG",
                phoneNumber: "752403639",
                email: "*****@*****.**",
                firstName: "test",
                lastName: "user",
                city: "Lagos",
                street: "Unknown 123",
                postalCode: "798983",
                birthDate: DateTime.Parse("1980-01-01"),
                ip: "127.0.0.1",
                addressDescription: "Description",
                documents: new List <Document>(),
                externalId: "SENDER-00001"
                );

            SenderRequest senderRequest = new SenderRequest(
                sender: sender
                );

            try
            {
                SenderResponse response = sendersApi.PostSenders(senderRequest);
                System.Console.WriteLine(response);
                return(response.Object.Id);
            }
            catch (ApiException e)
            {
                if (e.IsValidationError)
                {
                    SenderResponse response = e.ParseObject <SenderResponse>();
                    System.Console.WriteLine("Validation Error when trying to create sender!");
                    System.Console.WriteLine(response);
                    System.Console.WriteLine(response.Object.Errors);
                    return(null);
                }
                else
                {
                    throw e;
                }
            }
        }
Пример #4
0
        private void ZabbixSender()
        {
            List <User> userList = new List <User>();
            Sender      sender   = new Sender(Settings.ZabbixServer, Settings.ZabbixPort);

            while (!ЗавершениеРаботы)
            {
                bool errorExist = false;
                userList.Clear();
                #region Сбор состояний пользователей
                using (ITerminalServer server = Settings.manager.GetLocalServer())
                {
                    try
                    {
                        server.Open();
                        foreach (ITerminalServicesSession session in server.GetSessions())
                        {
                            try
                            {
                                if (session.UserAccount == null)
                                {
                                    continue;
                                }

                                if (Settings.IgnoreUsername.Contains(session.UserAccount.ToString()))
                                {
                                    continue;
                                }

                                int    state = 0;
                                double idle  = Math.Floor(session.IdleTime.TotalSeconds);

                                if (session.ConnectionState == Cassia.ConnectionState.Active || session.ConnectionState == Cassia.ConnectionState.Idle)
                                {
                                    if (idle < Settings.IdleTime)
                                    {
                                        state = 2;
                                    }
                                    else
                                    {
                                        state = 1;
                                    }
                                }

                                userList.Add(new User(session.UserAccount.ToString(), state));
                            }
                            catch (Exception ex)
                            {
                                Settings.logger.Error(ex, "Ошибка чтения состояния пользователя:");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Settings.logger.Error(ex, "Ошибка чтения списка пользователей:");
                    }
                }
                #endregion

                foreach (User usr in userList)
                {
                    Settings.logger.Debug("{0} = {1}", usr.Username, usr.Condition);
                }



                Settings.logger.Debug("Отправка данных в zabbix");
                foreach (ZabbixUser zabbix_usr in Settings.list)
                {
                    User usr = userList.Find(x => x.Equals(zabbix_usr.Username));
                    if (usr == null)
                    {
                        Settings.logger.Debug("{1} = {2}", zabbix_usr.ZabbixUsername, 0);

                        string send = String.Format("user.work[{0},{1}]", zabbix_usr.ZabbixUsername, Settings.ZabbixParam);
                        try
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, "0");

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                        catch (Exception ex)
                        {
                            Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                            errorExist = true;
                        }
                    }
                    else
                    {
                        Settings.logger.Debug("{0}({1}) = {2}", usr.Username, zabbix_usr.ZabbixUsername, usr.Condition);

                        string send = String.Format("user.work[{0},{1}]", zabbix_usr.ZabbixUsername, Settings.ZabbixParam);
                        try
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, usr.Condition.ToString());

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                        catch (Exception ex)
                        {
                            Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                            errorExist = true;
                        }
                    }
                }

                #region подсчет количества
                int _CountSummary = userList.Count;
                int _CountActive  = 0;
                int _CountIdle    = 0;
                int _CountOffline = 0;

                foreach (User usr in userList)
                {
                    if (usr.Condition == 2)
                    {
                        _CountActive++;
                    }
                    if (usr.Condition == 1)
                    {
                        _CountIdle++;
                    }
                    if (usr.Condition == 0)
                    {
                        _CountOffline++;
                    }
                }
                #endregion

                #region Отправка количества итого
                if (Settings.SendSummary)
                {
                    string send = String.Format("user.work[{0},{1}]", "Summary", Settings.ZabbixParam);
                    try
                    {
                        if (!errorExist)
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, _CountSummary.ToString());

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                    }
                    catch (Exception ex)
                    {
                        Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                        errorExist = true;
                    }
                }
                #endregion

                #region Отправка количества активных
                if (Settings.SendActive)
                {
                    string send = String.Format("user.work[{0},{1}]", "Active", Settings.ZabbixParam);
                    try
                    {
                        if (!errorExist)
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, _CountActive.ToString());

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                    }
                    catch (Exception ex)
                    {
                        Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                        errorExist = true;
                    }
                }
                #endregion

                #region Отправка количества отсутствующих
                if (Settings.SendIdle)
                {
                    string send = String.Format("user.work[{0},{1}]", "Idle", Settings.ZabbixParam);
                    try
                    {
                        if (!errorExist)
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, _CountIdle.ToString());

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                    }
                    catch (Exception ex)
                    {
                        Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                        errorExist = true;
                    }
                }
                #endregion

                #region Отправка количества отключенных
                if (Settings.SendOffline)
                {
                    string send = String.Format("user.work[{0},{1}]", "Offline", Settings.ZabbixParam);
                    try
                    {
                        if (!errorExist)
                        {
                            SenderResponse response = sender.Send(Settings.ZabbixNodename, send, _CountOffline.ToString());

                            Settings.logger.Debug(send);
                            Settings.logger.Debug(response.Response);
                            Settings.logger.Debug(response.Info);
                        }
                    }
                    catch (Exception ex)
                    {
                        Settings.logger.Error(ex, "Ошибка отправки данных в zabbix:");
                        errorExist = true;
                    }
                }
                #endregion
                Settings.logger.Debug("Окончание отправки данных в zabbix");


                for (int i = 0; (i <= Settings.Delay && !ЗавершениеРаботы); i += 1000)
                {
                    Thread.Sleep(1000);
                }
            }
        }