Пример #1
0
        App()
        {
#if DEBUG
            System.Diagnostics.DefaultTraceListener dtl = (System.Diagnostics.DefaultTraceListener)System.Diagnostics.Debug.Listeners["Default"];
            dtl.LogFileName = Environment.CurrentDirectory + "\\_DEBUG_LOG.txt";
#endif
        }
Пример #2
0
        public static void Initialize()
        {
            var name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            var listenerDtl = new System.Diagnostics.DefaultTraceListener
            {
                LogFileName = "TraceLog_" + name + "_" + DateTime.Now.ToString("yyyMMdd") + ".txt"
            };

            System.Diagnostics.Trace.Listeners.Add(listenerDtl);

            var listenerTwtl = new System.Diagnostics.TextWriterTraceListener();

            listenerTwtl.Writer = Console.Out;
            //listenerTwtl.Writer = new System.IO.StreamWriter(name + ".txt", true, Encoding.UTF8);
            System.Diagnostics.Trace.Listeners.Add(listenerTwtl);

            //var listenerEltl = new System.Diagnostics.EventLogTraceListener();
            //System.Diagnostics.Trace.Listeners.Add(listenerEltl);

            //listenerEltl.EventLog = new System.Diagnostics.EventLog(name, Environment.MachineName, name);
            //var listenerEptl = new System.Diagnostics.Eventing.EventProviderTraceListener("{89185535-C194-48D9-82FB-0B01F7147461}", name);
            //System.Diagnostics.Trace.Listeners.Add(listenerEptl);
        }
Пример #3
0
 internal static void SetUpTests()
 {
     System.Diagnostics.DefaultTraceListener listener = (System.Diagnostics.DefaultTraceListener)System.Diagnostics.Trace.Listeners[0];
     listener.AssertUiEnabled = true;
 }
Пример #4
0
        /// <summary>
        /// This is used to return the property value for the specified property name
        /// </summary>
        /// <param name="item">The item from which to get the info</param>
        /// <param name="field">The field on which to get the info</param>
        /// <returns>The found property value or the item itself if not found</returns>
        protected object FilterItemOnProperty(object item, string field)
        {
            if(item != null && field != null && field.Length > 0)
            {
                try
                {
                    PropertyDescriptor pd;

                    if(dataManager != null)
                        pd = dataManager.GetItemProperties().Find(field, true);
                    else
                        pd = TypeDescriptor.GetProperties(item).Find(field, true);

                    if(pd != null)
                        item = pd.GetValue(item);
                }
                catch(Exception ex)
                {
                    // Should this really eat exceptions?  The .NET ListControl class does.  We'll log them for
                    // debugging purposes for the time being.
                    if(System.Diagnostics.Debugger.IsAttached)
                    {
                        // Can't use System.Diagnostics.Debug as it gets excluded from the release build.  This
                        // does the same thing though but is compiled into the release build.
                        using(var dtl = new System.Diagnostics.DefaultTraceListener())
                        {
                            dtl.WriteLine(LR.GetString("ExFilterItemOnProp", this.Name, ex.Message));
                        }
                    }
                }
            }

            return item;
        }
Пример #5
0
        /// <summary>
        /// This is used to create the rows and bind each one to a row in the data source
        /// </summary>
		private void BindData()
		{
            TemplateControl ctl;
            Separator sep;
            int idx, top = 0, sepTop = 0, sepWidth = pnlRows.Width;
            bool bindFailed = false;

            if(inBindData)
                return;

            Cursor oldCursor = this.Cursor;

            if(oldCursor != Cursors.WaitCursor)
                this.Cursor = Cursors.WaitCursor;

            inBindData = isBinding = true;

            try
            {
                pnlRows.Visible = false;
                pnlRows.SuspendLayout();
                pnlRows.AutoScrollPosition = new Point(0, 0);
                RemoveRows();
                this.Select(-1, -1, -1);

                // If we don't have both, there's nothing to do
    			if(rowTemplate == null || listManager == null)
                    return;

                // Bind the header and footer controls
                if(header != null)
                {
                    header.SetRowSourceInternal(dataSource);
                    header.Bind();
                    header.HasBeenBound = true;
                    OnHeaderDataBound(new DataListEventArgs(-1, header));
                }

                if(footer != null)
                {
                    footer.SetRowSourceInternal(dataSource);
                    footer.Bind();
                    footer.HasBeenBound = true;
                    OnFooterDataBound(new DataListEventArgs(-1, footer));
                }

                // Create the row template items
                ConstructorInfo ctor = rowTemplate.GetConstructor(Type.EmptyTypes);
                rowHeight = -1;

    			for(idx = 0; idx < listManager.Count; idx++, top += rowHeight, sepTop += rowHeight)
    			{
                    ctl = (TemplateControl)ctor.Invoke(null);
                    ctl.Enter += RowTemplate_Enter;
                    ctl.TemplateParentInternal = this;

                    if(rowHeight == -1)
                    {
                        ctl.InitializeTemplate();
                        ctl.HasBeenInitialized = true;

                        sepTop = rowHeight = ctl.Height;
                        if(showSep)
                            rowHeight += sepHeight;

                        if(ctl.Width > sepWidth)
                            sepWidth = ctl.Width;
                    }

    				ctl.Location = new Point(0, top);
    				pnlRows.Controls.Add(ctl);

                    if(showSep)
                    {
                        sep = new Separator(sepColor, sepHeight, sepWidth, 0, sepTop);
                        pnlRows.Controls.Add(sep);
                    }

                    // Set the control's row source
                    ctl.SetRowSourceInternal(listManager.List[idx]);
    			}
            }
            catch(Exception ex)
            {
                bindFailed = true;

                // Something in the data binding hierarchy tends to eat exceptions that occur during binding and
                // you never see them (i.e. bad field names in a binding).  This logs them to the debugger if one
                // is attached.
                if(System.Diagnostics.Debugger.IsAttached)
                {
                    // Can't use System.Diagnostics.Debug as it gets excluded from the release build.  This does
                    // the same thing though but is compiled into the release build.
                    using(var dtl = new System.Diagnostics.DefaultTraceListener())
                    {
                        dtl.WriteLine(LR.GetString("ExBindData1", this.Name, ex.Message));
                    }
                }
            }
            finally
            {
                this.CalculateGlyphPoints();

                if(!bindFailed)
                    if(!changePolicy.AllowAdditions)
                    {
                        this.Invalidate(new Rectangle(0, 0, rowHeaderWidth, this.Height), false);
                        this.Update();
                    }
                    else
                        this.AddNewRowTemplate();

                lblRowCount.Text = LR.GetString("DLNavRowCount", (listManager != null) ? listManager.Count : 0);

                if(oldCursor != Cursors.WaitCursor)
                    this.Cursor = oldCursor;

                inBindData = false;

                // Problems with the bindings will manifest themselves here (i.e. bad field names, etc).
                try
                {
                    pnlRows.ResumeLayout();
                    pnlRows.Visible = true;
                    this.Invalidate();
                    this.Update();
                }
                catch(Exception ex)
                {
                    // As above.  Log the exception so that we know it occurred.
                    if(System.Diagnostics.Debugger.IsAttached)
                        using(var dtl = new System.Diagnostics.DefaultTraceListener())
                        {
                            dtl.WriteLine(LR.GetString("ExBindData2", this.Name, ex.Message));
                        }
                }
                finally
                {
                    isBinding = false;
                }

                // Force the focus to the proper row
                currentRow = (dataSource == null) ? 0 : -1;
                DataSource_PositionChanged(this, EventArgs.Empty);

                if(listManager != null && listManager.Count == 0)
                    OnNoRows(EventArgs.Empty);
            }
		}