Esempio n. 1
0
        /// <summary>
        /// Internal execution fonction to toggle switches
        /// </summary>
        /// <returns>An error comment if needed, empty of no error</returns>
        private static string ToggleSwitchesExecute()
        {
            bool canUpdate = false;

            // Load all Diagram Element and selection
            if (!IsDiagramUsable(GetAllElements: false, GetSelection: true))
            {
                return("");
            }

            if (GlobalSelectedJunctionIDs.Count == 0)
            {
                return("There are no junction selected");
            }

            Dictionary <long, List <Guid> > guidBySourceId = new Dictionary <long, List <Guid> >();

            // retrieve the junctions GlobalId
            foreach (long oid in GlobalSelectedJunctionIDs)
            {
                DiagramJunctionElement junctionElement = GlobalDiagramJunctionElements.FirstOrDefault(a => a.ObjectID == oid);
                if (junctionElement != null)
                {
                    if (!guidBySourceId.TryGetValue(junctionElement.AssociatedSourceID, out List <Guid> guidList))
                    {
                        guidList = new List <Guid>();
                        guidBySourceId.Add(junctionElement.AssociatedSourceID, guidList);
                    }

                    if (!guidList.Contains(junctionElement.AssociatedGlobalID))
                    {
                        guidList.Add(junctionElement.AssociatedGlobalID);
                    }
                }
            }

            IReadOnlyList <NetworkSource> theSources = GlobalUtilityNetwork.GetDefinition().GetNetworkSources();

            List <string> searchFields = new List <string> {
                cDeviceStatusFieldName, "ObjectId", "AssetGroup"
            };

            foreach (NetworkSource source in theSources)
            {
                if (guidBySourceId.TryGetValue(source.ID, out List <Guid> guidList))
                {
                    // Get a cursor of guid list, get the qualified fields name
                    using (RowCursor sel = GetRowCursorFromSourceNameAndGuidList(SourceName: source.Name.Replace(" ", ""), SearchGuid: guidList, ListSearchFields: searchFields, WhereField: "GlobalId", FieldsName: out List <Tuple <string, string> > FieldsName))
                    {
                        int deviceStatusIndex = -1;
                        int assetGroupIndex   = -1;
                        // retrieved the fields indexes
                        foreach (Tuple <string, string> findTuple in FieldsName)
                        {
                            if (findTuple.Item1 == cDeviceStatusFieldName)
                            {
                                deviceStatusIndex = sel.FindField(findTuple.Item2);
                            }
                            else if (findTuple.Item1 == "AssetGroup")
                            {
                                assetGroupIndex = sel.FindField(findTuple.Item2);
                            }
                        }

                        if (deviceStatusIndex >= 0)                         // run only if there is a device status
                        {
                            var modifyStringsOperation = new EditOperation
                            {
                                Name = String.Format("Modify string field '{0}' in source {1}.", cDeviceStatusFieldName, source.Name)
                            };

                            ICollection <long> oidSet = new List <long>();
                            while (sel.MoveNext())
                            {
                                string AssetGroupValue = sel.Current[assetGroupIndex].ToString();
                                // verify if the Asset Group is correct
                                if (!String.IsNullOrEmpty(AssetGroupValue) && AssetGroupValue == cAssetGroupFieldValue)
                                {
                                    string deviceStatus  = sel.Current[deviceStatusIndex]?.ToString();
                                    Guid   globalIdValue = sel.Current.GetGlobalID();
                                    long   oid           = sel.Current.GetObjectID();

                                    // set up a new dictionary with fields to modify
                                    var modifiedAttributes = new Dictionary <string, object>
                                    {
                                        // add the name of the string field and the new attribute value to the dictionary
                                        { cDeviceStatusFieldName, deviceStatus == "2" ? 1 : 2 }
                                    };

                                    // put the modify operation on the editor stack
                                    modifyStringsOperation.Modify(sel.Current, modifiedAttributes);
                                    oidSet.Add(oid);
                                }
                            }

                            if (oidSet.Count > 0)
                            {                              // execute the modify operation to apply the changes
                                modifyStringsOperation.Execute();
                                canUpdate = true;
                            }
                            else
                            {
                                modifyStringsOperation.Abort();
                            }
                        }
                    }
                }
            }

            return(canUpdate ? "" : "This command only applies to medium voltage switches. Please make sure there is at least one selected medium voltage switch in the active diagram before its execution.");
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="junction">DiagramJunctionElement</param>
 public CustomJunction(DiagramJunctionElement junction)
 {
     this.Element = junction;
     this.Rank    = -1;
     this.ID      = junction.ID;
 }