コード例 #1
0
        public void Should_Convert_Guid_Correctly()
        {
            var id      = Guid.NewGuid();
            var shortId = ShortGuid.ToShortId(id);
            var longId  = ShortGuid.FromShortId(shortId);

            Assert.Equal(id, longId);
        }
コード例 #2
0
 /// <summary>
 /// Create a new ChatMessage
 /// </summary>
 /// <param name="sourceIdentifier">The source identifier</param>
 /// <param name="sourceName">The source name</param>
 /// <param name="message">The message to be sent</param>
 /// <param name="messageIndex">The index of this message</param>
 public ChatMessage(ShortGuid sourceIdentifier, string sourceName, string message, long messageIndex)
 {
     this._sourceIdentifier = sourceIdentifier;
     this.SourceName        = sourceName;
     this.Message           = message;
     this.MessageIndex      = messageIndex;
     this.RelayCount        = 0;
 }
コード例 #3
0
 /// <summary>
 /// Create an ChunkAvailabilityReply which will precede the requested data.
 /// </summary>
 /// <param name="sourceNetworkIdentifier">The network identifier of the source of this ChunkAvailabilityReply</param>
 /// <param name="itemCheckSum">The checksum of the DFS item</param>
 /// <param name="chunkIndex">The chunkIndex of the requested item</param>
 /// <param name="packetIdentifier">The packet identifier used to send the data</param>
 public ChunkAvailabilityReply(ShortGuid sourceNetworkIdentifier, string itemCheckSum, byte chunkIndex, string packetIdentifier)
 {
     this.SourceNetworkIdentifier = sourceNetworkIdentifier;
     this.ItemCheckSum            = itemCheckSum;
     this.ChunkIndex       = chunkIndex;
     this.PacketIdentifier = packetIdentifier;
     this.ReplyState       = ChunkReplyState.DataIncluded;
 }
コード例 #4
0
ファイル: GuidTests.cs プロジェクト: joskraps/short-guid
        public void SerializationTest()
        {
            var sg       = new ShortGuid(Guid.NewGuid());
            var strSg    = JsonConvert.SerializeObject(sg);
            var expected = "\"" + sg + "\"";

            Assert.AreEqual(expected, strSg);
        }
コード例 #5
0
ファイル: GuidTests.cs プロジェクト: joskraps/short-guid
        public void DeSerializationTest()
        {
            var origional    = new ShortGuid(Guid.NewGuid());
            var jsonData     = "\"" + origional.Value + "\"";
            var deserialized = JsonConvert.DeserializeObject <ShortGuid>(jsonData);

            Assert.AreEqual(origional.Guid, deserialized.Guid);
        }
コード例 #6
0
ファイル: GuidTests.cs プロジェクト: joskraps/short-guid
        public void ShortGuidEncodingUsingShortGuidConstructor()
        {
            var g     = Guid.NewGuid();
            var sg    = new ShortGuid(g).Value;
            var newSg = new ShortGuid(sg);

            Assert.AreEqual(g, newSg.Guid);
        }
        public DummyMoleculeContainerDTO MapFrom(IObjectBase objectBase)
        {
            var dto = Map <DummyMoleculeContainerDTO>(objectBase);

            dto.Id = ShortGuid.NewGuid();
            dto.MoleculePropertiesContainer = _objectBaseToDTOObjectBaseMapper.MapFrom(_moleculePropertiesContainer);
            return(dto);
        }
コード例 #8
0
ファイル: ShortGuidTests.cs プロジェクト: Box9d/box9d-pi-api
        public void CreateShortGuidFromTheSameGuidTwice_ReturnsTheSameResult()
        {
            var guid = Guid.NewGuid();

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

            Assert.Equal(shortGuid1.ToString(), shortGuid2.ToString());
        }
コード例 #9
0
        private EntityMetaData mapFrom(CurveChart chart)
        {
            var entityMetaData = new EntityMetaData {
                Id = ShortGuid.NewGuid()
            };

            serialize(entityMetaData, chart);
            return(entityMetaData);
        }
コード例 #10
0
        public void FromShortId_Should_Convert_Correctly()
        {
            var shortId = Guid.NewGuid().ToShortId() + "==";

            Assert.NotNull(ShortGuid.FromShortId(shortId));

            shortId = ShortGuid.ToShortId(Guid.NewGuid()) + "==";
            Assert.NotNull(ShortGuid.FromShortId(shortId));
        }
コード例 #11
0
        public string CreateUserAndAccount(string userName, string password, string email, Guid myGuid,
                                           bool requireConfirmationToken = false)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException(nameof(userName));
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException(nameof(email));
            }


            string token = null;

            if (requireConfirmationToken)
            {
                token = ShortGuid.NewGuid();
            }

            var isConfirmed = !requireConfirmationToken;

            if (token == null)
            {
                return(null);
            }

            var user = new ApplicationUser
            {
                UserName          = userName.Trim(),
                Email             = email.Trim(),
                ConfirmationToken = token.Trim(),
                IsConfirmed       = isConfirmed
            };

            user.TrackingState = TrackingState.Added;

            var result = _userManager.Create(user, password.Trim());

            if (result.Succeeded)
            {
                return(token);
            }
            var innerMsg = new StringBuilder();

            foreach (var msg in result.Errors)
            {
                innerMsg.Append(msg);
            }
            var ex = new MembershipCreateUserException(innerMsg.ToString());

            throw ex;
        }
        public DummyReactionDTO MapFrom(IReactionBuilder reactionBuilder, IContainer container)
        {
            var dto = Map <DummyReactionDTO>(reactionBuilder);

            dto.Id = ShortGuid.NewGuid();
            dto.ReactionBuilder = reactionBuilder;
            dto.StructureParent = container;
            return(dto);
        }
コード例 #13
0
 public UsedObservedDataNode(UsedObservedData usedObservedData, DataRepository observedData)
     : base(usedObservedData)
 {
     _observedData = observedData;
     Tag           = usedObservedData;
     UpdateText();
     //new id should not be the one from the data repository=>hence a new id
     _id = ShortGuid.NewGuid();
 }
コード例 #14
0
        public DummyMoleculeDTO MapFrom(IMoleculeBuilder moleculeBuilder, IContainer container)
        {
            var dto = Map <DummyMoleculeDTO>(moleculeBuilder);

            dto.MoleculeBuilder = moleculeBuilder;
            dto.StructureParent = container;
            dto.Id = ShortGuid.NewGuid();
            return(dto);
        }
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //Dont redirect for Post action, as we may loose the form data
            if (requestContext.HttpContext.Request.HttpMethod == HttpMethod.Post.ToString())
            {
                return base.GetHttpHandler(requestContext);
            }

            //Get current unique id from RouteData
            var guidString = Convert.ToString(requestContext.RouteData.Values["tabid"]);

            //if true, then construct new url with tab id
            if (!string.IsNullOrEmpty(guidString))
            {
                //create new guid
                guidString = ShortGuid.NewGuid().ToString();

                //construct redirect url
                string rootUrl = requestContext.AbsoluteUriBeforeRoute();
                string controller = Convert.ToString(requestContext.RouteData.Values["controller"]);
                string action = Convert.ToString(requestContext.RouteData.Values["action"]);
                string id = Convert.ToString(requestContext.RouteData.Values["id"]);
                string queryString = requestContext.HttpContext.Request.Url.Query;

                string url = $"{rootUrl}/t/{guidString}";

                bool skipToQueryString = false;

                if (controller.Equals("Main", StringComparison.OrdinalIgnoreCase) &&
                    action.Equals("Index", StringComparison.OrdinalIgnoreCase))
                {
                    skipToQueryString = true;
                }

                if(!skipToQueryString)
                {
                    url += $"/{controller}";

                    if (!action.Equals("Index", StringComparison.OrdinalIgnoreCase))
                    {
                        url += $"/{action}";
                    }
                }

                if (!string.IsNullOrWhiteSpace(id))
                {
                    url += $"/{id}";
                }

                url += queryString;

                //redirect permanantly to unique tab url
                requestContext.HttpContext.Response.Redirect(url, true);
            }

            return base.GetHttpHandler(requestContext);
        }
コード例 #16
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         var shortGuid = new ShortGuid(value.ToString());
         return(shortGuid);
     }
     return(base.ConvertFrom(context, culture, value));
 }
コード例 #17
0
        private void SetListActionViewBags(IProjectPoco projectWithUsers)
        {
            var projectUsers = projectWithUsers.ProjectUsers.Select(p => p.User);

            ViewBag.PId          = ShortGuid.Encode(projectWithUsers.Id);
            ViewBag.ProjectUsers = projectUsers.ToDictionary(p => p.Id, d => d.UserName);
            ViewBag.PriorityList = lookupService.GetAllTaskPriority().ToDictionary(p => p.Id, d => d.Name);
            ViewBag.StatusList   = lookupService.GetAllTaskStatus().ToDictionary(p => p.Id, d => d.Name);
        }
コード例 #18
0
 public SimulationTransfer()
 {
     AllObservedData       = new List <DataRepository>();
     PkmlVersion           = Constants.PKML_VERSION;
     ReactionDimensionMode = ReactionDimensionMode.AmountBased;
     Id          = ShortGuid.NewGuid();
     Favorites   = new Favorites();
     JournalPath = string.Empty;
 }
コード例 #19
0
 public RootNodeType(string name, ApplicationIcon icon, ClassificationType classificationType = ClassificationType.Unknown)
 {
     Id              = ShortGuid.NewGuid().ToString();
     Name            = name;
     Icon            = icon;
     _classification = new Classification {
         ClassificationType = classificationType
     };
 }
コード例 #20
0
        public void NewGuidTest()
        {
            ShortGuid expected = new ShortGuid(); // TODO: Initialize to an appropriate value
            ShortGuid actual;

            actual = ShortGuid.NewGuid();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #21
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();
        }
コード例 #22
0
ファイル: Message.cs プロジェクト: Tacktel/bataille-game
 /// <summary>
 /// Message constructer
 /// </summary>
 /// <param name="header">message type</param>
 /// <param name="message">message readable contents</param>
 public Message(ShortGuid sourceIdentifier, string sourceName, string header, string message, long messageIndex)
 {
     this._sourceIdentifier = sourceIdentifier;
     this.SourceName        = sourceName;
     this.coincheHeader     = header;
     this.MessageContent    = message;
     this.MessageIndex      = messageIndex;
     this.RelayCount        = 0;
 }
コード例 #23
0
        protected override void unpack(BinaryBitReader reader)
        {
            CheckFlags flags = (CheckFlags)reader.ReadByte();

            if (flags.HasFlag(CheckFlags.HasByskyToken))
            {
                ByskyToken = new ShortGuid(reader.ReadBytes(16));
            }
        }
コード例 #24
0
ファイル: ChartTasks.cs プロジェクト: onwhenrdy/MoBi
        public void ShowData(IReadOnlyList <DataRepository> data)
        {
            var chart = _chartFactory.Create <CurveChart>().WithAxes();

            chart.Id   = ShortGuid.NewGuid();
            chart.Name = getChartName(data);
            addChartToProject(chart);
            ShowChart(chart, data);
        }
コード例 #25
0
 public Curve()
 {
     Id           = ShortGuid.NewGuid();
     _name        = string.Empty;
     _description = string.Empty;
     _xData       = null;
     _yData       = null;
     CurveOptions = new CurveOptions();
     Rules        = new BusinessRuleSet();
 }
コード例 #26
0
        void instance_equality_equals()
        {
            var actual = new ShortGuid(SampleShortGuidString);

            Assert.True(actual.Equals(actual));
            Assert.False(actual.Equals(null));
            Assert.True(actual.Equals(SampleGuid));
            Assert.True(actual.Equals(SampleGuidString));
            Assert.True(actual.Equals(SampleShortGuidString));
        }
コード例 #27
0
        private void PeerDiscovered(ShortGuid peerIdentifier, Dictionary <ConnectionType, List <EndPoint> > discoveredListenerEndPoints)
        {
            if (discoveredListenerEndPoints[ConnectionType.UDP].Any())
            {
                var address = discoveredListenerEndPoints[ConnectionType.UDP].First();
                (address as IPEndPoint).Port = CommonHelpers.PeerPort;

                AddPeer(address);
            }
        }
コード例 #28
0
        public void op_ImplicitTest3()
        {
            ShortGuid shortGuid = new ShortGuid(); // TODO: Initialize to an appropriate value
            string    expected  = string.Empty;    // TODO: Initialize to an appropriate value
            string    actual;

            actual = shortGuid;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #29
0
        public void DecodeTest()
        {
            string value    = string.Empty; // TODO: Initialize to an appropriate value
            Guid   expected = new Guid();   // TODO: Initialize to an appropriate value
            Guid   actual;

            actual = ShortGuid.Decode(value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #30
0
        public void GetHashCodeTest()
        {
            ShortGuid target   = new ShortGuid(); // TODO: Initialize to an appropriate value
            int       expected = 0;               // TODO: Initialize to an appropriate value
            int       actual;

            actual = target.GetHashCode();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #31
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.");
        }
コード例 #32
0
        public void ConvertGuidToShortGuidTest() {
            Stopwatch watch = Stopwatch.StartNew();
            for (int i = 0; i < 1000000; i++) {
                Guid g = Guid.NewGuid();
                ShortGuid s = g;
                string v = s.Value;

                var s2 = new ShortGuid(v);
                Assert.AreEqual(s, s2);

                Guid g2 = s2;
                Assert.AreEqual(g, g2);
            }
            watch.Stop();
            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
コード例 #33
0
    public void ConvertZero()
    {
      Stopwatch watch = Stopwatch.StartNew();
      Guid g = Guid.Empty;
      ShortGuid s = g;
      string v = s.Value;

      ShortGuid s2 = new ShortGuid(v);

      watch.Stop();
      Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);

      Assert.AreEqual(s, s2);

      Guid g2 = s2;
      Assert.AreEqual(g, g2);

    }
コード例 #34
0
 async Task<bool> Commit(Package package) {
     var done = Version.IsBlank()
         ? package.Commit(Force, !NoDownCase)
         : package.Commit(Version, Force, !NoDownCase);
     if (done && Register != null && _config.RegisterKey != null) {
         System.Console.WriteLine("Registering with the API... please stand by");
         var registeredId =
             await package.Register(_publishingApi, Register, _config.RegisterKey).ConfigureAwait(false);
         var shortId = new ShortGuid(registeredId);
         System.Console.WriteLine("The ID of the registration is: " + shortId);
     }
     return done;
 }
コード例 #35
0
 public static string ToShortString(this Guid guid)
 {
     var id = new ShortGuid(guid);
     return id.Value;
 }
コード例 #36
0
        protected virtual List<string> ReplceTempToStaticUrls(List<string> urls, string contentID)
        {
            List<string> result = new List<string>();
            string tempBaseUrl = PathCreator.CreateTempUrlRoot();

            foreach (string url in urls)
            {
                if (!url.StartsWith(tempBaseUrl))
                {
                    result.Add(url);
                    continue;
                }

                Guid? fileID = PathCreator.ExtractFileIDFromTemp(url);
                if (fileID == null)
                {
                    result.Add(string.Empty);
                    continue;
                }

                string shortFileID = new ShortGuid(fileID.Value);
                string staticUrl = PathCreator.CreateStaticUrl(contentID, shortFileID);
                result.Add(staticUrl);
            }

            return result;
        }      
コード例 #37
0
        protected virtual Task<bool> CopyTempToStatic(List<string> tempNamePaths, string contentID)
        {
            List<string> oldNamePaths = new List<string>();
            List<string> newNamePaths = new List<string>();

            foreach (string tempNamePath in tempNamePaths)
            {
                Guid? fileID = PathCreator.ExtractFileIDFromTemp(tempNamePath);
                if (fileID == null)
                    continue;

                string shortFileID = new ShortGuid(fileID.Value);
                string staticNamePath = PathCreator.CreateStaticNamePath(contentID, shortFileID);

                oldNamePaths.Add(tempNamePath);
                newNamePaths.Add(staticNamePath);
            }

            return oldNamePaths.Count > 0
                ? FileStorage.Copy(oldNamePaths, newNamePaths)
                : Task.FromResult(true);
        }
コード例 #38
0
 public string GetNewShortGuid()
 {
     var sguid = new ShortGuid(Guid.NewGuid());
     return sguid.Value;
 }