Example #1
0
 public Producer()
 {
     ProducerId = IdUtils.GetId();
 }
Example #2
0
        public static RecoveryPointBase GetPSAzureVMRecoveryPoint(
            ServiceClientModel.RecoveryPointResource rp, ItemBase item)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            string containerName     = IdUtils.GetNameFromUri(containerUri);
            string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

            ServiceClientModel.IaasVMRecoveryPoint recoveryPoint =
                rp.Properties as ServiceClientModel.IaasVMRecoveryPoint;

            DateTime recoveryPointTime = DateTime.MinValue;

            if (recoveryPoint.RecoveryPointTime.HasValue)
            {
                recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTime;
            }
            else
            {
                throw new ArgumentNullException("RecoveryPointTime is null");
            }

            bool isInstantILRSessionActive =
                recoveryPoint.IsInstantIlrSessionActive.HasValue ?
                (bool)recoveryPoint.IsInstantIlrSessionActive : false;

            AzureVmRecoveryPoint rpBase = new AzureVmRecoveryPoint()
            {
                RecoveryPointId      = rp.Name,
                BackupManagementType = item.BackupManagementType,
                ItemName             = protectedItemName,
                ContainerName        = containerName,
                ContainerType        = item.ContainerType,
                RecoveryPointTime    = recoveryPointTime,
                RecoveryPointType    = recoveryPoint.RecoveryPointType,
                Id           = rp.Id,
                WorkloadType = item.WorkloadType,
                RecoveryPointAdditionalInfo = recoveryPoint.RecoveryPointAdditionalInfo,
                SourceVMStorageType         = recoveryPoint.SourceVMStorageType,
                SourceResourceId            = item.SourceResourceId,
                EncryptionEnabled           = recoveryPoint.IsSourceVMEncrypted.HasValue ?
                                              recoveryPoint.IsSourceVMEncrypted.Value : false,
                IlrSessionActive        = isInstantILRSessionActive,
                IsManagedVirtualMachine = recoveryPoint.IsManagedVirtualMachine.HasValue ?
                                          recoveryPoint.IsManagedVirtualMachine.Value : false,
                OriginalSAEnabled = recoveryPoint.OriginalStorageAccountOption.HasValue ?
                                    recoveryPoint.OriginalStorageAccountOption.Value : false,
                Zones = recoveryPoint.Zones,
                RehydrationExpiryTime = (DateTime?)null,
            };

            if (recoveryPoint.RecoveryPointTierDetails != null)
            {
                bool isHardenedRP         = false;
                bool isInstantRecoverable = false;
                bool isArchived           = false;
                bool isRehydrated         = false;

                foreach (ServiceClientModel.RecoveryPointTierInformation tierInfo in recoveryPoint.RecoveryPointTierDetails)
                {
                    if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Rehydrated)
                    {
                        if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
                        {
                            isRehydrated = true;

                            rpBase.RehydrationExpiryTime = (tierInfo.ExtendedInfo.ContainsKey("RehydratedRPExpiryTime")) ? DateTime.Parse(tierInfo.ExtendedInfo["RehydratedRPExpiryTime"]) : (DateTime?)null;
                        }
                    }

                    if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Valid)
                    {
                        if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.InstantRP)
                        {
                            isInstantRecoverable = true;
                        }
                        if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.HardenedRP)
                        {
                            isHardenedRP = true;
                        }
                        if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
                        {
                            isArchived = true;
                        }
                    }
                }

                if ((isHardenedRP && isArchived) || (isRehydrated))
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandardRehydrated;
                }
                else if (isInstantRecoverable && isHardenedRP)
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultStandard;
                }
                else if (isInstantRecoverable && isArchived)
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultArchive;
                }
                else if (isArchived)
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.VaultArchive;
                }
                else if (isInstantRecoverable)
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.Snapshot;
                }
                else if (isHardenedRP)
                {
                    rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandard;
                }
            }


            if (rpBase.EncryptionEnabled && recoveryPoint.KeyAndSecret != null)
            {
                rpBase.KeyAndSecretDetails = new KeyAndSecretDetails()
                {
                    SecretUrl     = recoveryPoint.KeyAndSecret.BekDetails.SecretUrl,
                    KeyUrl        = recoveryPoint.KeyAndSecret.KekDetails.KeyUrl,
                    SecretData    = recoveryPoint.KeyAndSecret.BekDetails.SecretData,
                    KeyBackupData = recoveryPoint.KeyAndSecret.KekDetails.KeyBackupData,
                    KeyVaultId    = recoveryPoint.KeyAndSecret.KekDetails.KeyVaultId,
                    SecretVaultId = recoveryPoint.KeyAndSecret.BekDetails.SecretVaultId,
                };
            }
            return(rpBase);
        }
Example #3
0
 public void Setup()
 {
     this.cliente = new Customer("Juan", "Perez", 0999999, "4809233-4");
     this.idUtils = new IdUtils();
 }
Example #4
0
        public T GetById(string id)
        {
            var key = IdUtils.CreateUrn <T>(id);

            return(this.GetValue(key));
        }
Example #5
0
 public static string GetSessionKey(string sessionId)
 {
     return(IdUtils.CreateUrn <IAuthSession>(sessionId));
 }
Example #6
0
 /// <summary>Converts an idValue to a safe path cache key.</summary>
 ///
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="idValue">The identifier value.</param>
 ///
 /// <returns>idValue as a string.</returns>
 public static string ToSafePathCacheKey <T>(string idValue)
 {
     return(IdUtils.CreateCacheKeyPath <T>(idValue));
 }
Example #7
0
        public void LongIncorrect2()
        {
            bool isValid = IdUtils.IdIsValid("9775707");

            Assert.False(isValid);
        }
        public bool ExpireIn(object id, TimeSpan expireIn)
        {
            var key = IdUtils.CreateUrn <T>(id);

            return(client.Expire(key, (int)expireIn.TotalSeconds) == RedisNativeClient.Success);
        }
Example #9
0
        public void IdCorrect3()
        {
            bool isValid = IdUtils.IdIsValid("9.775.7078");

            Assert.True(isValid);
        }
Example #10
0
        public void IdCorrect5()
        {
            bool isValid = IdUtils.IdIsValid("9....775707-8");

            Assert.True(isValid);
        }
 public void IdChecking()
 {
     Equals(IdUtils.IdIsValid("5.146.871-5"), false);
 }
 public void IdVacio()
 {
     Equals(IdUtils.IdIsValid(""), false);
 }
 public void IdFunciona()
 {
     Equals(IdUtils.IdIsValid(person.ID), true);
 }
Example #14
0
        // <summary>
        /// Helper function to convert ps recovery point model from service response.
        /// </summary>
        public static RecoveryPointBase GetPSAzureRecoveryPoints(
            ServiceClientModel.RecoveryPointResource rpResponse,
            ItemBase item)
        {
            if (rpResponse == null)
            {
                throw new ArgumentNullException(Resources.GetRPResponseIsNull);
            }

            RecoveryPointBase result = null;

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string containerName     = IdUtils.GetNameFromUri(containerUri);
            string protectedItemUri  = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
            string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

            if (rpResponse.Properties.GetType() ==
                typeof(ServiceClientModel.IaasVMRecoveryPoint))
            {
                ServiceClientModel.IaasVMRecoveryPoint recPoint =
                    rpResponse.Properties as ServiceClientModel.IaasVMRecoveryPoint;

                DateTime recPointTime = DateTime.MinValue;
                if (recPoint.RecoveryPointTime.HasValue)
                {
                    recPointTime = (DateTime)recPoint.RecoveryPointTime;
                }
                else
                {
                    throw new ArgumentNullException("RecoveryPointTime is null");
                }

                bool isInstantILRSessionActive =
                    recPoint.IsInstantILRSessionActive.HasValue ?
                    (bool)recPoint.IsInstantILRSessionActive : false;
                AzureVmRecoveryPoint vmResult = new AzureVmRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    EncryptionEnabled           = recPoint.IsSourceVMEncrypted.HasValue ?
                                                  recPoint.IsSourceVMEncrypted.Value : false,
                    IlrSessionActive    = isInstantILRSessionActive,
                    SourceResourceId    = item.SourceResourceId,
                    SourceVMStorageType = recPoint.SourceVMStorageType,
                    OriginalSAEnabled   = recPoint.OriginalStorageAccountOption.HasValue ?
                                          recPoint.OriginalStorageAccountOption.Value : false,
                };

                if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null)
                {
                    vmResult.KeyAndSecretDetails = new KeyAndSecretDetails()
                    {
                        SecretUrl     = recPoint.KeyAndSecret.BekDetails.SecretUrl,
                        KeyUrl        = recPoint.KeyAndSecret.KekDetails.KeyUrl,
                        SecretData    = recPoint.KeyAndSecret.BekDetails.SecretData,
                        KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData,
                        KeyVaultId    = recPoint.KeyAndSecret.KekDetails.KeyVaultId,
                        SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId,
                    };
                }

                result = vmResult;
            }

            if (rpResponse.Properties.GetType() ==
                typeof(ServiceClientModel.GenericRecoveryPoint))
            {
                ServiceClientModel.GenericRecoveryPoint recPoint =
                    rpResponse.Properties as ServiceClientModel.GenericRecoveryPoint;

                DateTime recPointTime = DateTime.MinValue;
                if (recPoint.RecoveryPointTime.HasValue)
                {
                    recPointTime = (DateTime)recPoint.RecoveryPointTime;
                }
                else
                {
                    throw new ArgumentNullException("RecoveryPointTime is null");
                }

                AzureSqlRecoveryPoint sqlResult = new AzureSqlRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    SourceResourceId            = item.SourceResourceId,
                    FriendlyName = recPoint.FriendlyName
                };

                result = sqlResult;
            }
            return(result);
        }
Example #15
0
        public void VerificationIncorrect()
        {
            bool isValid = IdUtils.IdIsValid("977570759");

            Assert.False(isValid);
        }
Example #16
0
        /// <summary>
        /// Helper function to convert ps recovery points list model from service response.
        /// </summary>
        public static List <RecoveryPointBase> GetPSAzureRecoveryPoints(
            List <ServiceClientModel.RecoveryPointResource> rpList,
            ItemBase item)
        {
            if (rpList == null)
            {
                throw new ArgumentNullException("RPList");
            }

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            string containerName     = IdUtils.GetNameFromUri(containerUri);
            string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

            List <RecoveryPointBase> result = new List <RecoveryPointBase>();

            foreach (ServiceClientModel.RecoveryPointResource rp in rpList)
            {
                if (rp.Properties.GetType() == typeof(ServiceClientModel.IaasVMRecoveryPoint))
                {
                    ServiceClientModel.IaasVMRecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.IaasVMRecoveryPoint;

                    DateTime recPointTime = DateTime.MinValue;
                    if (recPoint.RecoveryPointTime.HasValue)
                    {
                        recPointTime = (DateTime)recPoint.RecoveryPointTime;
                    }
                    else
                    {
                        throw new ArgumentNullException("RecoveryPointTime is null");
                    }

                    bool isInstantILRSessionActive =
                        recPoint.IsInstantILRSessionActive.HasValue ?
                        (bool)recPoint.IsInstantILRSessionActive : false;

                    AzureVmRecoveryPoint rpBase = new AzureVmRecoveryPoint()
                    {
                        RecoveryPointId      = rp.Name,
                        BackupManagementType = item.BackupManagementType,
                        ItemName             = protectedItemName,
                        ContainerName        = containerName,
                        ContainerType        = item.ContainerType,
                        RecoveryPointTime    = recPointTime,
                        RecoveryPointType    = recPoint.RecoveryPointType,
                        Id           = rp.Id,
                        WorkloadType = item.WorkloadType,
                        RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                        SourceVMStorageType         = recPoint.SourceVMStorageType,
                        SourceResourceId            = item.SourceResourceId,
                        EncryptionEnabled           = recPoint.IsSourceVMEncrypted.HasValue ?
                                                      recPoint.IsSourceVMEncrypted.Value : false,
                        IlrSessionActive  = isInstantILRSessionActive,
                        OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ?
                                            recPoint.OriginalStorageAccountOption.Value : false,
                    };
                    result.Add(rpBase);
                }

                if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
                {
                    ServiceClientModel.GenericRecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.GenericRecoveryPoint;

                    DateTime recPointTime = DateTime.MinValue;
                    if (recPoint.RecoveryPointTime.HasValue)
                    {
                        recPointTime = (DateTime)recPoint.RecoveryPointTime;
                    }
                    else
                    {
                        throw new ArgumentNullException("RecoveryPointTime is null");
                    }

                    AzureSqlRecoveryPoint rpBase = new AzureSqlRecoveryPoint()
                    {
                        RecoveryPointId      = rp.Name,
                        BackupManagementType = item.BackupManagementType,
                        ItemName             = protectedItemName,
                        ContainerName        = containerUri,
                        ContainerType        = item.ContainerType,
                        RecoveryPointTime    = recPointTime,
                        RecoveryPointType    = recPoint.RecoveryPointType,
                        Id           = rp.Id,
                        WorkloadType = item.WorkloadType,
                        RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                        FriendlyName = recPoint.FriendlyName,
                    };

                    result.Add(rpBase);
                }
            }

            return(result);
        }
Example #17
0
        public void DigitIncorrect()
        {
            bool isValid = IdUtils.IdIsValid("aaaaaaaa");

            Assert.False(isValid);
        }
        public bool ExpireAt(object id, DateTime expireAt)
        {
            var key = IdUtils.CreateUrn <T>(id);

            return(client.ExpireAt(key, expireAt.ToUnixTime()) == RedisNativeClient.Success);
        }
Example #19
0
        public void EmptyIncorrect()
        {
            bool isValid = IdUtils.IdIsValid("");

            Assert.False(isValid);
        }
Example #20
0
 /// <summary>A T extension method that converts an entity to an URN.</summary>
 ///
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="id">The identifier.</param>
 ///
 /// <returns>entity as a string.</returns>
 public static string ToUrn <T>(object id)
 {
     return(IdUtils.CreateUrn <T>(id));
 }
Example #21
0
        public void NullIncorrect()
        {
            bool isValid = IdUtils.IdIsValid(null);

            Assert.False(isValid);
        }
Example #22
0
 /// <summary>
 /// Returns key with explicit object type and id.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public string UrnKey(Type type, object id)
 {
     return(String.Concat(NamespacePrefix, IdUtils.CreateUrn(type, id)));
 }
Example #23
0
        public static void SaveAll <T>(this IDbCommand dbCommand, IEnumerable <T> objs)
            where T : new()
        {
            var saveRows = objs.ToList();

            var firstRow = saveRows.FirstOrDefault();

            if (Equals(firstRow, default(T)))
            {
                return;
            }

            var defaultIdValue = ReflectionUtils.GetDefaultValue(IdUtils.GetId(firstRow).GetType());

            var idMap = defaultIdValue != null
                                ? saveRows.Where(x => !defaultIdValue.Equals(IdUtils.GetId(x))).ToDictionary(x => IdUtils.GetId(x))
                                : saveRows.Where(x => IdUtils.GetId(x) != null).ToDictionary(x => IdUtils.GetId(x));

            var existingRowsMap = dbCommand.GetByIds <T>(idMap.Keys).ToDictionary(x => IdUtils.GetId(x));

            using (var dbTrans = dbCommand.Connection.BeginTransaction())
            {
                dbCommand.Transaction = dbTrans;

                foreach (var saveRow in saveRows)
                {
                    var id = IdUtils.GetId(saveRow);
                    if (id != defaultIdValue && existingRowsMap.ContainsKey(id))
                    {
                        dbCommand.Update(saveRow);
                    }
                    else
                    {
                        dbCommand.Insert(saveRow);
                    }
                }

                dbTrans.Commit();
            }
        }
Example #24
0
 public void TestCIValida() // Cambiá el nombre para indicar qué estás probando
 {
     Assert.True(IdUtils.IdIsValid(cliente.ID));
 }
Example #25
0
 public Society()
 {
     SocietyId = IdUtils.GetId();
 }
Example #26
0
 /// <summary>
 /// Returns key with explicit object id.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 internal string UrnKey <T>(object id)
 {
     return(string.Concat(NamespacePrefix, IdUtils.CreateUrn <T>(id)));
 }
Example #27
0
 public DefaultTransport(IRpcContext <TMessage> context)
 {
     this._context = context;
     this.Id       = IdUtils.NewId();
 }