protected bool WriteFeature(FeatureReport oFeaRep)
        {
            bool success = false;

            try
            {
                success = HidD_SetFeature(m_hHandle, oFeaRep.Buffer, oFeaRep.BufferLength);
            }
            catch (IOException)
            {
                HandleDeviceRemoved();
                OnDeviceRemoved?.Invoke(this, new EventArgs());
                Dispose();
            }
            return(success);
        }
Exemple #2
0
        public ScenarioReportingContext CreateReport()
        {
            FeatureReport featureReport  = null;
            var           scenarioReport = new List <string>();
            var           stepReport     = new List <string>();

            var scenario = ExtractAttributeFromScenarioTest <ScenarioAttribute>();
            var feature  = scenario == null ? null : scenario.Feature;

            if (feature != null)
            {
                featureReport = new FeatureReport(feature.ToString());

                var featureAttribute = feature.GetType().GetField(featureReport.Name)
                                       .AttributeOrDefault <FeatureDescriptionAttribute>();
                if (featureAttribute != null)
                {
                    featureReport.Set(featureAttribute.Summary, featureAttribute.Details);
                }
            }

            var tagAttributes = ExtractAttributesFromScenarioTest <TagAttribute>();

            if (tagAttributes != null)
            {
                scenarioReport.AddRange(tagAttributes.Select(tag => string.Format("@{0}", tag.Name)));
            }

            var scenarioAttribute = ExtractAttributeFromScenarioTest <ScenarioAttribute>();

            if (scenarioAttribute != null)
            {
                scenarioReport.Add(GetScenarioDescriptionOrDefaultValue(scenarioAttribute, _scenarioTestType));
            }

            stepReport.AddRange(GetStepReport(StepType.Given));
            stepReport.AddRange(GetStepReport(StepType.When));
            stepReport.AddRange(GetStepReport(StepType.Then));

            return(new ScenarioReportingContext(
                       featureReport,
                       scenarioReport,
                       stepReport,
                       Settings));
        }
        protected bool ReadFeature(FeatureReport oFeaRep)
        {
            byte[] arrBuff = new byte[FeatureReportLength];
            bool   success = false;

            try
            {
                success = HidD_GetFeature(m_hHandle, arrBuff, arrBuff.Length);
                oFeaRep.SetData(arrBuff);
            }
            catch (IOException)
            {
                HandleDeviceRemoved();
                OnDeviceRemoved?.Invoke(this, new EventArgs());
                Dispose();
            }

            return(success);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void SendToParts(object sender, EventArgs e)
        {
            //Check assembly state before the features migration
            switch (FeatureUtilities.CheckAssemblyState(_AssemblyDocument))
            {
            case FeatureUtilities.AssemblyStateEnum.kAssemblyNotSaved:
            {
                string msg = "Assembly and its sub-components need to be saved on the disk" + System.Environment.NewLine +
                             "for the features migration."
                             + System.Environment.NewLine +
                             "Please save each file first and run the command again...";

                System.Windows.Forms.MessageBox.Show(msg,
                                                     "Feature Migrator",
                                                     MessageBoxButtons.OK,
                                                     MessageBoxIcon.Error);

                return;
            }

            case FeatureUtilities.AssemblyStateEnum.kException:
                return;

            default:
                break;
            }

            Transaction Tx = null;

            try
            {
                Tx = FeatureUtilities.Application.TransactionManager.StartTransaction(
                    _AssemblyDocument as _Document,
                    "Send Features");

                List <FeatureReport> results = new List <FeatureReport>();

                foreach (TreeNode node in TreeView.SelectedNodesBottomUp)
                {
                    if (!(node.Tag is PartFeature))
                    {
                        continue;
                    }

                    PartFeature Feature = node.Tag as PartFeature;

                    if (Feature.Suppressed)
                    {
                        //Do not migrate a suppressed feature
                        continue;
                    }

                    List <ComponentOccurrence> Participants = new List <ComponentOccurrence>();

                    foreach (TreeNode occNode in node.Nodes)
                    {
                        //Check if node is enabled
                        if (occNode.Tag != null && occNode.Tag is ComponentOccurrence)
                        {
                            Participants.Add(occNode.Tag as ComponentOccurrence);
                        }
                    }

                    if (Participants.Count != 0)
                    {
                        FeatureReport result = FeatureUtilities.SendToParts(_AssemblyDocument, Feature, Participants);

                        if (result != null)
                        {
                            results.Add(result);
                        }
                    }
                }

                if (results.Count != 0)
                {
                    if (FeatureUtilities.SingleFeatureOptions)
                    {
                        ActionPreFinalize(results);

                        DetailReportControl detailReportControl = new DetailReportControl(_AssemblyDocument, results);

                        detailReportControl.ShowAsChildModal();
                    }
                    else
                    {
                        ActionPreFinalize(results);
                        ActionFinalize(results);
                    }
                    System.IO.FileInfo fi = new System.IO.FileInfo(_AssemblyDocument.FullFileName);

                    string logfile = fi.DirectoryName + "\\" + fi.Name.Substring(0, fi.Name.Length - 4) + ".log";
                    FeatureReport.LogReport(results, logfile);
                }

                Tx.End();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace,
                                "Exception occurred!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Tx.Abort();
            }
            finally
            {
                RefreshControl(_AssemblyDocument as Document);
                _AssemblyDocument.Update2(true);
                this.Parent.Refresh();
            }
        }