Skip to content

Commit

Permalink
Added initial integrity check command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Reddick committed Jan 30, 2014
1 parent 58e1ba6 commit 63d9775
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 79 deletions.
202 changes: 202 additions & 0 deletions Commands/IntegrityCheckCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
| Version 10.1.1
| Copyright 2012 Esri
|
| 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.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Esri_Telecom_Tools.Helpers;
using ESRI.ArcGIS.Geodatabase;
using Esri_Telecom_Tools.Core.Utils;
using ESRI.ArcGIS.ADF;
using System.Diagnostics;


namespace Esri_Telecom_Tools.Commands
{
public class IntegrityCheckCommand : ESRI.ArcGIS.Desktop.AddIns.Button
{
// For logging messages
protected static LogHelper _logHelper = LogHelper.Instance();
private TelecomWorkspaceHelper _wkspHelper = TelecomWorkspaceHelper.Instance();

public IntegrityCheckCommand()
{
}

protected override void OnClick()
{
try
{
if (_wkspHelper.CurrentWorkspace == null)
{
MessageBox.Show("You must select and open a telecom workspace before running this tool");
return;
}

DialogResult res = MessageBox.Show(null, "This test may run for a considerable time (15+ minutes) and may make modifications to the database to resolve issues. \n\nConsider taking a backup before doing this. \n\nDo you wish to proceed?", "DB Integrity Check", MessageBoxButtons.OKCancel);
if (res != DialogResult.OK)
return;

IFeatureClass cableFc = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
if (cableFc == null) { return; }

IFeatureWorkspace fworkspace =_wkspHelper.CurrentWorkspace;
if (fworkspace == null) { return; }

// --------------------------------------------
// Check the integrity of the cable feature class
// --------------------------------------------
IRelationshipClass fiberCableToFiberRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToFiberRelClassName);
IRelationshipClass fiberCableToBufferRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToBufferRelClassName);
IFeature feature;
bool badCable = false;
bool badBuffers = false;
bool badFibers = false;
bool conversionRequired = false;
IWorkspaceEdit2 edit = fworkspace as IWorkspaceEdit2;
ITransactions transaction = edit as ITransactions;

edit.StartEditing(true);
edit.StartEditOperation();

IQueryFilter qf = new QueryFilter();
qf.AddField(ConfigUtil.NumberOfBuffersFieldName);
qf.AddField(ConfigUtil.NumberOfFibersFieldName);
qf.AddField(ConfigUtil.IpidFieldName);

using (ComReleaser comReleaser = new ComReleaser())
{
IFeatureCursor fCursor = (IFeatureCursor)cableFc.Update(qf, false);
ICursor pCursor = fCursor as ICursor;
comReleaser.ManageLifetime(fCursor);

int buffersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfBuffersFieldName);
int fibersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfFibersFieldName);
int ipidFieldIdx = cableFc.FindField(ConfigUtil.IpidFieldName);

int count = 0;
while ((feature = fCursor.NextFeature()) != null)
{
// Cables should have non null field values
if (feature.get_Value(ipidFieldIdx) == DBNull.Value)
{
badCable = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL IPID value");
continue;
}
if (feature.get_Value(buffersFieldIdx) == DBNull.Value)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
if (feature.get_Value(fibersFieldIdx) == DBNull.Value)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL fiber field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}

int bufferCount = (int)feature.get_Value(buffersFieldIdx);
int fiberCount = (int)feature.get_Value(fibersFieldIdx);

// Cables should have non zero values
if (bufferCount == 0)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
if (fiberCount == 0)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 strand field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}

// Cables should have relationships
int rcBufferCount = fiberCableToBufferRc.GetObjectsRelatedToObject(feature).Count;
if (rcBufferCount == 0)
{
badBuffers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related buffers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}
int rcFiberCount = fiberCableToFiberRc.GetObjectsRelatedToObject(feature).Count;
if (rcFiberCount == 0)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related fibers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}

// Buffer field count & relationships to buffers not matching
if (bufferCount != rcBufferCount)
{
badBuffers = true;
String output = "Expected: " + bufferCount + " Found: " + rcBufferCount + " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString();
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with buffer count->relationship mismatch", output);
continue;
}

// other checks
if (rcFiberCount % rcBufferCount != 0)
{
badFibers = true;
_logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Fiber Cable with invalid strand count - (relationships % buffercount) is non zero", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
continue;
}

// we must be dealing with a total count (convert to per buffer tube value)
if (fiberCount == rcFiberCount && bufferCount > 1)
{
count++;
Debug.Write(count + " Strand Total to Strands Per Buffer conversion", " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString() + "\n");
conversionRequired = true;
// _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Strand Total to Strands Per Buffer conversion", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
feature.set_Value(fibersFieldIdx, rcFiberCount / rcBufferCount);
feature.Store();
}
}
}
edit.StopEditOperation();
edit.StopEditing(true);

if (badCable)
MessageBox.Show("Database integrity issues were detected. Found invalid Fiber Cable. Please see the log file for more details");
if (badBuffers)
MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with buffer count issues. Please see the log file for more details");
if (badFibers)
MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with strands count issues. Please see the log file for more details");
if (conversionRequired)
MessageBox.Show("Database integrity issues were detected. Strand Total to Strands Per Buffer conversion was done.");
}
catch (Exception e)
{
_logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Integrity Check Error", e.Message);
}

MessageBox.Show("The results of the DB checks are listed in the tools Log window");
}

protected override void OnUpdate()
{
}
}
}
Binary file modified Config.Designer.cs
Binary file not shown.
8 changes: 5 additions & 3 deletions Config.esriaddinx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<Image>Images\Esri Telecom Tools.png</Image>
<Author>Esri., Inc.</Author>
<Company>Esri., Inc.</Company>
<Date>11/6/2013</Date>
<Date>1/29/2014</Date>
<Targets>
<Target name="Desktop" version="10.2"/>
<Target name="Desktop" version="10.1"/>
<Target name="Desktop" version="10.2" />
<Target name="Desktop" version="10.1" />
</Targets>
<AddIn language="CLR" library="esriTelcoTools.dll" namespace="Esri_Telecom_Tools.Extension">
<ArcMap>
Expand All @@ -20,6 +20,7 @@
<Button onDemand="false" id="esriTelcoTools_FiberDeviceConnectionCommand" class="Esri_Telecom_Tools.Commands.FiberDeviceConnectionCommand" message="View or edit the splicing information between selected devices and cables." caption="View Or Edit Fiber Device Connections" tip="View Or Edit Fiber Device Connections" category="Add-In Controls" image="Images\FiberDeviceConnectionCommand.png" />
<Button onDemand="false" id="esriTelcoTools_TelecomToolsLogCommand" class="Esri_Telecom_Tools.Commands.TelecomToolsLogCommand" message="Telecom Tools Log" caption="Telecom Tools Log" tip="Telecom Tools Log" category="Add-In Controls" image="Images\LogCommand.png" />
<Button onDemand="false" id="esriTelcoTools_CloseWorkspaceCommand" class="Esri_Telecom_Tools.Commands.CloseWorkspaceCommand" message="Closes the current telecom workspace and stops any editing session." caption="Close Workspace" tip="Close workspace" category="Add-In Controls" image="Images\CloseWorkspaceCommand.png" />
<Button onDemand="false" id="esriTelcoTools_IntegrityCheckCommand" class="Esri_Telecom_Tools.Commands.IntegrityCheckCommand" message="Run DB Integrity Check" caption="DB Integrity Check" tip="Run DB Integrity Check" category="Add-In Controls" image="Images\IntegrityCheckCommand_1.png" />
</Commands>
<Toolbars>
<Toolbar id="esriTelcoTools_Fiber_Toolbar" caption="Esri Fiber Editing" showInitially="true">
Expand All @@ -35,6 +36,7 @@
<Tool refID="esriTelcoTools_FiberTraceCommand" />
<Tool refID="esriTelcoTools_FiberDeviceConnectionCommand" />
<Tool refID="esriTelcoTools_TelecomToolsLogCommand" />
<Tool refID="esriTelcoTools_IntegrityCheckCommand" />
</Items>
</Toolbar>
</Toolbars>
Expand Down
10 changes: 9 additions & 1 deletion Esri Telecom Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>false</RegisterForComInterop>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<ItemGroup>
<Reference Include="ESRI.ArcGIS.ADF.Connection.Local, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ESRI.ArcGIS.ADF.Local, Version=10.2.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ESRI.ArcGIS.ArcMap, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>False</EmbedInteropTypes>
Expand Down Expand Up @@ -124,6 +127,7 @@
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\IntegrityCheckCommand.cs" />
<Compile Include="Commands\CloseWorkspaceCommand.cs" />
<Compile Include="Commands\OpenWorkspaceCommand.cs" />
<Compile Include="Commands\TelecomToolsLogCommand.cs" />
Expand Down Expand Up @@ -311,6 +315,8 @@
<AddInContent Include="Images\close-application.png" />
<AddInContent Include="Images\CloseWorkspaceCommand.png" />
<AddInContent Include="Images\Folder.png" />
<AddInContent Include="Images\IntegrityCheckCommand.png" />
<AddInContent Include="Images\IntegrityCheckCommand_1.png" />
</ItemGroup>
<ItemGroup>
<COMReference Include="MSXML2">
Expand All @@ -332,11 +338,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Debug\</OutputPath>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<LangVersion>default</LangVersion>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
Expand Down
Loading

0 comments on commit 63d9775

Please sign in to comment.