public void CanOnlyMapCorrespondingTypes()
    {
        var blob = new Parts("o/r1", TreeEntryTargetType.Blob, "b1", "a");
        var tree = new Parts("o/r1", TreeEntryTargetType.Tree, "b1", "c");

        var m = new Mapper();

        Assert.Throws<ArgumentException>(() => m.Add(blob, tree));
        Assert.Throws<ArgumentException>(() => m.Add(tree, blob));
    }
    public void CanOnlyMapCorrespondingTypes()
    {
        var blob = new Parts("o/r1", TreeEntryTargetType.Blob, "b1", "a");
        var tree = new Parts("o/r1", TreeEntryTargetType.Tree, "b1", "c");

        var m = new Mapper();

        Assert.Throws <ArgumentException>(() => m.Add(blob, tree));
        Assert.Throws <ArgumentException>(() => m.Add(tree, blob));
    }
Exemple #3
0
        public void CreateMapTest()
        {
            Mapper mapper = new Mapper();
            StringCollection propertyList = mapper.GetPaymentProperties();
            mapper.Add("ClaimID", propertyList[0]);
            mapper.Add("Fee", propertyList[1]);
            mapper.Add("UID", propertyList[2]);
            mapper.Add("InsurerContractCode", propertyList[11]);

            //StringDictionary dict = mapper.GetCurrentMap();
            Assert.That(mapper.Count == 4);
            Assert.IsTrue(mapper.ContainsKey("Fee"));
            Assert.IsTrue(mapper["Fee"] == "Amount");
        }
        public void Create(DateTime startSession, int duration, string training, string trainer, string location, string student, string company)
        {
            if (training.IsEmpty() || trainer.IsEmpty() || location.IsEmpty() || student.IsEmpty() || company.IsEmpty())
            {
                return;
            }

            var key = $"{training}-{startSession:d}";

            try
            {
                if (!Mapper.Exists(key))
                {
                    var session = App.Command <PlanSession>().Execute(
                        _trainingCreator.GetId(_trainingCreator.ConstructKey(training)),
                        startSession, duration, 20,
                        _locationCreator.GetId(_locationCreator.ConstructKey(location)),
                        _trainerCreator.GetId(_trainerCreator.ConstructKey(trainer)));

                    Mapper.Add(key, session.AggregateId);
                }

                var seat = App.Command <BookSeat>().Execute(Mapper.GetId(key),
                                                            _studentCreator.GetId(_studentCreator.ConstructKey(student)),
                                                            _companyCreator.GetCompanyId(_companyCreator.ConstructKey(company)), false);

                App.Command <ValidateSeat>().Execute(seat.AggregateId, false);
            }
            catch (DomainException e)
            {
                Console.WriteLine(e.Message);
            }
        }
 private void ProcessExecutedChanges(List <Protocal.Commands.OrderPhaseChange> orderChanges)
 {
     try
     {
         Dictionary <Guid, Transaction> trans = new Dictionary <Guid, Transaction>();
         foreach (var eachChange in orderChanges)
         {
             if (eachChange.ChangeType == Protocal.Commands.OrderChangeType.Executed)
             {
                 var tran = eachChange.Source.Owner;
                 if (!trans.ContainsKey(tran.Id))
                 {
                     trans.Add(tran.Id, (Transaction)tran);
                 }
             }
         }
         foreach (var eachTran in trans.Values)
         {
             _mapper.Add(eachTran.ToXml().ToXmlNode());
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
Exemple #6
0
 /// <summary>
 /// CheckForClosestCountries method.
 /// According to the longtitude and latitude that were
 /// calculated earlier - take from table the 8 most close
 /// areas to the latitude and longtitue point according
 /// to a well known formula
 /// </summary>
 public void CheckForClosestCountries()
 {
     try
     {
         StringBuilder subQuery = new StringBuilder();
         subQuery.Append("Select LocationId, location_name, count(location_name) FROM ");
         subQuery.Append("(SELECT area.LocationId,area.location_name FROM area ");
         subQuery.Append("WHERE area.latitude != 0 AND area.longitude != 0 ");
         subQuery.Append("GROUP BY area.location_name ");
         subQuery.Append("order by (6371 * acos( cos( radians(area.latitude) ) * cos( radians(" + area.Latitude.ToString() + ")) ");
         subQuery.Append("* cos( radians(" + Area.Longtitude.ToString() + ") - radians(area.longitude) ) + sin( radians(area.latitude) ) * sin(radians(" + Area.Latitude.ToString() + ")))) Asc ");
         subQuery.Append("LIMIT 12) AS country ");
         subQuery.Append("JOIN artists JOIN Songs ");
         subQuery.Append("WHERE songs.artists_idArtists = artists.idArtists AND artists.Area_LocationId = country.LocationId ");
         subQuery.Append("GROUP BY location_name order by count(location_name) desc Limit 10");
         DataTable set = this.executer.ExecuteCommandWithResults(subQuery.ToString());
         string    ans = QueryInterpreter.Instance.getQueryEntitesObject(QueryInterpreter.QueryType.AreaSongsCount, set);
         Dictionary <string, int> tempDic = JsonConvert.DeserializeObject <Dictionary <string, int> >(ans);
         foreach (string item in tempDic.Keys)
         {
             int count;
             tempDic.TryGetValue(item, out count);
             Mapper.Add(JsonConvert.DeserializeObject <Area>(item), count);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Data);
     }
 }
 /// <summary>
 /// Fills data into its corresponding Sheet.
 /// </summary>
 /// <typeparam name="T">Type of Information to be Added in the Excel Sheet.</typeparam>
 /// <param name="list">The list of Data be Added.</param>
 /// <param name="sheet">The Excel Sheet where Data should be Added.</param>
 /// <param name="mapper">The Mapper that contains the functions to retrieve Data's Information.</param>
 public void fill <T>(IEnumerable <T> list, string sheet, Mapper <T> mapper) where T : DashboardTable
 {
     try {
         //Adds the Base Columns all Tables have
         mapper.Add("ID", data => getCurrentCounter() + 1);
         mapper.Add("Programa", data => data.Program.getProgram());
         if (isAcumulative && !mapper.ContainsKey("Alumno"))
         {
             mapper.Add("Alumno", data => data.Student);
         }
         //Generates Data in the Excel Sheet
         SearchSheet(sheet);
         fill(list, mapper);
     } catch (Exception e) {
         Console.WriteLine(e.Message);
     }
 }
    public void CannotRemoveAnAlreadyAddedTargetPath()
    {
        var m    = new Mapper();
        var from = new Parts("source/r", TreeEntryTargetType.Blob, "branch", "file.txt");
        var to   = new Parts("target/r", TreeEntryTargetType.Blob, "branch", "file.txt");

        m.Add(from, to);
        Assert.Throws <InvalidOperationException>(() => m.Remove(to));
    }
        public void MapButtons(IEnumerable <KeyValuePair <CommandKey, ToolStripButton> > mappings)
        {
            foreach (var item in mappings)
            {
                _buttonMap.Add(item.Key, item.Value);
                item.Value.Click += BoundButtonClickHandler;

                Invalidate(item.Key);
            }
        }
        private void MapMenuItem(CommandKey key, ToolStripMenuItem item)
        {
            if (key != CommandKey.Unknown && item != null)
            {
                _menuMap.Add(key, item);
                item.Click += BoundMenuClickHandler;

                Invalidate(key);
            }
        }
Exemple #11
0
    public Mapper GetMapper(List<SyncItem> syncItems)
    {
        var mapper = new Mapper();

        foreach (var syncItem in syncItems)
        {
            var toPart = new Parts("Particular/" + Name, syncItem.Parts.Type, Branch, ApplyTargetPathTemplate(syncItem));

            mapper.Add(syncItem.Parts, toPart);
        }

        return mapper;
    }
Exemple #12
0
        /// <summary>
        /// Configure using the current type. This is special because
        /// it has not accessor to get at the sub property type.
        /// </summary>
        /// <typeparam name="TSub">The new type</typeparam>
        /// <param name="configure">Lambda expression that configures the mapping</param>
        /// <param name="lookupStrategy">The mapper's lookup strategy.</param>
        public void Configure <TSub>(Action <IConfigureChain <TSub> > configure,
                                     LookupStrategyEnum lookupStrategy    = LookupStrategyEnum.ConcreteOnly,
                                     string typeNameResourceKey           = "",
                                     Func <TSub, string> TypeNameAccessor = null)
        {
            SelectorMapper <TSub> mapper = new SelectorMapper <TSub>(lookupStrategy)
            {
                TypeNameResourceKey = typeNameResourceKey,
                TypeNameAccessor    = TypeNameAccessor
            };

            Mapper.Add <TSub>(mapper);
            configure(mapper);
        }
Exemple #13
0
        public void Create(string trainingName)
        {
            if (trainingName.IsEmpty())
            {
                return;
            }
            if (Mapper.Exists(trainingName))
            {
                return;
            }

            var training = App.Command <CreateTraining>().Execute(trainingName, 8, GetRandomColor());

            Mapper.Add(trainingName, training.AggregateId);
        }
        public void Create(string locationName)
        {
            if (locationName.IsEmpty())
            {
                return;
            }
            if (Mapper.Exists(locationName))
            {
                return;
            }

            var location = App.Command <CreateLocation>().Execute(locationName, "", 8);

            Mapper.Add(locationName, location.AggregateId);
        }
        public void Create(string name, string address, string zipCode, string city)
        {
            if (name.IsEmpty())
            {
                return;
            }

            if (Mapper.Exists(name))
            {
                return;
            }

            var company = App.Command <CreateCompany>().Execute(name, address, zipCode, city);

            Mapper.Add(name, company.AggregateId);
        }
Exemple #16
0
        private void Initialize(LevelX proxy, Project project)
        {
            if (proxy.PropertyGroup != null)
            {
                Extra = new List <XmlElement>(proxy.PropertyGroup.Extra ?? new XmlElement[0]);
            }

            _project       = project;
            _x             = proxy.OriginX;
            _y             = proxy.OriginY;
            _width         = Math.Max(1, proxy.Width);
            _height        = Math.Max(1, proxy.Height);
            _indexSequence = proxy.TileIndex.Sequence;

            Dictionary <int, Guid> tileIndex = new Dictionary <int, Guid>();

            foreach (var entry in proxy.TileIndex.Entries)
            {
                _localTileIndex.Add(entry.Id, entry.Uid);
                tileIndex.Add(entry.Id, entry.Uid);

                if (entry.Id >= _indexSequence)
                {
                    _indexSequence = entry.Id + 1;
                }
            }

            foreach (LevelX.LayerX layerProxy in proxy.Layers)
            {
                if (layerProxy is LevelX.MultiTileGridLayerX)
                {
                    Layers.Add(new MultiTileGridLayer(layerProxy as LevelX.MultiTileGridLayerX, this, tileIndex));
                }
                else if (layerProxy is LevelX.ObjectLayerX)
                {
                    Layers.Add(new ObjectLayer(layerProxy as LevelX.ObjectLayerX, this));
                }
            }

            if (proxy.Properties != null)
            {
                foreach (var propertyProxy in proxy.Properties)
                {
                    PropertyManager.CustomProperties.Add(Property.FromXmlProxy(propertyProxy));
                }
            }
        }
Exemple #17
0
        public void Create(string name)
        {
            if (name.IsEmpty())
            {
                return;
            }

            if (Mapper.Exists(ConstructKey(name)))
            {
                return;
            }

            var fullname = new Name(name);
            var student  = App.Command <CreateStudent>().Execute(fullname.Lastname, fullname.Firstname);

            Mapper.Add(ConstructKey(name), student.AggregateId);
        }
        public void Create(string trainerName)
        {
            if (trainerName.IsEmpty())
            {
                return;
            }

            if (Mapper.Exists(ConstructKey(trainerName)))
            {
                return;
            }

            var tn = new Name(trainerName);

            var trainer = App.Command <CreateTrainer>().Execute(tn.Lastname, tn.Firstname, string.Empty);

            Mapper.Add(ConstructKey(trainerName), trainer.AggregateId);
        }
    public Mapper GetMapper(List <SyncItem> syncItems)
    {
        var mapper = new Mapper();

        foreach (var syncItem in syncItems)
        {
            var toPart = new Parts($"{Owner}/{Repo}", syncItem.Parts.Type, TargetBranch, ApplyTargetPathTemplate(syncItem));

            if (syncItem.ToBeAdded)
            {
                mapper.Add(syncItem.Parts, toPart);
            }
            else
            {
                mapper.Remove(toPart);
            }
        }

        return(mapper);
    }
Exemple #20
0
        public void Create(string contact, string email, string telephone, string companyName)
        {
            if (companyName.IsEmpty())
            {
                return;
            }
            if (contact.IsEmpty())
            {
                return;
            }

            if (Mapper.Exists(ConstructKey(contact)))
            {
                return;
            }

            var contactName    = new Name(contact);
            var createdContact = App.Command <CreateContact>().Execute(_companyCreator.GetCompanyId(companyName), contactName.Lastname, contactName.Firstname, email, telephone);

            Mapper.Add(ConstructKey(contact), createdContact.AggregateId);
        }
Exemple #21
0
    internal async Task <Mapper> Diff(Mapper input)
    {
        Guard.AgainstNull(input, nameof(input));
        var outMapper = new Mapper();

        foreach (var kvp in input.ToBeAddedOrUpdatedEntries)
        {
            var source = kvp.Key;

            log($"Diff - Analyze {source.Type} source '{source.Url}'.");

            var richSource = await EnrichWithShas(source, true);

            foreach (var destination in kvp.Value)
            {
                log($"Diff - Analyze {source.Type} target '{destination.Url}'.");

                var richDestination = await EnrichWithShas(destination, false);

                if (richSource.Sha == richDestination.Sha)
                {
                    log($"Diff - No sync required. Matching sha ({richSource.Sha.Substring(0, 7)}) between target '{destination.Url}' and source '{source.Url}.");

                    continue;
                }

                log(string.Format("Diff - {4} required. Non-matching sha ({0} vs {1}) between target '{2}' and source '{3}.",
                                  richSource.Sha.Substring(0, 7), richDestination.Sha?.Substring(0, 7) ?? "NULL", destination.Url, source.Url, richDestination.Sha == null ? "Creation" : "Updation"));

                outMapper.Add(richSource, richDestination);
            }
        }

        foreach (var p in input.ToBeRemovedEntries)
        {
            outMapper.Remove(p);
        }

        return(outMapper);
    }
Exemple #22
0
        public static void Main(string[] args)
        {
            var scanner = new Scanner("Star Trek TOS Plot Summaries from Eric W Weisstein.txt");
            var mapper  = new Mapper();

            int i = 0;

            while (!scanner.IsEnd())
            {
                mapper.Add(scanner.Next());
            }

            string word = "";
            int    j    = 0;

            do
            {
                var b = j == 0 ? mapper.MaxWord() : mapper.MaxWord(word);
                word = b.Second + "-" + b.Suffix;
                Console.Write(b.First + " ");
            } while (j++ < 50);
            Console.Read();
        }
Exemple #23
0
        public async Task <SyncContext> CalculateSyncContext(RepositoryInfo targetRepository)
        {
            var syncContext = new SyncContext(targetRepository);

            using (var syncer = new Syncer(targetRepository.Credentials, null, log))
            {
                var diffs         = new List <Mapper>();
                var includedPaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                var descriptionBuilder = new StringBuilder();
                descriptionBuilder.AppendLine("This is an automated synchronization PR.");
                descriptionBuilder.AppendLine();
                descriptionBuilder.AppendLine("The following source template repositories were used:");

                // Note: iterate backwards, later registered sources should override earlier registrations
                for (var i = sources.Count - 1; i >= 0; i--)
                {
                    var source      = sources[i];
                    var displayName = $"{source.Owner}/{source.Repository}";
                    var itemsToSync = new List <SyncItem>();

                    foreach (var item in await OctokitEx.GetRecursive(source.Credentials, source.Owner, source.Repository, null, source.Branch))
                    {
                        if (includedPaths.Contains(item))
                        {
                            continue;
                        }

                        includedPaths.Add(item);

                        ProcessItem(item, itemsToSync, source);
                    }

                    var targetRepositoryToSync = new RepoToSync
                    {
                        Owner        = targetRepository.Owner,
                        Repo         = targetRepository.Repository,
                        TargetBranch = targetRepository.Branch
                    };

                    var sourceMapper = targetRepositoryToSync.GetMapper(itemsToSync);
                    var diff         = await syncer.Diff(sourceMapper);

                    if (diff.ToBeAddedOrUpdatedEntries.Any() ||
                        diff.ToBeRemovedEntries.Any())
                    {
                        diffs.Add(diff);

                        descriptionBuilder.AppendLine($"* {displayName}");
                    }
                }

                var finalDiff = new Mapper();

                foreach (var diff in diffs)
                {
                    foreach (var item in diff.ToBeAddedOrUpdatedEntries)
                    {
                        foreach (var value in item.Value)
                        {
                            log($"Mapping '{item.Key.Url}' => '{value.Url}'");

                            finalDiff.Add(item.Key, value);
                        }
                    }

                    // Note: how to deal with items to be removed
                }

                syncContext.Diff        = finalDiff;
                syncContext.Description = descriptionBuilder.ToString();
            }

            return(syncContext);
        }
Exemple #24
0
        public async Task <SyncContext> CalculateSyncContext(RepositoryInfo targetRepository)
        {
            var syncContext = new SyncContext(targetRepository);

            using (var syncer = new Syncer(targetRepository.Credentials, null, log))
            {
                var diffs         = new List <Mapper>();
                var includedPaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                var descriptionBuilder = new StringBuilder();
                descriptionBuilder.AppendLine("This is an automated synchronization PR.");
                descriptionBuilder.AppendLine();
                descriptionBuilder.AppendLine("The following source template repositories were used:");

                // Note: iterate backwards, later registered sources should override earlier registrations
                for (var i = sources.Count - 1; i >= 0; i--)
                {
                    var sourceRepository            = sources[i];
                    var sourceRepositoryDisplayName = $"{sourceRepository.Owner}/{sourceRepository.Repository}";
                    var itemsToSync = new List <SyncItem>();

                    foreach (var item in await OctokitEx.GetRecursive(sourceRepository.Credentials, sourceRepository.Owner, sourceRepository.Repository))
                    {
                        if (includedPaths.Contains(item))
                        {
                            continue;
                        }

                        includedPaths.Add(item);

                        if (manualSyncItems.Any(x => item.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
                        {
                            switch (syncMode)
                            {
                            case SyncMode.IncludeAllByDefault:
                                // Continue
                                break;

                            case SyncMode.ExcludeAllByDefault:
                                // Ignore this file
                                continue;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(syncMode), $"Sync mode '{syncMode}' is not supported");
                            }
                        }

                        itemsToSync.Add(new SyncItem
                        {
                            Parts = new Parts($"{sourceRepository.Owner}/{sourceRepository.Repository}",
                                              TreeEntryTargetType.Blob, sourceRepository.Branch, item),
                            ToBeAdded = true,
                            Target    = null
                        });
                    }

                    var targetRepositoryToSync = new RepoToSync
                    {
                        Owner        = targetRepository.Owner,
                        Repo         = targetRepository.Repository,
                        TargetBranch = targetRepository.Branch
                    };

                    var sourceMapper = targetRepositoryToSync.GetMapper(itemsToSync);
                    var diff         = await syncer.Diff(sourceMapper);

                    if (diff.ToBeAddedOrUpdatedEntries.Count() > 0 ||
                        diff.ToBeRemovedEntries.Count() > 0)
                    {
                        diffs.Add(diff);

                        descriptionBuilder.AppendLine($"* {sourceRepositoryDisplayName}");
                    }
                }

                var finalDiff = new Mapper();

                foreach (var diff in diffs)
                {
                    foreach (var item in diff.ToBeAddedOrUpdatedEntries)
                    {
                        foreach (var value in item.Value)
                        {
                            log($"Mapping '{item.Key.Url}' => '{value.Url}'");

                            finalDiff.Add(item.Key, value);
                        }
                    }

                    // Note: how to deal with items to be removed
                }

                syncContext.Diff        = finalDiff;
                syncContext.Description = descriptionBuilder.ToString();
            }

            return(syncContext);
        }