示例#1
0
        public void GrainID_AsGuid()
        {
            string  guidString  = "0699605f-884d-4343-9977-f40a39ab7b2b";
            Guid    grainIdGuid = Guid.Parse(guidString);
            GrainId grainId     = GrainId.GetGrainIdForTesting(grainIdGuid);
            //string grainIdToKeyString = grainId.ToKeyString();
            string grainIdToFullString = grainId.ToFullString();
            string grainIdToGuidString = GrainIdToGuidString(grainId);
            string grainIdKeyString    = grainId.Key.ToString();

            output.WriteLine("Guid={0}", grainIdGuid);
            output.WriteLine("GrainId={0}", grainId);
            //output.WriteLine("GrainId.ToKeyString={0}", grainIdToKeyString);
            output.WriteLine("GrainId.Key.ToString={0}", grainIdKeyString);
            output.WriteLine("GrainIdToGuidString={0}", grainIdToGuidString);
            output.WriteLine("GrainId.ToFullString={0}", grainIdToFullString);

            // Equal: Public APIs
            //Assert.Equal(guidString, grainIdToKeyString); // GrainId.ToKeyString
            Assert.Equal(guidString, grainIdToGuidString);      // GrainIdToGuidString
            // Equal: Internal APIs
            Assert.Equal(grainIdGuid, grainId.GetPrimaryKey()); // GetPrimaryKey Guid
            // NOT-Equal: Internal APIs
            Assert.NotEqual(guidString, grainIdKeyString);      // GrainId.Key.ToString
        }
示例#2
0
        internal string GrainIdToGuidString(GrainId grainId)
        {
            const string pkIdentifierStr   = "PrimaryKey:";
            string       grainIdFullString = grainId.ToFullString();
            int          pkStartIdx        = grainIdFullString.IndexOf(pkIdentifierStr, StringComparison.Ordinal) + pkIdentifierStr.Length + 1;
            string       pkGuidString      = grainIdFullString.Substring(pkStartIdx, Guid.Empty.ToString().Length);

            return(pkGuidString);
        }
示例#3
0
文件: Program.cs 项目: wattsm/orleans
        private static GrainId ConstructGrainId(string[] args, string operation)
        {
            if (args == null || args.Length < 2)
            {
                PrintUsage();
                return(null);
            }
            string interfaceTypeCodeOrImplClassName = args[0];
            int    interfaceTypeCodeDataLong;
            long   implementationTypeCode;

            var grainTypeResolver = (IGrainTypeResolver)client.ServiceProvider.GetService(typeof(IGrainTypeResolver));

            if (int.TryParse(interfaceTypeCodeOrImplClassName, out interfaceTypeCodeDataLong))
            {
                // parsed it as int, so it is an interface type code.
                implementationTypeCode =
                    GetImplementation(grainTypeResolver, interfaceTypeCodeDataLong).GrainTypeCode;
            }
            else
            {
                // interfaceTypeCodeOrImplClassName is the implementation class name
                implementationTypeCode = GetImplementation(grainTypeResolver, interfaceTypeCodeOrImplClassName).GrainTypeCode;
            }

            var     grainIdStr = args[1];
            GrainId grainId    = null;
            long    grainIdLong;
            Guid    grainIdGuid;

            if (long.TryParse(grainIdStr, out grainIdLong))
            {
                grainId = GrainId.GetGrainId(implementationTypeCode, grainIdLong);
            }
            else if (Guid.TryParse(grainIdStr, out grainIdGuid))
            {
                grainId = GrainId.GetGrainId(implementationTypeCode, grainIdGuid);
            }
            else
            {
                grainId = GrainId.GetGrainId(implementationTypeCode, grainIdStr);
            }

            WriteStatus(string.Format("**Full Grain Id to {0} is: GrainId = {1}", operation, grainId.ToFullString()));
            return(grainId);
        }
示例#4
0
 internal string GrainIdToGuidString(GrainId grainId)
 {
     const string pkIdentifierStr = "PrimaryKey:";
     string grainIdFullString = grainId.ToFullString();
     int pkStartIdx = grainIdFullString.IndexOf(pkIdentifierStr, StringComparison.Ordinal) + pkIdentifierStr.Length + 1;
     string pkGuidString = grainIdFullString.Substring(pkStartIdx, Guid.Empty.ToString().Length);
     return pkGuidString;
 }