Example #1
0
        private void OnReadOnlyChildListChanged()
        {
            CleanTemplateContextByValue(Constants.ReadOnlyChildList);

            foreach (var entity in ReadOnlyChildListEntities)
            {
                string key = String.Format(Constants.ReadOnlyListFormat, entity.EntityKeyName);

                if (ContextData.Get(key) != null)
                {
                    ContextData.Remove(key);
                }

                ReadOnlyListEntities.Remove(entity);

                ContextData.Add(key, Constants.ReadOnlyChildList);

                if (State == TemplateState.RestoringProperties)
                {
                    continue;
                }

                AddChildEntity(entity, true, true);
            }
        }
Example #2
0
        public void CanFeedGenericProviderWithDictionaryConstructor()
        {
            var dic = new Dictionary<object, object>();
            var data = new ContextData(new GenericContextProvider(() => dic));

            data.Set("test", 123);
            data.Get("test").Should().Be(123);

            data.Set("test2", 124);
            data.Get("test2").Should().Be(124);

            dic.Count.Should().Be(1);

            dic = new Dictionary<object, object>();
            data.Get("test").Should().Be(null);
        }
Example #3
0
        public bool IsReadOnly(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", association.ForeignEntity.EntityKeyName, suffix);

            if (ContextData.Get(key) == null)
            {
                return(false);
            }

            var value = ContextData[key];

            switch (value)
            {
            case Constants.ReadOnlyChild:
            case Constants.ReadOnlyRoot:
            case Constants.ReadOnlyChildList:
            case Constants.ReadOnlyList:
                return(true);
            }

            return(false);
        }
Example #4
0
        private void OnEditableChildListChanged()
        {
            CleanTemplateContextByValue(Constants.EditableChildList);

            foreach (var entity in EditableChildListEntities)
            {
                string key = String.Format(Constants.ListFormat, entity.EntityKeyName);

                if (ContextData.Get(key) != null)
                {
                    ContextData.Remove(key);
                }

                DynamicRootListEntities.Remove(entity);
                EditableRootListEntities.Remove(entity);
                DynamicListBaseEntities.Remove(entity);

                ContextData.Add(key, Constants.EditableChildList);

                if (State == TemplateState.RestoringProperties)
                {
                    continue;
                }

                AddChildEntity(entity, false, true);
            }
        }
Example #5
0
        private IClientSession GetSessionInternal(String sessionId, bool createIfNotExists)
        {
            sessionId = sessionId.HasValue() ? sessionId
                : (HttpContext.Current == null ? (string)ContextData.Get(CLIENT_SESSION_KEY)
                    : HttpContext.Current.Session[CLIENT_SESSION_KEY].AsString());

            if (sessionId.IsEmpty())
            {
                sessionId = Guid.NewGuid().ToString("N").ToLower();
            }

            IClientSession result = null;

            if (!_sessions.TryGetValue(sessionId, out result) && createIfNotExists)
            {
                lock (__lockObject)
                {
                    result = new ClientSession(sessionId, this);
                    if (HttpContext.Current == null)
                    {
                        ContextData.Set(CLIENT_SESSION_KEY, sessionId);
                    }
                    else
                    {
                        HttpContext.Current.Session[CLIENT_SESSION_KEY] = sessionId;
                    }
                    _sessions[sessionId] = result;
                }
            }
            else if (!result.isAlive)
            {
                return(GetSessionInternal(Guid.NewGuid().ToString("N").ToLower(), true));
            }
            return(result);
        }
        /// <summary>
        /// This is used to detect to see if the context data contains a class. It is used in the case where we want to see if a read-write class exists before a read only..
        /// </summary>
        /// <param name="association"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public bool BusinessObjectExists(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", association.Entity.EntityKeyName, suffix);

            return(ContextData.Get(key) != null);
        }
        /// <summary>
        /// This is used to detect to see if the context data contains a class. It is used in the case where we want to see if a read-write class exists before a read only..
        /// </summary>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public bool BusinessObjectExists(string suffix)
        {
            if (Entity == null)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", Entity.EntityKeyName, suffix);

            return(ContextData.Get(key) != null);
        }
Example #8
0
        private void OnNameListChanged()
        {
            CleanTemplateContextByValue(Constants.NameValueList);

            foreach (var entity in NameValueListEntities)
            {
                string key = String.Format(Constants.ListFormat, entity.Name);

                if (ContextData.Get(key) != null)
                {
                    ContextData.Remove(key);
                }

                ReadOnlyListEntities.Remove(entity);

                ContextData.Add(key, Constants.NameValueList);
            }
        }
        public bool IsSwitchableObject(string suffix)
        {
            string key = String.Format("{0}{1}", Entity.EntityKeyName, suffix);

            if (ContextData.Get(key) == null)
            {
                return(false);
            }

            var value = ContextData[key];

            switch (value)
            {
            case Constants.SwitchableObject:
                return(true);
            }

            return(false);
        }
Example #10
0
        private void OnReadOnlyRootChanged()
        {
            CleanTemplateContextByValue(Constants.ReadOnlyRoot);

            foreach (var entity in ReadOnlyRootEntities)
            {
                string key = String.Format(Constants.ReadOnlyFormat, entity.EntityKeyName);

                if (ContextData.Get(key) != null)
                {
                    ContextData.Remove(key);
                }

                ReadOnlyChildEntities.Remove(entity);

                ContextData.Add(key, Constants.ReadOnlyRoot);

                if (State == TemplateState.RestoringProperties)
                {
                    continue;
                }

                //Many-To-One
                foreach (var childEntity in GetChildAssociations(entity.Associations))
                {
                    foreach (AssociationProperty property in childEntity.Properties)
                    {
                        AddChildEntity(property.Association.Entity, true, true);
                    }
                }

                //One-To-Many & Many-To-Many
                foreach (var childList in GetChildListAssociations(entity.Associations))
                {
                    foreach (AssociationProperty property in childList.Properties)
                    {
                        AddChildList(property.Association.Entity, true, true);
                    }
                }
            }
        }
Example #11
0
        private void OnSwitchableObjectChanged()
        {
            CleanTemplateContextByValue(Constants.SwitchableObject);

            foreach (var entity in SwitchableObjectEntities)
            {
                if (ContextData.Get(entity.EntityKeyName) != null)
                {
                    ContextData.Remove(entity.EntityKeyName);
                }

                DynamicRootEntities.Remove(entity);
                EditableChildEntities.Remove(entity);
                EditableRootEntities.Remove(entity);

                ContextData.Add(entity.EntityKeyName, Constants.SwitchableObject);

                if (State == TemplateState.RestoringProperties)
                {
                    continue;
                }

                //Many-To-One
                foreach (var childEntity in GetChildAssociations(entity.Associations))
                {
                    foreach (AssociationProperty property in childEntity.Properties)
                    {
                        AddChildEntity(property.Association.Entity, false, true);
                    }
                }

                //One-To-Many & Many-To-Many
                foreach (var childList in GetChildListAssociations(entity.Associations))
                {
                    foreach (AssociationProperty property in childList.Properties)
                    {
                        AddChildList(property.Association.Entity, false, true);
                    }
                }
            }
        }
        public bool IsChildBusinessObject(string suffix)
        {
            string key = String.Format("{0}{1}", Entity.EntityKeyName, suffix);

            if (ContextData.Get(key) == null)
            {
                return(false);
            }

            var value = ContextData[key];

            switch (value)
            {
            case Constants.EditableChild:
            case Constants.ReadOnlyChild:
            case Constants.EditableChildList:
            case Constants.ReadOnlyChildList:
                return(true);
            }

            return(false);
        }
        public bool IsNameValueListBusinessObject(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", association.ForeignEntity.EntityKeyName, suffix);

            if (ContextData.Get(key) == null)
            {
                return(false);
            }

            var value = ContextData[key];

            switch (value)
            {
            case Constants.NameValueList:
                return(true);
            }

            return(false);
        }
Example #14
0
    public PhraseSequence InsertContext(ContextData context)
    {
        if (context == null) {
            return this;
        }

        var p = new PhraseSequence();
        p.Translation = Translation;
        foreach (var w in PhraseElements) {
            if (w.ElementType == PhraseSequenceElementType.ContextSlot) {
                var cd = context.Get(w.Text);
                if (cd != null) {
                    PhraseSequence replace = cd.Data;
                    foreach (var e in replace.PhraseElements) {
                        p.Add(e);
                    }
                    p.Translation = p.Translation.Replace("[" + w.Text + "]", HelperGetTranslation(replace));
                } else {
                    p.Add(w);
                }
            } else {
                p.Add(w);
            }
        }
        return p;
    }
Example #15
0
 public List<PhraseSequence> GetContextWords(ContextData context)
 {
     var contextWords = new List<PhraseSequence>();
     foreach (var w in PhraseElements) {
         if (w.ElementType == PhraseSequenceElementType.ContextSlot) {
             var cd = context.Get(w.Text);
             if (cd != null) {
                 contextWords.Add(cd.Data);
             }
         }
     }
     return contextWords;
 }
Example #16
0
        public void DifferentContextDataWithSameProviderWillReturnSameValues()
        {
            var provider = new DictionaryContextProvider();
            var data1 = new ContextData(provider);
            var data2 = new ContextData(provider);

            data1.Set("abc", 123);

            data1.Get<int>("abc").Should().Be(123);
            data2.Get<int>("abc").Should().Be(123);
        }
Example #17
0
        public void DifferentContextDataWithDifferentProvidersWillReturnDifferentValues()
        {
            var data1 = new ContextData(new DictionaryContextProvider());
            var data2 = new ContextData(new DictionaryContextProvider());

            data1.Set("abc", 123);

            data1.Get<int>("abc").Should().Be(123);
            data2.Get<int>("abc").Should().Be(0);
            data2.Get("abc").Should().Be(null);
        }
    public string GetText(JapaneseScriptType scriptType, ContextData context)
    {
        switch (ElementType) {
            case PhraseSequenceElementType.Text:
                //Debug.Log("IS TEXT");
                return Text;
            case PhraseSequenceElementType.FixedWord:
                var e = DictionaryData.Instance.GetEntryFromID(WordID);
                return ConjugationTool.GetForm(e, FormID, scriptType);
            case PhraseSequenceElementType.TaggedSlot:
                if (Tags.Count > 0) {
                    var s = "";
                    foreach (var t in Tags) {
                        s += "<" + t + "> ";
                    }
                    return s;
                } else {
                    return "<>";
                }
            case PhraseSequenceElementType.ContextSlot:
                //Debug.Log(Text);
                return context.Get(Text).Data.GetText(scriptType);

            case PhraseSequenceElementType.Wildcard:
                return "*";
        }
        return Text;
    }