예제 #1
0
        public async Task <MachineExecutionResult> GetMachines(string siteModelID,
                                                               [FromServices] ICoordinateServiceUtility coordinateServiceUtility)
        {
            Log.LogInformation($"{nameof(GetMachines)}: siteModelID: {siteModelID}");

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(GetMachines), siteModelID);
            var CSIB      = siteModel.CSIB();

            if (string.IsNullOrEmpty(CSIB))
            {
                Log.LogError($"{nameof(GetMachines)}: siteModel has no CSIB");
                throw new ServiceException(System.Net.HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "The SiteModel has no CSIB."));
            }

            var machines = siteModel.Machines.ToList();
            var result   = new MachineExecutionResult(new List <MachineStatus>(machines.Count));

            if (machines.Any())
            {
                var resultMachines = machines.Select(machine => AutoMapperUtility.Automapper.Map <MachineStatus>(machine)).ToList();
                var response       = await coordinateServiceUtility.PatchLLH(siteModel.CSIB(), resultMachines);

                result.MachineStatuses = resultMachines;

                // todo once corex is implemented, we will have a better idea why patching fails
                //if (response == ContractExecutionStatesEnum.ExecutedSuccessfully)
                //  result.MachineStatuses = resultMachines;
                //else
                //  return (MachineExecutionResult) new ContractExecutionResult(response);
            }

            Log.LogInformation($"{nameof(GetMachines)}: result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
예제 #2
0
        public Task <ContractExecutionResult> UpdateDesign([FromBody] DesignRequest designRequest)
        {
            Log.LogInformation($"{nameof(UpdateDesign)}: {JsonConvert.SerializeObject(designRequest)}");
            designRequest.Validate();
            GatewayHelper.ValidateAndGetSiteModel(nameof(UpdateDesign), designRequest.ProjectUid, true);

            if (!DesignExists(designRequest.ProjectUid, designRequest.FileType, designRequest.DesignUid))
            {
                return(Task.FromResult(new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Design doesn't exist. Cannot update.")));
            }

            if (designRequest.FileType == ImportedFileType.DesignSurface || designRequest.FileType == ImportedFileType.SurveyedSurface)
            {
                return(WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainer
                                                           .Build <UpdateTTMDesignExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                           .ProcessAsync(designRequest)));
            }

            if (designRequest.FileType == ImportedFileType.Alignment)
            {
                return(WithServiceExceptionTryExecuteAsync(() =>
                                                           RequestExecutorContainer
                                                           .Build <UpdateSVLDesignExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                           .ProcessAsync(designRequest)));
            }
            throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "File type must be DesignSurface, SurveyedSurface or Alignment"));
        }
예제 #3
0
        /// <summary>
        /// Filter validation common to APIs passing 3dp Filter/s
        /// </summary>
        /// <param name="method"></param>
        /// <param name="projectUid"></param>
        /// <param name="filterResult"></param>
        /// <exception cref="ServiceException"></exception>
        protected void ValidateFilterMachines(string method, Guid?projectUid, FilterResult filterResult)
        {
            if (projectUid == null || projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"Invalid project UID {projectUid}"));
            }
            var siteModel = GatewayHelper.ValidateAndGetSiteModel(method, projectUid.Value);

            if (filterResult?.ContributingMachines != null)
            {
                GatewayHelper.ValidateMachines(filterResult.ContributingMachines.Select(m => m.AssetUid).ToList(), siteModel);
            }

            if (filterResult != null && !string.IsNullOrEmpty(filterResult.OnMachineDesignName))
            {
                var machineDesign = siteModel.SiteModelMachineDesigns.Locate(filterResult.OnMachineDesignName);
                if (machineDesign == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           $"Unknown DesignName: {filterResult.OnMachineDesignName}."));
                }

                filterResult.OnMachineDesignId = machineDesign.Id;
            }
        }
예제 #4
0
        public void GatewayHelper_NoMachines()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);

            var contributingMachines = new List <Guid?>();

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
        /// <summary>
        /// Adds a named <see cref="HttpClient"/> for the specified gateway.
        /// </summary>
        /// <typeparam name="TGateway"></typeparam>
        /// <param name="services"></param>
        public static IHttpClientBuilder AddHttpClientForGateway <TGateway>(this IServiceCollection services) where TGateway : class, IGateway
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            return(services.AddHttpClient(GatewayHelper.GetCompleteGatewayName <TGateway>()));
        }
예제 #6
0
        public void GatewayHelper_NoContributingMachines()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>();

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
예제 #7
0
        public AssetOnDesignLayerPeriodsExecutionResult GetMachineLayers(string siteModelID)
        {
            Log.LogInformation($"{nameof(GetMachineLayers)}: siteModelID: {siteModelID}");

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(GetMachineLayers), siteModelID);
            var result    = new AssetOnDesignLayerPeriodsExecutionResult(siteModel.GetAssetOnDesignLayerPeriods());

            Log.LogInformation($"{nameof(GetMachineLayers)}: result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
예제 #8
0
        public async Task <IActionResult> ChangeWanIp()
        {
            GatewayHelper.ChangeWanIp();
            if (ConfigHelper.Instance.HitWhenIpChanges.HasValue())
            {
                await _updateEndpointClient.GetAsync(ConfigHelper.Instance.HitWhenIpChanges);
            }

            _lastKnownIp = GatewayHelper.GetCurrentIp();
            return(RedirectToAction(nameof(Index)));
        }
예제 #9
0
        public IActionResult Change(bool redirect, string ip)
        {
            if (redirect)
            {
                GatewayHelper.AddRedirection(ip);
            }
            else
            {
                GatewayHelper.DeleteRedirection(ip);
            }

            return(Redirect("/"));
        }
예제 #10
0
        public void GatewayHelper_ContributingMachineEmptyGuid()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?> {
                new Guid()
            };
            var result = Assert.Throws <ServiceException>(() => GatewayHelper.ValidateMachines(contributingMachines, siteModel));

            result.Code.Should().Be(HttpStatusCode.BadRequest);
            result.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            result.GetResult.Message.Should().Be($"ValidateMachines: SiteModel: {siteModel.ID} machineUid not found: {contributingMachines[0]}");
        }
예제 #11
0
파일: Program.cs 프로젝트: g3rv4/DnsChanger
        static void Main(string[] args)
        {
            ConfigHelper.Init("/Users/gervasio/Projects/DnsChanger/config.json");

            var status = GatewayHelper.GetRedirectedIps();

            GatewayHelper.AddRedirection("192.168.4.6");
            GatewayHelper.AddRedirection("192.168.3.9");
            status = GatewayHelper.GetRedirectedIps();
            GatewayHelper.DeleteRedirection("192.168.4.6");
            GatewayHelper.DeleteRedirection("192.168.3.9");
            status = GatewayHelper.GetRedirectedIps();
            Console.WriteLine("Hello World!");
        }
예제 #12
0
        public void GatewayHelper_ContributingMachineMultiExists()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine1  = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var machine2  = siteModel.Machines.CreateNew("Test Machine 2", "", MachineType.Dozer, DeviceTypeEnum.SNM940, true, Guid.NewGuid());
            var machine3  = siteModel.Machines.CreateNew("Test Machine 3", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>
            {
                new Guid(machine3.ID.ToString()),
                new Guid(machine2.ID.ToString())
            };

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
        /// <summary>
        /// Sets the gateway from the pre-defined <see cref="Gateway"/> enum.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="gateway"></param>
        /// <exception cref="InvalidEnumArgumentException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder UseGateway(this IInvoiceBuilder builder, Gateway gateway)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (!Enum.IsDefined(typeof(Gateway), gateway))
            {
                throw new InvalidEnumArgumentException(nameof(gateway), (int)gateway, typeof(Gateway));
            }

            var gatewayType = GatewayHelper.FindGatewayTypeByName(gateway.ToString());

            return(builder.SetGatewayType(gatewayType));
        }
        /// <summary>
        /// Sets the gateway using the given name. The given name must match the values of
        /// <see cref="Gateway"/> enum.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="gatewayName"></param>
        /// <exception cref="GatewayNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder UseGateway(this IInvoiceBuilder builder, string gatewayName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (gatewayName == null)
            {
                throw new ArgumentNullException(nameof(gatewayName));
            }

            var gatewayType = GatewayHelper.FindGatewayTypeByName(gatewayName, throwException: true);

            return(builder.SetGatewayType(gatewayType));
        }
예제 #15
0
        public ContractExecutionResult RebuildProject([FromBody] ProjectRebuildRequest rebuildRequest)
        {
            Log.LogInformation($"{nameof(RebuildProject)}: {JsonConvert.SerializeObject(rebuildRequest)}");
            rebuildRequest.Validate();
            GatewayHelper.ValidateAndGetSiteModel(nameof(RebuildProject), rebuildRequest.ProjectUid, true);

            if (rebuildRequest.DataOrigin == TransferProxyType.TAGFiles)
            {
                return(WithServiceExceptionTryExecute(() =>
                                                      RequestExecutorContainer
                                                      .Build <ProjectRebuildExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                      .Process(rebuildRequest)));
            }

            throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Data origin must be ''TAGFiles'' (enum TransferProxyType.TAGFiles)"));
        }
예제 #16
0
        public void GatewayHelper_NoSiteModel_Fail(Guid projectUid)
        {
            var mockSiteModels = new Mock <ISiteModels>();

            mockSiteModels.Setup(x => x.GetSiteModel(It.IsAny <Guid>(), It.IsAny <bool>())).Returns((ISiteModel)null);

            DIBuilder
            .New()
            .AddLogging()
            .Add(x => x.AddSingleton <ISiteModels>(mockSiteModels.Object))
            .Complete();

            var ex = Assert.Throws <ServiceException>(() => GatewayHelper.ValidateAndGetSiteModel("ValidateReportData_GriddedNoSiteModel_Fail", projectUid));

            ex.Code.Should().Be(HttpStatusCode.BadRequest);
            ex.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            ex.GetResult.Message.Should().Be($"ValidateReportData_GriddedNoSiteModel_Fail: SiteModel: {projectUid} not found ");
        }
예제 #17
0
        public ProjectStatisticsResult GetStatistics([FromBody] ProjectStatisticsTRexRequest projectStatisticsTRexRequest)
        {
            Log.LogInformation($"#In# {nameof(GetStatistics)}: projectStatisticsTRexRequest: {JsonConvert.SerializeObject(projectStatisticsTRexRequest)}");

            try
            {
                projectStatisticsTRexRequest.Validate();
                GatewayHelper.ValidateAndGetSiteModel(nameof(GetStatistics), projectStatisticsTRexRequest.ProjectUid);

                return(WithServiceExceptionTryExecute(() =>
                                                      RequestExecutorContainer
                                                      .Build <SiteModelStatisticsExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                      .Process(projectStatisticsTRexRequest) as ProjectStatisticsResult));
            }
            finally
            {
                Log.LogInformation($"#Out# {nameof(GetStatistics)}: projectStatisticsTRexRequest: {JsonConvert.SerializeObject(projectStatisticsTRexRequest)}");
            }
        }
예제 #18
0
        public BoundingBox3DGrid GetExtents(string siteModelID)
        {
            Log.LogInformation($"{nameof(GetExtents)}: siteModelID: {siteModelID}");

            var extents = GatewayHelper.ValidateAndGetSiteModel(nameof(GetExtents), siteModelID).SiteModelExtent;

            if (extents != null)
            {
                return(new BoundingBox3DGrid(
                           extents.MinX,
                           extents.MinY,
                           extents.MinZ,
                           extents.MaxX,
                           extents.MaxY,
                           extents.MaxZ
                           ));
            }

            return(null);
        }
예제 #19
0
        public void ValidateReportData_GriddedSuccess(Guid projectUid, Guid cutFillDesignUid, double?cutFillDesignOffset, Guid?alignmentDesignUid)
        {
            var mockSiteModel  = new Mock <ISiteModel>();
            var mockSiteModels = new Mock <ISiteModels>();

            mockSiteModels.Setup(x => x.GetSiteModel(It.IsAny <Guid>(), It.IsAny <bool>())).Returns(mockSiteModel.Object);

            var mockDesign        = new Mock <IDesign>();
            var mockDesigns       = new Mock <IDesigns>();
            var mockDesignManager = new Mock <IDesignManager>();

            mockDesignManager.Setup(x => x.List(It.IsAny <Guid>())).Returns(mockDesigns.Object);
            mockDesigns.Setup(x => x.Locate(It.IsAny <Guid>())).Returns(mockDesign.Object);

            var mockAlignments       = new Mock <IAlignments>();
            var mockAlignmentManager = new Mock <IAlignmentManager>();

            mockAlignmentManager.Setup(x => x.List(It.IsAny <Guid>())).Returns(mockAlignments.Object);
            mockAlignments.Setup(x => x.Locate(It.IsAny <Guid>())).Returns((IAlignment)null);

            DIBuilder
            .New()
            .AddLogging()
            .Add(x => x.AddSingleton <ISiteModels>(mockSiteModels.Object))
            .Add(x => x.AddSingleton <IDesignManager>(mockDesignManager.Object))
            .Add(x => x.AddSingleton <IAlignmentManager>(mockAlignmentManager.Object))
            .Add(x => x.AddTransient <IReportDataValidationUtility, ReportDataValidationUtility>())
            .Complete();

            var request = new CompactionReportGridTRexRequest(
                projectUid, null,
                true, true, true, true, true, true,
                cutFillDesignUid, cutFillDesignOffset,
                null, GridReportOption.Automatic,
                800000, 400000, 800001, 400001, 2, null, null);

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(ValidateReportData_GriddedSuccess), projectUid);
            var isOk      = DIContext.Obtain <IReportDataValidationUtility>().ValidateData(nameof(ValidateReportData_GriddedSuccess), projectUid, request);

            Assert.True(isOk);
        }
예제 #20
0
        public async Task <IActionResult> UpdateEndpointIfChanged()
        {
            if (ConfigHelper.Instance.HitWhenIpChanges.IsNullOrEmpty())
            {
                return(new EmptyResult());
            }

            var currentIp = GatewayHelper.GetCurrentIp();

            if (currentIp == _lastKnownIp)
            {
                return(new EmptyResult());
            }

            _lastKnownIp = currentIp;
            var response = await _updateEndpointClient.GetAsync(ConfigHelper.Instance.HitWhenIpChanges);

            var content = await response.Content.ReadAsStringAsync();

            return(Content(content));
        }
예제 #21
0
        static dynamic IBSGateway(string path, string login)
        {
            // this does not work with .NET Core 2.0

            // Attempt to get the latest gateway version registered on the server
            string latestGateway = GatewayHelper.GetLatestRegisteredGateway();

            if (string.IsNullOrWhiteSpace(latestGateway))
            {
                throw new Exception("A registered gateway could not be found");
            }
            // Create the gateway object
            Type    gatewayType = Type.GetTypeFromProgID(latestGateway);
            dynamic gw          = Activator.CreateInstance(gatewayType);

            gw.Init();
            gw.setpath(path);
            gw.login(login);

            return(gw);
        }
예제 #22
0
        public IActionResult Index()
        {
            var status  = GatewayHelper.GetRedirectedIps();
            var builder = ImmutableArray.CreateBuilder <DeviceWitStatus>();

            foreach (var device in ConfigHelper.Instance.Devices.OrderBy(d => d.Name))
            {
                builder.Add(new DeviceWitStatus(device, status.ContainsKey(device.Ip)));
            }

            var currentIp = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            if (!currentIp.Contains(":"))
            {
                builder.Add(new DeviceWitStatus(new Device($"This device ({currentIp})", currentIp),
                                                status.ContainsKey(currentIp)));
            }

            var model = new IndexModel(builder.ToImmutable(), GatewayHelper.GetCurrentIp());

            return(View(model));
        }
예제 #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestObj"></param>
        /// <returns></returns>
        /// <exception cref="ServiceException"></exception>
        public bool ValidateData(string method, Guid?projectUid, object requestObj)
        {
            if (projectUid == null || projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       "Invalid project UID."));
            }
            GatewayHelper.ValidateAndGetSiteModel(method, projectUid.Value);

            var request = requestObj as CompactionReportTRexRequest;

            if (request.CutFillDesignUid.HasValue &&
                !(request.CutFillDesignUid == Guid.Empty) &&
                DIContext.Obtain <IDesignManager>().List(request.ProjectUid).Locate(request.CutFillDesignUid.Value) == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"CutFill design {request.CutFillDesignUid.Value} is not found."));
            }

            if (requestObj != null &&
                requestObj.GetType() == typeof(CompactionReportStationOffsetTRexRequest))
            {
                var alignmentUid = ((CompactionReportStationOffsetTRexRequest)requestObj).AlignmentDesignUid;
                if (!(alignmentUid == Guid.Empty) &&
                    DIContext.Obtain <IAlignmentManager>().List(request.ProjectUid).Locate(alignmentUid) == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           $"Alignment design {alignmentUid} is not found."));
                }
            }

            return(true);
        }
예제 #24
0
        /// <summary>
        /// Initializes an instance of <see cref="GatewayDescriptor"/>.
        /// </summary>
        /// <param name="gatewayType">Type of the gateway.</param>
        public GatewayDescriptor(Type gatewayType)
        {
            GatewayHelper.IsGateway(gatewayType, throwException: true);

            GatewayType = gatewayType;
        }
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <returns></returns>
        private bool SaveChanges()
        {
            OutgoingMessageType messageType =(OutgoingMessageType)StringEnum.Parse(typeof(OutgoingMessageType), cboMessageType.Text);
          
            // Validate recipients are not empty
            if (!FormHelper.ValidateNotEmpty(txtTo, Resources.MsgRecipientsRequired))
            {
                return false;
            }

            if (messageType == OutgoingMessageType.SMS) 
            {
                // Validate message is not empty
                if (!FormHelper.ValidateNotEmpty(txtMessageContent, Resources.MsgContentRequired))
                {
                    return false;
                }
            } 
            else if (messageType == OutgoingMessageType.WAPPush)
            {
                 // Validate URL
                if (!FormHelper.ValidateNotEmpty(txtWapPushUrl, Resources.MsgURLRequired))
                {
                    return false;
                }

                // Validate message is not empty
                if (!FormHelper.ValidateNotEmpty(txtWapPushMessage, Resources.MsgContentRequired))
                {
                    return false;
                }
            }


            // The To list can be separated by comma or semicolon
            string[] toList = txtTo.Text.Split(GuiHelper.SupportedSeparators, StringSplitOptions.RemoveEmptyEntries);                                   
            try
            {  
                string groupId = GatewayHelper.GenerateUniqueIdentifier();  
                using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
                {                    
                    using (TransactionScope ts = new TransactionScope())
                    {
                        try
                        {
                            foreach (string to in toList)
                            {
                                OutgoingMessage message = new OutgoingMessage();
                                message.Id = GatewayHelper.GenerateUniqueIdentifier();
                                message.GatewayId = cboChannel.Text;
                                message.Recipient = to.Trim();
                                message.Originator = txtFrom.Text;
                                message.MessageType = cboMessageType.Text;                                
                                message.MessageFormat = cboMessageFormat.Text;
                                message.LastUpdate = DateTime.Now;
                                message.CreateDate = message.LastUpdate;
                                message.SrcPort = Convert.ToInt32(npdSourcePort.Value);
                                message.DestPort = Convert.ToInt32(npdDestinationPort.Value);
                                message.Status = StringEnum.GetStringValue(MessageStatus.Pending);
                                message.MessageClass = cboMessageClass.Text;
                                message.Priority = cboPriority.Text;
                                message.StatusReport = cboStatusReport.Text;
                                message.Quantity = Convert.ToInt32(npdQuantity.Value);
                                message.GroupId = groupId;
                                if (chkScheduleSendTime.Checked)
                                    message.ScheduledDate = dtpScheduleTime.Value;

                                if (messageType == OutgoingMessageType.SMS)
                                {
                                    message.Message = txtMessageContent.Text;
                                }
                                else if (messageType == OutgoingMessageType.WAPPush)
                                {
                                    message.WapUrl = txtWapPushUrl.Text;
                                    message.WapSignal = cboWapPushSignal.Text;
                                    message.Message = txtWapPushMessage.Text;
                                    if (chkWapPushCreated.Checked)
                                        message.WapCreateDate = dtpWapPushCreated.Value;
                                    if (chkWapPushExpiry.Checked)                                    
                                        message.WapExpiryDate = dtpWapPushExpiryDate.Value;
                                    
                                }

                                message.Save();
                            }
                        }
                        finally
                        {
                            try
                            {
                                ts.Complete();
                            }
                            catch (Exception) { }   
                            
                            // Refresh the message view
                            RefreshMessageView(ViewAction.RefreshOutbox);
                        }
                    }
                }
               
            }
            catch (Exception ex)
            {
                FormHelper.ShowError(ex.Message);
                return false;
            }

            // Show successful save message
            if (toList.Count() == 1)
            {
                FormHelper.ShowInfo(Resources.MsgSingleMessageCreated);
            }
            else
            {
                FormHelper.ShowInfo(string.Format(Resources.MsgMultipleMessagesCreated, toList.Count()));
            }

            return true;
        }