Ejemplo n.º 1
0
        public void Merge(ModelCollection <T, TK> models)
        {
            if (ModelsByKey == null)
            {
                lock (_lock)
                {
                    if (ModelsByKey == null)
                    {
                        ModelDictionary modelsByKey = new ModelDictionary();

                        foreach (T model in this)
                        {
                            modelsByKey.TryAdd(model.Key, model);
                        }

                        ModelsByKey = modelsByKey;
                    }
                }
            }
            foreach (T model in models)
            {
                ModelsByKey.AddOrUpdate(model.Key,
                                        k =>
                {
                    Add(model);
                    return(model);
                },
                                        (k, m) => m.Merge(model));
            }
        }
Ejemplo n.º 2
0
 public ModelCache()
 {
     referenceList        = new ModelDictionary();
     registeredModelTypes = new Dictionary <Type, ModelRegister>();
     modelBuffer          = new List <KeyValuePair <DateTime, object> >();
     //this.leagueContext = leagueContext;
 }
Ejemplo n.º 3
0
        public List <CustomAttributesAc> GetAttributeListByActivityId(int activityId)
        {
            try
            {
                var customAttributeCollection = new List <CustomAttributesAc>();
                var dictionaryCollection      = ModelDictionary.GetModelDictionary();

                var dictionaryDetails = dictionaryCollection.FirstOrDefault(x => x.Key == activityId);
                var dictinaryModel    = (Type)dictionaryDetails.Value;
                if (dictinaryModel != null)
                {
                    var properties = dictinaryModel.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                     .Where(p => p.GetCustomAttributes(typeof(CustomAttribute), false).Count() == 1).ToList();
                    foreach (var propertyInfo in properties)
                    {
                        if (propertyInfo.PropertyType.FullName != "System.Boolean")
                        {
                            var attributeAc = new CustomAttributesAc();
                            attributeAc.VariableName = propertyInfo.Name;
                            customAttributeCollection.Add(attributeAc);
                        }
                    }
                }
                ////key.

                return(customAttributeCollection);
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
Ejemplo n.º 4
0
 public void AnonymousObjectPropertiesInDictionary()
 {
     IDictionary<string, object> args = new ModelDictionary(new {name = "foo", bar = "quux"});
     Assert.AreEqual(2, args.Count);
     Assert.AreEqual("foo", args["name"]);
     Assert.AreEqual("quux", args["bar"]);
 }
Ejemplo n.º 5
0
        public void AnonymousObjectPropertiesInDictionary()
        {
            IDictionary <string, object> args = new ModelDictionary(new { name = "foo", bar = "quux" });

            Assert.AreEqual(2, args.Count);
            Assert.AreEqual("foo", args["name"]);
            Assert.AreEqual("quux", args["bar"]);
        }
        internal MacroFeatureRegister(string baseName, IModule parentModule)
        {
            m_BaseName = baseName;
            m_Logger   = LoggerFactory.Create(parentModule, this.GetType().Name);

            m_Register          = new ModelDictionary();
            m_LifecycleManagers = new Dictionary <IModelDoc2, MacroFeatureLifecycleManager>();
        }
Ejemplo n.º 7
0
 public void broadcastVehiclesToPlayer(ServerPlayer player)
 {
     foreach (var pair in vehicleController.vehicles)
     {
         var bpf = new BinaryPacketFormatter(Commands.Vehicle_create);
         bpf.Add(pair.Value.id);
         bpf.Add(pair.Value.position);
         bpf.Add(pair.Value.orientation);
         bpf.Add(ModelDictionary.getVehicleByName(pair.Value.model));
         player.connection.write(bpf.getBytes());
     }
 }
Ejemplo n.º 8
0
 public void broadcastPlayerModel(ServerPlayer player)
 {
     InvokeParallelForEachPlayer((single) =>
     {
         if (single != player)
         {
             var bpf = new BinaryPacketFormatter(Commands.Global_setPlayerModel);
             bpf.Add(player.id);
             bpf.Add(ModelDictionary.getPedModelByName(player.Model));
             single.connection.write(bpf.getBytes());
         }
     });
 }
        public static ModelDictionary GetModel(IEnumerable <PropertySearchInfo> propertySearchInfos, EntityRelated index)
        {
            var propByRelatedAndIndex = propertySearchInfos.GroupBy(s => new { s.Related, s.IndexClass, s.Index }).Select(s => s.FirstOrDefault());
            var enumEmun        = GetDescription(typeof(EnumRelated));
            var modelInfo       = ResourceExtension.ResourceModel(Related.REFERENCE, propByRelatedAndIndex.FirstOrDefault().IndexClass);
            var modelDictionary = new ModelDictionary()
            {
                Index       = index,
                Description = modelInfo.Description,
                ShortName   = modelInfo.ShortName,
                Title       = modelInfo.Title,
                BoolData    = GetDictionaryFromRelated(propByRelatedAndIndex, Related.BOOL),
                StringData  = GetDictionaryFromRelated(propByRelatedAndIndex, Related.STR),
                DateData    = GetDictionaryFromRelated(propByRelatedAndIndex, Related.DATE),
                DoubleData  = GetDictionaryFromRelated(propByRelatedAndIndex, Related.DBL),
                EnumData    = GetEnumDictionaryFromRelated(propByRelatedAndIndex, enumEmun),
                GeoData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.GEO),
                NumData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.NUM32),
                relData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.REFERENCE),
            };
            var suggestions           = GetDictionaryFromRelated(propByRelatedAndIndex, Related.SUGGESTION);
            var num64                 = GetDictionaryFromRelated(propByRelatedAndIndex, Related.NUM64);
            var suggestionNotInString = suggestions.Where(sg => !modelDictionary.StringData.Any(s => s.Key == sg.Key));
            var num64NotInNum         = num64.Where(sg => !modelDictionary.NumData.Any(s => s.Key == sg.Key));
            var relLocal              = GetDictionaryFromRelated(propByRelatedAndIndex, Related.LOCAL_REFERENCE);

            if (suggestionNotInString.Any())
            {
                foreach (var item in suggestionNotInString)
                {
                    modelDictionary.StringData.Add(item.Key, item.Value);
                }
            }
            if (num64NotInNum.Any())
            {
                foreach (var item in num64NotInNum)
                {
                    modelDictionary.NumData.Add(item.Key, item.Value);
                }
            }
            if (relLocal.Any())
            {
                foreach (var item in relLocal)
                {
                    modelDictionary.relData.Add(item.Key, item.Value);
                }
            }


            return(modelDictionary);
        }
Ejemplo n.º 10
0
        // Generate a unique ID of normalized key names + key values
        private string GetUniqueIdFromCommand(CommandHandlerContext filterContext)
        {
            Contract.Requires(filterContext != null);
            Contract.Requires(filterContext.Configuration != null);
            Contract.Requires(filterContext.Command != null);

            IModelFlattener       flattener        = filterContext.Configuration.Services.GetModelFlattener();
            ModelMetadataProvider metadataProvider = filterContext.Configuration.Services.GetModelMetadataProvider();
            ModelDictionary       parameters       = flattener.Flatten(filterContext.Command, filterContext.Command.GetType(), metadataProvider, string.Empty);
            IEnumerable <string>  keys             = SplitVaryByParam(this.VaryByParams);

            keys = (keys ?? parameters.Keys).OrderBy(key => key, StringComparer.Ordinal);

            return(CreateUniqueId(keys.Concat(keys.Select(key => parameters.ContainsKey(key) ? parameters[key] : null))));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks if a given Sitecore template has a corresponding interface. This method does NOT check any base templates this template may have for synchronization.
        /// </summary>
        public TemplateComparisonResult IsTemplateSynchronized(TemplateItem template)
        {
            var signature = _signatureProvider.GenerateTemplateSignature(template);
            ModelTemplateReference reference;

            if (ModelDictionary.TryGetValue(template.ID.ToString(), out reference))
            {
                return(new TemplateComparisonResult(
                           template.ID.ToString(),
                           GetTemplateName(template),
                           GetModelName(reference),
                           signature,
                           reference.Metadata.VersionSignature));
            }

            return(new TemplateComparisonResult(template.ID.ToString(), GetTemplateName(template), null, signature, null));
        }
Ejemplo n.º 12
0
 public void SaveDictionary(ModelDictionary Dict)
 {
     if (Dict.Id == 0)
     {
         context.DictionaryList.Add(Dict);
     }
     else
     {
         ModelDictionary dbEntry = context.DictionaryList.Find(Dict.Id);
         if (dbEntry != null)
         {
             dbEntry.Type  = Dict.Type;
             dbEntry.Value = Dict.Value;
         }
     }
     context.SaveChanges();
 }
Ejemplo n.º 13
0
 public async Task<WebRequest> Build(object service, string action, object model)
 {
     Service = service;
     ServiceType = service.GetType();
     Action = action;
     Model = model ?? new { };
     ModelType = Model.GetType();
     ActionMetadata = actionMetadataProvider.GetMetadataFor(Service, Action, Model);
     ServiceMetadata = serviceMetadataProvider.GetMetadataFor(Service);
     ModelDictionary = new ModelDictionary(Model); 
     
     BuildValues();
     BuildRoute();
     Request = WebRequest.CreateHttp(Route);
     Request.Method = ActionMetadata.HttpMethod;
     BuildHeaders();
     BuildContent();
     return Request;
 }
Ejemplo n.º 14
0
        public ServerVehicle create(string model, Vector3 position, Quaternion orientation)
        {
            uint          vid = findLowestFreeId();
            ServerVehicle veh = new ServerVehicle(vid);

            veh.position    = position;
            veh.orientation = orientation;
            veh.model       = model;
            vehicles.Add(vid, veh);
            Server.instance.InvokeParallelForEachPlayer((player) =>
            {
                var bpf = new BinaryPacketFormatter(Commands.Vehicle_create);
                bpf.Add(veh.id);
                bpf.Add(veh.position);
                bpf.Add(veh.orientation);
                bpf.Add(ModelDictionary.getVehicleByName(veh.model));
                player.connection.write(bpf.getBytes());
            });
            return(veh);
        }
Ejemplo n.º 15
0
 public ModelIndex(ModelDictionary models, ModelIndexLinks links = null)
 {
     Links   = links;
     Models  = models;
     Version = "1.0";
 }
Ejemplo n.º 16
0
        private void onIncomingConnection(IAsyncResult iar)
        {
            Console.WriteLine("Connecting");
            TcpClient client = server.EndAcceptTcpClient(iar);

            server.BeginAcceptTcpClient(onIncomingConnection, null);

            ClientConnection connection = new ClientConnection(client);

            connection.OnConnect += delegate(string nick)
            {
                if (playerpool.Count >= config.getInt("max_players"))
                {
                    Console.WriteLine("Connection from " + nick + " rejected due to Player limit");
                    client.Close();
                    return;
                }
                Console.WriteLine("Connect from " + nick);
                uint         id     = findLowestFreeId();
                ServerPlayer player = new ServerPlayer(id, nick, connection);
                connection.SetPlayer(player);
                InvokeParallelForEachPlayer((p) =>
                {
                    player.connection.write(
                        new BinaryPacketFormatter(Commands.Global_createPlayer, p.id, ModelDictionary.getPedModelByName(p.Model), p.Nick)
                        .getBytes());
                    p.connection.write(
                        new BinaryPacketFormatter(Commands.Global_createPlayer, player.id, ModelDictionary.getPedModelByName("M_Y_SWAT"), nick)
                        .getBytes());
                });
                player.Nick  = nick;
                player.Model = "M_Y_SWAT";
                playerpool.Add(player);
                broadcastVehiclesToPlayer(player);
                broadcastNPCsToPlayer(player);
                //broadcastPlayerName(Player);
                //broadcastPlayerModel(Player);

                api.invokeOnPlayerConnect(client.Client.RemoteEndPoint, player);
                api.invokeOnPlayerSpawn(player);

                var starter = new BinaryPacketFormatter(Commands.Client_resumeBroadcast);
                connection.write(starter.getBytes());
                connection.write(new BinaryPacketFormatter(Commands.Client_enableUDPTunnel, player.udpTunnel.getPort()).getBytes());

                connection.flush();
            };

            connection.startReceiving();
        }
Ejemplo n.º 17
0
 public ServerVehicle createVehicle(uint model, Vector3 position, Quaternion orientation)
 {
     return(server.vehicleController.create(ModelDictionary.getVehicleById(model), position, orientation));
 }
Ejemplo n.º 18
0
        public static int RepoIndex(DirectoryInfo localRepo, FileInfo outputFile, int pageLimit)
        {
            if (localRepo == null)
            {
                localRepo = new DirectoryInfo(Path.GetFullPath("."));
            }

            if (!localRepo.Exists)
            {
                Outputs.WriteError($"Invalid target repository directory: {localRepo.FullName}.");
                return(ReturnCodes.InvalidArguments);
            }

            int      currentPageCount = 0;
            int      pageIdentifier   = 1;
            FileInfo currentPageFile  = outputFile;
            var      modelDictionary  = new ModelDictionary();
            var      currentLinks     = new ModelIndexLinks
            {
                Self = currentPageFile.FullName
            };

            foreach (string file in Directory.EnumerateFiles(localRepo.FullName, "*.json",
                                                             new EnumerationOptions {
                RecurseSubdirectories = true
            }))
            {
                if (file.ToLower().EndsWith(".expanded.json"))
                {
                    continue;
                }

                // TODO: Debug plumbing.
                // Outputs.WriteDebug($"Processing: {file}");

                try
                {
                    var             modelFile  = new FileInfo(file);
                    ModelIndexEntry indexEntry = ParsingUtils.ParseModelFileForIndex(modelFile);
                    modelDictionary.Add(indexEntry.Dtmi, indexEntry);
                    currentPageCount += 1;

                    if (currentPageCount == pageLimit)
                    {
                        var nextPageFile = new FileInfo(
                            Path.Combine(
                                currentPageFile.Directory.FullName,
                                $"index.page.{pageIdentifier}.json"));
                        currentLinks.Next = nextPageFile.FullName;
                        var nextLinks = new ModelIndexLinks
                        {
                            Self = nextPageFile.FullName,
                            Prev = currentLinks.Self
                        };

                        var modelIndex = new ModelIndex(modelDictionary, currentLinks);
                        IndexPageUtils.WritePage(modelIndex);
                        currentPageCount -= pageLimit;
                        modelDictionary   = new ModelDictionary();
                        currentPageFile   = nextPageFile;
                        currentLinks      = nextLinks;
                        pageIdentifier   += 1;
                    }
                }
                catch (Exception e)
                {
                    Outputs.WriteError($"Failure processing model file: {file}, {e.Message}");
                    return(ReturnCodes.ProcessingError);
                }
            }

            if (modelDictionary.Count > 0)
            {
                var modelIndex = new ModelIndex(modelDictionary, currentLinks);
                IndexPageUtils.WritePage(modelIndex);
            }

            return(ReturnCodes.Success);
        }