private void Execute(GetDataDelegate action)
 {
     ResetVisiblityDataGrid();
     Thread thread = new Thread(new ThreadStart(action));
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
 }
 public IncrementalObservableCollection(GetDataDelegate getData, AddDataDelegate addData, Action <Exception> failed)
 {
     _getData = getData;
     _addData = addData;
     _failed  = failed;
 }
Ejemplo n.º 3
0
        public void Setup(
            string tableName, string tableFolder, string primaryKey, bool pageLoad
            , GetDataDelegate getDataDelegate, GetColumnDelegate getColumnDelegate
            , bool isPaging, int entityKey, string UserPreferenceCategory = "")
        {
            EntityKey = entityKey;
            Prefix    = entityKey.ToString();

            _getData                 = getDataDelegate;
            _getColumnDelegate       = getColumnDelegate;
            ViewState["TableFolder"] = tableFolder;
            ViewState["TableName"]   = tableName;

            var userPreferenceCategory = UserPreferenceCategory;

            if (string.IsNullOrEmpty(userPreferenceCategory))
            {
                userPreferenceCategory = tableName;
            }

            if (ViewState[Prefix + "TableName"] == null)
            {
                ViewState.Add(Prefix + "TableName", tableName);
            }

            if (ViewState[Prefix + "TableName"] != null && !(ViewState[Prefix + "TableName"].ToString().Equals(tableName)))
            {
                ViewState[Prefix + "TableName"]        = tableName;
                ViewState[Prefix + "CurrentPageIndex"] = 0;
            }

            ViewState["TableName"]  = tableName;
            ViewState["PrimaryKey"] = primaryKey;
            //ViewState["IsTesting"] = SessionVariables.IsTesting;
            ViewState["PageLoad"] = pageLoad;

            dtGlobal = GetData();

            Sample(dtGlobal, primaryKey, HideData, SessionVariables.IsTesting);
            MainGridView.DataSource = dtGlobal;

            if (isPaging)
            {
                MainGridView.PageSize = DefaultRowCount;

                oGridPagiation = new GridPagiation();
                oGridPagiation.Setup(plcPaging, litPagingSummary, lblCacheStatus, dtGlobal, MainGridView, Page, SettingCategory);
                oGridPagiation.Changed += oGridPagiation_Changed;

                if (ViewState[Prefix + "CurrentPageIndex"] != null)
                {
                    oGridPagiation.PageIndexInSession = int.Parse(ViewState[Prefix + "CurrentPageIndex"].ToString());
                }

                oGridPagiation.ManagePaging(dtGlobal);
            }
            else
            {
                MainGridView.AllowPaging = isPaging;
            }

            MainGridView.DataBind();
        }
Ejemplo n.º 4
0
        protected void GetData <V, R>(IDictionary <ICacheRetriever, IList <V> > assignedArguments, IList <R> result, GetDataDelegate <V, R> getDataDelegate)
        {
            if (ThreadPool == null || assignedArguments.Count == 1)
            {
                // Serialize GetEntities() requests
                DictionaryExtension.Loop(assignedArguments, delegate(ICacheRetriever cacheRetriever, IList <V> arguments)
                {
                    IList <R> partResult = getDataDelegate.Invoke(cacheRetriever, arguments);
                    foreach (R partItem in partResult)
                    {
                        result.Add(partItem);
                    }
                });
                return;
            }
            int       remainingResponses = assignedArguments.Count;
            Exception routedException    = null;

            // Execute CacheRetrievers in parallel
            DictionaryExtension.Loop(assignedArguments, delegate(ICacheRetriever cacheRetriever, IList <V> arguments)
            {
                ThreadPool.Queue(delegate()
                {
                    try
                    {
                        IList <R> partResult = getDataDelegate.Invoke(cacheRetriever, arguments);

                        lock (result)
                        {
                            foreach (R partItem in partResult)
                            {
                                result.Add(partItem);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        routedException = e;
                    }
                    finally
                    {
                        lock (result)
                        {
                            remainingResponses--;
                            Monitor.Pulse(result);
                        }
                    }
                });
            });
            lock (result)
            {
                while (remainingResponses > 0 && routedException == null)
                {
                    Monitor.Wait(result);
                }
            }
            if (routedException != null)
            {
                throw new Exception("Error occured while retrieving entities", routedException);
            }
        }
Ejemplo n.º 5
0
        private bool ValidateProperty(object sender, PropertyInfo property, Attribute attribute, PropertyInfo invalid, GetDataDelegate getDataCallback)
        {
            //  reset the invalid message
            invalid.SetValue(sender, string.Empty);

            Validator validatorAttribute = attribute as Validator;

            //  instantiate the validator
            if (validatorAttribute == null)
            {
                throw new Exception(string.Format("Could not construct validator for attribute. {0}", attribute));
            }
            if (!validatorAttribute.IsValid(property.GetValue(sender)))
            {
                //  update the invalid property with the message
                invalid.SetValue(sender, validatorAttribute.Message);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        private bool ValidateProperty(object sender, PropertyInfo property, PropertyInfo invalid, GetDataDelegate getDataCallback)
        {
            //  find the validator attribute
            var attributes       = property.GetCustomAttributes <Validator>(true);
            var sortedAttributes = attributes.OrderBy(si => si.Order).ToList();

            foreach (Attribute attribute in sortedAttributes)
            {
                if (!ValidateProperty(sender, property, attribute, invalid, getDataCallback))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 7
0
        virtual public bool Validate <T>(object sender, Expression <Func <T> > property, GetDataDelegate getDataCallback)
        {
            PropertyInfo p = GetProperty(sender, property);

            return(ValidateProperty(sender, p, sender.GetType().GetRuntimeProperty(p.Name + "Invalid"), getDataCallback));
        }
Ejemplo n.º 8
0
 public DataReciever(SensorsContext context)
 {
     myDelegate = new GetDataDelegate(RecieveData);
     _context   = context;
     _dbw       = new DBWorker(_context);
 }
        private void GetDataAsync(int index)
        {
            GetDataDelegate d = new GetDataDelegate(GetData);

            d.BeginInvoke(index, new AsyncCallback(DataLoaded), null);
        }
Ejemplo n.º 10
0
        private bool ValidateProperty(object sender, PropertyInfo property, Attribute attribute, PropertyInfo invalid, GetDataDelegate getDataCallback)
        {
            //  reset the invalid message
            invalid.SetValue(sender, string.Empty);

            Validator validatorAttribute = attribute as Validator;

            //  instantiate the validator
            if (validatorAttribute == null)
            {
                throw new Exception(string.Format("Could not construct validator for attribute. {0}", attribute));
            }
            try
            {
                if (!validatorAttribute.IsValid(property.GetValue(sender)))
                {
                    //  update the invalid property with the message
                    invalid.SetValue(sender, validatorAttribute.Message);
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("*** ValidationService.ValidateProperty ({0}) - Exception: {1}", property.Name, ex));
                //  update the invalid property with the message
                invalid.SetValue(sender, validatorAttribute.Message);
                return(false);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor that takes sync delegate
 /// </summary>
 /// <param name="getData">Delegate that calculate synchronously result based on given dataNumber.</param>
 /// <param name="predecessors">Predecessor nodes</param>
 public UniversalNode(GetDataDelegate getData, params Node <T>[] predecessors) : base(predecessors)
 {
     this.getData = getData;
 }
Ejemplo n.º 12
0
		static Win32DnD()
		{
			// Required for all other OLE functions to work
			Win32OleInitialize(IntPtr.Zero);

			// We reuse those
			DragDropEventArgs = new DragEventArgs(new DataObject(DataFormats.FileDrop, new string[0]), 0, 0, 0, DragDropEffects.None, DragDropEffects.None);
			DragFeedbackEventArgs = new GiveFeedbackEventArgs(DragDropEffects.None, true);
			DragContinueEventArgs = new QueryContinueDragEventArgs(0, false, DragAction.Continue);
			DragFormats = new ArrayList();
			DragFormatArray = new FORMATETC[0];
			DragMediums = new ArrayList();

			// Set up delegates
			// IDataObject
			DOQueryInterface = new QueryInterfaceDelegate(ComIDataObject.QueryInterface);
			DOAddRef = new AddRefDelegate(ComIDataObject.AddRef);
			DORelease = new ReleaseDelegate(ComIDataObject.Release);
			GetData = new GetDataDelegate(ComIDataObject.GetData);
			GetDataHere = new GetDataHereDelegate(ComIDataObject.GetDataHere);
			QueryGetData = new QueryGetDataDelegate(ComIDataObject.QueryGetData);
			GetCanonicalFormatEtc = new GetCanonicalFormatEtcDelegate(ComIDataObject.GetCanonicalFormatEtc);
			SetData = new SetDataDelegate(ComIDataObject.SetData);
			EnumFormatEtc = new EnumFormatEtcDelegate(ComIDataObject.EnumFormatEtc);
			DAdvise = new DAdviseDelegate(ComIDataObject.DAdvise);
			DUnadvise = new DUnadviseDelegate(ComIDataObject.DUnadvise);
			EnumDAdvise = new EnumDAdviseDelegate(ComIDataObject.EnumDAdvise);

			// IDropSource
			DSQueryInterface = new QueryInterfaceDelegate(ComIDropSource.QueryInterface);
			DSAddRef = new AddRefDelegate(ComIDropSource.AddRef);
			DSRelease = new ReleaseDelegate(ComIDropSource.Release);
			QueryContinueDrag = new QueryContinueDragDelegate(ComIDropSource.QueryContinueDrag);
			GiveFeedback = new GiveFeedbackDelegate(ComIDropSource.GiveFeedback);

			// IDropTarget
			DTQueryInterface = new QueryInterfaceDelegate(ComIDropTarget.QueryInterface);
			DTAddRef = new AddRefDelegate(ComIDropTarget.AddRef);
			DTRelease = new ReleaseDelegate(ComIDropTarget.Release);
			DragEnter = new DragEnterDelegate(ComIDropTarget.DragEnter);
			DragOver = new DragOverDelegate(ComIDropTarget.DragOver);
			DragLeave = new DragLeaveDelegate(ComIDropTarget.DragLeave);
			Drop = new DropDelegate(ComIDropTarget.Drop);
		}
Ejemplo n.º 13
0
        /// <summary>
        /// Calculates fixations from raw data and writes them into
        /// the database in the fixations tables.
        /// </summary>
        /// <param name="sampleType">The <see cref="SampleType"/> of the data, gaze or mouse</param>
        /// <param name="subject">A <see cref="String"/> with the subject name</param>
        /// <param name="trialsTable">The database trials <see cref="DataTable"/></param>
        /// <param name="worker">The <see cref="BackgroundWorker"/> of the calculation</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> of the <see cref="BackgroundWorker"/></param>
        public void CalcFixations(
            SampleType sampleType,
            string subject,
            System.Data.DataTable trialsTable,
            BackgroundWorker worker,
            DoWorkEventArgs e)
        {
            // Fixation  Calculating Objects //////////////////////////////////////////
            FixationDetection objFixationDetection = new FixationDetection();

            // Instantiate the delegate using the method as a parameter
            GetDataDelegate getDataMethod = null;
            int             minSamples    = 0;
            int             maxDistance   = 0;

            if (sampleType == (sampleType | SampleType.Gaze))
            {
                getDataMethod = Queries.GetGazeData;
                minSamples    = this.gazeMinSamples;
                maxDistance   = this.gazeMaxDistance;
            }
            else if (sampleType == (sampleType | SampleType.Mouse))
            {
                getDataMethod = Queries.GetMouseData;
                minSamples    = this.mouseMinSamples;
                maxDistance   = this.mouseMaxDistance;
            }

            bool point_found_delayed;
            /* sample gazepoint-found flag,      */
            /*   min_fix_samples ago             */
            float x_delayed; /* sample gazepoint coordinates,     */
            float y_delayed; /*   min_fix_samples ago             */
            float deviation_delayed;
            /* deviation of the gaze from the    */
            /*   present fixation,               */
            /*   min_fix_samples ago             */
            /* Fixation data - delayed:          */
            float x_fix_delayed = new float(); /* fixation point as estimated       */
            float y_fix_delayed = new float(); /*   min_fix_samples ago             */
            int   saccade_duration_delayed;
            /* duration of the saccade           */
            /*   preceeding the preset fixation  */
            /*   (samples)                       */
            long fix_start_time = new long();
            int  fix_duration_delayed_samples      = new int();  /* duration of the present fixation  */
            long fix_duration_delayed_milliseconds = new long(); /* duration of the present fixation  */

            EyeMotionState currentState = new EyeMotionState();

            // OtherVars
            int    counterTrial       = 0;
            PointF trialLastFixCenter = new PointF(0, 0);

            // Loop Rows=Trials
            foreach (DataRow trialRow in trialsTable.Rows)
            {
                List <Fixation> fixations = new List <Fixation>();

                // Reinitialize Fixation detection object
                // to ensure no overlay between fixations of
                // trials that follow each other.
                objFixationDetection.InitFixation(minSamples);

                int trialID       = (int)trialRow["TrialID"];
                int trialSequence = (int)trialRow["TrialSequence"];

                // Holds RawData corresponding to selected trial and subject
                DataTable rawDataTable   = Queries.GetRawDataBySubjectAndTrialSequence(subject, trialSequence);
                long      trialStartTime = rawDataTable.Rows.Count > 0 ? (long)rawDataTable.Rows[0]["Time"] : 0;

                int  counterRows = 0;
                int  counterFix  = 0;
                bool isFixation  = false;

                // Loop RawData
                foreach (DataRow rowRaw in rawDataTable.Rows)
                {
                    PointF?        newPt;
                    SampleValidity isValidData = getDataMethod(
                        rowRaw,
                        Document.ActiveDocument.PresentationSize,
                        out newPt);

                    bool useSample = false;
                    switch (isValidData)
                    {
                    case SampleValidity.Valid:
                        useSample = true;
                        break;

                    case SampleValidity.Empty:
                        useSample = true;
                        break;

                    case SampleValidity.Null:
                        break;

                    case SampleValidity.OutOfStimulus:
                        useSample = true;
                        break;
                    }

                    if (useSample)
                    {
                        PointF dataPoint = newPt.Value;

                        currentState = objFixationDetection.DetectFixation(
                            dataPoint.IsEmpty ? false : true,
                            Convert.ToInt64(rowRaw[3]),
                            dataPoint.X,
                            dataPoint.Y,
                            maxDistance,
                            minSamples,
                            out point_found_delayed,
                            out x_delayed,
                            out y_delayed,
                            out deviation_delayed,
                            out x_fix_delayed,
                            out y_fix_delayed,
                            out saccade_duration_delayed,
                            out fix_start_time,
                            out fix_duration_delayed_milliseconds,
                            out fix_duration_delayed_samples);

                        switch (currentState)
                        {
                        case EyeMotionState.FIXATING:
                            if (!isFixation)
                            {
                                isFixation = true;
                            }

                            break;

                        case EyeMotionState.FIXATION_COMPLETED:
                            PointF fixationCenter = new PointF(x_fix_delayed, y_fix_delayed);

                            // if (!Queries.OutOfScreen(fixationCenter)) TODO
                            {
                                Fixation completedFixation = new Fixation();
                                completedFixation.CountInTrial  = counterFix + 1;
                                completedFixation.Length        = fix_duration_delayed_milliseconds;
                                completedFixation.PosX          = x_fix_delayed;
                                completedFixation.PosY          = y_fix_delayed;
                                completedFixation.SampleType    = sampleType;
                                completedFixation.StartTime     = fix_start_time - trialStartTime;
                                completedFixation.SubjectName   = (string)trialRow["SubjectName"];
                                completedFixation.TrialID       = (int)trialRow["TrialID"];
                                completedFixation.TrialSequence = (int)trialRow["TrialSequence"];

                                if (this.eliminateFirstFixation && this.eliminateFirstFixationSimple == false && counterFix == 0 && VGPolyline.Distance(fixationCenter, trialLastFixCenter) < maxDistance && fix_duration_delayed_milliseconds < this.limitForFirstFixation)
                                {
                                    // Eliminate if applicable
                                }
                                else if (this.eliminateFirstFixationSimple && counterFix == 0)
                                {
                                    // do nothing, just go on with the next fixation eliminating this one
                                    counterFix++;
                                }
                                else
                                {
                                    fixations.Add(completedFixation);
                                    counterFix++;
                                }
                            }

                            isFixation = false;
                            break;

                        case EyeMotionState.ERROR:
                            break;

                        default:
                            break;
                        }
                    }

                    counterRows++;

                    // End RawData Loop
                }

                // Save last Fix if it has not been saved by a following saccade
                if (isFixation && fix_duration_delayed_milliseconds > 0)
                {
                    Fixation lastFixation = new Fixation();
                    lastFixation.CountInTrial  = counterFix + 1;
                    lastFixation.Length        = fix_duration_delayed_milliseconds;
                    lastFixation.PosX          = x_fix_delayed;
                    lastFixation.PosY          = y_fix_delayed;
                    lastFixation.SampleType    = sampleType;
                    lastFixation.StartTime     = fix_start_time - trialStartTime;
                    lastFixation.SubjectName   = (string)trialRow["SubjectName"];
                    lastFixation.TrialID       = (int)trialRow["TrialID"];
                    lastFixation.TrialSequence = (int)trialRow["TrialSequence"];
                    fixations.Add(lastFixation);
                }

                // Save last FixCenter for Eliminating first Fix of new trial if choosen in UI
                trialLastFixCenter.X = x_fix_delayed;
                trialLastFixCenter.Y = y_fix_delayed;

                if (this.mergeConsecutiveFixations)
                {
                    // Look for consecutive fixations that are beneath each other
                    // (within GazeMaxDistance) because of
                    // miscalculation due to blinks or missing data.
                    List <Fixation> mergedFixations = new List <Fixation>();
                    if (fixations.Count > 1)
                    {
                        Fixation foregoingFixation       = fixations[0];
                        bool     merged                  = false;
                        int      mergedCounter           = 0;
                        int      consecutiveMerges       = 0;
                        int      trialFixCounter         = 1;
                        PointF   foregoingFixationCenter = new PointF(foregoingFixation.PosX, foregoingFixation.PosY);
                        for (int i = 1; i < fixations.Count; i++)
                        {
                            // Test if consecutive calculated fixations lie in GazeMaxDistanceRange
                            PointF fixationCenter = new PointF(fixations[i].PosX, fixations[i].PosY);
                            int    distance       = (int)VGPolyline.Distance(foregoingFixationCenter, fixationCenter);
                            if (distance < maxDistance)
                            {
                                long sumOfDuration = foregoingFixation.Length + fixations[i].Length;
                                foregoingFixation.PosX = (foregoingFixation.PosX * foregoingFixation.Length +
                                                          fixations[i].PosX * fixations[i].Length) / sumOfDuration;
                                foregoingFixation.PosY = (foregoingFixation.PosY * foregoingFixation.Length +
                                                          fixations[i].PosY * fixations[i].Length) / sumOfDuration;
                                foregoingFixation.Length = fixations[i].StartTime - foregoingFixation.StartTime + fixations[i].Length;
                                merged = true;
                                mergedCounter++;
                                consecutiveMerges++;
                            }
                            else
                            {
                                if (!merged)
                                {
                                    foregoingFixation.CountInTrial = trialFixCounter;
                                    mergedFixations.Add(foregoingFixation);
                                    trialFixCounter++;
                                }
                                else
                                {
                                    merged = false;
                                    foregoingFixation.CountInTrial -= mergedCounter - 1;
                                    foregoingFixation.CountInTrial  = trialFixCounter;
                                    mergedFixations.Add(foregoingFixation);
                                    consecutiveMerges = 0;
                                    trialFixCounter++;
                                }

                                foregoingFixation       = fixations[i];
                                foregoingFixationCenter = fixationCenter;
                            }
                        }

                        if (!merged)
                        {
                            foregoingFixation.CountInTrial = trialFixCounter;
                            mergedFixations.Add(foregoingFixation);
                            trialFixCounter++;
                        }
                    }
                    else
                    {
                        mergedFixations = fixations;
                    }

                    foreach (Fixation fixationToSave in mergedFixations)
                    {
                        this.SaveFixationToTable(fixationToSave);
                    }
                }
                else
                {
                    // Don not merge fixations, use the originals.
                    foreach (Fixation fixationToSave in fixations)
                    {
                        this.SaveFixationToTable(fixationToSave);
                    }
                }

                // increase TrialCounter
                counterTrial++;

                if (worker != null)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }
                    else
                    {
                        // Report progress as a percentage of the total task.
                        int percentComplete = Convert.ToInt32(Convert.ToSingle(counterTrial) / trialsTable.Rows.Count * 100);
                        worker.ReportProgress(percentComplete);
                    }
                }

                // End Trial Loop
            }

            // Save Data to MDF File
            this.WriteToMDF(sampleType);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="tableFolder"></param>
        /// <param name="primaryKey"></param>
        /// <param name="pageLoad"></param>
        /// <param name="getDataDelegate"></param>
        /// <param name="getColumnDelegate"></param>
        /// <param name="isPaging">flag for paging</param>
        public void Setup(string tableName, string tableFolder, string primaryKey, bool pageLoad, GetDataDelegate getDataDelegate, GetColumnDelegate getColumnDelegate, bool isPaging, bool isUpdateColumn = true, bool isDeleteColumn = true, string userPreferenceCategory = "")
        {
            _getData           = getDataDelegate;
            _getColumnDelegate = getColumnDelegate;

            ViewState["TableFolder"] = tableFolder;
            if (!string.IsNullOrEmpty(SessionVariables.ActiveTableName))
            {
                SessionVariables.ActiveTableName = tableName;
            }

            if (!string.IsNullOrEmpty(SessionVariables.ActiveTableName) && !(SessionVariables.ActiveTableName.Equals(tableName)))
            {
                SessionVariables.ActiveTableName = tableName;
            }
            if (CurrentPageIndex == null)
            {
                CurrentPageIndex = 0;
            }

            ViewState["TableName"]  = tableName;
            ViewState["PrimaryKey"] = primaryKey;
            //ViewState["IsTesting"] = SessionVariables.IsTesting;
            ViewState["PageLoad"]    = pageLoad;
            MainGridView.AllowPaging = isPaging;

            if (string.IsNullOrEmpty(userPreferenceCategory))
            {
                UserPreferenceCategory = tableName;
            }
            else
            {
                UserPreferenceCategory = userPreferenceCategory;
            }
            SetUserPreferenceCategory();

            if (isPaging)
            {
                MainGridView.PageSize = SessionVariables.DefaultRowCount;

                oGridPagiation = new GridPagiation();
                oGridPagiation.Setup(plcPaging, litPagingSummary, lblCacheStatus, dtGlobal, MainGridView, Page, SettingCategory);
                oGridPagiation.Changed += oGridPagiation_Changed;
                if (CurrentPageIndex != null)
                {
                    oGridPagiation.PageIndexInSession = CurrentPageIndex.Value;
                }
                oGridPagiation.ManagePaging(dtGlobal);
            }

            this.IsUpdateColumn = isUpdateColumn;
            this.IsDeleteColumn = isDeleteColumn;
        }
Ejemplo n.º 15
0
        public void Setup(string tableName, string tableFolder, string primaryKey, bool pageLoad, GetDataDelegate getDataDelegate, GetColumnDelegate getColumnDelegate)
        {
            _getData           = getDataDelegate;
            _getColumnDelegate = getColumnDelegate;

            ViewState["TableFolder"] = tableFolder;
            ViewState["TableName"]   = tableName;
            ViewState["PrimaryKey"]  = primaryKey;
            ViewState["IsTesting"]   = HttpContext.Current.Session["IsTesting"];
            ViewState["PageLoad"]    = pageLoad;
        }
Ejemplo n.º 16
0
 private void Execute(GetDataDelegate action)
 {
     Thread thread = new Thread(new ThreadStart(action));
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
 }
Ejemplo n.º 17
0
 public Class1(GetDataDelegate getData)
 {
     GetData += getData;
 }