예제 #1
0
        /// <summary>
        /// Create a connectionInfo object which can be used to inform a remote peer of local connectivity
        /// </summary>
        /// <param name="connectionType">The type of connection</param>
        /// <param name="localNetworkIdentifier">The local network identifier</param>
        /// <param name="localEndPoint">The localEndPoint which should be referenced remotely</param>
        /// <param name="isConnectable">True if connectable on provided localEndPoint</param>
        /// <param name="applicationLayerProtocol">If enabled NetworkComms.Net uses a custom
        /// application layer protocol to provide useful features such as inline serialisation,
        /// transparent packet transmission, remote peer handshake and information etc. We strongly
        /// recommend you enable the NetworkComms.Net application layer protocol.</param>
        public ConnectionInfo(ConnectionType connectionType, ShortGuid localNetworkIdentifier, EndPoint localEndPoint,
                              bool isConnectable, ApplicationLayerProtocolStatus applicationLayerProtocol)
        {
            if (localEndPoint == null)
            {
                throw new ArgumentNullException("localEndPoint", "localEndPoint may not be null");
            }

            if (applicationLayerProtocol == ApplicationLayerProtocolStatus.Undefined)
            {
                throw new ArgumentException("A value of ApplicationLayerProtocolStatus.Undefined is invalid when creating instance of ConnectionInfo.", "applicationLayerProtocol");
            }

            this.ConnectionType       = connectionType;
            this.NetworkIdentifierStr = localNetworkIdentifier.ToString();
            this.LocalEndPoint        = localEndPoint;

            switch (localEndPoint.AddressFamily)
            {
            case AddressFamily.InterNetwork:
                this.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                break;

            case AddressFamily.InterNetworkV6:
                this.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Any, 0);
                break;

            case (AddressFamily)32:
                this.RemoteEndPoint = new BluetoothEndPoint(BluetoothAddress.None, BluetoothService.SerialPort);
                break;
            }

            this.IsConnectable            = isConnectable;
            this.ApplicationLayerProtocol = applicationLayerProtocol;
        }
예제 #2
0
        public async Task <IActionResult> CreateAsync(OrderModel ordermodel)
        {
            if (ModelState.IsValid)
            {
                var trackingNumber = new ShortGuid(Guid.NewGuid());
                var orderNumber    = new ShortGuid(Guid.NewGuid());
                var user           = await _userManager.FindByEmailAsync(User.Identity.Name);

                var    userId = user.Id;
                Orders order  = new Orders();
                order.TrackingNumber   = trackingNumber.ToString().ToUpper();
                order.OrderNumber      = orderNumber.ToString().ToUpper();
                order.VendorId         = userId;
                order.CreatedBy        = userId;
                order.CreatedOn        = DateTime.Now;
                order.Name             = ordermodel.Name;
                order.Location         = ordermodel.Location;
                order.Email            = ordermodel.Email;
                order.Phone            = ordermodel.Phone;
                order.StatusId         = ordermodel.StatusId;
                order.ShippingDetailId = ordermodel.ShippingDetailId;
                order.PaymentDetailId  = ordermodel.PaymentDetailId;
                order.Weight           = ordermodel.Weight;
                order.Dimension        = ordermodel.Dimension;
                _orderRepository.Insert(order);
                _orderRepository.Commit();
                return(RedirectToAction(nameof(List)));
            }
            return(View(ordermodel));
        }
예제 #3
0
파일: Default.cs 프로젝트: trullock/MuonKit
        protected override void When()
        {
            var shortGuid = new ShortGuid(this.guid);

            ShortGuid outed;
            ShortGuid.TryParse(shortGuid.ToString(), out outed);

            this.returned = outed.ToGuid();
        }
예제 #4
0
        public void CreateShortGuidFromTheSameGuidTwice_ReturnsTheSameResult()
        {
            var guid = Guid.NewGuid();

            var shortGuid1 = new ShortGuid(guid);
            var shortGuid2 = new ShortGuid(guid);

            Assert.Equal(shortGuid1.ToString(), shortGuid2.ToString());
        }
예제 #5
0
        public void ToStringTest()
        {
            ShortGuid target   = new ShortGuid(); // TODO: Initialize to an appropriate value
            string    expected = string.Empty;    // TODO: Initialize to an appropriate value
            string    actual;

            actual = target.ToString();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
예제 #6
0
        public IActionResult CreateDisaster()
        {
            DisasterModel model = new DisasterModel();

            Guid      guid      = Guid.NewGuid();
            ShortGuid shortGuid = guid;

            model.SerialNo = shortGuid.ToString();
            model.GlideNo  = shortGuid.ToString();

            var cities = _cityService.GetAll();

            cities.Insert(0, new City {
                CityId = 0, CityName = "Seçiniz"
            });

            ViewBag.CityList      = new SelectList(cities, "CityId", "CityName");
            ViewBag.ApproveStates = Enum.GetValues(typeof(EnumApproveState));
            model.ApproveState    = EnumApproveState.waiting;

            return(View(model));
        }
예제 #7
0
        public string CreateGame(string name, string connectionId)
        {
            ShortGuid newGameId = Guid.NewGuid();

            try
            {
                _games.Add(new Game()
                {
                    PlayerA = new Player()
                    {
                        Name         = name,
                        ConnectionId = connectionId
                    },
                    GameId = newGameId
                });
            }
            catch (Exception ex) { }

            return(newGameId.ToString());
        }
예제 #8
0
        public void ShortGuidEqualsTest()
        {
            const string x = "fe66b08f-a1bd-4d40-9711-4e1469c5193a";
            const string y = "07bb23cd-7b24-42b4-8467-3f0be7fa9ea5";

            Guid xg   = new Guid(x);
            var  xsg  = new ShortGuid(x);
            var  xsg2 = new ShortGuid(x);

            Assert.IsTrue(xsg.Equals(xsg2));
            Assert.IsTrue(xsg.Equals(x));
            Assert.IsTrue(xsg.Equals(xg));
            Assert.IsTrue(xsg.Equals(xsg2));
            Assert.IsTrue(xsg.Equals(xsg2.ToString()));
            Assert.IsTrue(xsg.Equals(xsg2.Value));
            Assert.IsFalse(xsg.Equals($"bad@{xsg2.Value}@bad"));


            Guid yg  = new Guid(y);
            var  ysg = new ShortGuid(y);

            Assert.IsFalse(xsg.Equals(ysg));
            Assert.IsFalse(xsg.Equals(y));
            Assert.IsFalse(xsg.Equals(yg));
            Assert.IsFalse(xsg.Equals(ysg));
            Assert.IsFalse(xsg.Equals(ysg.ToString()));
            Assert.IsFalse(xsg.Equals(ysg.Value));
            Assert.IsFalse(xsg.Equals($"bad@{ysg.Value}@bad"));

            const string gs = "DwUBBA8PDAAPBAYFBAEEDw";

            var sg1 = new ShortGuid(gs);
            var sg2 = new ShortGuid(gs);

            Assert.IsTrue(sg1 == sg2);
            Assert.IsTrue(ShortGuid.Empty.Equals(new ShortGuid(Guid.Empty)));
        }
예제 #9
0
        // GET: Media
        public async Task <JObject> Create()
        {
            var allowImageFileType = AppSettings.GetSettingAsString("allowImageFileType");
            var allowAudioFileType = AppSettings.GetSettingAsString("allowAudioFileType");
            var allowVideoFileType = AppSettings.GetSettingAsString("allowVideoFileType");
            var file = Request.Files["file"];

            if (file == null)
            {
                return(ExtJs.WriterJObject(false, msg: Message.NoFileUpload));
            }
            var       fileType = file.InputStream.GetFileType();
            var       ext      = fileType?.Extension;
            MediaType?type     = null;

            if (allowImageFileType.IndexOf($",{ext},", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                type = MediaType.Image;
            }
            else if (allowAudioFileType.IndexOf($",{ext},", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                type = MediaType.Audio;
            }
            else if (allowVideoFileType.IndexOf($",{ext},", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                type = MediaType.Video;
            }
            if (type == null)
            {
                return(ExtJs.WriterJObject(false, msg: Message.FileTypeNotAllow + ext));
            }

            var size = AppSettings.GetSettingAsInteger("allowUploadSize") ?? 10485760;

            if (file.ContentLength == 0 || file.ContentLength > size)
            {
                return(ExtJs.WriterJObject(false, msg: Message.FileSizeNotAllow));
            }

            var       guid     = Guid.NewGuid();
            ShortGuid sguid    = guid;
            var       filename = sguid.ToString();
            var       path     = $"{filename.Substring(0, 2)}/{filename.Substring(2, 2)}";
            var       dir      = Server.MapPath($"~/upload/{path}");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            file.SaveAs($"{dir}\\{filename}.{ext}");

            var media = new Media()
            {
                Filename    = $"{filename}.{ext}",
                Description = file.FileName,
                Size        = file.ContentLength,
                Path        = path,
                Type        = (byte)type,
                Uploaded    = DateTime.Now
            };

            DbContext.Mediae.Add(media);
            await DbContext.SaveChangesAsync();

            return(ExtJs.WriterJObject(true, data: new JObject()
            {
                { "Id", media.Id },
                { "FileName", media.Filename },
                { "Description", media.Description },
                { "Size", media.Size },
                { "Path", media.Path },
                { "Type", media.Type },
                { "Uploaded", media.Uploaded?.ToString(Message.DefaultDatetimeFormat) }
            }));
        }
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        var customValue = new ShortGuid((Guid)value);

        writer.WriteValue(customValue.ToString());
    }
예제 #11
0
        public async Task <IActionResult> CreateDisaster(DisasterModel model, IFormFile[] files)
        {
            if (ModelState.IsValid)
            {
                if (files.Count() != 0)
                {
                    var entity = new Disaster()
                    {
                        SerialNo      = model.SerialNo,
                        GlideNo       = model.GlideNo,
                        StartDate     = model.StartDate,
                        FinishDate    = model.FinishDate,
                        DisasterType  = model.DisasterType,
                        CityId        = model.CityId,
                        TownId        = model.TownId,
                        Why           = model.Why,
                        Latitute      = model.Latitute,
                        Longtitute    = model.Longtitute,
                        Description   = model.Description,
                        AffectedAreas = model.AffectedAreas,
                        ApproveState  = model.ApproveState,
                    };

                    entity.Sources = new List <Source>();

                    foreach (IFormFile source in files)
                    {
                        string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.Trim('"');

                        filename = this.EnsureCorrectFilename(filename);

                        entity.Sources.Add(
                            new Source()
                        {
                            SourceName = filename
                        }
                            );
                        using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename)))
                            await source.CopyToAsync(output);
                        ViewBag.Message += string.Format("<b>{0}</b> dosyası yüklendi.<br />", filename);
                    }


                    _disasterService.Create(entity);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            Guid      guid      = Guid.NewGuid();
            ShortGuid shortGuid = guid;

            model.SerialNo        = shortGuid.ToString();
            model.GlideNo         = shortGuid.ToString();
            ViewBag.ApproveStates = Enum.GetValues(typeof(EnumApproveState));
            var cities = _cityService.GetAll();


            cities.Insert(0, new City {
                CityId = 0, CityName = "Seçiniz"
            });

            ViewBag.CityList = new SelectList(cities, "CityId", "CityName");

            return(View(model));
        }
예제 #12
0
        public void ShortGuid_ShouldGenerateCorrectValue(string guid, string shortGuid)
        {
            var sut = new ShortGuid(new Guid(guid));

            Assert.Equal(shortGuid, sut.ToString());
        }
예제 #13
0
 /// <summary>
 /// Replaces the current networkIdentifier with that provided
 /// </summary>
 /// <param name="networkIdentifier">The new networkIdentifier for this connectionInfo</param>
 public void ResetNetworkIdentifer(ShortGuid networkIdentifier)
 {
     NetworkIdentifierStr = networkIdentifier.ToString();
 }