コード例 #1
0
ファイル: HighlightDataHelper.cs プロジェクト: DannyGB/OxTail
        public HighlightCollection<HighlightItem> Read()
        {
            HighlightCollection<HighlightItem> highlights = new HighlightCollection<HighlightItem>();

            DbConnection.Open();

            using (DbTransaction trans = DbConnection.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                using (DbDataAdapter adpt = Factory.CreateDataAdapter())
                {
                    using (DbCommand cmd = DbConnection.CreateCommand())
                    {
                        cmd.Transaction = trans;
                        cmd.CommandText = Constants.HIGHTLIGHTITEMS_SELECT_ALL;
                        cmd.ExecuteNonQuery();
                        adpt.SelectCommand = cmd;

                        using (DbCommandBuilder bld = Factory.CreateCommandBuilder())
                        {
                            bld.DataAdapter = adpt;

                            using (DataTable tbl = new DataTable())
                            {
                                adpt.Fill(tbl);

                                foreach (DataRow row in tbl.Rows)
                                {
                                    HighlightItem item = new HighlightItem()
                                    {
                                        ID = int.Parse(row[0].ToString()),
                                        Pattern = row[1].ToString(),
                                        Order = int.Parse(row[2].ToString()),
                                    };

                                    //HACK: System.Drawing.Color allows storing of the colour as one integer, gonna use this to populate DB and re-hydrate back in code. Easier!

                                    System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(int.Parse(row[3].ToString()));
                                    Color tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.ForeColour = tempCol2;

                                    tempCol = System.Drawing.Color.FromArgb(int.Parse(row[4].ToString()));
                                    tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.BackColour = tempCol2;

                                    tempCol = System.Drawing.Color.FromArgb(int.Parse(row[5].ToString()));
                                    tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.BorderColour = tempCol2;

                                    highlights.Add(item);
                                }
                            }
                        }
                    }
                }
            }

            DbConnection.Close();

            return highlights;
        }
コード例 #2
0
        public HighlightCollection <HighlightItem> Read()
        {
            HighlightCollection <HighlightItem> highlights = new HighlightCollection <HighlightItem>();

            DbConnection.Open();

            using (DbTransaction trans = DbConnection.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                using (DbDataAdapter adpt = Factory.CreateDataAdapter())
                {
                    using (DbCommand cmd = DbConnection.CreateCommand())
                    {
                        cmd.Transaction = trans;
                        cmd.CommandText = Constants.HIGHTLIGHTITEMS_SELECT_ALL;
                        cmd.ExecuteNonQuery();
                        adpt.SelectCommand = cmd;

                        using (DbCommandBuilder bld = Factory.CreateCommandBuilder())
                        {
                            bld.DataAdapter = adpt;

                            using (DataTable tbl = new DataTable())
                            {
                                adpt.Fill(tbl);

                                foreach (DataRow row in tbl.Rows)
                                {
                                    HighlightItem item = new HighlightItem()
                                    {
                                        ID      = int.Parse(row[0].ToString()),
                                        Pattern = row[1].ToString(),
                                        Order   = int.Parse(row[2].ToString()),
                                    };

                                    //HACK: System.Drawing.Color allows storing of the colour as one integer, gonna use this to populate DB and re-hydrate back in code. Easier!

                                    System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(int.Parse(row[3].ToString()));
                                    Color tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.ForeColour = tempCol2;

                                    tempCol         = System.Drawing.Color.FromArgb(int.Parse(row[4].ToString()));
                                    tempCol2        = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.BackColour = tempCol2;

                                    tempCol           = System.Drawing.Color.FromArgb(int.Parse(row[5].ToString()));
                                    tempCol2          = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B);
                                    item.BorderColour = tempCol2;

                                    highlights.Add(item);
                                }
                            }
                        }
                    }
                }
            }

            DbConnection.Close();

            return(highlights);
        }
コード例 #3
0
        public Highlighting(IHighlightsHelper highlightHelper, IExpressionBuilderWindow expressionBuilder)
        {
            InitializeComponent();

            ExpressionBuilder                    = expressionBuilder;
            this.HighlightHelper                 = highlightHelper;
            this.Patterns                        = highlightHelper.Patterns;
            this.buttonColour.SelectedColour     = ((SolidColorBrush)this.textBoxPattern.Foreground).Color;
            this.buttonBackColour.SelectedColour = ((SolidColorBrush)this.textBoxPattern.Background).Color;
        }
コード例 #4
0
        public static HighlightState GetHighlightState(HighlightCollection highlights, TimeSpan position)
        {
            if (highlights == null)
            {
                return(HighlightState.Begin);
            }

            return(highlights.Any(h => !h.IsHighlightClosed() && h.Begin < position) ?
                   HighlightState.End : HighlightState.Begin);
        }
        public MediaPositionSliderHighlightElementsList(MediaPositionSlider parent, HighlightCollection highlights)
        {
            this.parent = parent;

            begins = new Dictionary <Highlight, MediaPositionSliderHighlightElement>();
            ends   = new Dictionary <Highlight, MediaPositionSliderEndHighlightElement>();

            SetDictionaries(highlights);

            highlights.CollectionChanged += Highlights_CollectionChanged;
        }
        private void SetDictionaries(HighlightCollection highlights)
        {
            begins.Clear();
            ends.Clear();

            foreach (Highlight highlight in highlights)
            {
                begins.Add(highlight, new MediaPositionSliderHighlightElement(parent, highlight, Brushes.Gray, 2));
                ends.Add(highlight, new MediaPositionSliderEndHighlightElement(parent, highlight, Brushes.Gray, 2));
            }
        }
コード例 #7
0
        public CurrentHighlights(HighlightCollection collection, TimeSpan position) : this()
        {
            highlights = collection;
            highlights.CollectionChanged += Highlights_CollectionChanged;

            foreach (Highlight highlight in collection)
            {
                Subscribe(highlight);
            }

            this.position = position;
            Update();
        }
コード例 #8
0
        private void Unsubscribe(HighlightCollection collection)
        {
            if (collection == null)
            {
                return;
            }

            foreach (Highlight highlight in collection)
            {
                Unsubscribe(highlight);
            }

            collection.CollectionChanged -= Highlights_CollectionChanged;
        }
コード例 #9
0
        private void BtnHighlight_Click(object sender, ButtonStateChangingEventArgs args)
        {
            HighlightCollection highlights         = viewModel.Manager.Source.Highlights;
            Highlight           firstOpenHighlight = highlights.OrderByBegin().FirstOrDefault(h => !h.IsHighlightClosed());

            if (firstOpenHighlight != null)
            {
                firstOpenHighlight.End = mps.MediaPosition;
            }
            else
            {
                highlights.Add(new Highlight(mps.MediaPosition));
            }

            args.NewValue = MediaPositionSlider.GetHighlightState(highlights, mps.MediaPosition);
        }
コード例 #10
0
ファイル: HighlightsHelper.cs プロジェクト: DannyGB/OxTail
 public HighlightsHelper(IHighlightItemData highlightData )
 {
     this.HighlightData = highlightData;
     this.patterns = this.HighlightData.Read();
     this.patterns.ApplySort(null, ListSortDirection.Descending);
 }
コード例 #11
0
ファイル: HexBox.cs プロジェクト: pmsanford/sic-debug
        /// <summary>
        /// Initializes a new instance of a HexBox class.
        /// </summary>
        public HexBox()
        {
            this._vScrollBar = new VScrollBar();
            this._vScrollBar.Scroll += new ScrollEventHandler(_vScrollBar_Scroll);

            this._builtInContextMenu = new BuiltInContextMenu(this);

            BackColor = Color.White;
            Font = new Font("Courier New", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            _stringFormat = new StringFormat(StringFormat.GenericTypographic);
            _stringFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

            ActivateEmptyKeyInterpreter();

            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            _thumbTrackTimer.Interval = 50;
            _thumbTrackTimer.Tick += new EventHandler(PerformScrollThumbTrack);

            _highlights = new HighlightCollection();
        }
コード例 #12
0
        public HighlightCollection <HighlightItem> Write(HighlightCollection <HighlightItem> items)
        {
            int retval = 0;

            DbConnection.Open();

            using (DbTransaction trans = DbConnection.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                using (DbDataAdapter adpt = Factory.CreateDataAdapter())
                {
                    using (DbCommand cmd = DbConnection.CreateCommand())
                    {
                        cmd.Transaction = trans;
                        cmd.CommandText = Constants.HIGHTLIGHTITEMS_SELECT_ALL;
                        cmd.ExecuteNonQuery();
                        adpt.SelectCommand = cmd;

                        using (DbCommandBuilder bld = Factory.CreateCommandBuilder())
                        {
                            bld.DataAdapter = adpt;

                            using (DataTable tbl = new DataTable())
                            {
                                adpt.Fill(tbl);
                                DataRow[] existingRows = tbl.Select(string.Empty, string.Empty, DataViewRowState.OriginalRows);

                                // Deletes rows
                                bool found;
                                foreach (DataRow row in existingRows)
                                {
                                    found = false;
                                    foreach (HighlightItem item in items)
                                    {
                                        if (item.ID > 0 && item.ID == int.Parse(row[0].ToString()))
                                        {
                                            found = true;
                                            continue;
                                        }
                                    }

                                    if (!found)
                                    {
                                        row.Delete();
                                    }
                                }

                                foreach (HighlightItem item in items)
                                {
                                    found = false;

                                    foreach (DataRow row in existingRows)
                                    {
                                        if (row.RowState == DataRowState.Deleted)
                                        {
                                            found = true;
                                            break;
                                        }

                                        // Updates existing rows
                                        if (int.Parse(row[0].ToString()) == item.ID)
                                        {
                                            row[1] = item.Pattern;
                                            row[2] = item.Order;

                                            System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(item.ForeColour.A, item.ForeColour.R, item.ForeColour.G, item.ForeColour.B);
                                            row[3] = tempCol.ToArgb();

                                            tempCol = System.Drawing.Color.FromArgb(item.BackColour.A, item.BackColour.R, item.BackColour.G, item.BackColour.B);
                                            row[4]  = tempCol.ToArgb();

                                            tempCol = System.Drawing.Color.FromArgb(item.BorderColour.A, item.BorderColour.R, item.BorderColour.G, item.BorderColour.B);
                                            row[5]  = tempCol.ToArgb();

                                            found = true;
                                            break;
                                        }
                                    }

                                    // Inserts new rows
                                    if (!found)
                                    {
                                        DataRow r = tbl.NewRow();

                                        r[1] = item.Pattern;
                                        r[2] = item.Order;

                                        System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(item.ForeColour.A, item.ForeColour.R, item.ForeColour.G, item.ForeColour.B);
                                        r[3] = tempCol.ToArgb();

                                        tempCol = System.Drawing.Color.FromArgb(item.BackColour.A, item.BackColour.R, item.BackColour.G, item.BackColour.B);
                                        r[4]    = tempCol.ToArgb();

                                        tempCol = System.Drawing.Color.FromArgb(item.BorderColour.A, item.BorderColour.R, item.BorderColour.G, item.BorderColour.B);
                                        r[5]    = tempCol.ToArgb();

                                        tbl.Rows.Add(r);
                                    }
                                }

                                try
                                {
                                    retval = adpt.Update(tbl);
                                    trans.Commit();
                                }
                                catch (Exception)
                                {
                                    trans.Rollback();
                                    throw new DatabaseWriteException();
                                }
                                finally
                                {
                                    DbConnection.Close();
                                }
                            }
                        }
                    }
                }
            }

            return(this.Read());
        }
コード例 #13
0
ファイル: HighlightDataHelper.cs プロジェクト: DannyGB/OxTail
        public HighlightCollection<HighlightItem> Write(HighlightCollection<HighlightItem> items)
        {
            int retval = 0;

            DbConnection.Open();

            using (DbTransaction trans = DbConnection.BeginTransaction(System.Data.IsolationLevel.Serializable))
            {
                using (DbDataAdapter adpt = Factory.CreateDataAdapter())
                {
                    using (DbCommand cmd = DbConnection.CreateCommand())
                    {
                        cmd.Transaction = trans;
                        cmd.CommandText = Constants.HIGHTLIGHTITEMS_SELECT_ALL;
                        cmd.ExecuteNonQuery();
                        adpt.SelectCommand = cmd;

                        using (DbCommandBuilder bld = Factory.CreateCommandBuilder())
                        {
                            bld.DataAdapter = adpt;

                            using (DataTable tbl = new DataTable())
                            {
                                adpt.Fill(tbl);
                                DataRow[] existingRows = tbl.Select(string.Empty, string.Empty, DataViewRowState.OriginalRows);

                                // Deletes rows
                                bool found;
                                foreach (DataRow row in existingRows)
                                {
                                    found = false;
                                    foreach (HighlightItem item in items)
                                    {
                                        if (item.ID > 0 && item.ID == int.Parse(row[0].ToString()))
                                        {
                                            found = true;
                                            continue;
                                        }
                                    }

                                    if (!found)
                                    {
                                        row.Delete();
                                    }
                                }

                                foreach (HighlightItem item in items)
                                {
                                    found = false;

                                    foreach (DataRow row in existingRows)
                                    {
                                        if (row.RowState == DataRowState.Deleted)
                                        {
                                            found = true;
                                            break;
                                        }

                                        // Updates existing rows
                                        if (int.Parse(row[0].ToString()) == item.ID)
                                        {
                                            row[1] = item.Pattern;
                                            row[2] = item.Order;

                                            System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(item.ForeColour.A, item.ForeColour.R, item.ForeColour.G, item.ForeColour.B);
                                            row[3] = tempCol.ToArgb();

                                            tempCol = System.Drawing.Color.FromArgb(item.BackColour.A, item.BackColour.R, item.BackColour.G, item.BackColour.B);
                                            row[4] = tempCol.ToArgb();

                                            tempCol = System.Drawing.Color.FromArgb(item.BorderColour.A, item.BorderColour.R, item.BorderColour.G, item.BorderColour.B);
                                            row[5] = tempCol.ToArgb();

                                            found = true;
                                            break;
                                        }
                                    }

                                    // Inserts new rows
                                    if (!found)
                                    {
                                        DataRow r = tbl.NewRow();

                                        r[1] = item.Pattern;
                                        r[2] = item.Order;

                                        System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(item.ForeColour.A, item.ForeColour.R, item.ForeColour.G, item.ForeColour.B);
                                        r[3] = tempCol.ToArgb();

                                        tempCol = System.Drawing.Color.FromArgb(item.BackColour.A, item.BackColour.R, item.BackColour.G, item.BackColour.B);
                                        r[4] = tempCol.ToArgb();

                                        tempCol = System.Drawing.Color.FromArgb(item.BorderColour.A, item.BorderColour.R, item.BorderColour.G, item.BorderColour.B);
                                        r[5] = tempCol.ToArgb();

                                        tbl.Rows.Add(r);
                                    }
                                }

                                try
                                {
                                    retval = adpt.Update(tbl);
                                    trans.Commit();
                                }
                                catch (Exception)
                                {
                                    trans.Rollback();
                                    throw new DatabaseWriteException();
                                }
                                finally
                                {
                                    DbConnection.Close();
                                }
                            }
                        }
                    }
                }
            }

            return this.Read();
        }
コード例 #14
0
ファイル: HighlightsHelper.cs プロジェクト: DannyGB/OxTail
 public HighlightCollection <HighlightItem> Write()
 {
     this.Patterns = this.HighlightData.Write(this.Patterns);
     return(this.Patterns);
 }
コード例 #15
0
ファイル: HighlightsHelper.cs プロジェクト: DannyGB/OxTail
 public HighlightsHelper(IHighlightItemData highlightData)
 {
     this.HighlightData = highlightData;
     this.patterns      = this.HighlightData.Read();
     this.patterns.ApplySort(null, ListSortDirection.Descending);
 }
コード例 #16
0
ファイル: HighlightItem.cs プロジェクト: DannyGB/OxTail
 /// <summary>
 /// Saves the highlight collection
 /// </summary>
 /// <param name="patterns">The collection of patterns</param>
 /// <param name="filename">The filename to save to</param>
 public static void SaveHighlights(HighlightCollection<HighlightItem> patterns, string filename)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(HighlightCollection<HighlightItem>), new Type[] { typeof(HighlightItem) });
     FileHelper.SerializeToExecutableDirectory(filename, serializer, patterns);
 }
コード例 #17
0
ファイル: HighlightsHelper.cs プロジェクト: DannyGB/OxTail
 public HighlightCollection<HighlightItem> Write()
 {
     this.Patterns = this.HighlightData.Write(this.Patterns);
     return this.Patterns;
 }