/// <summary> /// Copy S7 block to the right. Returns true if right project structure changed (block added/removed) /// </summary> /// <param name="leftBlock"></param> /// <param name="rightBlock"></param> /// <param name="rightFolder"></param> /// <returns></returns> public bool CopyBlock(S7Block leftBlock, S7Block rightBlock, IS7Container rightFolder) { // Standard blocks FB/FC/DB bool bRes = false; if (leftBlock != null) { // Source block exists if (rightBlock != null) { // Target block also exists - copy! EventFire.Info("Copying S7 Block. Copying block to the right."); // Magic happened here. Deleting and re-creating block doesn't affect cache // Because new block somehow gets created with the same array index as the old one rightBlock.Remove(); leftBlock.Copy(rightBlock.Parent); EventFire.Info("Copying S7 Block. Done."); } else { if (rightFolder != null) { // Right block does not exists - create a new one EventFire.Info("Copying S7 Block. Right block does not exisits. Creating new block."); leftBlock.Copy(rightFolder); EventFire.Info("Copying S7 Block. Done."); // Just created a new block - need to update right cache // TODO: Smart cache update - only current folder bRes = true; } else { EventFire.Error("Copying S7 Block. Right block does not exisits. Can't find corresponding parent foder in the right Simatic project."); } } } else { // Source block does not exists - remove target block EventFire.Info("Copying S7 Block. Left block does not exists. Deleting right block."); rightBlock.Remove(); // TODO: Maybe we don't need to refresh cache? Verify // Just deleted a block - need to update cache bRes = true; EventFire.Info("Copying S7 Block. Done."); } return bRes; }
/// <summary> /// Copy S7 block to the right. Returns true if right project structure changed (block added/removed) /// </summary> /// <param name="leftBlock"></param> /// <param name="rightBlock"></param> /// <param name="rightFolder"></param> /// <returns></returns> public bool CopyBlock(S7Block leftBlock, S7Block rightBlock, IS7Container rightFolder) { // Standard blocks FB/FC/DB bool bRes = false; if (leftBlock != null) { // Source block exists if (rightBlock != null) { // Target block also exists - copy! EventFire.Info("Copying S7 Block. Copying block to the right."); // Magic happened here. Deleting and re-creating block doesn't affect cache // Because new block somehow gets created with the same array index as the old one rightBlock.Remove(); leftBlock.Copy(rightBlock.Parent); EventFire.Info("Copying S7 Block. Done."); } else { if (rightFolder != null) { // Right block does not exists - create a new one EventFire.Info("Copying S7 Block. Right block does not exisits. Creating new block."); leftBlock.Copy(rightFolder); EventFire.Info("Copying S7 Block. Done."); // Just created a new block - need to update right cache // TODO: Smart cache update - only current folder bRes = true; } else { EventFire.Error("Copying S7 Block. Right block does not exisits. Can't find corresponding parent foder in the right Simatic project."); } } } else { // Source block does not exists - remove target block EventFire.Info("Copying S7 Block. Left block does not exists. Deleting right block."); rightBlock.Remove(); // TODO: Maybe we don't need to refresh cache? Verify // Just deleted a block - need to update cache bRes = true; EventFire.Info("Copying S7 Block. Done."); } return(bRes); }
/// <summary> /// Copy source block to the right /// </summary> /// <param name="CurrentBlock"></param> public bool CopyBlock(S7Source leftBlock, S7Source rightBlock, IS7Container rightFolder) { // Copying source block bool bRes = false; if (leftBlock != null) { // Source block exists if (rightBlock != null) { // Target block also exists - copy! EventFire.Info("Copying Source Block. Copying block to the right."); // Magic happened here. Deleting and re-creating block doesn't affect cache // Because new block somehow gets created with the same array index as the old one rightBlock.Remove(); leftBlock.Copy(rightBlock.Parent); } else { if (rightFolder != null) { // Right block does not exists - create a new one EventFire.Info("Copying Source Block. Right block does not exisits. Creating new block."); leftBlock.Copy(rightFolder); // Just created a new block - need to update right cache // TODO: Smart cache update - only current folder bRes = true; } else { EventFire.Error("Copying Source Block. Right block does not exisits. Can't find corresponding parent foder in the right Simatic project."); return false; } } // TODO: Enable compiling block after copy //// Source copied, time to compile it //EventFire.Info("Copying Source Blocks. Compiling block"); //S7SWItems s7swReturn = rightBlock.Compile(); //// AppWindowHandle crashes. Find window hwnd and wait till they done editing/compiling //IntPtr hwnd = IntPtr.Zero; //Process[] processRunning = Process.GetProcesses(); //Process proc = null; //foreach (Process pr in processRunning) //{ // if (pr.ProcessName == "s7sclapx") // { // proc = pr; // hwnd = pr.Handle; // break; // } //} //// TODO: Seems to be a bug, Compile always returns 0 //EventFire.Info("Copying Source Block. Please review/compile block and close SCL editor."); //ShowWindow(hwnd, 3); // 3 - maximize //rightBlock.Edit(); //// Wait till they fixed it and close the window //while (!proc.HasExited); EventFire.Info("Copying Source Block. Done."); } else { // Source block does not exists - remove target block EventFire.Info("Copying Source Block. Left block does not exists. Deleting right block."); rightBlock.Remove(); EventFire.Info("Copying Source Blocks. Done."); // Just deleted a block - need to update cache // TODO: Smart cache update - only current folder bRes = true; } return bRes; }
/// <summary> /// Copy source block to the right /// </summary> /// <param name="CurrentBlock"></param> public bool CopyBlock(S7Source leftBlock, S7Source rightBlock, IS7Container rightFolder) { // Copying source block bool bRes = false; if (leftBlock != null) { // Source block exists if (rightBlock != null) { // Target block also exists - copy! EventFire.Info("Copying Source Block. Copying block to the right."); // Magic happened here. Deleting and re-creating block doesn't affect cache // Because new block somehow gets created with the same array index as the old one rightBlock.Remove(); leftBlock.Copy(rightBlock.Parent); } else { if (rightFolder != null) { // Right block does not exists - create a new one EventFire.Info("Copying Source Block. Right block does not exisits. Creating new block."); leftBlock.Copy(rightFolder); // Just created a new block - need to update right cache // TODO: Smart cache update - only current folder bRes = true; } else { EventFire.Error("Copying Source Block. Right block does not exisits. Can't find corresponding parent foder in the right Simatic project."); return(false); } } // TODO: Enable compiling block after copy //// Source copied, time to compile it //EventFire.Info("Copying Source Blocks. Compiling block"); //S7SWItems s7swReturn = rightBlock.Compile(); //// AppWindowHandle crashes. Find window hwnd and wait till they done editing/compiling //IntPtr hwnd = IntPtr.Zero; //Process[] processRunning = Process.GetProcesses(); //Process proc = null; //foreach (Process pr in processRunning) //{ // if (pr.ProcessName == "s7sclapx") // { // proc = pr; // hwnd = pr.Handle; // break; // } //} //// TODO: Seems to be a bug, Compile always returns 0 //EventFire.Info("Copying Source Block. Please review/compile block and close SCL editor."); //ShowWindow(hwnd, 3); // 3 - maximize //rightBlock.Edit(); //// Wait till they fixed it and close the window //while (!proc.HasExited); EventFire.Info("Copying Source Block. Done."); } else { // Source block does not exists - remove target block EventFire.Info("Copying Source Block. Left block does not exists. Deleting right block."); rightBlock.Remove(); EventFire.Info("Copying Source Blocks. Done."); // Just deleted a block - need to update cache // TODO: Smart cache update - only current folder bRes = true; } return(bRes); }