public Entities.Address ReadAddress(int postalCode, string addressLine1)
 {
     using (var database = new EstateBrokerContext())
     {
         return((Entities.Address)AddressFactory.CreateAddress(database.Addresses.Find(postalCode, addressLine1)));
     }
 }
示例#2
0
        private SipRequest CreateRegisterRequest()
        {
            var requestUri   = AddressFactory.CreateUri(null, "registrar.ocean.com");
            var toAddressUri = AddressFactory.CreateUri("hannes", "ocean.com");
            var toAddress    = AddressFactory.CreateAddress("hannes", toAddressUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, 1028);
            var callId       = SipUtil.CreateCallId();
            var callIdheader = HeaderFactory.CreateCallIdHeader(callId);
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address, SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Register,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
            var localHostUri   = AddressFactory.CreateUri(null, MainForm.SipProvider.ListeningPoint.ToString());
            var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
            var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);

            request.Routes.Add(routeHeader);
            request.Contacts.Add(contactHeader);
            return(request);
        }
示例#3
0
        private SipRequest CreateRegisterRequest(string user)
        {
            FormHelper.ValidateIsNotEmpty(_txtCallId.Text, "device id");

            var requestUri   = AddressFactory.CreateUri(null, MainForm.Configuration.RegistrarDomain);
            var toAddressUri = AddressFactory.CreateUri(user, MainForm.Configuration.RegistrarDomain);
            var toAddress    = AddressFactory.CreateAddress(null, toAddressUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, ++commandSequence);
            var callIdheader = HeaderFactory.CreateCallIdHeader(_txtCallId.Text);
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address,
                                                             SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Register,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add routes and contacts*/
            var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
            var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
            var localHostUri   = AddressFactory.CreateUri(null, _txtContactAddress.Text);
            var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);

            request.Routes.Add(routeHeader);

            return(request);
        }
示例#4
0
        private void Invite()
        {
            FormHelper.ValidateCondition(SipUtil.IsSipUri(_txtFromUri.Text), "From-uri");

            FormHelper.ValidateCondition(SipUtil.IsSipUri(_txtToUri.Text), "To-uri");

            var fromUri = SipUtil.ParseSipUri(_txtFromUri.Text);
            var toUri   = SipUtil.ParseSipUri(_txtToUri.Text);

            if (_chkPeerToPeer.Checked)
            {
                FormHelper.ValidateCondition(SipUtil.IsIpEndPoint(toUri.Host), "To-uri");
            }

            var requestUri   = toUri;
            var toAddress    = AddressFactory.CreateAddress(_txtToAlias.Text, toUri);
            var fromAddress  = AddressFactory.CreateAddress(_txtFromAlias.Text, fromUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(fromAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Invite, ++commandSequence);
            var callIdheader = HeaderFactory.CreateCallIdHeader(SipUtil.CreateCallId());
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address,
                                                             SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader(1);
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Invite,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add routes and contacts*/
            if (!_chkPeerToPeer.Checked)
            {
                var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
                proxyServerUri.IsLooseRouting = true;
                var routeHeader = HeaderFactory.CreateRouteHeader(proxyServerUri);
                request.Routes.Add(routeHeader);
            }
            var contactUri    = AddressFactory.CreateUri(fromUri.User, viaHeader.SentBy.ToString());
            var contactHeader = HeaderFactory.CreateContactHeader(contactUri);

            request.Contacts.Add(contactHeader);

            var transaction = SipProvider.CreateClientTransaction(request);

            _dialog = SipProvider.CreateClientDialog(transaction);
            transaction.SendRequest();
        }
示例#5
0
        private void _btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                var requestUri   = AddressFactory.CreateUri(null, "registrar." + MainForm.Configuration.RegistrarDomain);
                var toAddressUri = AddressFactory.CreateUri("hannes", MainForm.Configuration.RegistrarDomain);
                var toAddress    = AddressFactory.CreateAddress("hannes", toAddressUri);
                var toHeader     = HeaderFactory.CreateToHeader(toAddress);
                var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
                var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, 1028);
                var callId       = SipUtil.CreateCallId();
                var callIdheader = HeaderFactory.CreateCallIdHeader(callId);
                var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address, SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                                 SipUtil.CreateBranch());
                var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
                var request           = MessageFactory.CreateRequest(
                    requestUri,
                    SipMethods.Register,
                    callIdheader,
                    cseqHeader,
                    fromHeader,
                    toHeader,
                    viaHeader,
                    maxForwardsHeader);

                var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
                var localHostUri   = AddressFactory.CreateUri(null, MainForm.SipProvider.ListeningPoint.ToString());
                var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
                var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);
                request.Routes.Add(routeHeader);
                request.Contacts.Add(contactHeader);

                EventAggregator.Instance.Publish(
                    new LogEvent(">>>>" + SipFormatter.FormatMessageEnvelope(request) + Environment.NewLine));

                if (_chbSendStateFull.Checked)
                {
                    var transaction = SipProvider.CreateClientTransaction(request);
                    transaction.SendRequest();
                }
                else
                {
                    SipProvider.SendRequest(request);
                }
            }
            catch (Exception ex)
            {
                MainForm.HandleException(ex);
            }
        }
        public async Task <IActionResult> Create(
            [Bind(adrProperties)] GeographicAddressView c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            c.ID = c.ID ?? Guid.NewGuid().ToString();
            var o = AddressFactory.CreateAddress(c.ID, c.AddressLine, c.City,
                                                 c.RegionOrState, c.ZipOrPostalCode, c.Country, c.ValidFrom, c.ValidTo);
            await addresses.AddObject(o);

            return(RedirectToAction("Index"));
        }
        [TestMethod] public void CreateAddressTest()
        {
            var r = GetRandom.Object <GeographicAddressData>();
            var o = AddressFactory.CreateAddress(
                r.ID,
                r.Address,
                r.CityOrAreaCode,
                r.RegionOrStateOrCountryCode,
                r.ZipOrPostCodeOrExtension,
                r.CountryID,
                r.ValidFrom,
                r.ValidTo);

            Assert.IsInstanceOfType(o, typeof(GeographicAddress));
            testVariables(o.Data, r.ID, r.Address, r.ValidFrom, r.ValidTo, r.CityOrAreaCode,
                          r.RegionOrStateOrCountryCode, o.Data.ZipOrPostCodeOrExtension);
            Assert.AreEqual(r.CountryID, o.Data.CountryID);
        }
示例#8
0
        /// <summary>
        /// Add new address
        /// </summary>
        /// <param name="addressDTO"></param>
        /// <param name="profile"></param>
        private void SaveAddress(AddressDTO addressDTO, Profile profile)
        {
            if (addressDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddProfileWithNullInformation);
            }

            // Create a new Address entity
            Address newAddress = AddressFactory.CreateAddress(addressDTO.AddressLine1, addressDTO.AddressLine2, addressDTO.City, addressDTO.State,
                                                              addressDTO.Country, addressDTO.ZipCode, "Anand", DateTime.Now, "Anand", DateTime.Now);

            SaveAddress(newAddress);

            AddressType addressType = _addressTypeRepository.Get(addressDTO.AddressTypeId);

            // Create a new Profile Address entity
            ProfileAddress newProfileAddress = ProfileAddressFactory.ProfileAddress(profile, newAddress, addressType, "Anand", DateTime.Now, "Anand", DateTime.Now);

            SaveProfileAddress(newProfileAddress);
        }
示例#9
0
        private void OnPhoneCallStarted(IInternalPhoneCall phoneCall)
        {
            Check.Require(phoneCall, "phoneCall");
            Check.IsTrue(InternalState == _stateProvider.GetIdle(), string.Format("Failed to start the call. The phone can only start calls while in 'IDLE' state. CurrentState: '{0}'", CurrentState));
            Check.IsTrue(_isRunning, "Failed to start the call. The phone must be started first.");

            _pendingPhoneCall = phoneCall;

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Starting new phonecall...");
            }
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Creating 'INVITE' request...");
            }
            var thisUri = AddressFactory.CreateUri(string.Empty, ListeningPoint.ToString());

            var requestUri   = phoneCall.GetToUri();
            var toAddress    = AddressFactory.CreateAddress(string.Empty, phoneCall.GetToUri());
            var fromAddress  = AddressFactory.CreateAddress(string.Empty, thisUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(fromAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Invite, MessageCounter++);
            var callIdheader = HeaderFactory.CreateCallIdHeader(SipUtil.CreateCallId());
            var viaHeader    = HeaderFactory.CreateViaHeader(ListeningPoint.Address,
                                                             ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader(1);
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Invite,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add contactheader*/
            var contactUri    = AddressFactory.CreateUri(thisUri.User, viaHeader.SentBy.ToString());
            var contactHeader = HeaderFactory.CreateContactHeader(contactUri);

            request.Contacts.Add(contactHeader);

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("'INVITE' request created. Sending to callee..");
            }

            var clientTransaction = SipProvider.CreateClientTransaction(request);
            var dialog            = SipProvider.CreateClientDialog(clientTransaction as SipInviteClientTransaction);

            clientTransaction.SendRequest();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("'INVITE' sent.");
            }

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Request sent. Transitioning to 'WAITPROVISIONAL' state...");
            }

            PendingInvite = new InviteInfo()
            {
                OriginalRequest = request,
                From            = request.From.SipUri,
                To = request.To.SipUri,
                InviteClientTransaction = (SipInviteClientTransaction)clientTransaction,
                IsIncomingCall          = false,
                Dialog = dialog
            };

            ChangeState(_stateProvider.GetWaitProvisional());
        }
示例#10
0
        public IHttpActionResult Get(string sort = "id", int page = 1, int pageSize = 5)
        {
            try
            {
                var addresses = _repository.GetAddresses().ApplySort(sort);

                if (pageSize > maxPageSize)
                {
                    pageSize = maxPageSize;
                }

                // calculate metadata
                var totalCount = addresses.Count();
                var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

                // Create URIs for nex and previous pages
                // we can use a urlhelper class that is available here
                var urlHelper = new UrlHelper(Request);
                var prevLink  = page > 1 ? urlHelper.Link("AddressesList",
                                                          new
                {
                    page    = page - 1,
                    pagSize = pageSize,
                    sort    = sort
                }
                                                          ):"";
                var nextLink = page < totalPages?urlHelper.Link("addressesList",
                                                                new
                {
                    page    = page + 1,
                    pagSize = pageSize,
                    sort    = sort
                }
                                                                ) : "";

                // Create a pagination object
                var paginationHeader = new
                {
                    currentPage      = page,
                    pageSize         = pageSize,
                    totalCount       = totalCount,
                    totalPages       = totalPages,
                    previousPageLink = prevLink,
                    nextPageLink     = nextLink
                };
                // add the pagination object to the header
                HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));

                return(Ok(addresses
                          .Skip(pageSize * (page - 1))
                          .Take(pageSize)
                          .ToList()
                          .Select(eg => _addressFactory.CreateAddress(eg))));


                //return Ok(addresses.ApplySort(sort).ToList()
                //    .Select(eg => _addressFactory.CreateAddress(eg)));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }