示例#1
0
        //*********************************************************************
        ///
        /// <summary>
        ///     This method is used to Sync VM Object with CMP.
        /// </summary>
        ///
        //*********************************************************************

        void SyncWithCmp()
        {
            var cmpi = new VMServiceRepository(_eventLog);
            var cwdb = new CmpWapDb();

            foreach (CreateVm vM in VmList.ToList())
            {
                //*** If status is complete or exception then don't process ***
                //if (vM.StatusCode.Equals(CmpInterfaceModel.Constants.StatusEnum.Complete.ToString()) ||
                //    vM.StatusCode.Equals(CmpInterfaceModel.Constants.StatusEnum.Exception.ToString()))

                if (vM.StatusCode.Equals(CmpInterfaceModel.Constants.StatusEnum.Complete.ToString()))
                {
                    continue;
                }

                try
                {
                    //*** Access the CMP service ***
                    var fetchedVm = cmpi.FetchCmpRequest(vM.CmpRequestId);

                    //*** update CmpWapDb if status has changed ***
                    //if (!vM.StatusCode.Equals(fetchedVm.Status))

                    if (true)

                    {
                        vM.StatusCode    = fetchedVm.Status;
                        vM.StatusMessage = fetchedVm.StatusMessage;



                        var cmpWapReq = new Models.CmpRequest
                        {
                            StatusCode       = fetchedVm.Status,
                            StatusMessage    = GetStatusMessage(fetchedVm),
                            ExceptionMessage = fetchedVm.ExceptionMessage,
                            Id     = vM.Id,
                            Config = fetchedVm.Config
                        };

                        if (null != fetchedVm.Config)
                        {
                            var vmc = CmpInterfaceModel.Models.VmConfig.Deserialize(fetchedVm.Config);
                            if (null != vmc)
                            {
                                if (null != vmc.InfoFromVM)
                                {
                                    cmpWapReq.AddressFromVm = vmc.InfoFromVM.VmAddress;
                                }
                            }
                        }

                        cwdb.SetVmDepRequestStatus(cmpWapReq, null);
                    }
                }
                catch (Exception)
                {
                    vM.StatusCode    = "NoCmpContact";
                    vM.StatusMessage = "Temporarily unable to contact CMP for status";
                }
            }
        }