コード例 #1
0
        public async Task <ApiKeyResponseModel> ApiKey(string id, [FromBody] OrganizationApiKeyRequestModel model)
        {
            var orgIdGuid = new Guid(id);

            if (!await HasApiKeyAccessAsync(orgIdGuid, model.Type))
            {
                throw new NotFoundException();
            }

            var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);

            if (organization == null)
            {
                throw new NotFoundException();
            }

            if (model.Type == OrganizationApiKeyType.BillingSync || model.Type == OrganizationApiKeyType.Scim)
            {
                // Non-enterprise orgs should not be able to create or view an apikey of billing sync/scim key types
                var plan = StaticStore.GetPlan(organization.PlanType);
                if (plan.Product != ProductType.Enterprise)
                {
                    throw new NotFoundException();
                }
            }

            var organizationApiKey = await _getOrganizationApiKeyCommand
                                     .GetOrganizationApiKeyAsync(organization.Id, model.Type);

            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (model.Type != OrganizationApiKeyType.Scim &&
                !await _userService.VerifySecretAsync(user, model.Secret))
            {
                await Task.Delay(2000);

                throw new BadRequestException("MasterPasswordHash", "Invalid password.");
            }
            else
            {
                var response = new ApiKeyResponseModel(organizationApiKey);
                return(response);
            }
        }
コード例 #2
0
        public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization")
        {
            Id                            = organization.OrganizationId.ToString();
            Name                          = organization.Name;
            UsePolicies                   = organization.UsePolicies;
            UseSso                        = organization.UseSso;
            UseKeyConnector               = organization.UseKeyConnector;
            UseScim                       = organization.UseScim;
            UseGroups                     = organization.UseGroups;
            UseDirectory                  = organization.UseDirectory;
            UseEvents                     = organization.UseEvents;
            UseTotp                       = organization.UseTotp;
            Use2fa                        = organization.Use2fa;
            UseApi                        = organization.UseApi;
            UseResetPassword              = organization.UseResetPassword;
            UsersGetPremium               = organization.UsersGetPremium;
            SelfHost                      = organization.SelfHost;
            Seats                         = organization.Seats;
            MaxCollections                = organization.MaxCollections;
            MaxStorageGb                  = organization.MaxStorageGb;
            Key                           = organization.Key;
            HasPublicAndPrivateKeys       = organization.PublicKey != null && organization.PrivateKey != null;
            Status                        = organization.Status;
            Type                          = organization.Type;
            Enabled                       = organization.Enabled;
            SsoBound                      = !string.IsNullOrWhiteSpace(organization.SsoExternalId);
            Identifier                    = organization.Identifier;
            Permissions                   = CoreHelpers.LoadClassFromJsonData <Permissions>(organization.Permissions);
            ResetPasswordEnrolled         = organization.ResetPasswordKey != null;
            UserId                        = organization.UserId?.ToString();
            ProviderId                    = organization.ProviderId?.ToString();
            ProviderName                  = organization.ProviderName;
            FamilySponsorshipFriendlyName = organization.FamilySponsorshipFriendlyName;
            FamilySponsorshipAvailable    = FamilySponsorshipFriendlyName == null &&
                                            StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise)
                                            .UsersCanSponsor(organization);
            PlanProductType = StaticStore.GetPlan(organization.PlanType).Product;
            FamilySponsorshipLastSyncDate = organization.FamilySponsorshipLastSyncDate;
            FamilySponsorshipToDelete     = organization.FamilySponsorshipToDelete;
            FamilySponsorshipValidUntil   = organization.FamilySponsorshipValidUntil;

            if (organization.SsoConfig != null)
            {
                var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig);
                KeyConnectorEnabled = ssoConfigData.KeyConnectorEnabled && !string.IsNullOrEmpty(ssoConfigData.KeyConnectorUrl);
                KeyConnectorUrl     = ssoConfigData.KeyConnectorUrl;
            }
        }
コード例 #3
0
        public StuffActor()
        {
            _address = Cluster.Get(Context.System).SelfAddress.ToString();

            SetReceiveTimeout(TimeSpan.FromSeconds(3));
            Receive <ReceiveTimeout>(receiveTimeout =>
            {
                ConsoleHelper.Write("Actor {0}/{1} timedout, sending passivate message to parent.", _address, PersistenceId);
                Context.Parent.Tell(new Passivate(PoisonPill.Instance));
            });

            ReceiveAsync <Stuff>(HandleStuffAsync);
            ReceiveAsync <GetInfo>(HandleGetInfoAsync);
            ConsoleHelper.Write("Actor {0}/{1} created", _address, PersistenceId);
            _messageCount = StaticStore.Get(Id);
        }
コード例 #4
0
        public async Task SetUpSponsorshipAsync(OrganizationSponsorship sponsorship,
                                                Organization sponsoredOrganization)
        {
            if (sponsorship == null)
            {
                throw new BadRequestException("No unredeemed sponsorship offer exists for you.");
            }

            var existingOrgSponsorship = await _organizationSponsorshipRepository
                                         .GetBySponsoredOrganizationIdAsync(sponsoredOrganization.Id);

            if (existingOrgSponsorship != null)
            {
                throw new BadRequestException("Cannot redeem a sponsorship offer for an organization that is already sponsored. Revoke existing sponsorship first.");
            }

            if (sponsorship.PlanSponsorshipType == null)
            {
                throw new BadRequestException("Cannot set up sponsorship without a known sponsorship type.");
            }

            // Do not allow self-hosted sponsorships that haven't been synced for > 0.5 year
            if (sponsorship.LastSyncDate != null && DateTime.UtcNow.Subtract(sponsorship.LastSyncDate.Value).TotalDays > 182.5)
            {
                await _organizationSponsorshipRepository.DeleteAsync(sponsorship);

                throw new BadRequestException("This sponsorship offer is more than 6 months old and has expired.");
            }

            // Check org to sponsor's product type
            var requiredSponsoredProductType = StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value)?.SponsoredProductType;

            if (requiredSponsoredProductType == null ||
                sponsoredOrganization == null ||
                StaticStore.GetPlan(sponsoredOrganization.PlanType).Product != requiredSponsoredProductType.Value)
            {
                throw new BadRequestException("Can only redeem sponsorship offer on families organizations.");
            }

            await _paymentService.SponsorOrganizationAsync(sponsoredOrganization, sponsorship);

            await _organizationRepository.UpsertAsync(sponsoredOrganization);

            sponsorship.SponsoredOrganizationId = sponsoredOrganization.Id;
            sponsorship.OfferedToEmail          = null;
            await _organizationSponsorshipRepository.UpsertAsync(sponsorship);
        }
コード例 #5
0
        public async Task <OrganizationSponsorship> CreateSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser,
                                                                           PlanSponsorshipType sponsorshipType, string sponsoredEmail, string friendlyName)
        {
            var sponsoringUser = await _userService.GetUserByIdAsync(sponsoringOrgUser.UserId.Value);

            if (sponsoringUser == null || string.Equals(sponsoringUser.Email, sponsoredEmail, System.StringComparison.InvariantCultureIgnoreCase))
            {
                throw new BadRequestException("Cannot offer a Families Organization Sponsorship to yourself. Choose a different email.");
            }

            var requiredSponsoringProductType = StaticStore.GetSponsoredPlan(sponsorshipType)?.SponsoringProductType;

            if (requiredSponsoringProductType == null ||
                sponsoringOrg == null ||
                StaticStore.GetPlan(sponsoringOrg.PlanType).Product != requiredSponsoringProductType.Value)
            {
                throw new BadRequestException("Specified Organization cannot sponsor other organizations.");
            }

            if (sponsoringOrgUser == null || sponsoringOrgUser.Status != OrganizationUserStatusType.Confirmed)
            {
                throw new BadRequestException("Only confirmed users can sponsor other organizations.");
            }

            var existingOrgSponsorship = await _organizationSponsorshipRepository
                                         .GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUser.Id);

            if (existingOrgSponsorship?.SponsoredOrganizationId != null)
            {
                throw new BadRequestException("Can only sponsor one organization per Organization User.");
            }

            var sponsorship = new OrganizationSponsorship
            {
                SponsoringOrganizationId     = sponsoringOrg.Id,
                SponsoringOrganizationUserId = sponsoringOrgUser.Id,
                FriendlyName        = friendlyName,
                OfferedToEmail      = sponsoredEmail,
                PlanSponsorshipType = sponsorshipType,
            };

            if (existingOrgSponsorship != null)
            {
                // Replace existing invalid offer with our new sponsorship offer
                sponsorship.Id = existingOrgSponsorship.Id;
            }

            try
            {
                await _organizationSponsorshipRepository.UpsertAsync(sponsorship);

                return(sponsorship);
            }
            catch
            {
                if (sponsorship.Id != default)
                {
                    await _organizationSponsorshipRepository.DeleteAsync(sponsorship);
                }
                throw;
            }
        }
コード例 #6
0
        private async Task <(IEnumerable <OrganizationSponsorshipData> data, IEnumerable <OrganizationSponsorship> toOffer)> DoSyncAsync(Organization sponsoringOrg, IEnumerable <OrganizationSponsorshipData> sponsorshipsData)
        {
            var existingSponsorshipsDict = (await _organizationSponsorshipRepository.GetManyBySponsoringOrganizationAsync(sponsoringOrg.Id))
                                           .ToDictionary(i => i.SponsoringOrganizationUserId);

            var sponsorshipsToUpsert   = new List <OrganizationSponsorship>();
            var sponsorshipIdsToDelete = new List <Guid>();
            var sponsorshipsToReturn   = new List <OrganizationSponsorshipData>();

            foreach (var selfHostedSponsorship in sponsorshipsData)
            {
                var requiredSponsoringProductType = StaticStore.GetSponsoredPlan(selfHostedSponsorship.PlanSponsorshipType)?.SponsoringProductType;
                if (requiredSponsoringProductType == null ||
                    StaticStore.GetPlan(sponsoringOrg.PlanType).Product != requiredSponsoringProductType.Value)
                {
                    continue; // prevent unsupported sponsorships
                }

                if (!existingSponsorshipsDict.TryGetValue(selfHostedSponsorship.SponsoringOrganizationUserId, out var cloudSponsorship))
                {
                    if (selfHostedSponsorship.ToDelete && selfHostedSponsorship.LastSyncDate == null)
                    {
                        continue; // prevent invalid sponsorships in cloud. These should have been deleted by self hosted
                    }
                    if (OrgDisabledForMoreThanGracePeriod(sponsoringOrg))
                    {
                        continue; // prevent new sponsorships from disabled orgs
                    }
                    cloudSponsorship = new OrganizationSponsorship
                    {
                        SponsoringOrganizationId     = sponsoringOrg.Id,
                        SponsoringOrganizationUserId = selfHostedSponsorship.SponsoringOrganizationUserId,
                        FriendlyName        = selfHostedSponsorship.FriendlyName,
                        OfferedToEmail      = selfHostedSponsorship.OfferedToEmail,
                        PlanSponsorshipType = selfHostedSponsorship.PlanSponsorshipType,
                        LastSyncDate        = DateTime.UtcNow,
                    };
                }
                else
                {
                    cloudSponsorship.LastSyncDate = DateTime.UtcNow;
                }

                if (selfHostedSponsorship.ToDelete)
                {
                    if (cloudSponsorship.SponsoredOrganizationId == null)
                    {
                        sponsorshipIdsToDelete.Add(cloudSponsorship.Id);
                        selfHostedSponsorship.CloudSponsorshipRemoved = true;
                    }
                    else
                    {
                        cloudSponsorship.ToDelete = true;
                    }
                }
                sponsorshipsToUpsert.Add(cloudSponsorship);

                selfHostedSponsorship.ValidUntil   = cloudSponsorship.ValidUntil;
                selfHostedSponsorship.LastSyncDate = DateTime.UtcNow;
                sponsorshipsToReturn.Add(selfHostedSponsorship);
            }
            var sponsorshipsToEmailOffer = sponsorshipsToUpsert.Where(s => s.Id == default).ToArray();

            if (sponsorshipsToUpsert.Any())
            {
                await _organizationSponsorshipRepository.UpsertManyAsync(sponsorshipsToUpsert);
            }
            if (sponsorshipIdsToDelete.Any())
            {
                await _organizationSponsorshipRepository.DeleteManyAsync(sponsorshipIdsToDelete);
            }

            return(sponsorshipsToReturn, sponsorshipsToEmailOffer);
        }
コード例 #7
0
        public static void CreateTiffImages(string InputPath, ZipArchive zip, string destination, string strImagePath, ConcurrentBag <Dictionary <string, string> > TanWiseAllFiles,
                                            ConcurrentBag <Dictionary <string, string> > TanWiseBestFiles, ConcurrentBag <Dictionary <string, string> > TanWiseKeywords, List <TanKeywords> keyWordsList)
        {
            List <string> Emptytans                      = new List <string>();
            var           TotalTanNumbers                = zip.Entries.Select(ze => ze.FullName.Split('.')[0]).Distinct();
            var           tifEntries                     = zip.Entries.Where(ze => ze.FullName.ToLower().EndsWith(".tif"));
            var           tanNumberWiseTifs              = tifEntries.GroupBy(te => te.FullName.Substring(0, 9)).ToDictionary(d => d.Key, d => d.ToList());
            int           count                          = TotalTanNumbers.Count();
            Dictionary <string, string> tanWiseAllFiles  = new Dictionary <string, string>();
            Dictionary <string, string> tanWiseBestFiles = new Dictionary <string, string>();
            Dictionary <string, string> tanWisekeyword   = new Dictionary <string, string>();

            foreach (var TanNumber in TotalTanNumbers)
            {
                try
                {
                    var    TanwiseFiles       = zip.Entries.Where(t => t.FullName.Contains(TanNumber) && !t.FullName.ToLower().EndsWith(".tif")).ToList();
                    var    TanFolder          = Path.Combine(destination, "ShipmentTans", strImagePath, TanNumber);
                    string strTiffPdfFileName = string.Empty;
                    if (!Directory.Exists(TanFolder))
                    {
                        Directory.CreateDirectory(TanFolder);
                    }
                    foreach (var CopyFiles in TanwiseFiles)
                    {
                        try
                        {
                            var fileName = System.IO.Path.GetFileName(CopyFiles.FullName);
                            var destFile = System.IO.Path.Combine(TanFolder, fileName);
                            System.IO.File.Copy(InputPath + "\\" + strImagePath + "\\" + CopyFiles, destFile, true);
                        }
                        catch (Exception ex)
                        {
                        }
                    }


                    #region Tiff To Pdf
                    var TanWiseTif = tanNumberWiseTifs.Where(t => t.Key == TanNumber);
                    foreach (var tanNumberWiseEntry in TanWiseTif)
                    {
                        try
                        {
                            string tanNumber = tanNumberWiseEntry.Key;
                            strTiffPdfFileName = tanNumber + "_tiff.pdf";
                            string pdfPath = Path.Combine(TanFolder, strTiffPdfFileName);
                            using (var pdfStream = new FileStream(pdfPath, FileMode.OpenOrCreate, FileAccess.Write))
                                using (var doc = new Document())
                                {
                                    PdfWriter.GetInstance(doc, pdfStream);
                                    doc.Open();
                                    doc.SetMargins(20f, 20f, 20f, 20f);
                                    int i = 0;
                                    foreach (var tifEntry in tanNumberWiseEntry.Value)
                                    {
                                        using (var tifStream = tifEntry.Open())
                                        {
                                            i++;
                                            try
                                            {
                                                var docImage = Image.GetInstance(tifStream);
                                                docImage.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
                                                doc.Add(docImage);

                                                if (i + 1 < tanNumberWiseEntry.Value.Count())
                                                {
                                                    doc.NewPage();
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                //Log.This(ex);
                                            }
                                        }
                                    }
                                    doc.Close();
                                }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    #endregion

                    #region Best File Selection
                    var TanWiseBestFileEntry = zip.Entries.Where(s => s.FullName.Contains(TanNumber) && s.FullName.Contains("markup")).OrderByDescending(x => x.Length).FirstOrDefault();
                    var TanWiseBestFile      = string.Empty;

                    if (TanWiseBestFileEntry != null)
                    {
                        TanWiseBestFile = TanWiseBestFileEntry.FullName;
                    }
                    else if (TanWiseBestFile == string.Empty && strTiffPdfFileName != string.Empty)
                    {
                        TanWiseBestFile = strTiffPdfFileName;
                    }
                    else if (zip.Entries.Where(s => s.FullName.Contains(TanNumber) && (s.FullName.Contains("article") || s.FullName.Contains("patent"))).Any())
                    {
                        TanWiseBestFile = zip.Entries.Where(s => s.FullName.Contains(TanNumber) && s.FullName.Contains("article") || s.FullName.Contains("patent")).OrderByDescending(x => x.Length).FirstOrDefault().FullName;
                    }
                    else if (zip.Entries.Where(s => s.FullName.Contains(TanNumber) && s.FullName.Contains(".pdf")).Any())
                    {
                        TanWiseBestFile = zip.Entries.Where(s => s.FullName.Contains(TanNumber) && s.FullName.Contains(".pdf")).FirstOrDefault().FullName;
                    }
                    var           TanWiseTotalDocumentsPath = zip.Entries.Where(s => s.FullName.Contains(TanNumber) && !s.FullName.Contains(".tif") && s.FullName != TanWiseBestFile && s.FullName.Contains(".pdf")).ToList();
                    List <string> TanwiseLocalPath          = new List <string>();
                    foreach (var TanwiseEachDocument in TanWiseTotalDocumentsPath)
                    {
                        TanwiseLocalPath.Add(@"ShipmentTans" + "\\" + strImagePath + "\\" + TanNumber + "\\" + TanwiseEachDocument.FullName);
                    }
                    string strTotalDocumentsPath = String.Join(",", TanwiseLocalPath);
                    tanWiseAllFiles[TanNumber] = strTotalDocumentsPath;
                    string TempKeywordDestnationPDF = $"ShipmentTans\\{strImagePath}\\{TanNumber}\\{(!string.IsNullOrEmpty(TanWiseBestFile) ? TanWiseBestFile : TanwiseLocalPath.Any() ? TanwiseLocalPath.First() : string.Empty)}";
                    tanWiseBestFiles[TanNumber] = TempKeywordDestnationPDF;

                    string strPDFfileData = string.Empty;
                    strPDFfileData = StaticStore.extractText(Path.Combine(destination, TempKeywordDestnationPDF));
                    if (strPDFfileData != "")
                    {
                        List <string> foundWords = new List <string>();
                        foreach (TanKeywords word in keyWordsList)
                        {
                            try
                            {
                                if (!String.IsNullOrEmpty(word.keyword))
                                {
                                    string upperWord = word.keyword.Trim().ToUpper();
                                    if (strPDFfileData.IndexOf(upperWord) > -1)
                                    {
                                        foundWords.Add(word.keyword);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                //Log.This(ex);
                            }
                        }
                        string combinedKeywords = String.Join(",", foundWords.ToArray());
                        tanWisekeyword[TanNumber] = combinedKeywords;
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    //Log.This(ex);
                }
            }
            TanWiseAllFiles.Add(tanWiseAllFiles);
            TanWiseBestFiles.Add(tanWiseBestFiles);
            TanWiseKeywords.Add(tanWisekeyword);
        }
 private StaticConcurrentHashTable CreateHashTable(long capacity = 56, Func <MemorySlice, long> hashFunction = null)
 {
     store     = CreateStore(capacity, hashFunction);
     hashTable = store.GetConcurrentHashTable();
     return(hashTable);
 }
コード例 #9
0
    public static void Main()
    {
        Random random = new Random();

        Console.WriteLine("--------------------Static store");

        StaticStore <Byte> staticByteStore = new StaticStore <Byte>(4);

        staticByteStore.Add(Byte.MinValue);
        staticByteStore.Add(Byte.MaxValue);
        staticByteStore.Add(1);
        staticByteStore.Add(8);
        //staticByteStore.Add(5);
        Console.WriteLine(staticByteStore);

        //StaticStore<Int16> staticInvalidShortStore = new StaticStore<Int16>(-1);
        StaticStore <Int16> staticShortStore = new StaticStore <Int16>(4);

        staticShortStore.Add(Int16.MinValue);
        staticShortStore.Add(Int16.MaxValue);
        staticShortStore.Add(2);
        staticShortStore.Add(16);
        Console.WriteLine(staticShortStore);

        StaticStore <Int32> staticIntegerStore = new StaticStore <Int32>(4);

        staticIntegerStore.Add(Int32.MinValue);
        staticIntegerStore.Add(Int32.MaxValue);
        staticIntegerStore.Add(4);
        staticIntegerStore.Add(32);
        Console.WriteLine(staticIntegerStore);

        StaticStore <Int64> staticLongStore = new StaticStore <Int64>(4);

        staticLongStore.Add(Int64.MinValue);
        staticLongStore.Add(Int64.MaxValue);
        staticLongStore.Add(8);
        staticLongStore.Add(64);
        Console.WriteLine(staticLongStore);

        StaticStore <Single> staticFloatStore = new StaticStore <Single>(6);

        staticFloatStore.Add(Single.MinValue);
        staticFloatStore.Add(Single.MaxValue);
        staticFloatStore.Add(Single.NegativeInfinity);
        staticFloatStore.Add(Single.PositiveInfinity);
        staticFloatStore.Add(Single.Epsilon);
        staticFloatStore.Add(Single.NaN);
        Console.WriteLine(staticFloatStore);

        StaticStore <Double> staticDoubleStore = new StaticStore <Double>(6);

        staticDoubleStore.Add(Double.MinValue);
        staticDoubleStore.Add(Double.MaxValue);
        staticDoubleStore.Add(Double.NegativeInfinity);
        staticDoubleStore.Add(Double.PositiveInfinity);
        staticDoubleStore.Add(Double.Epsilon);
        staticDoubleStore.Add(Double.NaN);
        Console.WriteLine(staticDoubleStore);

        StaticStore <Char> staticCharacterStore = new StaticStore <Char>(2);

        staticCharacterStore.Add(Char.MinValue);
        staticCharacterStore.Add(Char.MaxValue);
        Console.WriteLine(staticCharacterStore);

        StaticStore <Boolean> staticBooleanStore = new StaticStore <Boolean>(2);

        staticBooleanStore.Add(false);
        staticBooleanStore.Add(true);
        Console.WriteLine(staticBooleanStore);

        StaticStore <String> staticStringStore = new StaticStore <String>(4);

        staticStringStore.Add("Fellow");
        staticStringStore.Add("Mellow");
        staticStringStore.Add("Yellow");
        staticStringStore.Add("Bellow");
        Console.WriteLine(staticStringStore);

        StaticStore <Object> staticObjectStore = new StaticStore <Object>(2);

        staticObjectStore.Add(null);
        staticObjectStore.Add(new Object());
        Console.WriteLine(staticObjectStore);

        Console.WriteLine("--------------------Static store replace item");

        StaticStore <Int32> staticReplacedIntegerStore = new StaticStore <Int32>(4);

        Console.WriteLine(staticReplacedIntegerStore);
        //staticReplacedIntegerStore.ReplaceAll(0);
        //Console.WriteLine(staticReplacedIntegerStore);
        staticReplacedIntegerStore.Add(1);
        //staticReplacedIntegerStore.Replace(1, 7);
        staticReplacedIntegerStore.Add(3);
        staticReplacedIntegerStore.Add(9);
        staticReplacedIntegerStore.Add(5);
        Console.WriteLine(staticReplacedIntegerStore);
        staticReplacedIntegerStore.ReplaceAll(0);
        Console.WriteLine(staticReplacedIntegerStore);
        staticReplacedIntegerStore.Replace(1, 7);
        Console.WriteLine(staticReplacedIntegerStore);
        //Console.WriteLine("Index of 9 = " + Convert.ToString(staticReplacedIntegerStore.GetIndex(9)));
        Console.WriteLine("Item at index 3 = " + Convert.ToString(staticReplacedIntegerStore.Get(3)));

        Console.WriteLine("--------------------Dynamic store");

        DynamicStore <Byte> dynamicByteStore = new DynamicStore <Byte>();

        dynamicByteStore.Add(Byte.MinValue);
        dynamicByteStore.Add(Byte.MaxValue);
        dynamicByteStore.Add(1);
        dynamicByteStore.Add(8);
        Console.WriteLine(dynamicByteStore);

        DynamicStore <Int16> dynamicShortStore = new DynamicStore <Int16>();

        dynamicShortStore.Add(Int16.MinValue);
        dynamicShortStore.Add(Int16.MaxValue);
        dynamicShortStore.Add(2);
        dynamicShortStore.Add(16);
        Console.WriteLine(dynamicShortStore);

        DynamicStore <Int32> dynamicIntegerStore = new DynamicStore <Int32>();

        dynamicIntegerStore.Add(Int32.MinValue);
        dynamicIntegerStore.Add(Int32.MaxValue);
        dynamicIntegerStore.Add(4);
        dynamicIntegerStore.Add(32);
        Console.WriteLine(dynamicIntegerStore);

        DynamicStore <Int64> dynamicLongStore = new DynamicStore <Int64>();

        dynamicLongStore.Add(Int64.MinValue);
        dynamicLongStore.Add(Int64.MaxValue);
        dynamicLongStore.Add(8);
        dynamicLongStore.Add(64);
        Console.WriteLine(dynamicLongStore);

        DynamicStore <Single> dynamicFloatStore = new DynamicStore <Single>();

        dynamicFloatStore.Add(Single.MinValue);
        dynamicFloatStore.Add(Single.MaxValue);
        dynamicFloatStore.Add(Single.NegativeInfinity);
        dynamicFloatStore.Add(Single.PositiveInfinity);
        dynamicFloatStore.Add(Single.Epsilon);
        dynamicFloatStore.Add(Single.NaN);
        Console.WriteLine(dynamicFloatStore);

        DynamicStore <Double> dynamicDoubleStore = new DynamicStore <Double>();

        dynamicDoubleStore.Add(Double.MinValue);
        dynamicDoubleStore.Add(Double.MaxValue);
        dynamicDoubleStore.Add(Double.NegativeInfinity);
        dynamicDoubleStore.Add(Double.PositiveInfinity);
        dynamicDoubleStore.Add(Double.Epsilon);
        dynamicDoubleStore.Add(Double.NaN);
        Console.WriteLine(dynamicDoubleStore);

        DynamicStore <Char> dynamicCharacterStore = new DynamicStore <Char>();

        dynamicCharacterStore.Add(Char.MinValue);
        dynamicCharacterStore.Add(Char.MaxValue);
        Console.WriteLine(dynamicCharacterStore);

        DynamicStore <Boolean> dynamicBooleanStore = new DynamicStore <Boolean>();

        dynamicBooleanStore.Add(false);
        dynamicBooleanStore.Add(true);
        Console.WriteLine(dynamicBooleanStore);

        DynamicStore <String> dynamicStringStore = new DynamicStore <String>();

        dynamicStringStore.Add("Fellow");
        dynamicStringStore.Add("Mellow");
        dynamicStringStore.Add("Yellow");
        dynamicStringStore.Add("Bellow");
        Console.WriteLine(dynamicStringStore);

        DynamicStore <Object> dynamicObjectStore = new DynamicStore <Object>();

        dynamicObjectStore.Add(null);
        dynamicObjectStore.Add(new Object());
        Console.WriteLine(dynamicObjectStore);

        Console.WriteLine("--------------------Dynamic sorted store");

        DynamicStore <Int32> dynamicSortedIntegerStore = new DynamicStore <Int32>();

        for (Int32 i = 0; i < 52; i++)
        {
            dynamicSortedIntegerStore.Add(random.Next(2000));
        }
        OneDimensionSorter <Int32> dynamicSortedIntegerStoreSingularSorter = new OneDimensionSorter <Int32>(dynamicSortedIntegerStore);

        dynamicSortedIntegerStoreSingularSorter.Sort();
        Console.WriteLine(dynamicSortedIntegerStore);

        DynamicStore <String> dynamicSortedStringStore = new DynamicStore <String>();

        dynamicSortedStringStore.Add("Fellow");
        dynamicSortedStringStore.Add("Mellow");
        dynamicSortedStringStore.Add("Yellow");
        dynamicSortedStringStore.Add("Bellow");
        OneDimensionSorter <String> dynamicSortedStringStoreSingularSorter = new OneDimensionSorter <String>(dynamicSortedStringStore);

        dynamicSortedStringStoreSingularSorter.Sort();
        Console.WriteLine(dynamicSortedStringStore);

        Console.WriteLine("--------------------Dynamic store replace item");

        DynamicStore <Int32> dynamicReplacedIntegerStore = new DynamicStore <Int32>();

        dynamicReplacedIntegerStore.Add(1);
        dynamicReplacedIntegerStore.Add(3);
        //dynamicReplacedIntegerStore.Replace(2, 7);
        dynamicReplacedIntegerStore.Add(9);
        dynamicReplacedIntegerStore.Add(5);
        Console.WriteLine(dynamicReplacedIntegerStore);
        dynamicReplacedIntegerStore.Replace(2, 7);
        Console.WriteLine(dynamicReplacedIntegerStore);

        Console.WriteLine("--------------------Dynamic store insert item");
        DynamicStore <Int32> dynamicInsertedIntegerStore = new DynamicStore <Int32>();

        dynamicInsertedIntegerStore.Add(1);
        dynamicInsertedIntegerStore.Add(3);
        dynamicInsertedIntegerStore.Add(9);
        dynamicInsertedIntegerStore.Add(5);
        Console.WriteLine(dynamicInsertedIntegerStore);
        dynamicInsertedIntegerStore.Insert(2, 7);
        Console.WriteLine(dynamicInsertedIntegerStore);
        dynamicInsertedIntegerStore.Insert(0, 8);
        Console.WriteLine(dynamicInsertedIntegerStore);
        dynamicInsertedIntegerStore.Insert(6, 4);
        Console.WriteLine(dynamicInsertedIntegerStore);
        //dynamicInsertedIntegerStore.Insert(9, 0);
        //Console.WriteLine(dynamicInsertedIntegerStore);
        //dynamicInsertedIntegerStore.Insert(-1, 6);
        //Console.WriteLine(dynamicInsertedIntegerStore);
        Console.WriteLine("Index of 9 = " + Convert.ToString(dynamicInsertedIntegerStore.GetIndex(9)));
        Console.WriteLine("Item at index 3 = " + Convert.ToString(dynamicInsertedIntegerStore.Get(3)));
        Console.WriteLine();

        Console.WriteLine("--------------------Dynamic unique item store");

        DynamicUniqueStore <Int32> dynamicUniqueIntegerStore = new DynamicUniqueStore <Int32>();

        dynamicUniqueIntegerStore.Add(1);
        dynamicUniqueIntegerStore.Add(2);
        dynamicUniqueIntegerStore.Add(1);
        dynamicUniqueIntegerStore.Add(3);
        Console.WriteLine(dynamicUniqueIntegerStore);

        Console.WriteLine("--------------------Dynamic key value store");

        DynamicMap <String, Int32> dynamicKeyValueStore = new DynamicMap <String, Int32>();

        dynamicKeyValueStore.Add("Yukon", 8);
        dynamicKeyValueStore.Add("Bicker", 9);
        dynamicKeyValueStore.Add("Shulz", 7);
        dynamicKeyValueStore.Add("Jems", 3);
        Console.WriteLine(dynamicKeyValueStore);

        DynamicMap <Int32, ItemStore <Int32> > dynamicKeyValueStoreWithListValue = new DynamicMap <Int32, ItemStore <Int32> >();

        dynamicKeyValueStoreWithListValue.Add(1, new StaticStore <Int32>(4));
        dynamicKeyValueStoreWithListValue.Add(2, new DynamicStore <Int32>());
        dynamicKeyValueStoreWithListValue.Add(3, new DynamicUniqueStore <Int32>());
        Console.WriteLine(dynamicKeyValueStoreWithListValue);

        Console.WriteLine("--------------------Dynamic sorted key value store");

        DynamicMap <Int32, String> dynamicSortedIntegerKeyValueStore = new DynamicMap <Int32, String>();

        dynamicSortedIntegerKeyValueStore.Add(88, "Yukon");
        dynamicSortedIntegerKeyValueStore.Add(832, "Bicker");
        dynamicSortedIntegerKeyValueStore.Add(832, "Blitzer");
        dynamicSortedIntegerKeyValueStore.Add(7, "Shulz");
        dynamicSortedIntegerKeyValueStore.Add(17, "Shulz");
        dynamicSortedIntegerKeyValueStore.Add(3, "Jems");
        TwoDimensionSorter <Int32, String> dynamicSortedIntegerKeyValueStoreSingularSorter = new TwoDimensionSorter <Int32, String>(dynamicSortedIntegerKeyValueStore);

        dynamicSortedIntegerKeyValueStoreSingularSorter.Sort(TwoDimensionConstants.KEY);
        Console.WriteLine(dynamicSortedIntegerKeyValueStore);
        Console.WriteLine("7 -> " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetValue(7)));
        //Console.WriteLine("Bicker <- " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetKey("Bicker")));
        Console.WriteLine("Blitzer <- " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetKey("Blitzer")));
        Console.WriteLine();

        DynamicMap <String, Int32> dynamicSortedStringKeyValueStore = new DynamicMap <String, Int32>();

        dynamicSortedStringKeyValueStore.Add("Yukon", 8);
        dynamicSortedStringKeyValueStore.Add("Bicker", 9);
        dynamicSortedStringKeyValueStore.Add("Shulz", 7);
        dynamicSortedStringKeyValueStore.Add("Jems", 3);
        TwoDimensionSorter <String, Int32> dynamicSortedStringKeyValueStoreSingularSorter = new TwoDimensionSorter <String, Int32>(dynamicSortedStringKeyValueStore);

        dynamicSortedStringKeyValueStoreSingularSorter.Sort(TwoDimensionConstants.VALUE);
        Console.WriteLine(dynamicSortedStringKeyValueStore);
        Console.WriteLine("Yukon -> " + Convert.ToString(dynamicSortedStringKeyValueStore.GetValue("Yukon")));
        Console.WriteLine("3 <- " + Convert.ToString(dynamicSortedStringKeyValueStore.GetKey(3)));
        Console.WriteLine();
    }
コード例 #10
0
 private async Task HandleStuffAsync(Stuff stuff)
 {
     ++_messageCount;
     StaticStore.Set(Id, _messageCount);
     await ConsoleHelper.WriteAsync("New message -> (Actor {0}/{1} received \"{2}\" - message count: {3})", _address, PersistenceId, stuff.Text, _messageCount);
 }