예제 #1
0
        public async Task <Repository <Candle> > GetCandleRepositoryAsync(string exchangeName, Instrument instrument, TimePeriod period)
        {
            var repo = new Repository <Candle>(_logger);

            var tableName = ExchangeUtils.GetCandleDataKey(exchangeName, instrument, period);

            if (_availableTables.All(x => x != tableName))
            {
                throw new IndexOutOfRangeException();
            }

            await repo.CreateTable(GetConnectionString(), ExchangeUtils.GetCandleDataKey(exchangeName, instrument, period));

            return(repo);
        }
예제 #2
0
        private void RegisterTableNames(IReadOnlyCollection <ExchangeConfig> exchangeConfigs)
        {
            _availableTables = new List <string>();

            var instruments = Enum.GetValues(typeof(Instrument)).Cast <Instrument>();
            var periods     = Enum.GetValues(typeof(TimePeriod)).Cast <TimePeriod>();

            foreach (var instrument in instruments)
            {
                foreach (var exchange in exchangeConfigs)
                {
                    var supportedPeriods = exchange.SupportedTimePeriods;

                    foreach (var period in supportedPeriods)
                    {
                        _availableTables.Add(ExchangeUtils.GetCandleDataKey(exchange.ExchangeName, instrument, period.Key));
                    }
                }
            }
        }
예제 #3
0
        private void DoSchedule(ScheduledAction Schedule)
        {
            // Correção de bug no Powershell. A data precisa estar no formato inglês.
            Collection <Command> cmd;

            if (Schedule.FullBackup)
            {
                mainLogger.WriteEntry("Executando agendamento de " + Schedule.Mailbox + " para " + Schedule.Target + " programado para " + Schedule.ScheduleTime + " com ID " + Schedule.Id + "\r\n" +
                                      "   - Exportação de Mailbox completa.");
                cmd = ExchangeUtils.ExportMailbox(Schedule.Id, Schedule.Mailbox, "*", "*", Schedule.Target);
            }
            else
            {
                mainLogger.WriteEntry("Executando agendamento de " + Schedule.Mailbox + " para " + Schedule.Target + " programado para " + Schedule.ScheduleTime + " com ID " + Schedule.Id + "\r\n" +
                                      "   - Exportação de Mailbox de (" + DateTime.Today.AddDays(-Schedule.LastDays).ToShortDateString() + ") até (" + DateTime.Today.ToShortDateString() + ")");
                cmd = ExchangeUtils.ExportMailbox(Schedule.Id, Schedule.Mailbox, DateTime.Today.AddDays(-Schedule.LastDays).ToShortDateString(), DateTime.Today.ToShortDateString(), Schedule.Target);
            }

            PSBGWorker exportWorker = new PSBGWorker(ServerUser, Utils.DecryptPassword(EncServerPass), ServerIP, cmd, 0);

            exportWorker.Completed += CmdCompleted;
            exportWorker.InitTask();
        }
예제 #4
0
        private void ScheduleAction(object sender, System.Timers.ElapsedEventArgs e)
        {
            mainLogger.WriteEntry("Backup Service Tick. Checking Scheduled Actions");
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            DateTime now = DateTime.Now;
            List <ScheduledAction> Schedules = dbman.GetScheduledActions();

            mainLogger.WriteEntry("Scheduled Actions: " + Schedules.Count);

            // Clean Requests
            Collection <Command> cmd          = ExchangeUtils.CleanDoneRequests();
            PSBGWorker           exportWorker = new PSBGWorker(ServerUser, Utils.DecryptPassword(EncServerPass), ServerIP, cmd, 0);

            exportWorker.InitTask();

            // Do Schedules
            foreach (ScheduledAction Schedule in Schedules)
            {
                if (Schedule.ScheduleTime.isOnDate(now))
                {
                    DoSchedule(Schedule);
                }
            }
        }
예제 #5
0
 public ChannelReader <PositionDto> StreamPosition(string exchange, Instrument instrument)
 {
     return(_hubControl.StreamPosition(ExchangeUtils.GetExchangePositionKey(exchange, instrument)));
 }
예제 #6
0
        private void AddOrRenameConnector(ref ConnectedMA MA, ref GALMA MAConfig, MVEntry mventry, CSEntry csentry = null)
        {
            //
            // All objects are provisioned as contacts
            //
            string cn                = null;
            int    numberToAppend    = 1;
            bool   successful        = false;
            bool   extendedNameTried = false;
            string extendedName      = null;
            string adminGroup        = null;
            bool   provisioningAdd   = false;
            int    cnLengthMax       = 0;
            string validatedName     = null;

            //
            // Add or Rename if only SynchronizationOU is defined
            //
            if ((MAConfig.SynchronizationOU == null) || MAConfig.SynchronizationOU.Equals(""))
            {
                return;
            }

            if (!mventry[COMMON_NAME].IsPresent || !mventry[MAIL_NICK_NAME].IsPresent || !mventry[TARGET_ADDRESS].IsPresent)
            {
                LogAndThrowUnexpectedDataException("Provisioning without cn, mailNickName or targetAddress");
            }

            if (null == csentry)
            {
                provisioningAdd = true;
            }

            cn = mventry[COMMON_NAME].Value.ToString();

            //
            // Active Directory does not distinguish CNs that differ only in use of diacritical marks (accents) etc.
            // whereas the sync service does. So force uniqueness by appending mailnickname to all CNs with extended
            // chars if doing so does not exceed CN max length.
            //
            IEnumerator cnEnum = cn.GetEnumerator();

            while (cnEnum.MoveNext())
            {
                if (Strings.AscW(cnEnum.Current.ToString()) > 127 && cn.Length + mventry[MAIL_NICK_NAME].Value.ToString().Length + 2 + RDN_TYPE.Length < AD_RDN_MAX_SIZE)
                {
                    cn = cn + "(" + mventry[MAIL_NICK_NAME].Value.ToString() + ")";
                    break;                     // TODO: might not be correct. Was : Exit While
                }
            }

            do
            {
                try {
                    //
                    // Create a DN for the new object, need UPPER case "CN=..."
                    //
                    string         rdn = RDN_TYPE + cn;
                    ReferenceValue dn  = MA.EscapeDNComponent(rdn).Concat(MAConfig.SynchronizationOU);

                    if (rdn.Length > AD_RDN_MAX_SIZE + RDN_TYPE.Length)
                    {
                        LogAndThrowUnexpectedDataException("RDN too long: " + rdn);
                    }

                    if (csentry == null)
                    {
                        //
                        // Try to add the object
                        //
                        //LoggingCs.Log("Adding " + dn.ToString());

                        csentry = ExchangeUtils.CreateMailEnabledContact(MA, dn, mventry[MAIL_NICK_NAME].Value.ToString(), mventry[TARGET_ADDRESS].Value.ToString());

                        adminGroup = GetAdminGroup(csentry);
                        if ((adminGroup != null))
                        {
                            //
                            // LegacyExhangeDN = adminGroup/cn=mailnickname-guid
                            //
                            validatedName = ValidateLegacyExhangeDN(mventry[MAIL_NICK_NAME].Value.ToCharArray());

                            if ((validatedName == null))
                            {
                                csentry[LEGACY_EXCHANGE_DN].Value = adminGroup + "/cn=" + System.Guid.NewGuid().ToString();
                            }
                            else
                            {
                                csentry[LEGACY_EXCHANGE_DN].Value = adminGroup + "/cn=" + validatedName + "-" + System.Guid.NewGuid().ToString();
                            }
                        }
                    }
                    else
                    {
                        //
                        // Try to rename the object
                        //
                        if (!csentry.DN.Equals(dn))
                        {
                            //LoggingCs.Log("Renaming " + dn.ToString());
                            csentry.DN = dn;
                        }
                    }
                    successful = true;
                } catch (MissingParentObjectException ex) {
                    //
                    // Typically the admin has to perform a full/delta import
                    // on the target CD, or disable provisioning until all
                    // forests are imported.
                    //
                    //LoggingCs.Log("Target MA " + MA.Name + " is not imported yet. " + "Please disable provisioning until all forests " + "are imported.");
                    throw ex;
                } catch (ObjectAlreadyExistsException ex) {
                    //
                    // If adding connector, throw away the instance to start over
                    //
                    if (provisioningAdd)
                    {
                        csentry = null;
                    }

                    //
                    // There is a duplicate object in the target AD,
                    // change the cn accordingly to avoid conflict.
                    //
                    if (!extendedNameTried)
                    {
                        extendedNameTried = true;
                        try {
                            if (mventry[DEPARTMENT].IsPresent)
                            {
                                extendedName = mventry[DEPARTMENT].Value;
                            }
                        } catch (NoSuchAttributeInObjectTypeException ex2) {
                        }
                    }

                    cn = null;
                    if (extendedName != null)
                    {
                        cn           = mventry[COMMON_NAME].Value + " (" + extendedName + ")";
                        extendedName = null;

                        if (cn.Length > AD_RDN_MAX_SIZE)
                        {
                            //
                            // If too long, we'll try without it
                            //
                            cn = null;
                        }
                    }


                    if (null == cn)
                    {
                        cn = mventry[COMMON_NAME].Value;

                        //
                        // To make sure that the number appended
                        // will not be truncated.
                        // The 2 spaces reserved is for "()"
                        //
                        cnLengthMax = AD_RDN_MAX_SIZE - (numberToAppend.ToString().Length + 2);
                        //
                        // If it's too long, we are going to truncate the
                        // name and preserve the number appended.
                        //
                        if (cn.Length > cnLengthMax)
                        {
                            cn = cn.Substring(0, cnLengthMax);
                        }

                        cn             = cn + "(" + numberToAppend.ToString() + ")";
                        numberToAppend = numberToAppend + 1;

                        if (numberToAppend > RETRY_NUM_LIMIT)
                        {
                            LogAndThrowUnexpectedDataException("Retry for " + mventry[COMMON_NAME].Value + " exceeds limit " + numberToAppend.ToString());
                        }
                    }
                }
            } while (!successful);
        }