Ejemplo n.º 1
0
        public IActionResult Delete(Guid id, [FromBody] Deletion deletion)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = repository.Find(id);

            if (timecard == null)
            {
                return(NotFound());
            }

            if (timecard.CanBeDeleted() == false)
            {
                return(StatusCode(409, new InvalidStateError()
                {
                }));
            }

            var transition = new Transition(deletion, TimecardStatus.Deleted);

            logger.LogInformation($"Deleting timesheet {transition}");

            timecard.Transitions.Add(transition);

            repository.Delete(id);

            return(Ok(transition));
        }
Ejemplo n.º 2
0
        public void LoadContent(Console console)
        {
            Console = console;

            Console.FontChanged += (s, e) =>
            {
                CalculateInputPrefixWidth();
                _inputBuffer.Font = console.Font;
                SetDirty();
            };
            _inputBuffer.Font          = console.Font;
            Console.WindowAreaChanged += (s, e) => SetDirty();
            Caret.Moved += (s, e) => SetDirty();

            CalculateInputPrefixWidth();

            Caret.LoadContent(this);
            RepeatingInput.LoadContent(this);
            InputHistory.LoadContent(this);
            Autocompletion.LoadContent(this);
            CopyPasting.LoadContent(this);
            Movement.LoadContent(this);
            Tabbing.LoadContent(this);
            Deletion.LoadContent(this);
            CommandExecution.LoadContent(this);
            CaseSenitivity.LoadContent(this);
            Selection.LoadContent(this);

            _loaded = true;
        }
        public IActionResult DeleteTimecard(string id, Deletion deletion)
        {
            Timecard timecard = Database.Find(id);

            if (timecard == null)
            {
                return(NotFound());
            }

            if (timecard.CanBeDeleted() == false)
            {
                return(StatusCode(409, new InvalidStateError()
                {
                }));
            }

            // This verifies that timecard deleter is timecard resource
            if (deletion.Resource != timecard.Resource)
            {
                return(StatusCode(409, new ResourceDoesNotManageError()));
            }

            Database.Delete(timecard);
            return(Ok());
        }
Ejemplo n.º 4
0
 public void DeletionMutationTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 15, 16, 17, 18, 19, 20 });
     Deletion<int> mutation = new Deletion<int>(3, 5);
     IChromosome<int> res = mutation.Mutate(a);
     IChromosome<int> exp = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 18, 19, 20 });
     Assert.AreEqual(exp, res);
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            List <String> CommandIntroduction = new List <string> {
                "0.Quit",
                "1.Add a to do",
                "2.Display current to-do list",
                "3.delte a to do list"
            };

            foreach (string i in CommandIntroduction)
            {
                Console.WriteLine(i);
            }
            int command;

            do
            {
                command = Convert.ToInt32((Console.ReadLine()));
                switch (command)
                {
                case 0:
                    Console.WriteLine("Goodbye");
                    break;

                case 1:
                    Console.WriteLine("Give the title");
                    string title = Console.ReadLine();
                    Console.WriteLine("Give the description");
                    string description = Console.ReadLine();
                    Console.WriteLine("Give the due date in dd/mm/yyyy");
                    DateTime due_date  = DateTime.ParseExact(Console.ReadLine(), "dd/mm/yyyy", CultureInfo.InvariantCulture);
                    Todo     new_event = new Todo(title, description, due_date);
                    Console.WriteLine("\n");
                    break;

                case 2:
                    Display.DisplayTodo();
                    Console.WriteLine("\n");
                    break;

                case 3:
                    Console.WriteLine("Give the string of title or a number as an id");
                    string input = Console.ReadLine();
                    int    id;
                    if (int.TryParse(input, out id))
                    {
                        Deletion.deleteTodo(id);
                    }
                    else
                    {
                        Deletion.deleteTodo(input);
                    }
                    Console.WriteLine("\n");
                    break;
                }
            }while(command != 0);
        }
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.Write($"case {SpecificEvent.VariableType.FullNameInCode()} {SpecificEvent.Usage}:");

            writer.IndentionLevel++;


            if (AlwaysDeletes)
            {
                writer.Write("return null;");
            }

            CreationFrame?.GenerateCode(method, writer);

            if (Apply != null)
            {
                if (CreationFrame == null)
                {
                    var defaultConstructor = AggregateType.GetConstructor(
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes,
                        null);

                    if (defaultConstructor?.IsPublic == true)
                    {
                        writer.Write($"{Aggregate.Usage} ??= new {AggregateType.FullNameInCode()}();");
                    }
                    else if (defaultConstructor?.IsPublic == false)
                    {
                        writer.Write($"{Aggregate.Usage} ??= AggregateBuilder();");
                    }
                    else
                    {
                        var errorMessage =
                            $"Projection for {AggregateType.FullName} should either have the Create Method or Constructor for event of type {SpecificEvent.VariableType.FullNameInCode()}, or {AggregateType.FullName} should have a Default Constructor.";

                        writer.Write(
                            $"if({Aggregate.Usage} == default) throw new ArgumentException(\"{errorMessage}\");");
                    }
                }

                Apply.GenerateCode(method, writer);
            }

            if (Deletion != null)
            {
                writer.Write($"if ({Aggregate.Usage} == null) return null;");

                Deletion.GenerateCode(method, writer);
            }

            writer.Write($"return {Aggregate.Usage};");

            writer.IndentionLevel--;

            Next?.GenerateCode(method, writer);
        }
Ejemplo n.º 7
0
        public void DeleteWhere <T>(Expression <Func <T, bool> > expression)
        {
            assertNotDisposed();

            var deletion = new Deletion(StorageFor <T>());

            deletion.ApplyFiltering(this, expression);

            _unitOfWork.Add(deletion);
        }
Ejemplo n.º 8
0
 public void ProcessAction(ConsoleAction action)
 {
     InputHistory.OnAction(action);
     Autocompletion.OnAction(action);
     CopyPasting.OnAction(action);
     Movement.OnAction(action);
     Tabbing.OnAction(action);
     Deletion.OnAction(action);
     CommandExecution.OnAction(action);
     CaseSenitivity.OnAction(action);
 }
        public void DeleteWhere <T>(Expression <Func <T, bool> > expression)
        {
            assertNotDisposed();

            var documentStorage = StorageFor <T>();
            var deletion        = new Deletion(documentStorage, documentStorage.DeleteFragment);

            deletion.ApplyFiltering(this, expression);

            _workTracker.Add(deletion);
        }
Ejemplo n.º 10
0
        public static Mutation CreateDeletedColumnMutation(IEnumerable <FluentMutation> mutation)
        {
            var columnNames = mutation.Select(m => m.Column.ColumnName).ToList();

            var deletion = new Deletion {
                Timestamp = DateTimeOffset.Now.ToTimestamp(),
                Predicate = CreateSlicePredicate(columnNames)
            };

            return(new Mutation {
                Deletion = deletion
            });
        }
 public override void deletebtn_Click(object sender, EventArgs e)
 {
     if (edit == 1)
     {
         DialogResult dr = MessageBox.Show("Are you sure , you want to delete record?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             Deletion d = new Deletion();
             d.delete(StockID, "st_stockdeletes", "@stockid");
             R.ShowStock(DataGridView1, StockIDGV, SprodIDGV, ProductNamepwGV, PQuantityGV, PurchaseRateGV, PSalesRateGV);
         }
     }
 }
Ejemplo n.º 12
0
 public override void BtnDelete_Click(object sender, EventArgs e)
 {
     if (edit == 1)
     {
         DialogResult dr = MessageBox.Show("Are you sure, You want to Delete record?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             Deletion d = new Deletion();
             d.delete(supplierID, "st_deleteSupplier", "@suppID");
             r.showSuppliers(dataGridView1, suppIDGV, companyGV, personGV, Phone1GV, phone2GV, addressGV, ntnGV, statusGV);
         }
     }
 }
Ejemplo n.º 13
0
        public static IEnumerable <Mutation> CreateDeletedColumnMutation(IEnumerable <FluentMutation> mutation)
        {
            foreach (var col in mutation)
            {
                var deletion = new Deletion {
                    Timestamp = col.ColumnTimestamp.ToCassandraTimestamp(),
                    Predicate = CreateSlicePredicate(new[] { col.Column.ColumnName })
                };

                yield return(new Mutation {
                    Deletion = deletion
                });
            }
        }
Ejemplo n.º 14
0
        internal static bool MatchesDeletion(Target target, Deletion deletion)
        {
            if (deletion.Id.Equals(target.Id))
            {
                return(true);
            }

            if (deletion.Document is Target t)
            {
                return(t.Id == target.Id);
            }

            return(false);
        }
Ejemplo n.º 15
0
    void DeleteGameObject(string json)
    {
        Deletion deletion = JsonUtility.FromJson <Deletion>(json);

        Debug.Log("%%%%%%%%%%%%%% DeleteGameObject from Java: " + deletion.id);
        GameObject toDelete = instances[deletion.id];

        // Failing to null these out causes a bug; the Destroy() method is too voracious.
        toDelete.GetComponent <MeshCollider>().sharedMesh     = null;
        toDelete.GetComponent <MeshRenderer>().sharedMaterial = null;
        toDelete.GetComponent <MeshFilter>().mesh             = null;
        instances.Remove(deletion.id);
        Destroy(toDelete);
    }
Ejemplo n.º 16
0
        public void AddDeletion()
        {
            var bm = new BatchMutation();
            var d1 = new Deletion();
            d1.SlicePredicate = new SlicePredicate();
            d1.SlicePredicate.ColumnNames.Add("c_name");
            bm.AddDeletion("key1", cfs, d1);
            Assert.Equal(1, bm["key1"].Count);

            var d2 = new Deletion();
            d2.SlicePredicate = new SlicePredicate();
            d2.SlicePredicate.ColumnNames.Add("c_name2");
            bm.AddDeletion("key1", cfs, d2);
            Assert.Equal(2, bm["key1"]["Standard1"].Count);
        }
Ejemplo n.º 17
0
        internal async Task <bool> HandleReactionAsync(BaseSocketClient client, SocketReaction reaction)
        {
            bool valid = await RunChecksAsync(client, reaction).ConfigureAwait(false) && (!IsUserRestricted || Users.Any(x => x.Id == reaction.UserId));

            if (Deletion.HasFlag(DeletionOptions.Invalids) && !valid)
            {
                await client.Rest.RemoveReactionAsync(reaction).ConfigureAwait(false);
            }
            if (Deletion.HasFlag(DeletionOptions.Valid) && valid)
            {
                await client.Rest.RemoveReactionAsync(reaction).ConfigureAwait(false);
            }

            return(valid);
        }
Ejemplo n.º 18
0
        public static Mutation CreateDeletedSuperColumnMutation(IEnumerable <FluentMutation> mutation)
        {
            var superColumn = mutation.Select(m => m.Column.GetPath().SuperColumn.ColumnName).FirstOrDefault();
            var columnNames = mutation.Select(m => m.Column.ColumnName).ToList();

            var deletion = new Deletion {
                Timestamp    = DateTimeOffset.Now.ToTimestamp(),
                Super_column = superColumn,
                Predicate    = CreateSlicePredicate(columnNames)
            };

            return(new Mutation {
                Deletion = deletion
            });
        }
Ejemplo n.º 19
0
        public void AddDeletion()
        {
            var bm = new BatchMutation();
            var d1 = new Deletion();

            d1.SlicePredicate = new SlicePredicate();
            d1.SlicePredicate.ColumnNames.Add("c_name");
            bm.AddDeletion("key1", cfs, d1);
            Assert.Equal(1, bm["key1"].Count);

            var d2 = new Deletion();

            d2.SlicePredicate = new SlicePredicate();
            d2.SlicePredicate.ColumnNames.Add("c_name2");
            bm.AddDeletion("key1", cfs, d2);
            Assert.Equal(2, bm["key1"]["Standard1"].Count);
        }
Ejemplo n.º 20
0
        public static IEnumerable <Mutation> CreateDeletedSuperColumnMutation(IEnumerable <FluentMutation> mutation)
        {
            foreach (var col in mutation)
            {
                var superColumn = col.Column.GetPath().SuperColumn.ColumnName.TryToBigEndian();

                var deletion = new Deletion {
                    Timestamp    = col.ColumnTimestamp.ToCassandraTimestamp(),
                    Super_column = superColumn,
                    Predicate    = CreateSlicePredicate(new[] { col.Column.ColumnName })
                };

                yield return(new Mutation {
                    Deletion = deletion
                });
            }
        }
Ejemplo n.º 21
0
        private async Task Delete()
        {
            await UsingTempFile(DefaultFileContents, async file =>
            {
                // Arrange
                var modification                = new Deletion(1, 3);
                _fileModifierStep.File          = file;
                _fileModifierStep.Modifications = new List <Modification> {
                    modification
                };

                // Act
                await _fileModifierStep.Run();

                // Assert
                var contents = await File.ReadAllTextAsync(file);
                contents.ShouldBe(@"4
5
");
            });
        }
        /// <summary>
        /// Serves as a hash function for a particular type.
        /// <see cref="GetHashCode"/> is suitable for use in hashing algorithms and data structures
        /// like a hash table.
        /// </summary>
        /// <returns>A hash code for the current object.</returns>
        public override int GetHashCode()
        {
            int result = Type.GetHashCode();

            if (Type == PatchOperationType.Addition)
            {
                result = 29 * result + Addition.GetHashCode();
            }

            if (Type == PatchOperationType.Deletion)
            {
                result = 29 * result + Deletion.GetHashCode();
            }

            if (Type == PatchOperationType.Copy)
            {
                result = 29 * result + Copy.GetHashCode();
            }

            return(result);
        }
Ejemplo n.º 23
0
        public IActionResult Delete(string id, [FromBody] Deletion deletion)
        {
            Timecard timecard = Database.Find(id);

            if (timecard != null)
            {
                if (timecard.Status != TimecardStatus.Draft && timecard.Status != TimecardStatus.Submitted)
                {
                    return(StatusCode(409, new InvalidStateError()
                    {
                    }));
                }

                var transition = new Transition(deletion, TimecardStatus.Deleted);
                timecard.Transitions.Add(transition);
                Database.Remove(timecard);
                return(Ok(transition));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 24
0
        public void deleteColumn(string keyspace, Object columnFamily, Object key, Object columnName)
        {
            client.set_keyspace(keyspace);
            Mutation       mutation = new Mutation();
            SlicePredicate sp       = new SlicePredicate();

            sp.Column_names = (new[] { columnName }).ToByteArrayListFromCollection <object>();
            Deletion deletion = new Deletion();

            deletion.Predicate = sp;
            //timestamp should be optional but its not
            deletion.Timestamp = createTimestamp();
            mutation.Deletion  = deletion;

            Dictionary <byte[], Dictionary <string, List <Mutation> > > mutation_map = new Dictionary <byte[], Dictionary <string, List <Mutation> > >();
            Dictionary <string, List <Mutation> > columnFamilyKey = new Dictionary <string, List <Mutation> >();
            List <Mutation> mutationList = new List <Mutation>();

            mutationList.Add(mutation);
            columnFamilyKey.Add(columnFamily.ToString(), mutationList);
            mutation_map.Add(key.ToByteArray(), columnFamilyKey);
            client.batch_mutate(mutation_map, consistencyLevel);
        }
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.Write($"case {SpecificEvent.VariableType.FullNameInCode()} {SpecificEvent.Usage}:");

            writer.IndentionLevel++;


            if (AlwaysDeletes)
            {
                writer.Write("return null;");
            }

            CreationFrame?.GenerateCode(method, writer);

            if (Apply != null)
            {
                if (AggregateType.GetConstructors().Any(x => !x.GetParameters().Any()))
                {
                    writer.Write($"{Aggregate.Usage} ??= new {AggregateType.FullNameInCode()}();");
                }

                Apply.GenerateCode(method, writer);
            }

            if (Deletion != null)
            {
                writer.Write($"if ({Aggregate.Usage} == null) return null;");

                Deletion.GenerateCode(method, writer);
            }

            writer.Write($"return {Aggregate.Usage};");

            writer.IndentionLevel--;

            Next?.GenerateCode(method, writer);
        }
Ejemplo n.º 26
0
 private long IgnoredDeletionsCount(Deletion deletion)
 {
     return(deletion.Ignored());
 }
Ejemplo n.º 27
0
 private string DeletionAuthor(Deletion deletion)
 {
     return(deletion.Email());
 }
Ejemplo n.º 28
0
        public static MiddleSnakeResult Middle(byte[] original, byte[] patched, Bounds bounds = null)
        {
            // Set bounds to default unless they have been specified. (-1 as 0 offset but +1 as extra row added to represent starting before the byte arays so cancel out)
            bounds = bounds ?? new Bounds(new Point(0, 0), new Point(patched.Length, original.Length));

            // Handle base cases with zero area
            if (bounds.IsVerticalBaseCase())
            {
                // As the lower and upper x values are the same, this implies the only move is down which denotes a deletion.
                // The index of the deletion corresponded to the x position at the start of the move.
                Edit edit = new Deletion(bounds.ToIndex(), bounds.Lower.X);

                // Increment the lower y value of the bounds and check that it still has an area
                Bounds upper = new Bounds(new Point(bounds.Lower.X, bounds.Lower.Y + 1), bounds.Upper);
                if (upper.Lower == upper.Upper)
                {
                    upper = null;
                }

                // Return the new middle snake
                return(new MiddleSnakeResult(edit, null, upper));
            }

            if (bounds.IsHorizontalBaseCase())
            {
                // Across => Insertion
                Edit edit = new Insertion(bounds.ToIndex(), bounds.Lower.X, patched[bounds.Lower.X]);

                Bounds upper = new Bounds(new Point(bounds.Lower.X + 1, bounds.Upper.Y), bounds.Upper);
                if (upper.Lower == upper.Upper)
                {
                    upper = null;
                }

                return(new MiddleSnakeResult(edit, null, upper));
            }

            // Store the size of the bounds.
            int N = bounds.Upper.Y - bounds.Lower.Y;
            int M = bounds.Upper.X - bounds.Lower.X;

            // Create an array to store x-distances along k-lines
            EditDistanceArray V = new EditDistanceArray(N, M);

            // Keep checking until a match must have been found
            for (int d = 0; d <= (N + M + 1) / 2; d++)
            {
                // Run the algorithm forwards and backwards
                foreach (Direction direction in Enum.GetValues(typeof(Direction)))
                {
                    // Check and update every other k-line within the current bounds.
                    for (int k = -d; k <= d; k += 2)
                    {
                        // Make sure the k-line is valid.

                        bool valid = N <M && k <= M && (k != -d && k > -N || k == -d && k >= -N) ||
                                        N> M && k >= -N && (k != d && k < M || k == d && k <= M) ||
                                     N == M && k >= -N && k <= M;

                        /*
                         * bool valid = ((N < M && k != -d && k > -N && k <= M) ||
                         *        (N < M && k == -d && k >= -N && k <= M) ||
                         *        (N > M && k != d && k >= -N && k < M) ||
                         *        (N > M && k == d && k >= -N && k <= M) ||
                         *        (N == M && k >= -N && k <= M))
                         * ? true
                         * : false;
                         */

                        /*
                         * if (N < M && k != -d && k > -N && k <= M)
                         * {
                         *  valid = true;
                         * }
                         *
                         * if (N < M && k == -d && k >= -N && k <= M)
                         * {
                         *  valid = true;
                         * }
                         *
                         * if (N > M && k != d && k >= -N && k < M)
                         * {
                         *  valid = true;
                         * }
                         *
                         * if (N > M && k == d && k >= -N && k <= M)
                         * {
                         *  valid = true;
                         * }
                         *
                         * if (N == M && k >= -N && k <= M)
                         * {
                         *  valid = true;
                         * }
                         */

                        if (valid)
                        {
                            // Check if the x-distance is larger by moving down/up or right/left and store it
                            bool down = ((k == -d) || (k != d) && V.GetX(k - 1, direction) < V.GetX(k + 1, direction));

                            int startX;
                            int startY;

                            // Update the current k-lines new x-distance
                            if (down)
                            {
                                startX = (int)V.GetX(k + 1, direction);
                                startY = (int)V.GetY(k + 1, direction);
                                V.SetX(k, direction, startX);
                            }
                            else
                            {
                                startX = (int)V.GetX(k - 1, direction);
                                startY = (int)V.GetY(k - 1, direction);
                                V.SetX(k, direction, startX + 1);
                            }

                            int currentX = (int)V.GetX(k, direction);
                            int currentY = (int)V.GetY(k, direction);

                            int currentSnake = Snake.Length(original, patched, bounds, (int)V.GetX(k, direction), (int)V.GetY(k, direction), direction);

                            int endX = currentX + currentSnake;
                            int endY = currentY + currentSnake;

                            // Update the current k-lines x-distance with the snake length from that point
                            V.SetX(k, direction, endX);

                            int globalEndX;
                            int globalEndY;

                            if (direction == Direction.Forward)
                            {
                                globalEndX = endX + bounds.Lower.X;
                                globalEndY = endY + bounds.Lower.Y;
                            }
                            else
                            {
                                globalEndX = bounds.Upper.X - endX;
                                globalEndY = bounds.Upper.Y - endY;
                            }

                            bool specialCase = false;

                            if (direction == Direction.Forward)
                            {
                                if (globalEndX == bounds.Upper.X && globalEndY == bounds.Upper.Y)
                                {
                                    specialCase = true;
                                }
                            }
                            else
                            {
                                if (globalEndX == bounds.Lower.X && globalEndY == bounds.Lower.Y)
                                {
                                    specialCase = true;
                                }
                            }
                            // Check if the middle snake reached the end of the bounds in one movement
                            if (specialCase)
                            {
                                Edit edit = null;

                                // Handle exact matches (No differences)
                                if (startY == -1)
                                {
                                    return(new MiddleSnakeResult(null, null, null));
                                }

                                if (direction == Direction.Forward)
                                {
                                    // Check if the move was down or across
                                    if (down)
                                    {
                                        edit = new Deletion(bounds.ToIndex(), bounds.Lower.X + startX);
                                    }
                                    else
                                    {
                                        edit = new Insertion(bounds.ToIndex(), bounds.Lower.X + startX, patched[bounds.Lower.X + startX]);
                                    }
                                }
                                else
                                {
                                    if (down)
                                    {
                                        edit = new Deletion(bounds.ToIndex(), bounds.Lower.Y + currentY);
                                    }
                                    else
                                    {
                                        edit = new Insertion(bounds.ToIndex(), bounds.Lower.Y + currentY, patched[bounds.Lower.Y + currentY]);
                                    }
                                }

                                return(new MiddleSnakeResult(edit, null, null));
                            }

                            // Check if there is an overlap along the current k-line from each end
                            if (V.Overlapped(k, direction))
                            {
                                // Values to store when returning the result of the middle snake.
                                Bounds upper;
                                Bounds lower;

                                if (direction == Direction.Reverse)
                                {
                                    // Invert the positions as they are from the bottom right not the top left
                                    startX = M - startX;
                                    startY = N - startY;
                                    endX   = M - endX;
                                    endY   = N - endY;

                                    // Lower bounds are from the lower bound point to snake end point
                                    lower = new Bounds(new Point(bounds.Lower.X, bounds.Lower.Y), new Point(endX + bounds.Lower.X, endY + bounds.Lower.Y));

                                    // Upper bounds are from the finish to the end
                                    upper = new Bounds(new Point(endX + bounds.Lower.X, endY + bounds.Lower.Y), new Point(bounds.Upper.X, bounds.Upper.Y));
                                }
                                else
                                {
                                    lower = new Bounds(new Point(bounds.Lower.X, bounds.Lower.Y), new Point(endX + bounds.Lower.X, endY + bounds.Lower.Y));

                                    upper = new Bounds(new Point(endX + bounds.Lower.X, endY + bounds.Lower.Y), new Point(bounds.Upper.X, bounds.Upper.Y));
                                }

                                if (lower.Lower.Equals(lower.Upper))
                                {
                                    lower = null;
                                }

                                if (upper.Lower.Equals(upper.Upper))
                                {
                                    upper = null;
                                }

                                return(new MiddleSnakeResult(null, lower, upper));
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 29
0
 private long DeletionsCount(Deletion deletion)
 {
     return(deletion.Counted());
 }
Ejemplo n.º 30
0
        public static int Main(string[] args)
        {
            int            retval = 0;
            SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "comp", 1);

            // create the document
            SBMLDocument document = new SBMLDocument(sbmlns);

            // create the Model
            Model model = document.createModel();

            // create a replacement parameter
            Parameter parameter = model.createParameter();

            parameter.setId("x");
            parameter.setConstant(true);

            // create a parameter to be a conversion factor
            Parameter param2 = model.createParameter();

            param2.setId("x_conv");
            param2.setMetaId("_110013");
            param2.setConstant(true);

            // create a parameter to be a conversion factor
            Parameter param3 = model.createParameter();

            param3.setId("lcf");
            param3.setConstant(true);

            // Convert parameter to the plugin version so we can add the new attributes and replacements to it.
            CompSBasePlugin splugin = (CompSBasePlugin)(parameter.getPlugin("comp"));

            // Add a replaced element.
            ReplacedElement rep1 = splugin.createReplacedElement();
            int             rv   = rep1.setSubmodelRef("submod1");

            rv = rep1.setConversionFactor("x_conv");
            rv = rep1.setIdRef("param1");

            // Add a second replaced element in a different way.
            ReplacedElement rep2 = new ReplacedElement();

            rv = rep2.setSubmodelRef("submod2");
            rv = rep2.setDeletion("del1");
            rv = splugin.addReplacedElement(rep2);

            //Now create a replaced element that points into a submodel.
            rep2.unsetDeletion();
            rep2.setIdRef("submod2");
            SBaseRef sbr5 = rep2.createSBaseRef();

            sbr5.setIdRef("submodelG");
            SBaseRef sbr6 = sbr5.createSBaseRef();

            sbr6.setIdRef("buriedElement");
            splugin.addReplacedElement(rep2);


            // Create a submodel
            CompModelPlugin        mplugin = (CompModelPlugin)(model.getPlugin("comp"));
            CompSBMLDocumentPlugin compdoc = (CompSBMLDocumentPlugin)(document.getPlugin("comp"));

            compdoc.setRequired(true);

            ModelDefinition moddef1 = compdoc.createModelDefinition();

            moddef1.setId("Mod1");
            Parameter m1param1 = moddef1.createParameter();

            m1param1.setId("param1");
            m1param1.setConstant(true);
            Parameter m1param2 = moddef1.createParameter();

            m1param2.setId("param2");
            m1param2.setConstant(false);
            m1param2.setValue(3.2);

            ModelDefinition moddef2 = new ModelDefinition();

            moddef2.setId("Mod2");
            Parameter subparam2 = moddef2.createParameter();

            subparam2.setId("subparam2");
            subparam2.setConstant(false);
            compdoc.addModelDefinition(moddef2);


            ExternalModelDefinition extmod1 = compdoc.createExternalModelDefinition();

            extmod1.setId("ExtMod1");
            extmod1.setSource("urn:miriam:biomodels.db:BIOMD0000000127");

            ExternalModelDefinition extmod2 = new ExternalModelDefinition();

            extmod2.setId("ExtMod2");
            extmod2.setSource("otherfile.xml");
            extmod2.setModelRef("modelnamethere");
            extmod2.setMd5("406022s908ge74sklj");
            compdoc.addExternalModelDefinition(extmod2);

            Submodel submod1 = mplugin.createSubmodel();

            submod1.setId("submod1");
            submod1.setModelRef("Mod1");
            Deletion del1 = submod1.createDeletion();

            del1.setId("deletionA");
            del1.setIdRef("param2");

            Submodel submod2 = new Submodel();

            submod2.setId("submod2");
            submod2.setModelRef("ExtMod1");
            submod2.setSubstanceConversionFactor("subcf");
            submod2.setTimeConversionFactor("tcf");
            submod2.setExtentConversionFactor("xtf");
            Deletion del2 = new Deletion();

            del2.setId("deletionB");
            del2.setMetaIdRef("_0010110");
            rv = submod2.addDeletion(del2);
            del2.setId("deletionC");
            del2.unsetMetaIdRef();
            del2.setPortRef("port2");
            rv = submod2.addDeletion(del2);
            del2.unsetId();
            del2.unsetPortRef();
            del2.setUnitRef("mph");
            rv = submod2.addDeletion(del2);
            del2.unsetUnitRef();
            del2.setIdRef("submodG");
            SBaseRef sbr = del2.createSBaseRef();

            sbr.setIdRef("element5");
            rv = submod2.addDeletion(del2);
            Deletion del3 = new Deletion();

            del3.setIdRef("submodG");
            SBaseRef sbr2 = new SBaseRef();

            sbr2.setIdRef("subsubmodQ");
            SBaseRef subsbr = sbr2.createSBaseRef();

            subsbr.setPortRef("toBdel");
            del3.setSBaseRef(sbr2);
            submod2.addDeletion(del3);
            mplugin.addSubmodel(submod2);

            Port port1 = mplugin.createPort();

            port1.setId("port1");
            port1.setMetaIdRef("_110013");
            Port port2 = new Port();

            port2.setId("port2");
            port2.setIdRef("x");
            mplugin.addPort(port2);
            port2.setId("port3");
            port2.setIdRef("submod2");
            port2.setSBaseRef(sbr2);
            mplugin.addPort(port2);

            libsbml.writeSBMLToFile(document, "comp_example1.xml");
            document = libsbml.readSBMLFromFile("comp_example1.xml");
            if (document == null)
            {
                Console.WriteLine("Error reading back in file.");
                retval = -1;
            }
            else
            {
                document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false);
                document.checkConsistency();
                if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 ||
                    document.getErrorLog().getNumFailsWithSeverity(3) > 0)
                {
                    OStringStream stream = new OStringStream();
                    document.printErrors(stream);
                    Console.WriteLine("Errors encoutered when round-tripping  SBML file: \n" +
                                      stream.str());
                    retval = -1;
                }
                libsbml.writeSBMLToFile(document, "comp_example1_rt.xml");
            }

            return(retval);
        }
Ejemplo n.º 31
0
            public MovieClip(FileData f) : this()
            {
                id   = f.readInt();
                unk1 = f.readInt();
                unk2 = f.readInt();

                int numLabels    = f.readInt();
                int numFrames    = f.readInt();
                int numKeyframes = f.readInt();

                unk3 = f.readInt();

                for (int i = 0; i < numLabels; i++)
                {
                    f.skip(0x08);

                    Label label = new Label();
                    label.nameId     = f.readInt();
                    label.startFrame = f.readInt();
                    label.unk1       = f.readInt();
                    labels.Add(label);
                }

                int totalFrames = numFrames + numKeyframes;

                for (int frameId = 0; frameId < totalFrames; frameId++)
                {
                    ChunkType frameType = (ChunkType)f.readInt();
                    f.skip(0x04);

                    Frame frame = new Frame();
                    frame.id = f.readInt();
                    int numChildren = f.readInt();

                    for (int childId = 0; childId < numChildren; childId++)
                    {
                        ChunkType childType = (ChunkType)f.readInt();
                        int       childSize = f.readInt();

                        if (childType == ChunkType.ObjectPlacement)
                        {
                            Placement placement = new Placement();
                            placement.objectId       = f.readInt();
                            placement.placementId    = f.readInt();
                            placement.unk1           = f.readInt();
                            placement.nameId         = f.readInt();
                            placement.unk2           = (short)f.readShort();
                            placement.unk3           = (short)f.readShort();
                            placement.mcObjectId     = (short)f.readShort();
                            placement.unk4           = (short)f.readShort();
                            placement.transformFlags = (short)f.readShort();
                            placement.transformId    = (short)f.readShort();
                            placement.positionFlags  = (short)f.readShort();
                            placement.positionId     = (short)f.readShort();
                            placement.colorId1       = f.readInt();
                            placement.colorId2       = f.readInt();
                            placement.numF037s       = f.readInt();
                            placement.numF014s       = f.readInt();

                            int numUnhandled = placement.numF037s + placement.numF014s;
                            for (int i = 0; i < numUnhandled; i++)
                            {
                                f.skip(0x04);
                                int size = f.readInt();
                                f.skip(size * 4);
                            }

                            frame.placements.Add(placement);
                        }
                        else if (childType == ChunkType.ObjectDeletion)
                        {
                            Deletion deletion = new Deletion();
                            deletion.unk1       = f.readInt();
                            deletion.mcObjectId = (short)f.readShort();
                            deletion.unk2       = (short)f.readShort();
                            frame.deletions.Add(deletion);
                        }
                        else if (childType == ChunkType.Action)
                        {
                            Action action = new Action();
                            action.actionId = f.readInt();
                            action.unk1     = f.readInt();
                            frame.actions.Add(action);
                        }
                    }

                    if (frameType == ChunkType.Keyframe)
                    {
                        keyframes.Add(frame);
                    }
                    else
                    {
                        frames.Add(frame);
                    }
                }
            }
Ejemplo n.º 32
0
        public static int Main(string[] args)
        {
            int retval = 0;
              SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "comp", 1);

              // create the document
              SBMLDocument document = new SBMLDocument(sbmlns);

              // create the Model
              Model model = document.createModel();

              // create a replacement parameter
              Parameter parameter = model.createParameter();
              parameter.setId("x");
              parameter.setConstant(true);

              // create a parameter to be a conversion factor
              Parameter param2 = model.createParameter();
              param2.setId("x_conv");
              param2.setMetaId("_110013");
              param2.setConstant(true);

              // create a parameter to be a conversion factor
              Parameter param3 = model.createParameter();
              param3.setId("lcf");
              param3.setConstant(true);

              // Convert parameter to the plugin version so we can add the new attributes and replacements to it.
              CompSBasePlugin splugin = (CompSBasePlugin) (parameter.getPlugin("comp"));

              // Add a replaced element.
              ReplacedElement rep1 = splugin.createReplacedElement();
              int rv = rep1.setSubmodelRef("submod1");
              rv = rep1.setConversionFactor("x_conv");
              rv = rep1.setIdRef("param1");

              // Add a second replaced element in a different way.
              ReplacedElement rep2 = new ReplacedElement();
              rv = rep2.setSubmodelRef("submod2");
              rv = rep2.setDeletion("del1");
              rv = splugin.addReplacedElement(rep2);

              //Now create a replaced element that points into a submodel.
              rep2.unsetDeletion();
              rep2.setIdRef("submod2");
              SBaseRef sbr5 = rep2.createSBaseRef();
              sbr5.setIdRef("submodelG");
              SBaseRef sbr6 = sbr5.createSBaseRef();
              sbr6.setIdRef("buriedElement");
              splugin.addReplacedElement(rep2);

              // Create a submodel
              CompModelPlugin mplugin = (CompModelPlugin) (model.getPlugin("comp"));
              CompSBMLDocumentPlugin compdoc = (CompSBMLDocumentPlugin) (document.getPlugin("comp"));
              compdoc.setRequired(true);

              ModelDefinition moddef1 = compdoc.createModelDefinition();
              moddef1.setId("Mod1");
              Parameter m1param1 = moddef1.createParameter();
              m1param1.setId("param1");
              m1param1.setConstant(true);
              Parameter m1param2 = moddef1.createParameter();
              m1param2.setId("param2");
              m1param2.setConstant(false);
              m1param2.setValue(3.2);

              ModelDefinition moddef2 = new ModelDefinition();
              moddef2.setId("Mod2");
              Parameter subparam2 = moddef2.createParameter();
              subparam2.setId("subparam2");
              subparam2.setConstant(false);
              compdoc.addModelDefinition(moddef2);

              ExternalModelDefinition extmod1 = compdoc.createExternalModelDefinition();
              extmod1.setId("ExtMod1");
              extmod1.setSource("urn:miriam:biomodels.db:BIOMD0000000127");

              ExternalModelDefinition extmod2 = new ExternalModelDefinition();
              extmod2.setId("ExtMod2");
              extmod2.setSource("otherfile.xml");
              extmod2.setModelRef("modelnamethere");
              extmod2.setMd5("406022s908ge74sklj");
              compdoc.addExternalModelDefinition(extmod2);

              Submodel submod1 = mplugin.createSubmodel();
              submod1.setId("submod1");
              submod1.setModelRef("Mod1");
              Deletion del1 = submod1.createDeletion();
              del1.setId("deletionA");
              del1.setIdRef("param2");

              Submodel submod2 = new Submodel();
              submod2.setId("submod2");
              submod2.setModelRef("ExtMod1");
              submod2.setSubstanceConversionFactor("subcf");
              submod2.setTimeConversionFactor("tcf");
              submod2.setExtentConversionFactor("xtf");
              Deletion del2 = new Deletion();
              del2.setId("deletionB");
              del2.setMetaIdRef("_0010110");
              rv = submod2.addDeletion(del2);
              del2.setId("deletionC");
              del2.unsetMetaIdRef();
              del2.setPortRef("port2");
              rv = submod2.addDeletion(del2);
              del2.unsetId();
              del2.unsetPortRef();
              del2.setUnitRef("mph");
              rv = submod2.addDeletion(del2);
              del2.unsetUnitRef();
              del2.setIdRef("submodG");
              SBaseRef sbr = del2.createSBaseRef();
              sbr.setIdRef("element5");
              rv = submod2.addDeletion(del2);
              Deletion del3 = new Deletion();
              del3.setIdRef("submodG");
              SBaseRef sbr2 = new SBaseRef();
              sbr2.setIdRef("subsubmodQ");
              SBaseRef subsbr = sbr2.createSBaseRef();
              subsbr.setPortRef("toBdel");
              del3.setSBaseRef(sbr2);
              submod2.addDeletion(del3);
              mplugin.addSubmodel(submod2);

              Port port1 = mplugin.createPort();
              port1.setId("port1");
              port1.setMetaIdRef("_110013");
              Port port2 = new Port();
              port2.setId("port2");
              port2.setIdRef("x");
              mplugin.addPort(port2);
              port2.setId("port3");
              port2.setIdRef("submod2");
              port2.setSBaseRef(sbr2);
              mplugin.addPort(port2);

              libsbml.writeSBMLToFile(document, "comp_example1.xml");
              document = libsbml.readSBMLFromFile("comp_example1.xml");
              if (document == null)
              {
            Console.WriteLine("Error reading back in file.");
            retval = -1;
              }
              else
              {
            document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false);
            document.checkConsistency();
            if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 ||
            document.getErrorLog().getNumFailsWithSeverity(3) > 0)
            {
              OStringStream stream = new OStringStream();
              document.printErrors(stream);
              Console.WriteLine("Errors encoutered when round-tripping  SBML file: \n" +
                            stream.str());
              retval = -1;
            }
            libsbml.writeSBMLToFile(document, "comp_example1_rt.xml");
              }

              return retval;
        }
Ejemplo n.º 33
0
        public override void Apply(byte **p, int length, int width, int height)
        {
            byte *ptr = *p;

            int bpp    = length / width / height;
            int stride = length / height;

            var tmpOnes = new List <int>();

            for (int i = stride + bpp; i < stride * height - stride - bpp; i += bpp)
            {
                if (ptr[i] == One)
                {
                    tmpOnes.Add(i);
                }
            }
            int[] ones = tmpOnes.ToArray();

            bool hasDeleted = true;

            while (hasDeleted)
            {
                hasDeleted = false;

                foreach (int i in ones)
                {
                    if (ptr[i + 3] == Zero || ptr[i + stride] == Zero ||
                        ptr[i - 3] == Zero || ptr[i - stride] == Zero)
                    {
                        ptr[i] = ptr[i + 1] = ptr[i + 2] = Two;
                    }
                }

                foreach (int i in ones)
                {
                    if (ptr[i] != Two && (
                            ptr[i + stride + 3] == Zero || ptr[i + stride - 3] == Zero ||
                            ptr[i - stride + 3] == Zero || ptr[i - stride - 3] == Zero))
                    {
                        ptr[i] = ptr[i + 1] = ptr[i + 2] = Three;
                    }
                }

                foreach (int i in ones)
                {
                    if (Fours.Contains(ComputeSum(i)))
                    {
                        ptr[i] = ptr[i + 1] = ptr[i + 2] = Four;
                    }
                }

                foreach (int i in ones)
                {
                    if (ptr[i] == Four && Deletion.Contains(ComputeSum(i)))
                    {
                        ptr[i] = ptr[i + 1] = ptr[i + 2] = Zero;
                    }
                }

                foreach (int i in ones)
                {
                    if (ptr[i] == Two && Deletion.Contains(ComputeSum(i)))
                    {
                        ptr[i]     = ptr[i + 1] = ptr[i + 2] = Zero;
                        hasDeleted = true;
                    }
                }

                foreach (int i in ones)
                {
                    if (ptr[i] == Three && Deletion.Contains(ComputeSum(i)))
                    {
                        ptr[i]     = ptr[i + 1] = ptr[i + 2] = Zero;
                        hasDeleted = true;
                    }
                }

                var tmp = new List <int>(ones.Length >> 1);
                for (int i = 0; i < ones.Length; i++)
                {
                    if (ptr[ones[i]] != Zero)
                    {
                        tmp.Add(ones[i]);
                    }
                }
                ones = tmp.ToArray();
            }

            int ComputeSum(int sumOffset)
            {
                int sum = 0;

                if (ptr[sumOffset + bpp] != Zero)
                {
                    sum += Matrix[5];
                }
                if (ptr[sumOffset - bpp] != Zero)
                {
                    sum += Matrix[3];
                }

                sumOffset += stride;

                if (ptr[sumOffset + bpp] != Zero)
                {
                    sum += Matrix[2];
                }
                if (ptr[sumOffset] != Zero)
                {
                    sum += Matrix[1];
                }
                if (ptr[sumOffset - bpp] != Zero)
                {
                    sum += Matrix[0];
                }

                sumOffset -= stride + stride;

                if (ptr[sumOffset + bpp] != Zero)
                {
                    sum += Matrix[8];
                }
                if (ptr[sumOffset] != Zero)
                {
                    sum += Matrix[7];
                }
                if (ptr[sumOffset - bpp] != Zero)
                {
                    sum += Matrix[6];
                }

                return(sum);
            }
        }