Skip to content

huangpf PR: dev <- Azure:dev #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ private static void GenerateModel(string fileName, Type omType, string modelName
CodeCompileUnit compileUnit = new CodeCompileUnit();
CodeNamespace codeNamespace = new CodeNamespace(ModelNamespace);
GenerateUsingDirectives(codeNamespace);
CodeTypeDeclaration codeType = new CodeTypeDeclaration(modelName);
codeType.IsClass = true;
codeType.TypeAttributes = TypeAttributes.Public;

var codeType = new CodeTypeDeclaration(modelName)
{
IsClass = true,
TypeAttributes = TypeAttributes.Public,
IsPartial = true, // allows us to provide some custom behaviours
};

codeNamespace.Types.Add(codeType);
compileUnit.Namespaces.Add(codeNamespace);

Expand Down Expand Up @@ -262,7 +267,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
CodeExpression[] codeArgumentReferences = new CodeExpression[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
bool isOmTypeArg= false;
bool isOmTypeArg = false;

string paramType = parameters[i].ParameterType.FullName;
if (OMtoPSClassMappings.ContainsKey(paramType))
Expand Down Expand Up @@ -296,7 +301,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
CodeAssignStatement omObjectAssignStatement = new CodeAssignStatement(new CodeVariableReferenceExpression(string.Format("{0}{1}", parameters[i].Name, "OmObject")), new CodeVariableReferenceExpression(string.Format("{0}.{1}", parameters[i].Name, OmObject)));
CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression(omObjectArgumentReference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));

// if the parameter is not null, use the omObject of the PS Wrapper class
// if the parameter is not null, use the omObject of the PS Wrapper class
constructor.Statements.Add(new CodeConditionStatement(nullCheck, omObjectAssignStatement));

passedInArg = string.Format("{0}{1}", parameters[i].Name, "OmObject");
Expand All @@ -311,7 +316,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
}

codeArgumentReferences[i] = new CodeArgumentReferenceExpression(passedInArg);
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
}

CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression(implementationType, codeArgumentReferences);
Expand All @@ -338,7 +343,6 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
(property.PropertyType.GetGenericTypeDefinition() == typeof(IList<>) || property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>));


CodeFieldReferenceExpression wrappedObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);
CodePropertyReferenceExpression wrappedObjectProperty = new CodePropertyReferenceExpression(wrappedObject, property.Name);
CodeFieldReferenceExpression fieldReference = null;
Expand All @@ -360,8 +364,8 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
codeProperty.Name = property.Name;
codeProperty.Type = new CodeTypeReference(propertyType);

// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
// the property.

if (isGenericCollection)
Expand Down Expand Up @@ -404,7 +408,7 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
CodeMethodInvokeExpression addToList = new CodeMethodInvokeExpression(listReference, "Add", createListItem);
loopStatement.Statements.Add(addToList);
}

// Initialize the backing field with the built list on first access of the property
CodeAssignStatement assignStatement;
if (property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Locks
public enum LockLevel
{
/// <summary>
/// The cannot delete lock.
/// The lock blocks delete.
/// </summary>
CanNotDelete,

/// <summary>
/// The lock blocks all updates and delete.
/// </summary>
ReadOnly
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2955,7 +2955,7 @@
<dev:version />
</command:details>
<maml:description>
<maml:para>Create a new resource lock. Resource Locks are useful to prevent accidental deletions of your azure resources. Once a lock is placed on a resource, it can't be deleted unless the lock is removed. </maml:para>
<maml:para>Create a new resource lock. Resource Lock is useful to prevent accidental deletion or update of your azure resource. Once a lock is placed on a resource, based on lock level it can't be deleted or updated unless the lock is removed. </maml:para>
<maml:para>If you find an issue with this cmdlet, please create an issue on https://github.com/Azure/azure-powershell/issues, with a lable "ResourceManager".</maml:para>
</maml:description>
<command:syntax>
Expand All @@ -2964,7 +2964,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3058,7 +3060,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3145,7 +3149,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3246,7 +3252,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3347,7 +3355,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3427,7 +3437,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed.</maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -3514,7 +3526,9 @@
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>LockLevel</maml:name>
<maml:description>
<maml:para>TThe level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
<dev:type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ function Test-ResourceLockCRUD
$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
Assert-AreEqual True $removed

#ReadOnly lock
$actual = New-AzureRMResourceLock -LockName $rname -LockLevel ReadOnly -Force -Scope $rg.ResourceId
Assert-AreEqual $expected.Name $actual.Name

$expected = Get-AzureRMResourceLock -LockName $rname -Scope $rg.ResourceId
Assert-AreEqual $expected.Properties.Level "ReadOnly"

$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
Assert-AreEqual True $removed
}
Loading