// ValidateDataModel - This sample is hard-wired to a particular version of the Naperville data model. // This routine checks to make sure we are using the correct one private bool ValidateDataModel(UtilityNetwork utilityNetwork) { bool dataModelIsValid = false; try { using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition()) using (NetworkSource transformerBankNetworkSource = GetNetworkSource(utilityNetworkDefinition, AssemblyNetworkSourceName)) using (AssetGroup transformerBankAssetGroup = transformerBankNetworkSource.GetAssetGroup(TransformerBankAssetGroupName)) using (AssetType transformerBankAssetType = transformerBankAssetGroup.GetAssetType(TransformerBankAssetTypeName)) // Transformer using (NetworkSource deviceNetworkSource = GetNetworkSource(utilityNetworkDefinition, DeviceNetworkSourceName)) using (AssetGroup transformerAssetGroup = deviceNetworkSource.GetAssetGroup(TransformerAssetGroupName)) using (AssetType transformerAssetType = transformerAssetGroup.GetAssetType(TransformerAssetTypeName)) // Arrester using (AssetGroup arresterAssetGroup = deviceNetworkSource.GetAssetGroup(ArresterAssetGroupName)) using (AssetType arresterAssetType = arresterAssetGroup.GetAssetType(ArresterAssetTypeName)) // Fuse using (AssetGroup fuseAssetGroup = deviceNetworkSource.GetAssetGroup(FuseAssetGroupName)) using (AssetType fuseAssetType = fuseAssetGroup.GetAssetType(FuseAssetTypeName)) { // Find the upstream terminal on the transformer TerminalConfiguration terminalConfiguration = transformerAssetType.GetTerminalConfiguration(); Terminal upstreamTerminal = null; foreach (Terminal terminal in terminalConfiguration.Terminals) { if (terminal.IsUpstreamTerminal) { upstreamTerminal = terminal; break; } } // Find the terminal on the fuse Terminal fuseTerminal = fuseAssetType.GetTerminalConfiguration().Terminals[0]; // Find the terminal on the arrester Terminal arresterTerminal = arresterAssetType.GetTerminalConfiguration().Terminals[0]; // All of our asset groups and asset types exist. Now we have to check for rules. IReadOnlyList <Rule> rules = utilityNetworkDefinition.GetRules(); if (ContainmentRuleExists(rules, transformerBankAssetType, transformerAssetType) && ContainmentRuleExists(rules, transformerBankAssetType, fuseAssetType) && ContainmentRuleExists(rules, transformerBankAssetType, arresterAssetType) && ConnectivityRuleExists(rules, transformerAssetType, upstreamTerminal, fuseAssetType, fuseTerminal) && ConnectivityRuleExists(rules, fuseAssetType, fuseTerminal, arresterAssetType, arresterTerminal)) { dataModelIsValid = true; } } } catch { } return(dataModelIsValid); }
public virtual bool BeginInstall(TerminalConfiguration termConfig) { this.OnTrace(TraceLevel.Info, "BasicTerminal.BeginInstall"); this.OnTrace(TraceLevel.Info, "BasicTerminal.BeginInstall - TerminalConfiguration\n" + "CommChannel = {0}\n" + "Currency = {1}\n" + "CustDisp.CPL = {2}\n" + "CustDisp.NOL = {3}\n" + "DeviceID = {4}\n" + "DeviceName = {5}\n" + "DeviceType = {6}\n" + "OperDisp.CPL = {7}\n" + "OperDisp.NOL = {8}\n" + "Receipt.CPL = {9}\n" + "TerminalID = '{10}'\n", termConfig.CommunicationChannel, termConfig.Currency, termConfig.CustomerDisplay.CharactersPerLine, termConfig.CustomerDisplay.NumberOfLines, termConfig.DeviceId, termConfig.DeviceName, termConfig.DeviceType.ToString(), termConfig.OperatorDisplay.CharactersPerLine, termConfig.OperatorDisplay.NumberOfLines, termConfig.ReceiptConfiguration.CharactersPerLine, termConfig.TerminalId); return(true); }
/// <summary> /// Connects with the terminal. /// </summary> /// <param name="termConfig"></param> /// <returns></returns> public override bool BeginInstall(TerminalConfiguration termConfig) { this.OnTrace(TraceLevel.Info, "BasicTerminal.BeginInstall"); #region Port communication // Configure parameters of the serial port. serialPort.SetPort(termConfig.CommunicationChannel); // Establish connection with the port. if (serialPort.Connect()) { this.OnTrace(TraceLevel.Info, "Connection established with device"); #region Terminal configuration // Trace Message this.OnTrace(TraceLevel.Info, "BasicTerminal.BeginInstall - TerminalConfiguration\n" + "CommChannel = {0}\n" + "Currency = {1}\n" + "CustDisp.CPL = {2}\n" + "CustDisp.NOL = {3}\n" + "DeviceID = {4}\n" + "DeviceName = {5}\n" + "DeviceType = {6}\n" + "OperDisp.CPL = {7}\n" + "OperDisp.NOL = {8}\n" + "Receipt.CPL = {9}\n" + "TerminalID = '{10}'\n", termConfig.CommunicationChannel, termConfig.Currency, termConfig.CustomerDisplay.CharactersPerLine, termConfig.CustomerDisplay.NumberOfLines, termConfig.DeviceId, termConfig.DeviceName, termConfig.DeviceType.ToString(), termConfig.OperatorDisplay.CharactersPerLine, termConfig.OperatorDisplay.NumberOfLines, termConfig.ReceiptConfiguration.CharactersPerLine, termConfig.TerminalId); #endregion //subscribe to reader event serialPort.MessageReceived += SerialPort_MessageReceived; return(true); } else { this.OnTrace(TraceLevel.Error, "Error - Couldn´t connect with device"); return(false); } #endregion }
public ActionResult Create(TerminalConfigurationViewModel model, string submit) { if (ModelState.IsValid) { //taruh logic Insert disini, TerminalConfiguration entSave = new TerminalConfiguration(); entSave.TerminalId = model.TerminalId; entSave.TerminalCategory = model.TerminalCategory; entSave.TerminalGroup = model.TerminalGroup; entSave.TerminalDescription = model.TerminalDescription; entSave.TerminalLocation = model.TerminalLocation; entSave.IsAllergen = model.IsAllergen; entSave.IsActive = model.IsActive; ent.Resolve <TerminalConfiguration>().Add(entSave); ent.Save(); return(RedirectToAction("Index")); } ViewBag.FormName = "Terminal Configuration"; return(View(model)); }
public void ReadConfig() { try { JsonSerializer serializer = new JsonSerializer(); string path = System.IO.Directory.GetCurrentDirectory(); fileName = path + "\\" + JSON_CONFIG; string FILE_CFG = File.ReadAllText(fileName); //string s = @"{ ""ModelFirmware"": { ""VP5300"": [ ""VP5300 FW v1.00.028.0192.S"", ""VP5300 FW v1.00.028.0192.S Test"" ] } }"; //var Json = JsonConvert.DeserializeObject<EMVDeviceSettings>(s); //string s = @"{ ""GroupTags"": { ""0"": [ ""9F53"" ], ""1"": [ ""DFED0A"" ] } }"; //var Json = JsonConvert.DeserializeObject<EMVGroupTags>(s); //string s = @"{ ""GroupTags"": { ""0"": [ ""9F53"" ], ""1"": [ ""DFED0A"" ] } }"; //EMVGroupTags Json = JsonConvert.DeserializeObject<EMVGroupTags>(s); terminalCfg = JsonConvert.DeserializeObject <TerminalConfiguration>(FILE_CFG); if (terminalCfg != null) { // devConfig DeviceConfig = terminalCfg.Configuration.First(); // Manufacturer Debug.WriteLine("device configuration: manufacturer ----------------: [{0}]", (object)DeviceConfig.ConfigurationID.Manufacturer); // Models md = DeviceConfig.ConfigurationID.Models; //DisplayCollection(mf.modelFirmware, "modelFirmware"); // AID List aid.Aid = DeviceConfig.EMVConfiguration.AIDList; //DisplayCollection(aid.Aid, "AIDList"); // CAPK List capk.CAPK = DeviceConfig.EMVConfiguration.CAPKList; //DisplayCollection(capk.Capk, "CapkList"); // Terminal Settings termSettings = DeviceConfig.EMVConfiguration.TerminalSettings; //Debug.WriteLine("device configuration: Terminal Settings --------------"); //Debug.WriteLine("MajorConfiguration : {0}", (object) termSettings.MajorConfiguration); //Debug.WriteLine("MajorConfigurationChecksum: {0}", (object) termSettings.MajorConfigurationChecksum[0]); // SerialNumberTag //Debug.WriteLine("device configuration: Serial Number TAG -----------: [{0}]", (object) termSettings.SerialNumberTag); // TerminalData //DisplayCollection(termSettings.TerminalData, "Terminal Data"); // TransactionTagsRequested //DisplayCollection(termSettings.TransactionTags, "TransactionTagsRequested"); // TransactionValues emvTransactionData = DeviceConfig.EMVTransactionData; //DisplayCollection(transactionValues.EMVKernelMapping, "EMVKernelMapping"); //DisplayCollection(transactionValues.TransactionStartTags, "TransactionStartTags"); //DisplayCollection(transactionValues.TransactionAuthenticateTags, "TransactionAuthenticateTags"); //DisplayCollection(transactionValues.TransactionCompleteTags, "TransactionCompleteTags"); emvDeviceSettings = DeviceConfig.EMVDeviceSettings; foreach (var devSettings in emvDeviceSettings) { EMVGroupTags item = new EMVGroupTags(devSettings.GroupTags); emvGroupTags.Add(item); } } } catch (Exception ex) { Debug.WriteLine("JsonSerializer: exception: {0}", (object)ex.Message); } }
/// <summary> /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it. /// </summary> /// <param name="geometry">The geometry created by the sketch.</param> /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns> protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (geometry == null) { return(false); } // Create an edit operation var createOperation = new EditOperation(); createOperation.Name = "Create Transformer Bank"; createOperation.SelectNewFeatures = true; bool success = false; string errorMessage = ""; await QueuedTask.Run(() => { Map map = GetMap(); using (UtilityNetwork utilityNetwork = GetUtilityNetwork()) { if (utilityNetwork == null) { errorMessage = "Please select a layer that participates in a utility network."; } else { using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition()) // Get the NetworkSource, AssetGroup, and AssetTypes for all of the features we want to create // If this was production code, you would want to check the return values to make sure that these asset groups and asset types existed. // TransformerBank using (NetworkSource transformerBankNetworkSource = utilityNetworkDefinition.GetNetworkSource(AssemblyNetworkSourceName)) using (AssetGroup transformerBankAssetGroup = transformerBankNetworkSource.GetAssetGroup(TransformerBankAssetGroupName)) using (AssetType transformerBankAssetType = transformerBankAssetGroup.GetAssetType(TransformerBankAssetTypeName)) // Transformer using (NetworkSource deviceNetworkSource = utilityNetworkDefinition.GetNetworkSource(DeviceNetworkSourceName)) using (AssetGroup transformerAssetGroup = deviceNetworkSource.GetAssetGroup(TransformerAssetGroupName)) using (AssetType transformerAssetType = transformerAssetGroup.GetAssetType(TransformerAssetTypeName)) // Arrester using (AssetGroup arresterAssetGroup = deviceNetworkSource.GetAssetGroup(ArresterAssetGroupName)) using (AssetType arresterAssetType = arresterAssetGroup.GetAssetType(ArresterAssetTypeName)) // Fuse using (AssetGroup fuseAssetGroup = deviceNetworkSource.GetAssetGroup(FuseAssetGroupName)) using (AssetType fuseAssetType = fuseAssetGroup.GetAssetType(FuseAssetTypeName)) { MapPoint clickPoint = geometry as MapPoint; // Create a transformer bank Layer transformerBankLayer = GetLayerForEdit(map, AssemblyNetworkSourceName, TransformerBankAssetGroupName); RowToken token = createOperation.CreateEx(transformerBankLayer, CreateAttributes(transformerBankAssetGroup, transformerBankAssetType, clickPoint)); RowHandle transformerBankHandle = new RowHandle(token); // Create three transformers, one for each phase Layer transformerLayer = GetLayerForEdit(map, DeviceNetworkSourceName, TransformerAssetGroupName); MapPoint transformerPointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, YOffset); token = createOperation.CreateEx(transformerLayer, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointA, APhase)); RowHandle transformerHandleA = new RowHandle(token); MapPoint transformerPointB = CreateOffsetMapPoint(clickPoint, 0, YOffset); token = createOperation.CreateEx(transformerLayer, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointB, BPhase)); RowHandle transformerHandleB = new RowHandle(token); MapPoint transformerPointC = CreateOffsetMapPoint(clickPoint, XOffset, YOffset); token = createOperation.CreateEx(transformerLayer, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointC, CPhase)); RowHandle transformerHandleC = new RowHandle(token); // Create containment associations between the bank and the transformers ContainmentAssociationDescription containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, transformerHandleA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, transformerHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, transformerHandleC, false); createOperation.Create(containmentAssociationDescription); // Create three arresters, one for each phase Layer arresterLayer = GetLayerForEdit(map, DeviceNetworkSourceName, ArresterAssetGroupName); MapPoint arresterPointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, 2 * YOffset); token = createOperation.CreateEx(arresterLayer, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointA, APhase)); RowHandle arresterHandlA = new RowHandle(token); MapPoint arresterPointB = CreateOffsetMapPoint(clickPoint, 0, 2 * YOffset); token = createOperation.CreateEx(arresterLayer, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointB, BPhase)); RowHandle arresterHandleB = new RowHandle(token); MapPoint arresterPointC = CreateOffsetMapPoint(clickPoint, XOffset, 2 * YOffset); token = createOperation.CreateEx(arresterLayer, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointC, CPhase)); RowHandle arresterHandleC = new RowHandle(token); // Create containment associations between the bank and the arresters containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, arresterHandlA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, arresterHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, arresterHandleC, false); createOperation.Create(containmentAssociationDescription); // Find the high-side terminal for transformers TerminalConfiguration transformerTerminalConfiguration = transformerAssetType.GetTerminalConfiguration(); IReadOnlyList <Terminal> terminals = transformerTerminalConfiguration.Terminals; Terminal highSideTerminal = terminals.First(x => x.IsUpstreamTerminal == true); long highSideTerminalID = highSideTerminal.ID; // Connect the high-side transformer terminals to the arresters (connect the A-phase transformer to the A-phase arrester, and so on) ConnectivityAssociationDescription connectivityAssociationDescription = new ConnectivityAssociationDescription(transformerHandleA, highSideTerminalID, arresterHandlA); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new ConnectivityAssociationDescription(transformerHandleB, highSideTerminalID, arresterHandleB); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new ConnectivityAssociationDescription(transformerHandleC, highSideTerminalID, arresterHandleC); createOperation.Create(connectivityAssociationDescription); // Create three fuses, one for each phase Layer fuseLayer = GetLayerForEdit(map, DeviceNetworkSourceName, FuseAssetGroupName); MapPoint fusePointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, 3 * YOffset); token = createOperation.CreateEx(fuseLayer, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointA, APhase)); RowHandle fuseHandleA = new RowHandle(token); MapPoint fusePointB = CreateOffsetMapPoint(clickPoint, 0, 3 * YOffset); token = createOperation.CreateEx(fuseLayer, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointB, BPhase)); RowHandle fuseHandleB = new RowHandle(token); MapPoint fusePointC = CreateOffsetMapPoint(clickPoint, XOffset, 3 * YOffset); token = createOperation.CreateEx(fuseLayer, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointC, CPhase)); RowHandle fuseHandleC = new RowHandle(token); // Create containment associations between the bank and the fuses containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, fuseHandleA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, fuseHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new ContainmentAssociationDescription(transformerBankHandle, fuseHandleC, false); createOperation.Create(containmentAssociationDescription); // Create connectivity associations between the fuses and the arresters (connect the A-phase fuse the A-phase arrester, and so on) connectivityAssociationDescription = new ConnectivityAssociationDescription(fuseHandleA, arresterHandlA); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new ConnectivityAssociationDescription(fuseHandleB, arresterHandleB); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new ConnectivityAssociationDescription(fuseHandleC, arresterHandleC); createOperation.Create(connectivityAssociationDescription); // Execute the edit operation, which creates all of the rows and associations success = createOperation.Execute(); if (!success) { errorMessage = createOperation.ErrorMessage; } } } } }); if (!success) { MessageBox.Show(errorMessage, "Create Transformer Bank Tool"); } return(success); }
/// <summary> /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it. /// </summary> /// <param name="geometry">The geometry created by the sketch.</param> /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns> protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (geometry == null) { return(false); } // Create an edit operation var createOperation = new EditOperation() { Name = "Create Transformer Bank", SelectNewFeatures = true }; bool success = false; string errorMessage = ""; await QueuedTask.Run(() => { Map map = GetMap(); using (UtilityNetwork utilityNetwork = GetUtilityNetwork()) { if (utilityNetwork == null) { errorMessage = "Please select a layer that participates in a utility network."; } else { if (!ValidateDataModel(utilityNetwork)) { errorMessage = "This sample is designed for a different utility network data model"; } else { using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition()) // Get the NetworkSource, FeatureClass, AssetGroup, and AssetTypes for all of the features we want to create // The existence of these values has already been confirmed in the ValidateDataModel() routine // TransformerBank using (NetworkSource transformerBankNetworkSource = GetNetworkSource(utilityNetworkDefinition, AssemblyNetworkSourceName)) using (FeatureClass transformerBankFeatureClass = utilityNetwork.GetTable(transformerBankNetworkSource) as FeatureClass) using (AssetGroup transformerBankAssetGroup = transformerBankNetworkSource.GetAssetGroup(TransformerBankAssetGroupName)) using (AssetType transformerBankAssetType = transformerBankAssetGroup.GetAssetType(TransformerBankAssetTypeName)) // Transformer using (NetworkSource deviceNetworkSource = GetNetworkSource(utilityNetworkDefinition, DeviceNetworkSourceName)) using (FeatureClass deviceFeatureClass = utilityNetwork.GetTable(deviceNetworkSource) as FeatureClass) using (AssetGroup transformerAssetGroup = deviceNetworkSource.GetAssetGroup(TransformerAssetGroupName)) using (AssetType transformerAssetType = transformerAssetGroup.GetAssetType(TransformerAssetTypeName)) // Arrester using (AssetGroup arresterAssetGroup = deviceNetworkSource.GetAssetGroup(ArresterAssetGroupName)) using (AssetType arresterAssetType = arresterAssetGroup.GetAssetType(ArresterAssetTypeName)) // Fuse using (AssetGroup fuseAssetGroup = deviceNetworkSource.GetAssetGroup(FuseAssetGroupName)) using (AssetType fuseAssetType = fuseAssetGroup.GetAssetType(FuseAssetTypeName)) { MapPoint clickPoint = geometry as MapPoint; // Create a transformer bank RowToken token = createOperation.CreateEx(transformerBankFeatureClass, CreateAttributes(transformerBankAssetGroup, transformerBankAssetType, clickPoint)); RowHandle transformerBankHandle = new RowHandle(token); // Create three transformers, one for each phase MapPoint transformerPointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointA, APhase)); RowHandle transformerHandleA = new RowHandle(token); MapPoint transformerPointB = CreateOffsetMapPoint(clickPoint, 0, YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointB, BPhase)); RowHandle transformerHandleB = new RowHandle(token); MapPoint transformerPointC = CreateOffsetMapPoint(clickPoint, XOffset, YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(transformerAssetGroup, transformerAssetType, transformerPointC, CPhase)); RowHandle transformerHandleC = new RowHandle(token); // Create containment associations between the bank and the transformers AssociationDescription containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, transformerHandleA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, transformerHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, transformerHandleC, false); createOperation.Create(containmentAssociationDescription); // Find the high-side terminal for transformers TerminalConfiguration transformerTerminalConfiguration = transformerAssetType.GetTerminalConfiguration(); IReadOnlyList <Terminal> terminals = transformerTerminalConfiguration.Terminals; Terminal highSideTerminal = terminals.First(x => x.IsUpstreamTerminal == true); long highSideTerminalID = highSideTerminal.ID; // Create three fuses, one for each phase MapPoint fusePointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, 2 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointA, APhase)); RowHandle fuseHandleA = new RowHandle(token); MapPoint fusePointB = CreateOffsetMapPoint(clickPoint, 0, 2 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointB, BPhase)); RowHandle fuseHandleB = new RowHandle(token); MapPoint fusePointC = CreateOffsetMapPoint(clickPoint, XOffset, 2 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(fuseAssetGroup, fuseAssetType, fusePointC, CPhase)); RowHandle fuseHandleC = new RowHandle(token); // Create containment associations between the bank and the fuses containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, fuseHandleA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, fuseHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, fuseHandleC, false); createOperation.Create(containmentAssociationDescription); // Connect the high-side transformer terminals to the fuses (connect the A-phase transformer to the A-phase fuse, and so on) AssociationDescription connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, transformerHandleA, highSideTerminalID, fuseHandleA); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, transformerHandleB, highSideTerminalID, fuseHandleB); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, transformerHandleC, highSideTerminalID, fuseHandleC); createOperation.Create(connectivityAssociationDescription); // Create three arresters, one for each phase MapPoint arresterPointA = CreateOffsetMapPoint(clickPoint, -1 * XOffset, 3 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointA, APhase)); RowHandle arresterHandleA = new RowHandle(token); MapPoint arresterPointB = CreateOffsetMapPoint(clickPoint, 0, 3 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointB, BPhase)); RowHandle arresterHandleB = new RowHandle(token); MapPoint arresterPointC = CreateOffsetMapPoint(clickPoint, XOffset, 3 * YOffset); token = createOperation.CreateEx(deviceFeatureClass, CreateDeviceAttributes(arresterAssetGroup, arresterAssetType, arresterPointC, CPhase)); RowHandle arresterHandleC = new RowHandle(token); // Create containment associations between the bank and the arresters containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, arresterHandleA, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, arresterHandleB, false); createOperation.Create(containmentAssociationDescription); containmentAssociationDescription = new AssociationDescription(AssociationType.Containment, transformerBankHandle, arresterHandleC, false); createOperation.Create(containmentAssociationDescription); // Create connectivity associations between the fuses and the arresters (connect the A-phase fuse the A-phase arrester, and so on) connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, fuseHandleA, arresterHandleA); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, fuseHandleB, arresterHandleB); createOperation.Create(connectivityAssociationDescription); connectivityAssociationDescription = new AssociationDescription(AssociationType.JunctionJunctionConnectivity, fuseHandleC, arresterHandleC); createOperation.Create(connectivityAssociationDescription); // Execute the edit operation, which creates all of the rows and associations success = createOperation.Execute(); if (!success) { errorMessage = createOperation.ErrorMessage; } } } } } }); if (!success) { MessageBox.Show(errorMessage, "Create Transformer Bank Tool"); } return(success); }
public void RequestTask(string TerminalId, int UserId) { Int64 MOQueueId = 0; string MONumber = ""; //BELUM!! Seharusnya digrouping terlebih dahulu terhadap Nomor MO, dengan default by : First In First Out DAN Skala Prioritas MO, tetapi harus selesai per TASK //Ketika Processed jadi TaskTimbang, masukin table QueueMO isinya: MONumber, IsPriority, Sequence, status. //1. Pertama cari yang on progress (status = "EXE") MOQueue moOnProgress = entTerminal.Resolve <MOQueue>().Get(x => x.Status == "EXE"); //2. Jika ada yg on Progress maka selesaikan if (moOnProgress != null) { MOQueueId = moOnProgress.MOQueueId; MONumber = moOnProgress.MoNumber; } else { //3. Jika ga ada yang sedang dikerjakan, ambil yang prioritas utama, urutan berdasarkan MOQueueId MOQueue moPriority = entTerminal.Resolve <MOQueue>().GetAll(x => x.Status == "NEW" && x.IsPriority == true).OrderBy(x => x.MOQueueId).FirstOrDefault(); if (moPriority != null) { MOQueueId = moPriority.MOQueueId; MONumber = moPriority.MoNumber; } else { //4. Jika ga ada yang prioritas, ambil MO paling pertama masuk FIFO, berdasarkan urutan Execute Date & MOQueueId MOQueue moFifo = entTerminal.Resolve <MOQueue>().GetAll(x => x.Status == "NEW").OrderBy(x => x.ExecuteDate).ThenBy(x => x.MOQueueId).FirstOrDefault(); if (moFifo != null) { MOQueueId = moFifo.MOQueueId; MONumber = moFifo.MoNumber; } else { //Tidak ada MO yang harus dikerjakan } } } if (MONumber != "") { //IsProcessed True artinya sudah dibentuk TaskTimbang List <Int64> listOracleHId = entTerminal.Resolve <OracleHeader>().GetAll(x => x.MoNumber == MONumber && x.IsProcessed == true).Select(x => x.OracleHeaderId).ToList(); //Cek dulu apakah semua Task Timbang untuk MO Number ini sudah diproses semua atau belum, jika sudah semua TMB atau COM, update MOQueue status jadi COM int taskPending = entTerminal.Resolve <TaskTimbang>().GetAll(x => listOracleHId.Contains(x.OracleHeaderId) && x.Status.Contains("PREP")).Count(); if (taskPending > 0) { //Get Semua Data Terminal Configuration Terlebih dahulu List <TerminalConfiguration> listAllTerminal = entTerminal.Resolve <TerminalConfiguration>().GetAll(); //Terminal Requester TerminalConfiguration terminal = listAllTerminal.Where(x => x.TerminalId == TerminalId).FirstOrDefault(); if (terminal.IsActive) { //Get (Task Allergen / Non Allergen) & sesuai dengan type timbangan (B / K) var listItemPeMO = (from a in entTerminal.Resolve <TaskTimbang>().AsQueryable() .Where(x => listOracleHId.Contains(x.OracleHeaderId) && x.IsAllergen == terminal.IsAllergen && x.Type == terminal.TerminalCategory) group a by new { a.ItemCode } into g orderby g.Count(x => x.ItemCode != null) descending select new { ItemCode = g.Key.ItemCode, Qty = g.Count(x => x.ItemCode != null), TerminalAssign = g.Count(x => x.TerminalId != null) }).ToList(); //var listItemPeMO = (from a in entTerminal.Resolve<TaskTimbang>().AsQueryable() // .Where(x => listOracleHId.Contains(x.OracleHeaderId) && x.Status == "PREP" && x.IsAllergen == terminal.IsAllergen && x.Type == terminal.TerminalCategory) // group a by a.ItemCode into g // let qty = g.Count() // orderby qty descending // select new { ItemCode = g.Key, Qty = qty }).ToList(); //jika sudah tidak ada Item lain yang kosong, maka boleh cross Item bool allowCrossItem = listItemPeMO.Where(x => x.TerminalAssign == 0).Count() > 0 ? false : true; //Bagi Task foreach (var item in listItemPeMO) { //Daftar Terminal yang sedang Execute Item Code ini List <TaskTimbang> listTaskTimbangPerItem = entTerminal.Resolve <TaskTimbang>().GetAll(x => x.ItemCode == item.ItemCode.ToString() && x.Type == terminal.TerminalCategory); List <string> listTerminalActive = listTaskTimbangPerItem.Where(x => x.ItemCode == item.ItemCode.ToString() && x.TerminalId != null && x.Type == terminal.TerminalCategory && x.Status == "TMB").Select(x => x.TerminalId).Distinct().ToList(); List <int?> terminalGroupActive = listAllTerminal.Where(x => listTerminalActive.Contains(x.TerminalId)).Select(x => x.TerminalGroup).Distinct().ToList(); int taskLeft = listTaskTimbangPerItem.Where(x => x.ItemCode == item.ItemCode.ToString() && x.TerminalId == null && x.Type == terminal.TerminalCategory && x.Status == "PREP").Count(); if (taskLeft > 0 && (terminalGroupActive.Contains(terminal.TerminalGroup) || listTerminalActive.Count == 0 || allowCrossItem)) { //Masih ada Item tersebut yang belum ditimbang, kasi task yang sama karena 1 group //kasi task sejumlah settingan, perhitungkan juga sisa tasknya jika < n%, kasi semua langsung int taskTimbangCount = int.Parse(GS.GetValue("TASK_TIMBANG_COUNT")); decimal percentage = ((Convert.ToDecimal(taskLeft) - Convert.ToDecimal(taskTimbangCount)) / Convert.ToDecimal(taskTimbangCount) * 100); List <Int64> taskIdToAssign = new List <Int64>(); if (percentage < decimal.Parse(GS.GetValue("TASK_LEFT_PERCENTAGE"))) { //Set semua TASK sesuai taskLeft taskIdToAssign = listTaskTimbangPerItem.Where(x => x.ItemCode == item.ItemCode.ToString() && x.TerminalId == null && x.Status == "PREP").Select(x => x.TaskTimbangId).ToList(); } else { //Set jumlah TASK sesuai taskTimbangCount taskIdToAssign = listTaskTimbangPerItem.Where(x => x.ItemCode == item.ItemCode.ToString() && x.TerminalId == null && x.Status == "PREP").OrderBy(x => x.Seq).Take(taskTimbangCount).Select(x => x.TaskTimbangId).ToList(); } //Update TaskTimbang, assign to Terminal entTerminal.StartTransaction(); //update Status MOQueue jadi EXEcute MOQueue queue = entTerminal.Resolve <MOQueue>().Get(x => x.MOQueueId == MOQueueId); queue.Status = "EXE"; //Assign Task to Terminal Timbang List <TaskTimbang> taskTimbangToAssign = entTerminal.Resolve <TaskTimbang>().GetAll(x => taskIdToAssign.Contains(x.TaskTimbangId)); DateTime executeDate = DateTime.Now; taskTimbangToAssign.ForEach(x => { x.TerminalId = terminal.TerminalId; x.UserId = UserId; x.ExecuteDate = executeDate; x.Status = "TMB"; }); entTerminal.Save(TransactionAttribute.Commit); break; } } } else { //ERROR : Terminal Tidak Active } } else { entTerminal.StartTransaction(); //update Status MOQueue jadi EXEcute MOQueue queue = entTerminal.Resolve <MOQueue>().Get(x => x.MOQueueId == MOQueueId); queue.Status = "COM"; entTerminal.Save(TransactionAttribute.Commit); } } }