Пример #1
0
        /// <summary>
        /// Search project library for the block required and returns it
        /// </summary>
        /// <param name="libraryFolder">Folder of the project library to search in</param>
        /// <param name="blockName">Name of the block to be search for</param>
        /// <returns>Block if found, null otherwise</returns>
        public static MasterCopy GetMasterCopy(MasterCopyFolder libraryFolder, string blockName, TextBox log)
        {
            // look for block in current folder
            foreach (var masterCopy in libraryFolder.MasterCopies)
            {
                if (masterCopy.Name.Equals(blockName))
                {
                    log.AppendText("Block to be copied found in " + libraryFolder.Name);
                    log.AppendText(Environment.NewLine);
                    return(masterCopy);
                }
            }

            // if not in this folder check subfolders
            foreach (var subfolder in libraryFolder.Folders)
            {
                MasterCopy result = GetMasterCopy(subfolder, blockName, log);

                if (result != null)
                {
                    return(result);
                }
            }

            log.AppendText("Block to be copied not found");
            log.AppendText(Environment.NewLine);
            return(null);
        }
        //Start copying drives
        // put master drive in mastercopy
        //fill listDevicesToCopy (=target devices)
        private void btnCopy_Click(object sender, EventArgs e)
        {
            if (cbDriveToCopy.SelectedItem.ToString().Equals("---") || cbDriveToCopy.SelectedItem.ToString().Equals(""))
            {
                //No Device is selected to copy
                StatusMessage("No Drive To Copy Selected.");
            }
            else
            {
                progressBar.Value = 5;

                btnCopy.Enabled     = false;
                btnDownload.Enabled = false;
                btnCancel.Enabled   = true;

                //Get drive to copy and selected drives in tree
                listDevicesToCopy.Clear();

                // search masterdrive
                //fill listDevicesToCopy (=target devices)
                foreach (DeviceExtended deviceextended in myOpenness.lsDeviceExtendeds)//collection of all devices (and their usergroup as extra)
                {
                    if (deviceextended.driveName.Equals(cbDriveToCopy.SelectedItem.ToString()))
                    {
                        //check all Gdevices if name equals 'drive to copy' => masterDrive
                        masterDrive = deviceextended.device;
                        continue;
                    }
                    else
                    {
                        //every drive that is selected and is not master drive => listDevicesToCopy (target devices)
                        //int nodeCounter = 0;
                        foreach (TreeNode parentNode in tvDevices.Nodes)     //parent node
                        {
                            foreach (TreeNode childNode in parentNode.Nodes) //child node
                            {
                                if (deviceextended.driveName.Equals(childNode.Text) && childNode.Checked)
                                {
                                    listDevicesToCopy.Add(new DeviceSinamicsG(deviceextended));
                                    continue;
                                }
                            }
                            // nodeCounter++;
                        }
                    }
                }

                //Start copying devices
                mastercopy = myOpenness.DeviceToLibrary(masterDrive);

                StatusMessage("Start copy devices");

                if (!backgroundWorker.IsBusy)
                {
                    backgroundWorker.RunWorkerAsync(new List <Object> {
                        BackgroundOperation.CopyDevices,
                    });
                }
            }
        }
Пример #3
0
        /// <summary>
        /// This method will randomly fill the <see cref="Deck"/> of all the connected users with a limit of 8 <see cref="Card"/> per user.
        /// </summary>
        private void FillUserDeck()
        {
            Random random = new Random();

            foreach (string username in this.Users)
            {
                while (this.UsersDeck[username].Array.Count() < 8 && MasterCopy.Array.Count() > 0)
                {
                    int  index = random.Next(0, MasterCopy.Array.Count());
                    Card card  = MasterCopy.Array.ElementAt(index);
                    this.UsersDeck[username].Add(card);
                    Console.WriteLine("_> Adding new card in the " + username + "'s deck: " + card.Value + ":" + card.Color + ". (" + MasterCopy.Array.Count() + " left in the deck)");
                    MasterCopy.Remove(index);
                }
                this.Send(username, PacketType.GAME, new Gamecall(GameAction.S_SET_USER_DECK, this.UsersDeck[username]));
            }
        }
Пример #4
0
        //=================================================================================================
        private static void RunTiaPortal()
        {
            #region tia and project
            Progress("Check running TIA Portal");
            bool tiaStartedWithoutInterface = false;

            Service.OpenProject(Parameters.ProjectPath, ref tiaPortal, ref project);

            if ((tiaPortal == null) || (project == null))
            {
                CancelGeneration("Could not open project.");
                return;
            }

            Progress(String.Format("Project {0} is open", project.Path.FullName));
            #endregion

            #region test models

            /*
             * Console.WriteLine("!!! TESTING !!!");
             * DeviceUserGroup testGroup = project.DeviceGroups.Find(Parameters.TemplateGroupName);
             * ManagePlc testPlcs = new ManagePlc(testGroup);
             *
             *
             * NetworkPort testPlcPort = testPlcs.AllDevices[0].DeviceItems[1].DeviceItems[6].DeviceItems[0].GetService<NetworkPort>();
             * NetworkPort patnerPort =  testPlcPort.ConnectedPorts[0];
             *
             * AttributeValue thisname = Service.GetAttribute(patnerPort, "Name");
             *
             * testPlcPort.DisconnectFromPort(patnerPort);
             * testPlcPort.ConnectToPort(patnerPort);
             */

            #endregion

            #region master copy
            Progress("Creating master copy.");

            DeviceUserGroup templateGroup = project.DeviceGroups.Find(Parameters.TemplateGroupName);
            if (templateGroup == null)
            {
                CancelGeneration("Group not found.");
                return;
            }

            //=======copy to master copy========
            //MasterCopyComposition masterCopies = project.ProjectLibrary.MasterCopyFolder.MasterCopies;
            MasterCopy templateCopy = null;
            try
            {
                templateCopy = project.ProjectLibrary.MasterCopyFolder.MasterCopies.Create(templateGroup);
            }
            catch (Exception ex)
            {
                CancelGeneration("Could not create master copy.", ex);
                return;
            }

            if (templateCopy == null)
            {
                CancelGeneration("Could not create master copy.");
                return;
            }

            MasterCopy deleteMasterCopy = project.ProjectLibrary.MasterCopyFolder.MasterCopies.Find(templateCopy.Name);
            #endregion

            #region get basic info from template group
            IList <Device> templatePlcDevices = Service.GetPlcDevicesInGroup(templateGroup);
            ManagePlc      templatePlcs       = new ManagePlc(templatePlcDevices);


            templatePlcs.GetAll_iDeviceParnerIoAdresses();


            if (templatePlcs.AllDevices.Count != 1)
            {
                CancelGeneration("No PLC or more than 1 PLC in group.");
                return;
            }

            #endregion

            #region change name and IP of first group (template Group)
            string indexformat  = "D2";
            uint   groupCounter = 1;

            Progress("Adjusting template group.");
            string currentPrefix = Parameters.Prefix + groupCounter.ToString(indexformat);
            //templateGroup.Name = templateGroup.Name + groupCounter.ToString(indexformat);
            templateGroup.Name = Parameters.NewGroupNamePrefix + groupCounter.ToString(indexformat);
            //templateNetworkInterface.IoControllers[0].IoSystem.Name = currentPrefix + temlateIoSystemName;

            Service.ChangeDeviceNames(templateGroup, currentPrefix);
            templatePlcs.ChangeIoSystemName(currentPrefix);

            #endregion

            #region copy group loop
            DeviceUserGroupComposition userGroups = project.DeviceGroups;

            while (++groupCounter <= Parameters.NumOfGroups)
            {
                #region copy group
                Progress("Creating Group " + groupCounter);
                currentPrefix = Parameters.Prefix + groupCounter.ToString(indexformat);

                DeviceUserGroup newGroup;
                try
                {
                    newGroup = userGroups.CreateFrom(templateCopy);
                }
                catch (Exception e)
                {
                    CancelGeneration("Could not create new Group", e);
                    return;
                }

                #endregion

                #region read in devices
                //newGroup.Name = newGroup.Name + groupCounter.ToString(indexformat); ;
                newGroup.Name = Parameters.NewGroupNamePrefix + groupCounter.ToString(indexformat);;
                Service.ChangeDeviceNames(newGroup, currentPrefix);

                IList <Device> plcDevices = Service.GetPlcDevicesInGroup(newGroup);
                ManagePlc      plcs       = new ManagePlc(plcDevices);

                IList <Device> hmiDevices = Service.GetHmiDevicesInGroup(newGroup);
                ManageHmi      hmis       = new ManageHmi(hmiDevices);

                IList <Device> driveDevices = Service.GetG120DevicesInGroup(newGroup);
                ManageDrive    drives       = new ManageDrive(driveDevices);

                IList <Device> allDevices    = Service.GetAllDevicesInGroup(newGroup);
                IList <Device> tempIoDevices = allDevices.Except(hmis.AllDevices).Except(drives.AllDevices).ToList();
                tempIoDevices.Remove(plcs.AllDevices[0]);
                ManageIo ioDevices = new ManageIo(tempIoDevices);

                #endregion

                #region change settigns
                plcs.ChangeIpAddresses(groupCounter - 1);
                plcs.CreateNewIoSystem(templatePlcs.originalSubnet, currentPrefix);
                plcs.ConnectToMasterIoSystem(templatePlcs.originalIoSystem);
                plcs.GetAll_iDeviceParnerIoAdresses();
                plcs.CopyFromTemplate(templatePlcs);
                plcs.AdjustFSettings(Parameters.FBaseAddrOffset * (groupCounter - 1), Parameters.FDestAddrOffset * (groupCounter - 1));
                plcs.AdjustPnDeviceNumberWithOffset((groupCounter - 1));
                plcs.AdjustPartnerIoAddresses(Parameters.IDeviceIoAddressOffset * (groupCounter - 1));
                plcs.Restore();
                plcs.ChangePnDeviceNames(currentPrefix);
                //plcs.SetAllIDeviceParnerAdresses();

                ioDevices.ChangeIpAddresses(groupCounter - 1);
                ioDevices.SwitchIoSystem(templatePlcs.originalSubnet, plcs.newIoSystem);
                if (templatePlcs.LowerBoundForFDestinationAddresses_attribues?.Value != null)
                {
                    ioDevices.AdjustFDestinationAddress(Parameters.FDestAddrOffset * (groupCounter - 1), (ulong)templatePlcs.LowerBoundForFDestinationAddresses_attribues.Value, (ulong)templatePlcs.UpperBoundForFDestinationAddresses_attribues.Value);
                }
                ioDevices.Restore();
                ioDevices.ChangePnDeviceNames(currentPrefix);

                hmis.ChangeIpAddresses(groupCounter - 1);
                hmis.DisconnectFromSubnet();
                hmis.ConnectToSubnet(templatePlcs.originalSubnet);
                hmis.Restore();
                hmis.ChangePnDeviceNames(currentPrefix);

                drives.ChangeIpAddresses(groupCounter - 1);
                drives.SwitchIoSystem(templatePlcs.originalSubnet, plcs.newIoSystem);
                if (templatePlcs.LowerBoundForFDestinationAddresses_attribues?.Value != null)
                {
                    drives.AdjustFDestinationAddress(Parameters.FDestAddrOffset * (groupCounter - 1), (ulong)templatePlcs.LowerBoundForFDestinationAddresses_attribues.Value, (ulong)templatePlcs.UpperBoundForFDestinationAddresses_attribues.Value);
                }
                drives.Restore();
                drives.ChangePnDeviceNames(currentPrefix);

                plcs.SetAllToConnections();


                plcs.RestoreAllPartnerPorts();
                hmis.RestoreAllPartnerPorts();
                drives.RestoreAllPartnerPorts();
                ioDevices.RestoreAllPartnerPorts();

                #endregion

                plcs.DelecteOldSubnet();
                //deleteNetworkSubnet.Delete();
            }

            #endregion

            try
            {
                deleteMasterCopy.Delete();
            }
            catch (Exception ex)
            {
                Program.FaultMessage("Could not delete Mastercopy.", ex);
            }

            Progress("");

            Console.WriteLine("Copy complete.");
            if (tiaStartedWithoutInterface == true)
            {
                Console.WriteLine("Saving project.");
                project.Save();
                project.Close();
            }
            else
            {
                Console.WriteLine("Please save project within TIAP.");
            }

            try
            {
                tiaPortal.Dispose();
            }
            catch
            {
            }
        }
 //Clean library
 private void CleanupLibrary(MasterCopy mastercopy)
 {
     mastercopy.Delete();
 }