public static void TraceIsolationSummary(IApplication app, string sourceFLName, string valveFLName, string operableFieldNameValve, string operableFieldNameSource,
double snapTol, bool processEvent, string[] opValues, string addSQL, bool traceIndeterminate, bool ZeroSourceCont,
string mainsFLName, string meterFLName, string metersCritFieldName, string metersCritValue,
string traceSum_LayerName, string traceSum_FacilityIDField, string traceSum_DateFieldName, string traceSum_ValveCountFieldName,
string traceSum_MeterCountFieldName, string traceSum_CritMeterCountFieldName, string traceSum_CommentsFieldName,
bool saveEntireLine)
{
IFeatureLayer mainsFL = null;
IFeatureLayer resultsLayer = null;
IFeatureClass mainFC = null;
INetworkClass mainsNetwork = null;
IFeatureClass resultsFC = null;
IFeatureSelection mainsFS = null;
IFeature pMainsFeat = null;
IProgressDialogFactory pProDFact = null;
IStepProgressor pStepPro = null;
IProgressDialog2 pProDlg = null;
ITrackCancel pTrkCan = null;
IWorkspaceEdit pWSEdit = null;
IFeatureCursor pFC = null;
IFeatureCursor pInsCur = null;
// IFeatureClassLoad featureClassLoad = null;
// ISchemaLock schemaLock = null;
IFeatureBuffer pSumFeatBuf = null;
IEnumIDs pSelectIDs = null;
ICurve pCurve = null;
IPoint pPnt = null;
IDataset pDS = null;
int facilityIDFieldPosition;
int resultsFacilityIDFieldPosition;
//int resultsSourceIDFieldPosition;
int resultsDateFieldPosition;
int resultsValveCountFieldPosition;
int resultsMeterCountFieldPosition;
int resultsCritMeterCountFieldPosition;
int resultsCommentsFieldPosition;
IGeometryDef pGeometryDefTest = null;
IFields pFieldsTest = null;
IField pFieldTest = null;
bool bZAware;
bool bMAware;
ESRI.ArcGIS.Geometry.IZAware zAware;
try
{
bool FCorLayerMains = true;
mainsFL = (IFeatureLayer)Globals.FindLayer(((IMxDocument)app.Document).FocusMap, mainsFLName, ref FCorLayerMains);
if (mainsFL == null)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + mainsFLName + " feature class was not found.\r\n Check the TraceIsolationSummary_Main_FeatureLayer tag in the config");
return;
}
mainFC = mainsFL.FeatureClass;
//Determine field position for facility id
facilityIDFieldPosition = mainFC.Fields.FindField("FACILITYID");
if (facilityIDFieldPosition == -1)
facilityIDFieldPosition = mainFC.Fields.FindField("FACID");
if (facilityIDFieldPosition == -1)
facilityIDFieldPosition = mainFC.Fields.FindField("ASSETID");
if (facilityIDFieldPosition == -1)
facilityIDFieldPosition = mainFC.Fields.FindField("LEGACYID");
if (facilityIDFieldPosition == -1)
facilityIDFieldPosition = mainFC.Fields.FindField(mainFC.OIDFieldName);
if (facilityIDFieldPosition == -1)
return;
mainsNetwork = mainFC as INetworkClass;
if ((mainsNetwork == null) || (mainsNetwork.GeometricNetwork == null))
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + mainsFLName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18a"));
return;
}
mainsFS = (IFeatureSelection)mainsFL;
int FeatureCount = 0;
if (mainsFS.SelectionSet.Count == 0)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("No") + mainsFL.Name + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18b"),
A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"), MessageBoxButtons.OK);
return;
}
FeatureCount = mainsFS.SelectionSet.Count;
bool boolCont = true;
// Create a CancelTracker
pTrkCan = new CancelTrackerClass();
// Create the ProgressDialog. This automatically displays the dialog
pProDFact = new ProgressDialogFactoryClass();
pProDlg = (IProgressDialog2)pProDFact.Create(pTrkCan, 0);
// Set the properties of the ProgressDialog
pProDlg.CancelEnabled = true;
pProDlg.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_18a");
pProDlg.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_18a");
pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe;
// Set the properties of the Step Progressor
pStepPro = (IStepProgressor)pProDlg;
pStepPro.MinRange = 1;
pStepPro.MaxRange = FeatureCount - 1;
pStepPro.StepValue = 1;
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_18a");
// Get Results feature class and test its schema
bool FCorLayerResults = true;
resultsLayer = (IFeatureLayer)Globals.FindLayer(((IMxDocument)app.Document).FocusMap, traceSum_LayerName, ref FCorLayerResults);
if (resultsLayer == null)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + traceSum_LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18c"));
return;
}
if (resultsLayer.FeatureClass == null)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + traceSum_LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18d"));
return;
}
resultsFC = resultsLayer.FeatureClass;
pDS = (IDataset)resultsFC;
pWSEdit = (IWorkspaceEdit)pDS.Workspace;
pDS = null;
bool alreadyEditing = pWSEdit.IsBeingEdited();
// if (alreadyEditing != true)
// pWSEdit.StartEditing(true);
// pWSEdit.StartEditOperation(
if (alreadyEditing == false)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_15d") + traceSum_LayerName + " layer must be editable.");
return;
}
// resultsFC = resultsLayer.FeatureClass;
resultsFacilityIDFieldPosition = resultsFC.Fields.FindField(traceSum_FacilityIDField);
resultsDateFieldPosition = resultsFC.Fields.FindField(traceSum_DateFieldName);
resultsValveCountFieldPosition = resultsFC.Fields.FindField(traceSum_ValveCountFieldName);
resultsMeterCountFieldPosition = resultsFC.Fields.FindField(traceSum_MeterCountFieldName);
resultsCritMeterCountFieldPosition = resultsFC.Fields.FindField(traceSum_CritMeterCountFieldName);
resultsCommentsFieldPosition = resultsFC.Fields.FindField(traceSum_CommentsFieldName);
if (resultsFacilityIDFieldPosition == -1)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("Field") + traceSum_FacilityIDField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18f"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"));
return;
}
//if (resultsDateFieldPosition == -1)
//{
// MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("Field") + traceSum_DateFieldName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18f"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"));
// return;
//}
//if (resultsValveCountFieldPosition == -1)
//{
// MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("Field") + traceSum_ValveCountFieldName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18f"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"));
// return;
//}
//if (resultsMeterCountFieldPosition == -1)
//{
// MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("Field") + traceSum_MeterCountFieldName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18f"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"));
// return;
//}
//if (resultsCritMeterCountFieldPosition == -1)
//{
// MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("Field") + traceSum_CritMeterCountFieldName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_18f"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a"));
// return;
//}
string sShpName = resultsFC.ShapeFieldName;
pFieldsTest = resultsFC.Fields;
int lGeomIndex = pFieldsTest.FindField(sShpName);
pFieldTest = pFieldsTest.get_Field(lGeomIndex);
pGeometryDefTest = pFieldTest.GeometryDef;
//Determine if M or Z aware
bZAware = pGeometryDefTest.HasZ;
bMAware = pGeometryDefTest.HasM;
string closedValveQuery = ConfigUtil.GetConfigValue("TraceIsolation_Valve_ClosedValveQuery", "");
pWSEdit.StartEditOperation();
pInsCur = resultsFC.Insert(true);
pSumFeatBuf = resultsFC.CreateFeatureBuffer();
int intValveCount = 0;
int intMeterCount = 0;
int intCritMeterCount = 0;
string comments = "";
pSelectIDs = mainsFS.SelectionSet.IDs;
int intCurID = pSelectIDs.Next();
List<int> processedIDs = new List<int>();
while (intCurID != -1)
{
intValveCount = 0;
intMeterCount = 0;
intCritMeterCount = 0;
comments = "";
try
{
//if( processedIDs.Contains(intCurID)) {
// pStepPro.Step();
// boolCont = pTrkCan.Continue();
// if (!boolCont)
// {
// pInsCur.Flush();
// pWSEdit.AbortEditOperation();
// return;
// }
// intCurID = pSelectIDs.Next();
// Marshal.ReleaseComObject(pMainsFeat);
// continue;
//}
// Globals.RemoveTraceGraphics(((IMxDocument)ArcMap.Application.Document).FocusMap, false);
// Globals.ClearSelected(ArcMap.Application, false);
Globals.ClearGNFlags(app, Globals.GNTypes.Flags);
pMainsFeat = mainsFL.FeatureClass.GetFeature(intCurID);
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_18b") + pStepPro.Position + A4LGSharedFunctions.Localizer.GetString("Of") + FeatureCount + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_18a");
pCurve = (ICurve)pMainsFeat.Shape;
pPnt = new PointClass();
pCurve.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, pPnt);
IPolyline mergedLines = new PolylineClass();
List<int> procoids = new List<int>();
string result = GeoNetTools.TraceIsolation(new double[] { pPnt.X }, new double[] { pPnt.Y }, app, sourceFLName, valveFLName, operableFieldNameValve,
operableFieldNameSource, snapTol, false, opValues, addSQL, traceIndeterminate, ZeroSourceCont, true, meterFLName, metersCritFieldName,
metersCritValue, closedValveQuery, mainsFL, out mergedLines, out procoids, false, true);
string[] resVals = result.Split('_');
processedIDs.Add(intCurID);
if (resVals.Length == 3)
{
intValveCount = Convert.ToInt32(resVals[0]);
intMeterCount = Convert.ToInt32(resVals[1]);
intCritMeterCount = Convert.ToInt32(resVals[2]);
comments = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_18a");
}
else
{
comments = result;
}
if (mergedLines != null && procoids != null && saveEntireLine == true)
{
if (mergedLines.IsEmpty)
{
comments = "Could not save merged geo: Length is null";
pSumFeatBuf.Shape = pMainsFeat.ShapeCopy;
}
else
{
processedIDs.AddRange(procoids);
try
{
if (bZAware)
{
zAware = (ESRI.ArcGIS.Geometry.IZAware)mergedLines;
if (zAware.ZAware == false)
{
zAware.ZAware = true;
}
ESRI.ArcGIS.Geometry.IZ IZ;
IZ = (ESRI.ArcGIS.Geometry.IZ)mergedLines;
IZ.SetConstantZ(0);
}
pSumFeatBuf.Shape = mergedLines;
}
catch (Exception Ex)
{
comments = "Could not save merged geo: " + Ex.Message;
pSumFeatBuf.Shape = pMainsFeat.ShapeCopy;
}
}
}
else
{
pSumFeatBuf.Shape = pMainsFeat.ShapeCopy;
}
// pStepPro.Message = "Saving Result: " + pStepPro.Position + A4LGSharedFunctions.Localizer.GetString("Of") + FeatureCount + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_18a");
if (resultsDateFieldPosition > -1)
{
pSumFeatBuf.set_Value(resultsDateFieldPosition, DateTime.Now);
}
pSumFeatBuf.set_Value(resultsFacilityIDFieldPosition, pMainsFeat.get_Value(facilityIDFieldPosition));
if (resultsValveCountFieldPosition > -1)
{
pSumFeatBuf.set_Value(resultsValveCountFieldPosition, intValveCount);
}
if (resultsMeterCountFieldPosition > -1)
{
pSumFeatBuf.set_Value(resultsMeterCountFieldPosition, intMeterCount);
}
if (resultsCritMeterCountFieldPosition > -1)
{
pSumFeatBuf.set_Value(resultsCritMeterCountFieldPosition, intCritMeterCount);
}
if (resultsCommentsFieldPosition > -1)
{
try
{
if (comments.Length > resultsFC.Fields.get_Field(resultsCommentsFieldPosition).Length)
{
comments = comments.Substring(0, resultsFC.Fields.get_Field(resultsCommentsFieldPosition).Length - 2);
}
pSumFeatBuf.set_Value(resultsCommentsFieldPosition, comments);
}
catch
{
}
}
pStepPro.Step();
pInsCur.InsertFeature(pSumFeatBuf);
//curIdx = curIdx + 1;
// pInsCur.InsertFeature (pFeatBuf);
boolCont = pTrkCan.Continue();
if (!boolCont)
{
pInsCur.Flush();
pWSEdit.AbortEditOperation();
return;
}
}
catch (Exception Ex)
{
System.Diagnostics.Debug.WriteLine(Ex.Message + A4LGSharedFunctions.Localizer.GetString("Step") + pStepPro.Position);
System.Diagnostics.Trace.WriteLine(Ex.Message + A4LGSharedFunctions.Localizer.GetString("Step") + pStepPro.Position);
// MessageBox.Show(Ex.Message);
}
intCurID = pSelectIDs.Next();
Marshal.ReleaseComObject(pMainsFeat);
}
try
{
pInsCur.Flush();
}
catch
{ }
pWSEdit.StopEditOperation();
}
catch (Exception ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_18a") + "\n" + ex.Message);
if (pWSEdit != null)
{
if (pWSEdit.IsBeingEdited() == true)
{
pWSEdit.AbortEditOperation();
// pWSEdit.StopEditing(false);
}
}
}
finally
{
//if (schemaLock != null)
// schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
//if (featureClassLoad != null)
// featureClassLoad.LoadOnlyMode = false;
//if (pWSEdit != null)
//{
// if (pWSEdit.IsBeingEdited() == true)
// {
// pWSEdit.AbortEditOperation();
// pWSEdit.StopEditing(false);
// }
//}
//if (pInsCur != null)
// pInsCur.Flush();
if (pProDlg != null)
pProDlg.HideDialog();
if (pFC != null)
Marshal.ReleaseComObject(pFC);
if (pInsCur != null)
Marshal.ReleaseComObject(pInsCur);
mainsFL = null;
resultsLayer = null;
mainFC = null;
mainsNetwork = null;
resultsFC = null;
mainsFS = null;
pMainsFeat = null;
pProDFact = null;
pStepPro = null;
pProDlg = null;
pTrkCan = null;
pWSEdit = null;
pFC = null;
pInsCur = null;
pSumFeatBuf = null;
pSelectIDs = null;
pCurve = null;
pPnt = null;
pDS = null;
}
}