Ejemplo n.º 1
0
        public void MergeBlocks(S7Source leftBlock, S7Source rightBlock, string ExtractRightProjectPath, KeyValuePair<String, Blocks> CurrentBlock)
        {
            // Should have both blocks
            if (leftBlock == null || rightBlock == null)
            {
                EventFire.Error("Merge Source Blocks. Can't find block in the Simatic structure.");
                return;
            }

            EventFire.Info("Merge Source Blocks. Exporting right source.");
            if (!Directory.Exists(_RightSourceFilePath)) Directory.CreateDirectory(_RightSourceFilePath);
            String rightSourceFileName = _RightSourceFilePath + rightBlock.Name + ".scl";
            rightBlock.Export(rightSourceFileName);

            EventFire.Info("Merge Source Blocks. Exporting left source.");
            if (!Directory.Exists(_LeftSourceFilePath)) Directory.CreateDirectory(_LeftSourceFilePath);
            String leftSourceFileName = _LeftSourceFilePath + leftBlock.Name + ".scl";
            leftBlock.Export(leftSourceFileName);

            String mergedSourceFileName = _MergedSourceFilePath + rightBlock.Name + ".scl";

            Process DiffProcess = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "TortoiseMerge.exe",
                    Arguments = "/base:\"" + leftSourceFileName + "\" /mine:\"" + rightSourceFileName + "\" /merged:\"" + mergedSourceFileName + "\""
                }
            };
            DiffProcess.Start();
            DiffProcess.WaitForExit();

            if (File.Exists(mergedSourceFileName))
            {
                // Can't find any gracefull way of importing source block - just override the file
                String strSrcFile = ExtractRightProjectPath + ((BlockSource)CurrentBlock.Value.RightBlock).Filename.Replace(@"/", @"\");
                File.Copy(mergedSourceFileName, strSrcFile, true);

                EventFire.Info("Merge Source Blocks. Compiling block");
                S7SWItems s7swReturn = rightBlock.Compile();

                // AppWindowHandle crashes. Find window hwnd and wait till they done editing/compiling
                //IntPtr hwnd = (IntPtr)rightBlock.AppWindowHandle;
                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;
                    }
                }

                //ShowWindow(hwnd, 6);    // 0 = hide the window, 6 = minimize

                // Seems to be a bug, compile always returns 0
                if (s7swReturn.Count <= 0)
                {
                    // Something is not right - show edit window
                    //EventFire.Error("Can't compile block, please resolve compilation errors");
                    EventFire.Info("Merge Source Blocks. 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 (IsWindow(hwnd)) ;
                    while (!proc.HasExited) ;
                }
                else
                {
                    // Close editor window
                    EventFire.Info("Merge Source Blocks. Compiled successfully");
                    SendMessage(hwnd, 0x0112, 0xF060, 0); // 0xF060 = SC_CLOSE; 0x0112 = WM_SYSCOMMAND
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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;
        }
Ejemplo n.º 4
0
        public void MergeBlocks(S7Source leftBlock, S7Source rightBlock, string ExtractRightProjectPath, KeyValuePair <String, Blocks> CurrentBlock)
        {
            // Should have both blocks
            if (leftBlock == null || rightBlock == null)
            {
                EventFire.Error("Merge Source Blocks. Can't find block in the Simatic structure.");
                return;
            }

            EventFire.Info("Merge Source Blocks. Exporting right source.");
            if (!Directory.Exists(_RightSourceFilePath))
            {
                Directory.CreateDirectory(_RightSourceFilePath);
            }
            String rightSourceFileName = _RightSourceFilePath + rightBlock.Name + ".scl";

            rightBlock.Export(rightSourceFileName);

            EventFire.Info("Merge Source Blocks. Exporting left source.");
            if (!Directory.Exists(_LeftSourceFilePath))
            {
                Directory.CreateDirectory(_LeftSourceFilePath);
            }
            String leftSourceFileName = _LeftSourceFilePath + leftBlock.Name + ".scl";

            leftBlock.Export(leftSourceFileName);

            String mergedSourceFileName = _MergedSourceFilePath + rightBlock.Name + ".scl";

            Process DiffProcess = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = "TortoiseMerge.exe",
                    Arguments = "/base:\"" + leftSourceFileName + "\" /mine:\"" + rightSourceFileName + "\" /merged:\"" + mergedSourceFileName + "\""
                }
            };

            DiffProcess.Start();
            DiffProcess.WaitForExit();

            if (File.Exists(mergedSourceFileName))
            {
                // Can't find any gracefull way of importing source block - just override the file
                String strSrcFile = ExtractRightProjectPath + ((BlockSource)CurrentBlock.Value.RightBlock).Filename.Replace(@"/", @"\");
                File.Copy(mergedSourceFileName, strSrcFile, true);

                EventFire.Info("Merge Source Blocks. Compiling block");
                S7SWItems s7swReturn = rightBlock.Compile();

                // AppWindowHandle crashes. Find window hwnd and wait till they done editing/compiling
                //IntPtr hwnd = (IntPtr)rightBlock.AppWindowHandle;
                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;
                    }
                }

                //ShowWindow(hwnd, 6);    // 0 = hide the window, 6 = minimize

                // Seems to be a bug, compile always returns 0
                if (s7swReturn.Count <= 0)
                {
                    // Something is not right - show edit window
                    //EventFire.Error("Can't compile block, please resolve compilation errors");
                    EventFire.Info("Merge Source Blocks. 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 (IsWindow(hwnd)) ;
                    while (!proc.HasExited)
                    {
                        ;
                    }
                }
                else
                {
                    // Close editor window
                    EventFire.Info("Merge Source Blocks. Compiled successfully");
                    SendMessage(hwnd, 0x0112, 0xF060, 0); // 0xF060 = SC_CLOSE; 0x0112 = WM_SYSCOMMAND
                }
            }
        }