Esempio n. 1
0
        public AbstractContext GetContext(string userId, BotType type)
        {
            // If userId is null, set a uniq id for each uatterance.
            if (string.IsNullOrWhiteSpace(userId))
            {
                userId = DateTime.Now.Ticks.ToString();
            }

            if (contextMap.ContainsKey(userId))
            {
                return(contextMap[userId]);
            }
            else
            {
                AbstractContext newContext = AbstractContext.GetAbstractContext(userId, type);
                contextMap.Add(userId, newContext);

                return(newContext);
            }
        }
Esempio n. 2
0
        public AbstractValue AbstractCall(AbstractContext context, IList <AbstractValue> args)
        {
            AbstractValue[] callArgs = new AbstractValue[_argBuilders.Count];
            for (int i = 0; i < _argBuilders.Count; i++)
            {
                callArgs[i] = _argBuilders[i].AbstractBuild(context, args);
            }

            Expression[] argExprs = new Expression[callArgs.Length];
            for (int i = 0; i < callArgs.Length; i++)
            {
                Expression expr = callArgs[i].Expression;
                if (expr == null)
                {
                    argExprs = null;
                    break;
                }
                else
                {
                    argExprs[i] = expr;
                }
            }

            Expression callExpr = null;

            if (argExprs != null)
            {
                MethodInfo mi = Method as MethodInfo;
                if (mi != null)
                {
                    Expression instance = mi.IsStatic ? null : _instanceBuilder.AbstractBuild(context, args).Expression;
                    callExpr = Ast.SimpleCallHelper(instance, mi, argExprs);
                }
                else
                {
                    callExpr = Ast.SimpleNewHelper((ConstructorInfo)Method, argExprs);
                }
            }

            return(AbstractValue.LimitType(this.ReturnType, callExpr));
        }
Esempio n. 3
0
        public static void ApplyContextualMigrationsFor <TEntity>(this AbstractContext context,
                                                                  IUnitOfWork unitOfWork,
                                                                  IFileSeedingService <TEntity> seedingService,
                                                                  string fileName)
            where TEntity : class, IDomainEntity
        {
            var fileEntities = seedingService.ReadFrom(fileName).ToList();
            var dbSet        = context.Set <TEntity>();

            var existingEntitiesOnDatabase = dbSet
                                             .Where(x => fileEntities
                                                    .Select(y => y.Id)
                                                    .Contains(x.Id))
                                             .ToList();

            var toBeAddedEntities = fileEntities
                                    .Where(x => !existingEntitiesOnDatabase
                                           .Select(y => y.Id)
                                           .Contains(x.Id));

            unitOfWork.Begin("SEEDED");
            unitOfWork.GetRepository <TEntity>().InsertRangeAsync(toBeAddedEntities).GetAwaiter().GetResult();
            unitOfWork.Commit();
        }
Esempio n. 4
0
    private void BindObject(object obj, TreeNode root)
    {
        int index = 0;

        if (obj is DataRow)
        {
            // DataRow source, bind column names
            DataRow dr = (DataRow)obj;

            // Create tree structure
            foreach (DataColumn col in dr.Table.Columns)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = dr[col.ColumnName];
                AppendChild(root, col.ColumnName, childObj, false);
            }
        }
        else if (obj is DataRowView)
        {
            // DataRowView source, bind column names
            DataRowView dr = (DataRowView)obj;

            // Create tree structure
            foreach (DataColumn col in dr.DataView.Table.Columns)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = dr[col.ColumnName];
                AppendChild(root, col.ColumnName, childObj, false);
            }
        }
        else if (obj is AbstractContext)
        {
            AbstractContext context = (AbstractContext)obj;

            // Create tree structure
            foreach (string col in context.Properties)
            {
                // Stop on max nodes
                if (index >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the property
                object childObj = context.GetProperty(col);
                AppendChild(root, col, childObj, false);
            }
        }
        else if (obj is IHierarchicalObject)
        {
            // Data container source
            IHierarchicalObject hc = (IHierarchicalObject)obj;

            // Create tree structure
            foreach (string col in hc.Properties)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the property
                object childObj = null;
                try
                {
                    hc.TryGetProperty(col, out childObj);
                }
                catch
                {
                }

                AppendChild(root, col, childObj, false);
            }
        }
        else if (obj is IDataContainer)
        {
            // Data container source
            IDataContainer dc = (IDataContainer)obj;

            // Create tree structure
            foreach (string col in dc.ColumnNames)
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the column
                object childObj = null;
                dc.TryGetValue(col, out childObj);

                AppendChild(root, col, childObj, false);
            }
        }

        // Enumerable objects
        if ((obj is IEnumerable) && !(obj is string))
        {
            IEnumerable collection = (IEnumerable)obj;
            IEnumerator enumerator = null;

            bool indexByName = false;

            INamedEnumerable namedCol = null;
            if (obj is INamedEnumerable)
            {
                // Collection with name enumerator
                namedCol = (INamedEnumerable)collection;
                if (namedCol.ItemsHaveNames)
                {
                    enumerator  = namedCol.GetNamedEnumerator();
                    indexByName = true;
                }
            }

            if (!indexByName)
            {
                // Standard collection
                enumerator = collection.GetEnumerator();
            }

            int i = 0;

            while (enumerator.MoveNext())
            {
                // Stop on max nodes
                if (index++ >= MacroResolver.MaxMacroNodes)
                {
                    AppendMore(root);
                    break;
                }

                // Add the item
                object item = SqlHelperClass.EncapsulateObject(enumerator.Current);
                if (indexByName)
                {
                    // Convert the name with dot to indexer
                    string name = namedCol.GetObjectName(item);
                    if (!ValidationHelper.IsIdentifier(name))
                    {
                        name = "[\"" + name + "\"]";
                    }

                    AppendChild(root, name, item, false);
                }
                else
                {
                    // Indexed item
                    AppendChild(root, i.ToString(), item, true);
                }

                i++;
            }
        }
    }
Esempio n. 5
0
        public static AbstractContext GetDefaultContext()
        {
            AbstractContext context = new AbstractContext();

            context.InstanceName      = "AbstractUI.DefaultUI.Context";
            context.Left              = new ComponentMeasurement(0, ComponentMeasurementUnit.Percentage);
            context.Top               = new ComponentMeasurement(0, ComponentMeasurementUnit.Percentage);
            context.Height            = new ComponentMeasurement(100, ComponentMeasurementUnit.Percentage);
            context.Width             = new ComponentMeasurement(100, ComponentMeasurementUnit.Percentage);
            context.PositioningMethod = ComponentPositioning.Absolute;

            #region Top panel components

            AbstractPanel panelTop = new AbstractPanel();
            panelTop.InstanceName    = "AbstractUI.DefaultUI.TopPanel";
            panelTop.Left            = new ComponentMeasurement(0, ComponentMeasurementUnit.Pixel);
            panelTop.Top             = new ComponentMeasurement(0, ComponentMeasurementUnit.Pixel);
            panelTop.Height          = new ComponentMeasurement(10, ComponentMeasurementUnit.Percentage);
            panelTop.Width           = new ComponentMeasurement(100, ComponentMeasurementUnit.Percentage);
            panelTop.ParentComponent = context;
            context.Controls.Add(panelTop);

            #endregion

            #region Left panel components

            AbstractPanel panelLeft = new AbstractPanel();
            panelLeft.InstanceName    = "AbstractUI.DefaultUI.LeftPanel";
            panelLeft.Left            = new ComponentMeasurement(0, ComponentMeasurementUnit.Pixel);
            panelLeft.Top             = new ComponentMeasurement(10, ComponentMeasurementUnit.Percentage);
            panelLeft.Height          = new ComponentMeasurement(90, ComponentMeasurementUnit.Percentage);
            panelLeft.Width           = new ComponentMeasurement(25, ComponentMeasurementUnit.Percentage);
            panelLeft.ParentComponent = context;
            context.Controls.Add(panelLeft);

            AbstractTreeView navigationTree = new AbstractTreeView();
            navigationTree.InstanceName    = "AbstractUI.DefaultUI.NafigationTree";         //;)
            navigationTree.Left            = new ComponentMeasurement(0, ComponentMeasurementUnit.Percentage);
            navigationTree.Top             = new ComponentMeasurement(0, ComponentMeasurementUnit.Percentage);
            navigationTree.Height          = new ComponentMeasurement(100, ComponentMeasurementUnit.Percentage);
            navigationTree.Width           = new ComponentMeasurement(100, ComponentMeasurementUnit.Percentage);
            navigationTree.ParentComponent = panelLeft;
            panelLeft.Controls.Add(navigationTree);

            #endregion

            #region Content panel components

            AbstractPanel panelContent = new AbstractPanel();
            panelContent.InstanceName    = "AbstractUI.DefaultUI.ContentPanel";
            panelContent.Left            = new ComponentMeasurement(25, ComponentMeasurementUnit.Percentage);
            panelContent.Top             = new ComponentMeasurement(10, ComponentMeasurementUnit.Percentage);
            panelContent.Height          = new ComponentMeasurement(90, ComponentMeasurementUnit.Percentage);
            panelContent.Width           = new ComponentMeasurement(75, ComponentMeasurementUnit.Percentage);
            panelContent.ParentComponent = context;
            context.Controls.Add(panelContent);

            #endregion

            //this is very-very important
            #region Providers

            StaticContentTreeNodeProvider staticContentProvider = new StaticContentTreeNodeProvider();
            staticContentProvider.InstanceName    = "AbstractUI.DefaultUI.NavigationTree.StaticContent";
            staticContentProvider.ParentComponent = context;
            navigationTree.NavigationListeners.Add(staticContentProvider);

            #endregion

            return(context);
        }
Esempio n. 6
0
 public Repository(AbstractContext context)
 {
     Context = context;
 }
Esempio n. 7
0
    /// <summary>
    /// Fills given list with properties of given object.
    /// </summary>
    /// <param name="properties">List to fill</param>
    /// <param name="dataProperties">List of data properties</param>
    /// <param name="obj">Object the properties of which should be added to the list</param>
    private static void FillObjectProperties(List <string> properties, List <string> dataProperties, object obj)
    {
        if (obj != null)
        {
            if (obj is DataRow)
            {
                // DataRow source, bind column names
                DataRow dr = (DataRow)obj;
                foreach (DataColumn col in dr.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is DataRowView)
            {
                // DataRowView source, bind column names
                DataRowView dr = (DataRowView)obj;
                foreach (DataColumn col in dr.DataView.Table.Columns)
                {
                    properties.Add(col.ColumnName);
                }
            }
            else if (obj is AbstractContext)
            {
                AbstractContext context = (AbstractContext)obj;
                properties.AddRange(context.Properties);
            }
            else if (obj is IHierarchicalObject)
            {
                // Data container source
                IHierarchicalObject hc = (IHierarchicalObject)obj;
                properties.AddRange(hc.Properties);
            }
            else if (obj is IDataContainer)
            {
                // Data container source
                IDataContainer dc = (IDataContainer)obj;
                properties.AddRange(dc.ColumnNames);
            }

            // Named enumerable objects
            if (obj is INamedEnumerable)
            {
                INamedEnumerable namedCol = (INamedEnumerable)obj;
                if (namedCol.ItemsHaveNames)
                {
                    IEnumerator enumerator = namedCol.GetNamedEnumerator();
                    while (enumerator.MoveNext())
                    {
                        // Named item
                        string name = namedCol.GetObjectName(enumerator.Current);
                        if (ValidationHelper.IsIdentifier(name))
                        {
                            dataProperties.Add(name);
                        }
                        else
                        {
                            dataProperties.Add("[\"" + name + "\"]");
                        }
                    }
                }
            }

            // Special case for TreeNode and PageInfo - append ediable parts
            if ((obj is CMS.TreeEngine.TreeNode) || (obj is PageInfo))
            {
                EditableItems eItems = null;

                if (obj is CMS.TreeEngine.TreeNode)
                {
                    // TreeNode editable fields
                    CMS.TreeEngine.TreeNode node = (CMS.TreeEngine.TreeNode)obj;
                    eItems = node.DocumentContent;
                }
                else
                {
                    PageInfo pi = (PageInfo)obj;
                    eItems = pi.EditableItems;
                }

                // Editable regions
                foreach (string item in eItems.EditableRegions.Keys)
                {
                    properties.Add(item);
                }

                // Editable webparts
                foreach (string item in eItems.EditableWebParts.Keys)
                {
                    properties.Add(item);
                }
            }
        }
    }
Esempio n. 8
0
        public override AbstractValue AbstractBuild(AbstractContext context, IList <AbstractValue> parameters)
        {
            AbstractValue value = parameters[_index];

            return(context.Binder.AbstractExecute(ConvertToAction.Make(_parameterType), new AbstractValue[] { value }));
        }
 public UnitOfWork(AbstractContext context)
 {
     this.Context = context;
 }
Esempio n. 10
0
 public void SetContext(string userId, AbstractContext context)
 {
     contextMap[userId] = context;
 }
Esempio n. 11
0
 public virtual AbstractValue AbstractBuild(AbstractContext context, IList <AbstractValue> parameters)
 {
     throw new NotImplementedException();
 }