コード例 #1
0
        public ActionResult CopyVersion(Signal signal)
        {
            //originalSignalVersion = SetDetectionTypes(originalSignalVersion);
            //MOE.Common.Models.Repositories.ISignalsRepository repository =
            //    MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create();
            //repository.AddOrUpdate(originalSignalVersion);
            Signal copyVersion = new Signal();

            Signal originalSignalVersion = _signalsRepository.GetLatestVersionOfSignalBySignalID(signal.SignalID);

            if (originalSignalVersion != null)
            {
                copyVersion = Signal.CopyVersion(originalSignalVersion);
                copyVersion.VersionActionId = 4;
                copyVersion.Start           = DateTime.Now;
                copyVersion.IPAddress       = originalSignalVersion.IPAddress;
                copyVersion.Note            = "Copy of Version " + originalSignalVersion.Note;
            }
            try
            {
                _signalsRepository.AddOrUpdate(copyVersion);
                var commentRepository = MOE.Common.Models.Repositories.MetricCommentRepositoryFactory.Create();
                foreach (var origVersionComment in originalSignalVersion.Comments)
                {
                    MetricComment metricComment = new MetricComment
                    {
                        CommentText = origVersionComment.CommentText,
                        VersionID   = copyVersion.VersionID,
                        SignalID    = originalSignalVersion.SignalID,
                        TimeStamp   = origVersionComment.TimeStamp,
                    };
                    if (origVersionComment.MetricTypes != null)
                    {
                        metricComment.MetricTypeIDs = new List <int>();
                        foreach (var metricType in origVersionComment.MetricTypes)
                        {
                            metricComment.MetricTypeIDs.Add(metricType.MetricID);
                        }
                    }
                    if (origVersionComment.MetricIDs != null)
                    {
                        metricComment.MetricIDs = (int[])origVersionComment.MetricIDs.Clone();
                    }
                    metricComment.MetricTypes = origVersionComment.MetricTypes;
                    //commentRepository.Add(metricComment);
                    copyVersion.Comments.Add(metricComment);
                }
                _signalsRepository.AddOrUpdate(copyVersion);
                copyVersion = _signalsRepository.GetLatestVersionOfSignalBySignalID(copyVersion.SignalID);
            }
            catch (Exception ex)
            {
                return(Content("<h1>" + ex.Message + "</h1>"));
            }
            finally
            {
                AddSelectListsToViewBag(copyVersion);
            }
            return(PartialView("Edit", copyVersion));
        }
コード例 #2
0
ファイル: SignalTests.cs プロジェクト: gmonk/ATSPM
        public void CopyVersionTest()
        {
            var    signalRepository = Repositories.SignalsRepositoryFactory.Create();
            Signal signal           = signalRepository.GetLatestVersionOfSignalBySignalID("7064");
            Signal signalCopy       = Signal.CopyVersion(signal);

            Assert.IsFalse(signal.VersionID == signalCopy.VersionID);
            Assert.IsTrue(signal.VersionList.Count == signalCopy.VersionList.Count);
            Assert.IsFalse(signal.Start == signalCopy.Start);
            Assert.IsFalse(signal.SelectListName == signalCopy.SelectListName);
            Assert.IsNotNull(signalCopy);
        }