Example #1
0
        protected override void BeginProcessing()
        {
            IPanel panel = Passive ? Far.Api.Panel2 : Far.Api.Panel;
            if (panel == null)
                return;

            // case: PSF panel
            var ap = panel as AnyPanel;
            if (ap != null)
            {
                IEnumerable<PSObject> items;
                if (All)
                {
                    items = ap.ShownItems;
                }
                else if (Selected)
                {
                    items = ap.SelectedItems;
                }
                else
                {
                    WriteObject(ap.CurrentItem);
                    return;
                }

                foreach (PSObject o in items)
                {
                    if (o != null)
                        WriteObject(o);
                }

                return;
            }

            // get and convert paths to items
            IList<FarFile> filesToProcess;
            if (All)
            {
                filesToProcess = panel.ShownFiles;
            }
            else if (Selected)
            {
                filesToProcess = panel.SelectedFiles;
            }
            else
            {
                WriteObject(InvokeCommand.NewScriptBlock("Get-Item -LiteralPath $args[0] -Force -ErrorAction 0").Invoke(GetCurrentPath(panel, panel)), true);
                return;
            }

            //! Bug [_090116_085532]
            // Count is 0, e.g. for SelectedFiles when nothing is selected and the current item is dots;
            // in this case Get-Item -LiteralPath fails: cannot bind an empty array to LiteralPath.
            if (filesToProcess.Count > 0)
            {
                //! @($args[0])
                using(IEnumerator<string> it = new PathEnumerator(filesToProcess, panel.CurrentDirectory, panel.RealNames, false))
                    WriteObject(InvokeCommand.NewScriptBlock("Get-Item -LiteralPath @($args[0]) -Force -ErrorAction 0").Invoke(it), true);
            }
        }
Example #2
0
        public void AddAllNonStoredPaths()
        {
            // The method adds entity (non-PK) columns from referenced (by FK) tables (recursively).
            int pathCounter = 0;

            ColumnAtt      path      = new ColumnAtt("");
            PathEnumerator primPaths = new PathEnumerator(this, ColumnType.IDENTITY_ENTITY);

            foreach (ColumnAtt p in primPaths)
            {
                if (p.Size < 2)
                {
                    continue;             // All primitive paths are stored in this set. We need at least 2 segments.
                }
                // Check if this path already exists
                path.Segments = p.Segments;
                if (GetGreaterPath(path) != null)
                {
                    continue;                               // Already exists
                }
                string pathName = "__inherited__" + ++pathCounter;

                ColumnAtt newPath = new ColumnAtt(pathName);
                newPath.Segments             = new List <DcColumn>(p.Segments);
                newPath.RelationalColumnName = newPath.Name;          // It actually will be used for relational queries
                newPath.RelationalFkName     = path.RelationalFkName; // Belongs to the same FK
                newPath.RelationalPkName     = null;
                //newPath.Input = this;
                //newPath.Output = p.Path[p.Length - 1].Output;

                AddGreaterPath(newPath);
            }
        }
Example #3
0
        protected override void BeginProcessing()
        {
            IPanel panel1 = Passive ? Far.Api.Panel2 : Far.Api.Panel;
            IPanel panel2 = Mirror ? (Passive ? Far.Api.Panel : Far.Api.Panel2) : panel1;

            // no panel?
            if (panel1 == null || panel2 == null)
            {
                return;
            }

            // get path(s)
            IEnumerator <string> it;

            if (All)
            {
                it = new PathEnumerator(panel1.ShownFiles, panel2.CurrentDirectory, panel1.RealNames, panel1 != panel2);
            }
            else if (Selected)
            {
                it = new PathEnumerator(panel1.SelectedFiles, panel2.CurrentDirectory, panel1.RealNames, panel1 != panel2);
            }
            else
            {
                WriteObject(GetCurrentPath(panel1, panel2));
                return;
            }
            using (it)
                while (it.MoveNext())
                {
                    WriteObject(it.Current);
                }
        }
Example #4
0
        public IFileElement GetElement(string path)
        {
            using (var pathEnumerator = new PathEnumerator(path)) {
                pathEnumerator.Reset();

                if (!pathEnumerator.MoveNext())
                {
                    throw new ArgumentException();
                }

                if (pathEnumerator.Current != this.Disk.Index.ToString())
                {
                    throw new ArgumentException();
                }

                var element = this.Root;
                while (pathEnumerator.MoveNext())
                {
                    if (!(element is IFolder))
                    {
                        throw new ArgumentException();
                    }

                    element = (element as IFolder) [pathEnumerator.Current];
                }

                return(element);
            }
        }
Example #5
0
        protected override void BeginProcessing()
        {
            IPanel panel1 = Passive ? Far.Api.Panel2 : Far.Api.Panel;
            IPanel panel2 = Mirror ? (Passive ? Far.Api.Panel : Far.Api.Panel2) : panel1;

            // no panel?
            if (panel1 == null || panel2 == null)
                return;

            // get path(s)
            IEnumerator<string> it;
            if (All)
            {
                it = new PathEnumerator(panel1.ShownFiles, panel2.CurrentDirectory, panel1.RealNames, panel1 != panel2);
            }
            else if (Selected)
            {
                it = new PathEnumerator(panel1.SelectedFiles, panel2.CurrentDirectory, panel1.RealNames, panel1 != panel2);
            }
            else
            {
                WriteObject(GetCurrentPath(panel1, panel2));
                return;
            }
            using (it)
                while (it.MoveNext())
                    WriteObject(it.Current);
        }
 public object Any(Complete request)
 {
     Node node = Trie.FollowPath (request.Word);
     if (node == null) {
         return new List<string> ();
     }
     PathEnumerator pathEnumerator = new PathEnumerator(node, request.Word);
     return new List<string> (pathEnumerator);
 }
Example #7
0
        public List<ColumnPath> GetOutputPaths(Table output) // Differences between this set and the specified set
        {
            if (output == null) return null;
            var paths = new PathEnumerator(this, output, ColumnType.IDENTITY_ENTITY);
            var ret = new List<ColumnPath>();
            foreach (var p in paths)
            {
                ret.Add(new ColumnPath(p)); // Create a path for each list of dimensions
            }

            return ret;
        }
Example #8
0
        public static string ExtractDiskIndex(string path)
        {
            using (var pathEnumerator = new PathEnumerator(path)) {
                pathEnumerator.Reset();

                if (!pathEnumerator.MoveNext())
                {
                    throw new ArgumentException();
                }

                return(pathEnumerator.Current);
            }
        }
Example #9
0
        public void CheckPaths(string path, List<string> expectedPaths)
        {
            Node node = trie.FollowPath(path);
            PathEnumerator pathEnumerator = new PathEnumerator(node, path);

            List<string> actualPaths = new List<string> ();
            foreach (string p in pathEnumerator) {
                actualPaths.Add (p);
            }
            actualPaths.Sort();

            Assert.AreEqual (expectedPaths, actualPaths);
        }
Example #10
0
        protected void DeleteTablePropagate(DcTable table)
        {
            //
            // Delete tables *generated* from this table (alternatively, leave them but with empty definition)
            //
            var paths = new PathEnumerator(new List <DcTable>(new DcTable[] { table }), new List <DcTable>(), false, ColumnType.GENERATING);

            foreach (var path in paths)
            {
                for (int i = path.Segments.Count - 1; i >= 0; i--)
                {
                    this.DeleteTable(path.Segments[i].Output); // Delete (indirectly) generated table
                }
            }
        }
Example #11
0
        public void IndexThis()
        {
            var pathEnumerator = new PathEnumerator("C:\\", new[]
            {
                @":\\Windows",
                @":\\Program Files \(x86\)\\",
                @":\\Program Files\\",
                @":\\Users\\.*\\\..*",
                @":\\Users\\.*\\AppData\\Local.*\\",
                @":\\Users\\.*\\AppData\\Roaming\\",
                @":\\Users\\.*\\Searches",
                @"IISExpress\\TraceLogFiles",
                @"\\node_modules",
                @"\\wwwroot\\lib"
            });

            Assert.That(() => pathEnumerator.Index(), Throws.Nothing);
            var path = pathEnumerator.NodeEnvelopes.First().ToString();
        }
Example #12
0
        public virtual bool CanAppend(ExprNode expr) // Determine if this expression (it has to be evaluated) can be added into this set as a new instance
        {
            // CanAppend: Check if the whole tuple can be added without errors
            // We do not check existence (it is done before). If tuple exists then no check is done and return false. If null then we check general criterial for adding (presence of all necessary data).

            //Debug.Assert(expr.OutputSet == this, "Wrong use: expression OutputSet must be equal to the set its value is appended/found.");

            //
            // Check that real (non-null) values are available for all identity dimensions
            //
            PathEnumerator primPaths = new PathEnumerator(table, ColumnType.IDENTITY);

            foreach (ColumnPath path in primPaths) // Find all primitive identity paths
            {
                // Try to find at least one node with non-null value on the path
                bool valueFound = false;

                /*
                 * for (Expression node = expr.GetLastNode(path); node != null; node = node.ParentExpression)
                 * {
                 *  if (node.Output != null) { valueFound = true; break; }
                 * }
                 */

                if (!valueFound)
                {
                    return(false);             // This primitive path does not provide a value so the whole instance cannot be created
                }
            }

            //
            // Check that it satisfies the constraints (where expression)
            //

            // TODO: it is a problem because for that purpose we need to have this instance in the set appended.
            // Then we can check and remove but nested removal is difficult because we have to know which nested tuples were found and which were really added.
            // Also, we need to check if nested inserted instances satsify their set constraints - this should be done during insertion and the process broken if any nested instance does not satsify the constraints.

            return(true);
        }
        virtual protected void OnDrawGizmos()
        {
            if (!this.IsCurveInputValid)
            {
                return;
            }

            const float radius = 0.1f;

            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(this.StartPoint.position, radius);
            Gizmos.color = new Color(0.0f, 0.5f, 0.0f, 1.0f);
            Gizmos.DrawWireSphere(this.StartControl.position, radius);
            Gizmos.color = new Color(0.5f, 0.0f, 0.0f, 1.0f);
            Gizmos.DrawWireSphere(this.EndControl.position, radius);
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(this.EndPoint.position, radius);

            PathEnumerator points = this.GetPointsEnumerator();

            if (points.MoveNext())
            {
                Gizmos.color  = Color.yellow;
                Gizmos.matrix = this.Transform.localToWorldMatrix;

                Vector3 previous;
                Vector3 current = (Vector3)points.Current;

                while (points.MoveNext())
                {
                    previous = current;
                    current  = (Vector3)points.Current;

                    Gizmos.DrawLine(previous, current);
                }
            }
        }
Example #14
0
        public void IndexPictures()
        {
            var pathEnumerator = new PathEnumerator(@"\\192.168.178.22\public", new[]
            {
                @":\\Windows",
                @":\\Program Files \(x86\)\\",
                @":\\Program Files\\",
                @":\\Users\\.*\\\..*",
                @":\\Users\\.*\\AppData\\Local.*\\",
                @":\\Users\\.*\\AppData\\Roaming\\",
                @":\\Users\\.*\\Searches",
                @"IISExpress\\TraceLogFiles",
                @"\\node_modules",
                @"\\wwwroot\\lib"
            });

            pathEnumerator.Index();

            var nodeEnvelopes = pathEnumerator.NodeEnvelopes;
            var root          = NodeHierarchyRoot.CreateNodeHierarchy(nodeEnvelopes);
            var envelopes     = JsonStringHelper.CreateString(pathEnumerator.NodeEnvelopes);

            JsonStringHelper.WriteToCompressedFile("envelopes.json.gz", envelopes);
        }
Example #15
0
        public void SchemaTest() // ComColumn. Manually add/remove tables/columns
        {
            DcTable t1 = schema.GetSubTable("Table 1");
            DcTable t2 = schema.GetSubTable("Table 2");

            // Finding by name and check various properties provided by the schema
            Assert.AreEqual(schema.GetPrimitiveType("Decimal").Name, "Decimal");

            Assert.AreEqual(t1.Name, "Table 1");
            Assert.AreEqual(t2.Name, "Table 2");
            Assert.AreEqual(schema.GetSubTable("Table 2"), t2);

            Assert.AreEqual(t1.GetColumn("Column 11").Name, "Column 11");
            Assert.AreEqual(t2.GetColumn("Column 21").Name, "Column 21");

            Assert.AreEqual(t2.GetColumn("Super").IsSuper, true);
            Assert.AreEqual(t2.SuperColumn.Input, t2);
            Assert.AreEqual(t2.SuperColumn.Output, schema.Root);

            // Test path enumerator
            var pathEnum = new PathEnumerator(t2, t1, ColumnType.IDENTITY_ENTITY);

            Assert.AreEqual(1, pathEnum.Count());
        }
Example #16
0
        protected override void BeginProcessing()
        {
            IPanel panel = Passive ? Far.Api.Panel2 : Far.Api.Panel;

            if (panel == null)
            {
                return;
            }

            // case: PSF panel
            var ap = panel as AnyPanel;

            if (ap != null)
            {
                IEnumerable <PSObject> items;
                if (All)
                {
                    items = ap.ShownItems;
                }
                else if (Selected)
                {
                    items = ap.SelectedItems;
                }
                else
                {
                    WriteObject(ap.CurrentItem);
                    return;
                }

                foreach (PSObject o in items)
                {
                    if (o != null)
                    {
                        WriteObject(o);
                    }
                }

                return;
            }

            // get and convert paths to items
            IList <FarFile> filesToProcess;

            if (All)
            {
                filesToProcess = panel.ShownFiles;
            }
            else if (Selected)
            {
                filesToProcess = panel.SelectedFiles;
            }
            else
            {
                WriteObject(InvokeCommand.NewScriptBlock("Get-Item -LiteralPath $args[0] -Force -ErrorAction 0").Invoke(GetCurrentPath(panel, panel)), true);
                return;
            }

            //! Bug [_090116_085532]
            // Count is 0, e.g. for SelectedFiles when nothing is selected and the current item is dots;
            // in this case Get-Item -LiteralPath fails: cannot bind an empty array to LiteralPath.
            if (filesToProcess.Count > 0)
            {
                //! @($args[0])
                using (IEnumerator <string> it = new PathEnumerator(filesToProcess, panel.CurrentDirectory, panel.RealNames, false))
                    WriteObject(InvokeCommand.NewScriptBlock("Get-Item -LiteralPath @($args[0]) -Force -ErrorAction 0").Invoke(it), true);
            }
        }
Example #17
0
        public ArithmeticBox(DcColumn column, bool whereExpression)
        {
            this.okCommand = new DelegateCommand(this.OkCommand_Executed, this.OkCommand_CanExecute);

            IsWhere = whereExpression;

            if (column.Input.Columns.Contains(column))
            {
                IsNew = false;
            }
            else
            {
                IsNew = true;
            }

            Column = column;
            DcTable  sourceTable = column.Input;
            DcSchema schema      = sourceTable.Schema;

            SourceTable = sourceTable;

            ExpressionModel = new ObservableCollection <ExprNode>(); // This contains what we will create/edit
            if (IsWhere)
            {
                if (SourceTable.Definition.WhereExpr != null)
                {
                    ExpressionModel.Add(SourceTable.Definition.WhereExpr);
                }
            }
            else
            {
                if (Column.Definition.FormulaExpr != null)
                {
                    ExpressionModel.Add(Column.Definition.FormulaExpr);
                }
            }

            InitializeComponent();

            newColumnName.Text = Column.Name;

            // Initialize a list of possible operations
            ActionType[] ops;
            if (whereExpression)
            {
                // Other ways: to collapse a grid row: http://stackoverflow.com/questions/2502178/wpf-hide-grid-row
                Controls.RowDefinitions[0].Height = new GridLength(0);
                sourceTableName.IsReadOnly        = false;

                ops = new ActionType[]
                {
                    ActionType.MUL, ActionType.DIV, ActionType.ADD, ActionType.SUB,
                    ActionType.LEQ, ActionType.GEQ, ActionType.GRE, ActionType.LES,
                    ActionType.EQ, ActionType.NEQ,
                    ActionType.AND, ActionType.OR,
                };
            }
            else
            {
                Controls.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Auto);
                sourceTableName.IsReadOnly        = true;

                ops = new ActionType[] { ActionType.MUL, ActionType.DIV, ActionType.ADD, ActionType.SUB };
            }
            operations.ItemsSource = ops;

            // Initialize a list of possible column accesses
            var paths = new PathEnumerator(
                new List <DcTable>(new DcTable[] { SourceTable }),
                new List <DcTable>(new DcTable[] { schema.GetPrimitive("Integer"), schema.GetPrimitive("Double") }),
                false,
                DimensionType.IDENTITY_ENTITY
                );

            SourcePaths = paths.ToList();

            // If we edit an existing column then we do not want to use it in the definition as an operand
            DimPath columnPath = SourcePaths.FirstOrDefault(p => p.FirstSegment == column);

            if (columnPath != null)
            {
                SourcePaths.Remove(columnPath);
            }

            RefreshAll();
        }
Example #18
0
        /*
         *          There are many open sets each showing a DataGrid. We need a global list of all open sets.
         *          When a set is open we need to dynamically create a DataGrid with dynamic list of columns corresponding to its dimensions.
         *          Here we need to dynamically show the currently active grid.
         *
         *          Bidning sources overview: http://msdn.microsoft.com/en-us/library/ms743643.aspx
         *          http://stackoverflow.com/questions/16120010/how-to-dynamically-create-a-datagrid-in-wpf
         *          Dynamic grid: http://paulstovell.com/blog/dynamic-datagrid
         *          Virtualization: http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization
         *
         *          Item source uses an IEnumerator of a set (MoveNext, Current etc.) which returns an object representing the current element. ElementEnemerator/Items<Item or string[]> Set.GetElementEnumerator/GetItemSource.
         *          It is better to use IList because it has an indexer of elements and can be used more efficiently for virtualization: IList<Element/Item/string[]> Set.GetItemList/GetItemSource.
         *          ElementItems : IList<Item/Element/Row/Member> GetElementItems() - produce such a list. Current and indexer return NEW Element
         *          StringItems : IList<string[]> - produce such a list. Current and indexer return NEW string[]
         *
         *          The returned object (Element/Item/string[]) cannot be shared so each time we have to return a new instance from Current or element indexer.
         *
         *          We might return an Item/Element object with offset and set reference. The class implements also a dimension indexer by dynamically accesses the set.
         + we can implement also other methods (say, access on dim names, converters etc.),
         +          Or we could simply return from Current an array of string values to be shown in the grid (which has by definition an indexer).
         +          -+ values are copied and transformed into string which is good if they are anyway copied, + formatting and options can be controled by the set parameters
         */
        public SetGridView(DcTable _set)
        {
            Set = _set;

            Grid       = new DataGrid();
            Grid.Style = Application.Current.MainWindow.FindResource("ReadOnlyGridStyle") as Style;
            Grid.AutoGenerateColumns = false;

            // Initialize paths we want to visualize
            var pathEnum = new PathEnumerator(Set, ColumnType.IDENTITY_ENTITY);

            Paths = new List <ColumnPath>();
            foreach (var path in pathEnum)
            {
                if (path.Segments.Count == 0)
                {
                    continue;                           // ERROR
                }
                if (path.Segments.Exists(x => x.IsSuper))
                {
                    continue;
                }

                if (path.Segments.Count == 1)
                {
                    path.Name = path.FirstSegment.Name;
                }
                else
                {
                    path.Name = path.NamePath;
                }

                Paths.Add(path);
            }

            if (ShowPaths) // Create and confiture grid columns for all paths
            {
                for (int i = 0; i < Paths.Count; i++)
                {
                    ColumnPath path = Paths[i];

                    Binding binding = new Binding(string.Format("[{0}]", i)); // Bind to an indexer

                    DataGridColumn col1 = new DataGridTextColumn()
                    {
                        Header = path.Name, Binding = binding
                    };                                                                                        // No custom cell template
                    DataGridColumn col2 = new CustomBoundColumn()
                    {
                        Header = path.Name, Binding = binding, TemplateName = "CellTemplate"
                    };                                                                                                                      // Custom cell template will be used
                    // Additional column parameters: Width = new DataGridLength(200), FontSize = 12

                    Grid.Columns.Add(col1);
                }
            }
            else // Create and configure grid columns for all direct greater dimensions
            {
                for (int i = 0; i < Set.Columns.Count; i++)
                {
                    DcColumn dim = Set.Columns[i];
                    if (dim.IsSuper)
                    {
                        continue;
                    }

                    Binding binding = new Binding(string.Format("[{0}]", i)); // Bind to an indexer

                    DataGridColumn col1 = new DataGridTextColumn()
                    {
                        Header = dim.Name, Binding = binding
                    };                                                                                       // No custom cell template
                    DataGridColumn col2 = new CustomBoundColumn()
                    {
                        Header = dim.Name, Binding = binding, TemplateName = "CellTemplate"
                    };                                                                                                                     // Custom cell template will be used
                    // Additional column parameters: Width = new DataGridLength(200), FontSize = 12

                    Grid.Columns.Add(col1);
                }
            }

            Grid.ItemsSource = new Elements(this);
        }
Example #19
0
 public bool IsInput(DcTable tab) // IsLess
 {
     var paths = new PathEnumerator(this, tab, ColumnType.IDENTITY_ENTITY);
     return paths.Count() > 0;
 }
        /// <summary>Create direcotry</summary>
        /// <exception cref="FileNotFoundException">If <see cref="Path"/> is not found.</exception>
        /// <exception cref="FileSystemExceptionEntryExists">If file or directory already existed at <see cref="Path"/> and <see cref="OperationPolicy.DstThrow"/> is true.</exception>
        protected override void InnerRun()
        {
            // Cannot get entry
            if (!FileSystem.CanGetEntry())
            {
                CreateBlind(); return;
            }

            try
            {
                // Test that directory already exists
                if (FileSystem.CanGetEntry())
                {
                    try
                    {
                        IEntry e = FileSystem.GetEntry(Path, this.Option.OptionIntersection(session.Option));
                        // Directory already exists
                        if (e != null)
                        {
                            // Throw
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstThrow))
                            {
                                // Nothing is done
                                CanRollback = true;
                                if (e.IsDirectory())
                                {
                                    throw new FileSystemExceptionDirectoryExists(FileSystem, Path);
                                }
                                else if (e.IsFile())
                                {
                                    throw new FileSystemExceptionFileExists(FileSystem, Path);
                                }
                                else
                                {
                                    throw new FileSystemExceptionEntryExists(FileSystem, Path);
                                }
                            }
                            // Skip
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstSkip))
                            {
                                CanRollback = true; SetState(OperationState.Skipped); return;
                            }
                            // Delete prev
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstOverwrite))
                            {
                                // Delete File
                                if (e.IsFile())
                                {
                                    CanRollback = false; FileSystem.Delete(Path, recurse: false, this.Option.OptionIntersection(session.Option));
                                }
                                // Skip
                                else if (e.IsDirectory())
                                {
                                    CanRollback = true; SetState(OperationState.Skipped); return;
                                }
                            }
                        }
                    }
                    catch (NotSupportedException) { }
                }

                // Enumerate paths
                PathEnumerator etor = new PathEnumerator(Path, true);
                while (etor.MoveNext())
                {
                    string path = Path.Substring(0, etor.Current.Length + etor.Current.Start);
                    IEntry e    = FileSystem.GetEntry(path, this.Option.OptionIntersection(session.Option));

                    // Entry exists
                    if (e != null)
                    {
                        continue;
                    }

                    FileSystem.CreateDirectory(path, this.Option.OptionIntersection(session.Option));
                    DirectoriesCreated.Add(path);
                }
            }
            catch (NotSupportedException)
            {
                CreateBlind();
            }
        }
Example #21
0
        /* TODO: Notify after deleting
         * public virtual void Remove()
         * {
         *  if (Output != null) Output.InputColumns.Remove(this);
         *  if (Input != null) Input.Columns.Remove(this);
         *
         *  // Notify that a new child has been removed
         *  if (Input != null) ((Table)Input).NotifyRemove(this);
         *  if (Output != null) ((Table)Output).NotifyRemove(this);
         * }
         */
        protected void DeleteColumnPropagate(DcColumn column)
        {
            DcSchema schema = column.Input.Schema;

            //
            // Delete related columns/tables
            //
            if (column.GetData().IsAppendData) // Delete all tables that are directly or indirectly generated by this column
            {
                DcTable gTab  = column.Output;
                var     paths = new PathEnumerator(new List <DcTable>(new DcTable[] { gTab }), new List <DcTable>(), false, ColumnType.GENERATING);
                foreach (var path in paths)
                {
                    for (int i = path.Segments.Count - 1; i >= 0; i--)
                    {
                        this.DeleteTable(path.Segments[i].Output); // Delete (indirectly) generated table
                    }
                }
                this.DeleteTable(gTab); // Delete (directly) generated table
                // This column will be now deleted as a result of the deletion of the generated table
            }
            else if (column.Input.GetData().DefinitionType == TableDefinitionType.PROJECTION) // It is a extracted table and this column is produced by the mapping (depends on function output tuple)
            {
                //DcColumn projDim = column.Input.InputColumns.Where(d => d.Definition.IsAppendData).ToList()[0];
                //Mapping mapping = projDim.Definition.Mapping;
                //PathMatch match = mapping.GetMatchForTarget(new DimPath(column));
                //mapping.RemoveMatch(match.SourcePath, match.TargetPath);
            }

            //
            // Delete all expression nodes that use the deleted column and all references to this column from other objects
            //
            List <DcTable> tables = schema.AllSubTables;
            var            nodes  = new List <ExprNode>();

            foreach (var tab in tables)
            {
                if (tab.IsPrimitive)
                {
                    continue;
                }

                foreach (var col in tab.Columns)
                {
                    if (col.GetData() == null)
                    {
                        continue;
                    }
                    DcColumnData data = col.GetData();

                    /* REFACTOR: Here essentially we want to manually find all uses and hence have to use dependencies API
                     * if (data.FormulaExpr != null)
                     * {
                     *  nodes = data.FormulaExpr.Find(column);
                     *  foreach (var node in nodes) if (node.Parent != null) node.Parent.RemoveChild(node);
                     * }
                     */
                }

                // Update table definitions by finding the uses of the specified column
                if (tab.GetData().WhereExpr != null)
                {
                    nodes = tab.GetData().WhereExpr.Find(column);
                    foreach (var node in nodes)
                    {
                        if (node.Parent != null)
                        {
                            node.Parent.RemoveChild(node);
                        }
                    }
                }
            }
        }
Example #22
0
        private void FactTables_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var lv        = (ListView)e.Source; // or sender
            var factTable = lv.SelectedItem;    // or SelectedValue

            if (factTable == null)
            {
                return;
            }

            //
            // Initialize grouping paths. Paths from the fact set to the source set
            //
            var grPaths = new PathEnumerator((DcTable)factTable, SourceTable, DimensionType.IDENTITY_ENTITY);

            GroupingPaths = grPaths.ToList <DimPath>();

            // Select some grouping path item
            if (!IsNew && factTable == Column.Definition.FactTable) // If the fact table as defined then grouping path also as defined (i.e., show the current definition)
            {
                foreach (var p in GroupingPaths)                    // Definition can store a different instance of the same path (so either override Equals for DimPath or compare manually)
                {
                    if (!p.SamePath(Column.Definition.GroupPaths[0]))
                    {
                        continue;
                    }
                    GroupingPath = p;
                    break;
                }
            }
            else // Recommend best grouping path: single choise, shortest path etc.
            {
                if (GroupingPaths.Count == 1)
                {
                    GroupingPath = GroupingPaths[0];
                }
            }

            //
            // Initialize measure paths. Paths from the fact set to numeric sets
            //
            DcSchema schema  = ((DcTable)factTable).Schema;
            var      mePaths = new PathEnumerator(
                new List <DcTable>(new DcTable[] { (DcTable)factTable }),
                new List <DcTable>(new DcTable[] { schema.GetPrimitive("Integer"), schema.GetPrimitive("Double") }),
                false,
                DimensionType.IDENTITY_ENTITY
                );

            MeasurePaths = mePaths.ToList <DimPath>();

            // Select some measure path item
            if (!IsNew && factTable == Column.Definition.FactTable)
            {
                foreach (var p in MeasurePaths) // Definition can store a different instance of the same path (so either override Equals for DimPath or compare manually)
                {
                    if (!p.SamePath(Column.Definition.MeasurePaths[0]))
                    {
                        continue;
                    }
                    MeasurePath = p;
                    break;
                }
            }
            else
            {
                if (MeasurePaths.Count == 1)
                {
                    MeasurePath = MeasurePaths[0];
                }
            }

            RefreshAll();
        }
Example #23
0
        public AggregationBox(DcColumn column, DcColumn measureColumn)
        {
            this.okCommand = new DelegateCommand(this.OkCommand_Executed, this.OkCommand_CanExecute);

            InitializeComponent();

            if (column.Input.Columns.Contains(column))
            {
                IsNew = false;
            }
            else
            {
                IsNew = true;
            }

            Column      = column;
            SourceTable = column.Input;

            newColumnName.Text = Column.Name;

            // Initialize all possible fact tables (lesser tables)
            FactTables = MappingModel.GetPossibleLesserSets(SourceTable);
            if (!IsNew)
            {
                FactTable = Column.Definition.FactTable;
            }
            else
            {
                if (FactTables.Count == 1)
                {
                    FactTable = FactTables[0];
                }
            }
            // By setting a fact table here we trigger item selection event where two controls will be filled: grouping paths and measure paths.

            // Use additional parameter for selecting desired measure
            if (IsNew && measureColumn != null)
            {
                // Find at least one fact table that has a measure path to this measure column
                foreach (DcTable table in FactTables)
                {
                    var pathEnum = new PathEnumerator(
                        table,
                        measureColumn.Output,
                        DimensionType.IDENTITY_ENTITY
                        );

                    var paths = pathEnum.ToList();
                    if (paths.Count() == 0)
                    {
                        continue;
                    }

                    FactTable   = table; // Here the list of measure paths has to be filled automatically
                    MeasurePath = paths[0];
                }
            }

            // Initialize aggregation functions
            AggregationFunctions = new List <string>(new string[] { "COUNT", "SUM", "MUL" });
            if (!IsNew)
            {
                AggregationFunction = Column.Definition.Updater;
            }
            else
            {
                AggregationFunction = "SUM";
            }

            RefreshAll();
        }
Example #24
0
            public Impl(Mode mode, TModel model, int maxBots)
            {
                this.mode    = mode;
                this.model   = model;
                this.maxBots = maxBots;
                state        = new TState(this.model);

                bots = new List <Bot>
                {
                    new Bot
                    {
                        Id    = 1,
                        Coord = new TCoord(0, 0, 0),
                        Seeds = new List <int>()
                    }
                };
                for (var i = 2; i <= 40; ++i)
                {
                    bots[0].Seeds.Add(i);
                }

                addedPositions     = new HashSet <TCoord>();
                availablePositions = new HashSet <TCoord>();
                botPositions       = new Dictionary <TCoord, Bot>();

                interferedCells = new HashSet <TCoord>();

                PathEnumerator = new PathEnumerator(model, state, depth_, interferedCells);

                switch (mode)
                {
                case Mode.Assembly:
                    CalcAssemblyDepth();

                    for (var x = 0; x < model.R; ++x)
                    {
                        for (var z = 0; z < model.R; ++z)
                        {
                            if (model[x, 0, z] == 1)
                            {
                                addedPositions.Add(new TCoord(x, 0, z));
                                availablePositions.Add(new TCoord(x, 0, z));
                            }
                        }
                    }

                    break;

                case Mode.Dissassembly:
                    // hack-hack
                    CalcAssemblyDepth();
                    for (var x = 0; x < model.R; ++x)
                    {
                        for (var y = 0; y < model.R; ++y)
                        {
                            for (var z = 0; z < model.R; ++z)
                            {
                                state.Matrix[x, y, z] = model[x, y, z];
                                if (model[x, y, z] == 1 && depth_[x, y, z] == 2)
                                {
                                    addedPositions.Add(new TCoord(x, y, z));
                                    availablePositions.Add(new TCoord(x, y, z));
                                }
                            }
                        }
                    }

                    CalcDisassemblyDepth();

                    break;
                }
            }