Skip to content

Commit

Permalink
#4 Reduce warning count in solution by replacing ArgumentNullExceptio…
Browse files Browse the repository at this point in the history
…n with ArgumentException, add readonly list, added globalsuppressions.cs, wrapped ShouldProcess, refactored using statements
  • Loading branch information
ddemeyer committed Jan 27, 2019
1 parent 8c6a30e commit 4d5f7c4
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ protected override void EndProcessing()
WriteDebug($"Id[{baselineId}] {++current}/{_baselineItemsToProcess.Keys.Count}");
if (ShouldProcess(baselineId))
{
StringWriter stringWriter;
using (stringWriter = new StringWriter())
using (StringWriter stringWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
{
Expand All @@ -132,8 +131,8 @@ protected override void EndProcessing()
}
xmlWriter.WriteEndElement();
}
IshSession.Baseline25.Update(baselineId, stringWriter.ToString());
}
IshSession.Baseline25.Update(baselineId, stringWriter.ToString());
}
}
WriteObject(IshObject, true); // Incoming IshObject is not altered, already contains optional PSNoteProperty, so continuing the pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ protected override void EndProcessing()
WriteDebug($"Id[{baselineId}] {++current}/{_baselineItemsToProcess.Keys.Count}");
if (ShouldProcess(baselineId))
{
StringWriter stringWriter;
using (stringWriter = new StringWriter())
using (StringWriter stringWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
{
Expand All @@ -166,8 +165,8 @@ protected override void EndProcessing()
}
xmlWriter.WriteEndElement();
}
IshSession.Baseline25.Update(baselineId, stringWriter.ToString());
}
IshSession.Baseline25.Update(baselineId, stringWriter.ToString());
}
}
WriteObject(IshObject, true); // Incoming IshObject is not altered, already contains optional PSNoteProperty, so continuing the pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,14 @@ protected override void ProcessRecord()
metadata.ToXml(),
_ishData.Edt,
_ishData.ByteArray));
IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
var response2 = IshSession.DocumentObj25.GetMetadata(new DocumentObj25ServiceReference.GetMetadataRequest(
response.logicalId, response.version, Lng, resolution,
requestedMetadata.ToXml()));
string xmlIshObjects = response2.xmlObjectList;
IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
returnIshObjects.AddRange(retrievedObjects.Objects);
}

IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
var response2 = IshSession.DocumentObj25.GetMetadata(new DocumentObj25ServiceReference.GetMetadataRequest(
response.logicalId, response.version, Lng, resolution,
requestedMetadata.ToXml()));
string xmlIshObjects = response2.xmlObjectList;
IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
returnIshObjects.AddRange(retrievedObjects.Objects);
}

WriteVerbose("returned object count[" + returnIshObjects.Count + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public IshFolder ToIshFolder
/// <summary>
/// Initially holds incoming IshObject entries from the pipeline to correct the incorrect array-objects from Trisoft.Automation
/// </summary>
private List<IshObject> _retrievedIshObjects = new List<IshObject>();
private readonly List<IshObject> _retrievedIshObjects = new List<IshObject>();
#endregion

protected override void BeginProcessing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected override void ProcessRecord()
string resolution = Resolution ?? "";
var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update);

string version;
string version = "-1";
if (Edt != null && FilePath != null)
{
IshData ishData = new IshData(Edt, FilePath);
Expand All @@ -219,8 +219,8 @@ protected override void ProcessRecord()
requiredCurrentMetadata.ToXml(),
ishData.Edt,
ishData.ByteArray));
version = response.version;
}
version = response.version;
}
else
{
Expand All @@ -235,8 +235,8 @@ protected override void ProcessRecord()
resolution,
metadata.ToXml(),
requiredCurrentMetadata.ToXml()));
version = response.version;
}
version = response.version;
}
IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read);
var response2 = IshSession.DocumentObj25.GetMetadata(new GetMetadataRequest(LogicalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Trisoft.ISHRemote.Cmdlets.EDT
/// </example>
[Cmdlet(VerbsCommon.Add, "IshEDT", SupportsShouldProcess = true)]
[OutputType(typeof(IshEDT))]
public sealed class AddIshEDT : EDTCmdlet
public sealed class AddIshEdt : EDTCmdlet
{

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Trisoft.ISHRemote.Cmdlets.EDT
/// </example>
[Cmdlet(VerbsCommon.Find, "IshEDT", SupportsShouldProcess = false)]
[OutputType(typeof(IshEDT))]
public sealed class FindIshEDT : EDTCmdlet
public sealed class FindIshEdt : EDTCmdlet
{
/// <summary>
/// <para type="description">The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Trisoft.ISHRemote.Cmdlets.EDT
/// </example>
[Cmdlet(VerbsCommon.Get, "IshEDT", SupportsShouldProcess = false)]
[OutputType(typeof(IshEDT))]
public sealed class GetIshEDT : EDTCmdlet
public sealed class GetIshEdt : EDTCmdlet
{
/// <summary>
/// <para type="description">The IshSession variable holds the authentication and contract information. This object can be initialized using the New-IshSession cmdlet.</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Trisoft.ISHRemote.Cmdlets.EDT
/// </example>
[Cmdlet(VerbsCommon.Set, "IshEDT", SupportsShouldProcess = true)]
[OutputType(typeof(IshEDT))]
public sealed class SetIshEDT : EDTCmdlet
public sealed class SetIshEdt : EDTCmdlet
{

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected override void EndProcessing()
{
using (XmlReader xmlReader = XmlReader.Create(streamReader, _xmlReaderSettings))
{
while (xmlReader.Read()) { }
while (xmlReader.Read());
}
}
WriteObject(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,17 @@ protected override void ProcessRecord()
LanguageCombination,
metadata.ToXml(),
requiredCurrentMetadata.ToXml()));
// Get the metadata of the object
IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, publishMetadata, Enumerations.ActionMode.Read);
var response2 =
IshSession.PublicationOutput25.GetMetadata(new PublicationOutput25ServiceReference.
GetMetadataRequest(
LogicalId, response.version, OutputFormat, LanguageCombination,
requestedMetadata.ToXml()));
string xmlIshObjects = response2.xmlObjectList;
IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
returnedObjects.AddRange(retrievedObjects.Objects);
}

// Get the metadata of the object
IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, publishMetadata, Enumerations.ActionMode.Read);
var response2 =
IshSession.PublicationOutput25.GetMetadata(new PublicationOutput25ServiceReference.
GetMetadataRequest(
LogicalId, response.version, OutputFormat, LanguageCombination,
requestedMetadata.ToXml()));
string xmlIshObjects = response2.xmlObjectList;
IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
returnedObjects.AddRange(retrievedObjects.Objects);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,21 @@ protected override void ProcessRecord()
File.SetAttributes(FilePath, FileAttributes.Normal);
}
// Write it as a text file
using (var stream = new FileStream(FilePath, fileMode, FileAccess.ReadWrite))
Stream stream = null;
try
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, Encoding.UTF8))
stream = new FileStream(FilePath, fileMode, FileAccess.ReadWrite);
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
{
stream = null;
writer.Write(value);
}
}
finally
{
if (stream != null)
stream.Dispose();
}
}
}
WriteVerbose("returned object count[1]");
Expand Down
11 changes: 6 additions & 5 deletions Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
using System.Xml;
using Trisoft.ISHRemote.Interfaces;
using Trisoft.ISHRemote.Folder25ServiceReference;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
namespace Trisoft.ISHRemote.Cmdlets
{
/// <summary>
Expand All @@ -44,13 +46,13 @@ public abstract class TrisoftCmdlet : PSCmdlet

public readonly ILogger Logger;

private string _levelNameValueTypeSeparator = "--"; // consider removing and get from IshSession.NameHelper
private readonly string _levelNameValueTypeSeparator = "--"; // consider removing and get from IshSession.NameHelper
private int _tickCountStart;

private ProgressRecord _parentProgressRecord;
private readonly ProgressRecord _parentProgressRecord;
protected int _parentCurrent;
protected int _parentTotal;
private ProgressRecord _childProgressRecord;
private readonly ProgressRecord _childProgressRecord;

/// <summary>
/// Name of the PSVariable so you don't have to specify '-IshSession $ishSession' anymore, should be set by New-IshSession
Expand All @@ -69,7 +71,7 @@ public string LevelNameValueTypeSeparator
get { return _levelNameValueTypeSeparator; }
}

public TrisoftCmdlet()
protected TrisoftCmdlet()
{
Logger = TrisoftCmdletLogger.Instance();
TrisoftCmdletLogger.Initialize(this);
Expand Down Expand Up @@ -239,7 +241,6 @@ internal virtual Folder25ServiceReference.BaseFolder BaseFolderLabelToEnum(IshSe
BaseFolder.System,
new string[] { "'" + baseFolderLabel + "'" }, // Use faulty folder path with quotes added, so we can throw the expected exception with errorcode=102001
"");

return BaseFolder.Data;
}

Expand Down
28 changes: 28 additions & 0 deletions Source/ISHRemote/Trisoft.ISHRemote/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 All Rights Reserved by the SDL Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1751:Jump statements should not be used unconditionally", Justification = "<Pending>", Scope = "member", Target = "~M:Trisoft.ISHRemote.HelperClasses.NameHelper.GetPSNoteProperty(Trisoft.ISHRemote.Objects.Enumerations.ISHType[],Trisoft.ISHRemote.Objects.Public.IshMetadataField)~System.Management.Automation.PSNoteProperty")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S1481:Unused local variables should be removed", Justification = "<Pending>", Scope = "member", Target = "~M:Trisoft.ISHRemote.Cmdlets.Session.NewIshSession.ProcessRecord")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S1481:Unused local variables should be removed", Justification = "<Pending>", Scope = "member", Target = "~M:Trisoft.ISHRemote.Cmdlets.TrisoftCmdlet.BaseFolderLabelToEnum(Trisoft.ISHRemote.Objects.Public.IshSession,System.String)~Trisoft.ISHRemote.Folder25ServiceReference.BaseFolder")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S2342:Enumeration types should comply with a naming convention", Justification = "<Pending>", Scope = "type", Target = "~T:Trisoft.ISHRemote.Objects.Enumerations.ISHType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in camel case", Justification = "<Pending>", Scope = "type", Target = "~T:Trisoft.ISHRemote.Objects.Public.IshEDT")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Critical Code Smell", "S2365:Properties should not make collection or array copies", Justification = "<Pending>", Scope = "member", Target = "~P:Trisoft.ISHRemote.Objects.IshTypeFieldSetup.IshTypeFieldDefinition")]

1 change: 1 addition & 0 deletions Source/ISHRemote/Trisoft.ISHRemote/ISHRemote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<Compile Include="Cmdlets\User\RemoveIshUser.cs" />
<Compile Include="Cmdlets\User\SetIshUser.cs" />
<Compile Include="Cmdlets\User\UserCmdlet.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="HelperClasses\IshObfuscator.cs" />
<Compile Include="HelperClasses\NonClosingStreamWrapper.cs" />
<Compile Include="HelperClasses\NameHelper.cs" />
Expand Down
Loading

0 comments on commit 4d5f7c4

Please sign in to comment.