예제 #1
0
        internal void StartDiffProcessAsync()
        {
            Simatic _Simatic;
            try
            {
                IsBusy = true;

                //_Simatic = new Simatic();

                ProgressBarMax = 10;
                ProgressBarCurrent = 1;

                DateTime tsSearchTimeStart = DateTime.Now;
                EventFire.Info("Merging. Search start timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                if (CurrentBlock.Value.LeftBlock.ModifiedSimilarity == BlockSimilarityType.Orphan)
                {
                    EventFire.Error("Merging. Can't merge orphan blocks.");
                    return;
                }
                _Simatic = new Simatic();

                if (_Simatic == null)
                {
                    EventFire.Info("Merging. Creating Simatic instance.");
                    _Simatic = new Simatic();
                }
                ProgressBarCurrent++;

                // Attaching both projects
                LoadingBothSimaticProjects(ref _Simatic);

                // Special logic to merge source files
                if (CurrentBlock.Value.LeftBlock.Type == PLCBlockType.SourceBlock && CurrentBlock.Value.RightBlock.Type == PLCBlockType.SourceBlock)
                {
                    S7Source rightBlock = null;
                    S7Source leftBlock = null;
                    rightBlock = FindCurrentSourceInProgram(_RightProject, ref _dicRightSimaticCache);
                    leftBlock = FindCurrentSourceInProgram(_LeftProject, ref _dicLeftSimaticCache);
                    // TODO: wrap it into function
                    // Find left and right blocks at the same time
                    //Thread thRight = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Merging Source. Searching for the right block in Simatic structure.");
                    //    rightBlock = FindCurrentSourceInProgram(_RightProject.Programs, ref _dicRightSimaticCache);
                    //    EventFire.Info("Merging Source. Right block found.");
                    //}));
                    //thRight.Start();

                    //Thread thLeft = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Merging Source. Searching for the left block in Simatic structure.");
                    //    leftBlock = FindCurrentSourceInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache);
                    //    EventFire.Info("Merging Source. Left block found.");
                    //}));
                    //thLeft.Start();

                    //// Wait for both threads to complete
                    //thRight.Join();
                    //thLeft.Join();
                    //// TODO: end wrap it into function

                    ProgressBarCurrent++;

                    EventFire.Info("Merging. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                    S7_BlockCopyMerge mrg = new S7_BlockCopyMerge();
                    mrg.MergeBlocks(leftBlock, rightBlock, ExtractRightProjectPath, CurrentBlock);
                }
                else
                {
                    // Standard FB/FC/DB

                    S7Block leftBlock = null;
                    S7Block rightBlock = null;
                    rightBlock = FindCurrentBlockInProgram(_RightProject, ref _dicRightSimaticCache);
                    leftBlock = FindCurrentBlockInProgram(_LeftProject, ref _dicLeftSimaticCache);
                    // TODO: wrap it into function
                    // Find left and right blocks at the same time
                    //Thread thRight = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Merging. Searching for the right block in Simatic structure.");
                    //    rightBlock = FindCurrentBlockInProgram(_RightProject.Programs, ref _dicRightSimaticCache);
                    //    EventFire.Info("Merging. Right block found.");
                    //}));
                    //thRight.Start();

                    //Thread thLeft = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Merging. Searching for the left block in Simatic structure.");
                    //    leftBlock = FindCurrentBlockInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache);
                    //    EventFire.Info("Merging. Left block found.");
                    //}));
                    //thLeft.Start();

                    //// Wait for both threads to complete
                    //thRight.Join();
                    //thLeft.Join();
                    // TODO: end wrap it into function

                    ProgressBarCurrent++;

                    EventFire.Info("Merging. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                    S7_BlockCopyMerge mrg = new S7_BlockCopyMerge();
                    mrg.MergeBlocks(leftBlock, rightBlock);

                }
                ProgressBarCurrent++;

                // TODO: Remove temp files

                // Refresh list
                EventFire.Info("Merging. Refreshing projects.");
                GetBlocksAsync(ExtractRightProjectPath, ExtractLeftProjectPath);

                ProgressBarCurrent = ProgressBarMax;

                EventFire.Info("Merging. Process completed.");
                IsBusy = false;
            }
            catch (Exception err)
            {
                EventFire.Error(err.ToString());
            }
        }
예제 #2
0
        internal void CopyBlockToRightAsync()
        {
            Simatic _Simatic = null;
            try
            {
                if (CurrentBlock.Key.Count() <= 0)
                {
                    return;
                }

                IsBusy = true;
                ProgressBarMax = 10;
                ProgressBarCurrent = 1;

                DateTime tsSearchTimeStart = DateTime.Now;
                EventFire.Info("Copying. Search start timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                if (_Simatic == null)
                {
                    EventFire.Info("Copying. Creating Simatic instance.");
                    _Simatic = new Simatic();
                }

                // Trying to find loaded projects
                LoadingBothSimaticProjects(ref _Simatic);

                // Special logic to copy source files
                if (CurrentBlock.Value.LeftBlock.Type == PLCBlockType.SourceBlock && CurrentBlock.Value.RightBlock.Type == PLCBlockType.SourceBlock)
                {
                    // Special case - copying source blocks
                    S7Source rightBlock = null;
                    S7Source leftBlock = null;
                    rightBlock = FindCurrentSourceInProgram(_RightProject, ref _dicRightSimaticCache);
                    leftBlock = FindCurrentSourceInProgram(_LeftProject, ref _dicLeftSimaticCache);

                    //// TODO: wrap it into function
                    //// Find left and right blocks at the same time
                    //Thread thRight = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Copying Source. Searching for the right block in Simatic structure.");
                    //    rightBlock = FindCurrentSourceInProgram(_RightProject.Programs, ref _dicRightSimaticCache);
                    //    EventFire.Info("Copying Source. Right block found.");
                    //}));
                    //thRight.Start();

                    //Thread thLeft = new Thread(new ThreadStart(() =>
                    // {
                    //    EventFire.Info("Copying Source. Searching for the left block in Simatic structure.");
                    //    leftBlock = FindCurrentSourceInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache);
                    //    EventFire.Info("Copying Source. Left block found.");
                    //}));
                    //thLeft.Start();

                    //// Wait for both threads to complete
                    //thRight.Join();
                    //thLeft.Join();
                    //// TODO: end wrap it into function

                    ProgressBarCurrent++;

                    // Find right block folder
                    IS7Container rightFolder = FindBlockFolderInProgram(CurrentBlock, _RightProject, ref _dicRightSimaticCache);

                    EventFire.Info("Copying. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                    S7_BlockCopyMerge mrg = new S7_BlockCopyMerge();
                    if (mrg.CopyBlock(leftBlock, rightBlock, rightFolder))
                    {
                        // Need to refresh right cache
                        EventFire.Info("Copying. Clearing right project cache.");
                        this._dicRightSimaticCache.dicProgramsLogPath.Clear();
                    }
                }
                else
                {
                    // Standard block FC/FB/DB
                    S7Block leftBlock = null;
                    S7Block rightBlock = null;
                    rightBlock = FindCurrentBlockInProgram(_RightProject, ref _dicRightSimaticCache);
                    leftBlock = FindCurrentBlockInProgram(_LeftProject, ref _dicLeftSimaticCache);

                    // TODO: wrap it into function
                    // Find left and right blocks at the same time
                    //Thread thRight = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Copying. Searching for the right block in Simatic structure.");
                    //    rightBlock = FindCurrentBlockInProgram(_RightProject.Programs, ref _dicRightSimaticCache);
                    //    EventFire.Info("Copying. Right block found.");
                    //}));
                    //thRight.SetApartmentState(ApartmentState.STA);
                    //thRight.Start();

                    //Thread thLeft = new Thread(new ThreadStart(() =>
                    //{
                    //    EventFire.Info("Copying. Searching for the left block in Simatic structure.");
                    //    leftBlock = FindCurrentBlockInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache);
                    //    EventFire.Info("Copying. Left block found.");
                    //}));
                    //thLeft.SetApartmentState(ApartmentState.STA);
                    //thLeft.Start();

                    //// Wait for both threads to complete
                    //thRight.Join();
                    //thLeft.Join();
                    //// TODO: end wrap it into function

                    ProgressBarCurrent++;

                    // Find right block folder
                    IS7Container rightFolder = FindBlockFolderInProgram(CurrentBlock, _RightProject, ref _dicRightSimaticCache);

                    EventFire.Info("Copying. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s");

                    // Copy block to the right
                    S7_BlockCopyMerge mrg = new S7_BlockCopyMerge();
                    if (mrg.CopyBlock(leftBlock, rightBlock, rightFolder))
                    {
                        // Need to refresh right cache
                        EventFire.Info("Copying. Clearing right project cache.");
                        this._dicRightSimaticCache.dicProgramsLogPath.Clear();
                    }

                    ProgressBarCurrent++;
                }

                ProgressBarCurrent++;

                EventFire.Info("Copying. Refreshing projects.");

                GetBlocksAsync(ExtractRightProjectPath, ExtractLeftProjectPath);

                ProgressBarCurrent = ProgressBarMax;
                EventFire.Info("Copying. Process completed.");
                IsBusy = false;
            }
            catch (Exception err)
            {
                EventFire.Error(err.ToString());
            }
        }