Пример #1
0
 private void CastAdapterPresentEvent(bool adapterPresent, AdapterType type)
 {
     if (onAdapterPresent != null)
     {
         onAdapterPresent(this, new AdapterEventArgs(adapterPresent, type));
     }
 }
Пример #2
0
 /// <summary>
 /// Creates an instance of <see cref="AdapterUserControl"/> class.
 /// </summary>
 public AdapterUserControl(AdapterType adapterType)
 {
     InitializeComponent();
     m_dataContext = new ViewModels.Adapters(7, adapterType);
     m_dataContext.PropertyChanged += ViewModel_PropertyChanged;
     this.DataContext = m_dataContext;
 }
Пример #3
0
        public async Task <ActionResult <AdapterType> > PostAdapterType(AdapterType adapterType)
        {
            AdapterContext.AdapterTypes.Add(adapterType);
            await AdapterContext.SaveChangesAsync();

            return(CreatedAtAction("GetAdapterType", new { id = adapterType.AdapterTypeId }, adapterType));
        }
Пример #4
0
    public virtual bool Refresh()
    {
        AdapterType someObj = null;

        someObj.DoSomething();
        return(true);
    }
Пример #5
0
        public async Task <IActionResult> PutAdapterType(int id, AdapterType adapterType)
        {
            if (id != adapterType.AdapterTypeId)
            {
                return(BadRequest());
            }

            AdapterContext.Entry(adapterType).State = EntityState.Modified;

            try
            {
                await AdapterContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdapterTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
 private void CastAdapterPresentEvent(bool adapterPresent, AdapterType type)
 {
     if (onAdapterPresent != null)
     {
         onAdapterPresent(this, new AdapterEventArgs(adapterPresent, type));
     }
 }
Пример #7
0
        public void Initialize(EndPoint env)
        {
            Trace.TraceInformation("TfsVCTestCaseAdapter: Initialize BEGIN");

            AdapterType = env.AdapterType;
            string serverPath = "test" + DateTime.Now.ToString("yyyy'-'MM'-'dd'_'HH'_'mm'_'ss");

            m_workspaceServerPath = String.Format("$/{0}/mt/{1}/{2}", env.TeamProject, serverPath, env.TestName);
            m_workspaceLocalPath  = Path.Combine(TestUtils.TextReportRoot, "ws" + TestUtils.GetRandomAsciiString(3));

            try
            {
                TfsTeamProjectCollection tfsProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(env.ServerUrl));
                m_tfsClient = (VersionControlServer)tfsProjectCollection.GetService(typeof(VersionControlServer));

                // Try deleting an existing test workspace if any
                m_workspace = m_tfsClient.GetWorkspace(env.WorkspaceName, Environment.UserName);
                CleanUpWorkspace();
            }
            catch (WorkspaceNotFoundException) { }

            // create workspace and map the path
            m_workspace = m_tfsClient.CreateWorkspace(env.WorkspaceName, Environment.UserName);
            m_workspace.Map(m_workspaceServerPath, m_workspaceLocalPath);

            Trace.TraceInformation("Created a workspace: {0}", m_workspace);
            Trace.TraceInformation("TfsVCTestCaseAdapter: Initialize END");
        }
Пример #8
0
        private void btnSendTest_Click(object sender, EventArgs e)
        {
            //{"command":"alert_incar","data":[{"dong":"811","ho":"101","car_number":"18��2876","date_time":"20200831153703"}]}
            //{\"command\":\"status_ack\",\"data\":[{\"code\":\"testcode\",\"message\":\"testmessage\"}]}
            //{"command":"alert_incar","data":[{"dong":"108","ho":"1203","car_number":"09서4666","date_time":"20200907150105"}]}
            //string dd = "{\"command\":\"alert_incar\",\"data\":[{\"dong\":\"108\",\"ho\":\"1203\",\"car_number\":\"09서4666\",\"date_time\":\"20200907150105\"}]}";
            string      dd       = "{\"command\":\"location_map\",\"data\":{\"dong\":\"108\",\"ho\":\"1203\",\"car_number\":\"97소1607\",\"date_time\":\"20200914095540\"}}";
            AdapterType type     = AdapterType.none;
            Encoding    encoding = null;

            if (rdoNexpa.Checked)
            {
                type     = AdapterType.nexpa;
                encoding = SysConfig.Instance.HomeNet_Encoding;
            }
            else if (rdoHomeNet.Checked)
            {
                type     = AdapterType.homenet;
                encoding = SysConfig.Instance.Nexpa_Encoding;
            }
            else
            {
                type = AdapterType.none;
            }
            pipe.TestSendMessage(type, encoding.GetBytes(txtMessage.Text));
        }
Пример #9
0
        public frmSettings()
        {
            InitializeComponent();
            string[] portNames = SerialPort.GetPortNames();
            foreach (string port in portNames)
            {
                if (port.StartsWith("COM"))
                {
                    cbWidebandComPort.Properties.Items.Add(port);
                }
            }
            cbWidebandComPort.SelectedIndex = 0;

            // Fetch adapter types from TrionicCANLib.API
            cbAdapterType.Properties.Items.Clear();
            foreach (var AdapterType in Enum.GetValues(typeof(CANBusAdapter)))
            {
                try
                {
                    cbAdapterType.Properties.Items.Add(((DescriptionAttribute)AdapterType.GetType().GetField(AdapterType.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false)[0]).Description.ToString());
                    cbAdapterType.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
                }
                catch (Exception ex)
                {
                    logger.Debug(ex.Message);
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Creates an instance of <see cref="AdapterUserControl"/> class.
 /// </summary>
 public AdapterUserControl(AdapterType adapterType)
 {
     InitializeComponent();
     m_dataContext = new ViewModels.Adapters(7, adapterType);
     m_dataContext.PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
     this.DataContext = m_dataContext;
 }
Пример #11
0
 public static IAdapter GetAdapter(AdapterType claimType,
                                   int mid        = 0,
                                   int tid        = 0,
                                   int siteID     = 0,
                                   string version = null)
 {
     // Create adapter here
 }
Пример #12
0
 public AdapterGroup(int _parentNodeId, bool _isLeftAdapter, AdapterType _myType, int _type, string _recipeSetName)
 {
     parentNodeId  = _parentNodeId;
     isLeftAdapter = _isLeftAdapter;
     myType        = _myType;
     type          = _type;
     recipeSetName = _recipeSetName;
 }
Пример #13
0
 /// <summary>
 /// Creates an instance of <see cref="Adapters"/> class.
 /// </summary>
 /// <param name="itemsPerPage">Integer value to determine number of items per page.</param>
 /// <param name="autoSave">Boolean value to determine is user changes should be saved automatically.</param>
 /// <param name="adapterType"><see cref="AdapterType"/> to determine type.</param>
 public Adapters(int itemsPerPage, AdapterType adapterType, bool autoSave = true)
     : base(0, autoSave) // Set items per page to zero to avoid load in the base class.
 {
     ItemsPerPage    = itemsPerPage;
     m_adapterType   = adapterType;
     SearchDirectory = FilePath.GetAbsolutePath("");
     Load();
 }
Пример #14
0
        // Static Methods

        /// <summary>
        /// Loads <see cref="Adapter"/> IDs as an <see cref="IList{T}"/>.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType"><see cref="AdapterType"/> collection to be returned.</param>
        /// <param name="sortMember">The field to sort by.</param>
        /// <param name="sortDirection"><c>ASC</c> or <c>DESC</c> for ascending or descending respectively.</param>
        /// <returns>Collection of <see cref="Int32"/>.</returns>
        public static IList <int> LoadIDs(AdoDataConnection database, AdapterType adapterType, string sortMember, string sortDirection)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string viewName;

                if (adapterType == AdapterType.Action)
                {
                    viewName = "CustomActionAdapterDetail";
                }
                else if (adapterType == AdapterType.Filter)
                {
                    viewName = "CustomFilterAdapterDetail";
                }
                else if (adapterType == AdapterType.Input)
                {
                    viewName = "CustomInputAdapterDetail";
                }
                else
                {
                    viewName = "CustomOutputAdapterDetail";
                }

                IList <int> adapterList = new List <int>();
                string      sortClause  = string.Empty;
                DataTable   adapterTable;
                string      query;

                if (!string.IsNullOrEmpty(sortMember))
                {
                    sortClause = string.Format("ORDER BY {0} {1}", sortMember, sortDirection);
                }

                query = database.ParameterizedQueryString(string.Format("SELECT ID FROM {0} WHERE NodeID = {{0}} {1}", viewName, sortClause), "nodeID");

                adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.CurrentNodeID());

                foreach (DataRow row in adapterTable.Rows)
                {
                    adapterList.Add(row.ConvertField <int>("ID"));
                }

                return(adapterList);
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Пример #15
0
        public static IMarketDataAdapter GetAdaptor(AdapterType type)
        {
            switch (type)
            {
            case AdapterType.Wind:
                return(new MarketDataAdapterWind());

            default:
                return(null);
            }
        }
Пример #16
0
 private Guid GetTCAdapterID(AdapterType adapterType)
 {
     foreach (AdapterMapping am in map)
     {
         if (adapterType == am.AdapterType)
         {
             return(new Guid(am.TCAdapterID));
         }
     }
     throw new Exception(String.Format("Failed to find TCAdapter ID for AdapterType {0}", adapterType));
 }
Пример #17
0
        public AdapterTypeViewModel(AdapterType adapterType)
        {
            if (adapterType == null)
            {
                throw new ArgumentNullException(nameof(adapterType));
            }

            AdapterTypeId = adapterType.AdapterTypeId;
            Description   = adapterType.Description;
            NrAvailable   = adapterType.GetAvailableAdapters().Count();
        }
Пример #18
0
        public static IFundDataAdapter GetAdaptor(AdapterType type)
        {
            switch (type)
            {
            case AdapterType.YSS:
                return(new FundDataAdapterYSS());

            default:
                return(null);
            }
        }
Пример #19
0
 public InfraAdapter GetAdapter(AdapterType type)
 {
     foreach (var adapter in Adapters)
     {
         if (adapter.Type == type)
         {
             return(adapter);
         }
     }
     return(null);
 }
Пример #20
0
        /// <summary>
        /// Creates an instance of <see cref="Adapters"/> class.
        /// </summary>
        /// <param name="itemsPerPage">Integer value to determine number of items per page.</param>
        /// <param name="autoSave">Boolean value to determine is user changes should be saved automatically.</param>
        /// <param name="adapterType"><see cref="AdapterType"/> to determine type.</param>
        public Adapters(int itemsPerPage, AdapterType adapterType, bool autoSave = true)
            : base(0, autoSave) // Set items per page to zero to avoid load in the base class.
        {
            AppDomain.CurrentDomain.AssemblyResolve += AppDomain_AssemblyResolve;
            ItemsPerPage = itemsPerPage;

            // Must attach to PropertyChanged event after setting m_adapterType!
            // Do not override OnPropertyChanged or you will regret it!
            m_adapterType    = adapterType;
            PropertyChanged += Adapters_PropertyChanged;

            SearchDirectory = FilePath.GetAbsolutePath("").EnsureEnd(Path.DirectorySeparatorChar);
            Load();
        }
Пример #21
0
        /// <summary>
        /// Gets the adapter's type string representation.
        /// </summary>
        public static string GetAdapterValue(this AdapterType adapterType)
        {
            MemberInfo memberInfo = typeof(AdapterType)
                                    .GetMember(adapterType.ToString())
                                    .FirstOrDefault();

            string adapterValue = string.Empty;

            if (memberInfo != null)
            {
                AdapterTypeValueAttribute attribute =
                    memberInfo.GetCustomAttribute <AdapterTypeValueAttribute>();
                adapterValue = attribute?.Value;
            }
            return(adapterValue);
        }
Пример #22
0
 public List <Adapter> GetAdapterList(bool enabledOnly, AdapterType adapterType, string nodeID)
 {
     try
     {
         return(CommonFunctions.GetAdapterList(null, enabledOnly, adapterType, nodeID));
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "Service.GetAdapterList", ex);
         CustomServiceFault fault = new CustomServiceFault()
         {
             UserMessage = "Failed to Retrieve Adapter List", SystemMessage = ex.Message
         };
         throw new FaultException <CustomServiceFault>(fault);
     }
 }
Пример #23
0
        /// <summary>
        /// Converts a string to it's matching <see cref="AdapterType"/> by searching through the
        /// adapter types' values.
        /// </summary>
        public static AdapterType ParseToAdapterType(this string adapterValue)
        {
            AdapterType adapterType = AdapterType.Unknown;

            foreach (FieldInfo field in typeof(AdapterType).GetFields())
            {
                AdapterTypeValueAttribute attribute =
                    field.GetCustomAttribute <AdapterTypeValueAttribute>();

                if (attribute != null && attribute.Value == adapterValue)
                {
                    adapterType = (AdapterType)field.GetValue(null);
                }
            }

            return(adapterType);
        }
Пример #24
0
        /// <summary>
        /// Gets the interface type of the adapter based on
        /// the given <see cref="AdapterType"/>.
        /// </summary>
        /// <param name="type">The adapter type.</param>
        /// <returns>The interface type corresponding to the adapter type.</returns>
        private Type GetAdapterInterfaceType(AdapterType type)
        {
            switch (type)
            {
            case AdapterType.Input:
                return(typeof(IInputAdapter));

            case AdapterType.Action:
                return(typeof(IActionAdapter));

            case AdapterType.Output:
                return(typeof(IOutputAdapter));

            default:
                return(null);
            }
        }
Пример #25
0
        /// <summary>
        /// Deletes specified <see cref="Adapter"/> record from database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType">Type of adapter to determine from which table record to be deleted.</param>
        /// <param name="adapterID">ID of the record to be deleted.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string Delete(AdoDataConnection database, AdapterType adapterType, int adapterID)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                // Setup current user context for any delete triggers
                CommonFunctions.SetCurrentUserContext(database);

                string tableName;

                if (adapterType == AdapterType.Action)
                {
                    tableName = "CustomActionAdapter";
                }
                else if (adapterType == AdapterType.Filter)
                {
                    tableName = "CustomFilterAdapter";
                }
                else if (adapterType == AdapterType.Input)
                {
                    tableName = "CustomInputAdapter";
                }
                else
                {
                    tableName = "CustomOutputAdapter";
                }

                string query = database.ParameterizedQueryString("DELETE FROM " + tableName + " WHERE ID = {0}", "adapterID");
                database.Connection.ExecuteNonQuery(query, DefaultTimeout, adapterID);

                CommonFunctions.SendCommandToService("ReloadConfig");

                return("Adapter deleted successfully");
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Пример #26
0
        /// <summary>
        /// Gets a <see cref="Dictionary{T1,T2}"/> style list of <see cref="Adapter"/> information.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType">Type of the <see cref="Adapter"/>.</param>
        /// <param name="isOptional">Indicates if selection on UI is optional for this collection.</param>
        /// <returns><see cref="Dictionary{T1,T2}"/> containing ID and Name of adapters defined in the database.</returns>
        public static Dictionary <int, string> GetLookupList(AdoDataConnection database, AdapterType adapterType, bool isOptional = false)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                Dictionary <int, string> adapterList = new Dictionary <int, string>();
                if (isOptional)
                {
                    adapterList.Add(0, "Select Adapter");
                }

                string tableName;

                if (adapterType == AdapterType.Action)
                {
                    tableName = "CustomActionAdapter";
                }
                else if (adapterType == AdapterType.Filter)
                {
                    tableName = "CustomFilterAdapter";
                }
                else if (adapterType == AdapterType.Input)
                {
                    tableName = "CustomInputAdapter";
                }
                else
                {
                    tableName = "CustomOutputAdapter";
                }

                string    query        = database.ParameterizedQueryString("SELECT ID, Name FROM " + tableName + " WHERE Enabled = {0} ORDER BY LoadOrder", "enabled");
                DataTable adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.Bool(true));

                foreach (DataRow row in adapterTable.Rows)
                {
                    adapterList[row.ConvertField <int>("ID")] = row.Field <string>("Name");
                }

                return(adapterList);
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Пример #27
0
        /// <summary>
        /// Loads <see cref="Adapter"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType"><see cref="AdapterType"/> collection to be returned.</param>
        /// <param name="keys">Keys of the adapters to be loaded from the database.</param>
        /// <returns>Collection of <see cref="Adapter"/>.</returns>
        public static ObservableCollection <Adapter> Load(AdoDataConnection database, AdapterType adapterType, IList <int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string viewName;

                if (adapterType == AdapterType.Action)
                {
                    viewName = "CustomActionAdapterDetail";
                }
                else if (adapterType == AdapterType.Filter)
                {
                    viewName = "CustomFilterAdapterDetail";
                }
                else if (adapterType == AdapterType.Input)
                {
                    viewName = "CustomInputAdapterDetail";
                }
                else
                {
                    viewName = "CustomOutputAdapterDetail";
                }

                string query;
                string commaSeparatedKeys;

                Adapter[] adapterList = null;
                DataTable adapterTable;
                int       id;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => "" + key.ToString() + "").Aggregate((str1, str2) => str1 + "," + str2);
                    query = database.ParameterizedQueryString(string.Format("SELECT NodeID, ID, AdapterName, AssemblyName, TypeName, ConnectionString, " +
                                                                            "LoadOrder, Enabled, NodeName FROM {0} WHERE NodeID = {{0}} AND ID IN ({1})", viewName, commaSeparatedKeys), "nodeID");

                    adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.CurrentNodeID());
                    adapterList  = new Adapter[adapterTable.Rows.Count];

                    foreach (DataRow row in adapterTable.Rows)
                    {
                        id = row.ConvertField <int>("ID");

                        adapterList[keys.IndexOf(id)] = new Adapter()
                        {
                            NodeID           = database.Guid(row, "NodeID"),
                            ID               = id,
                            AdapterName      = row.Field <string>("AdapterName"),
                            AssemblyName     = row.Field <string>("AssemblyName"),
                            TypeName         = row.Field <string>("TypeName"),
                            ConnectionString = row.Field <string>("ConnectionString"),
                            LoadOrder        = row.ConvertField <int>("LoadOrder"),
                            Enabled          = Convert.ToBoolean(row.Field <object>("Enabled")),
                            NodeName         = row.Field <string>("NodeName"),
                            Type             = adapterType
                        };
                    }
                }

                return(new ObservableCollection <Adapter>(adapterList ?? new Adapter[0]));
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Пример #28
0
        /// <summary>
        /// Loads <see cref="Adapter"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>        
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType"><see cref="AdapterType"/> collection to be returned.</param>     
        /// <param name="keys">Keys of the adapters to be loaded from the database.</param>   
        /// <returns>Collection of <see cref="Adapter"/>.</returns>
        public static ObservableCollection<Adapter> Load(AdoDataConnection database, AdapterType adapterType, IList<int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string viewName;

                if (adapterType == AdapterType.Action)
                    viewName = "CustomActionAdapterDetail";
                else if (adapterType == AdapterType.Input)
                    viewName = "CustomInputAdapterDetail";
                else
                    viewName = "CustomOutputAdapterDetail";

                ObservableCollection<Adapter> adapterList = new ObservableCollection<Adapter>();
                DataTable adapterTable;
                string query;
                string commaSeparatedKeys;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => "" + key.ToString() + "").Aggregate((str1, str2) => str1 + "," + str2);
                    query = database.ParameterizedQueryString(string.Format("SELECT NodeID, ID, AdapterName, AssemblyName, TypeName, ConnectionString, " +
                        "LoadOrder, Enabled, NodeName FROM {0} WHERE NodeID = {{0}} AND ID IN ({1})", viewName, commaSeparatedKeys), "nodeID");

                    adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.CurrentNodeID());

                    foreach (DataRow row in adapterTable.Rows)
                    {
                        adapterList.Add(new Adapter()
                        {
                            NodeID = database.Guid(row, "NodeID"),
                            ID = row.ConvertField<int>("ID"),
                            AdapterName = row.Field<string>("AdapterName"),
                            AssemblyName = row.Field<string>("AssemblyName"),
                            TypeName = row.Field<string>("TypeName"),
                            ConnectionString = row.Field<string>("ConnectionString"),
                            LoadOrder = row.ConvertField<int>("LoadOrder"),
                            Enabled = Convert.ToBoolean(row.Field<object>("Enabled")),
                            NodeName = row.Field<string>("NodeName"),
                            Type = adapterType
                        });
                    }
                }

                return adapterList;
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Пример #29
0
        /// <summary>
        /// Gets a <see cref="Dictionary{T1,T2}"/> style list of <see cref="Adapter"/> information.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType">Type of the <see cref="Adapter"/>.</param>
        /// <param name="isOptional">Indicates if selection on UI is optional for this collection.</param>
        /// <returns><see cref="Dictionary{T1,T2}"/> containing ID and Name of adapters defined in the database.</returns>
        public static Dictionary<int, string> GetLookupList(AdoDataConnection database, AdapterType adapterType, bool isOptional = false)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                Dictionary<int, string> adapterList = new Dictionary<int, string>();
                if (isOptional)
                    adapterList.Add(0, "Select Adapter");

                string tableName;

                if (adapterType == AdapterType.Action)
                    tableName = "CustomActionAdapter";
                else if (adapterType == AdapterType.Input)
                    tableName = "CustomInputAdapter";
                else
                    tableName = "CustomOutputAdapter";

                string query = database.ParameterizedQueryString("SELECT ID, Name FROM " + tableName + " WHERE Enabled = {0} ORDER BY LoadOrder", "enabled");
                DataTable adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.Bool(true));

                foreach (DataRow row in adapterTable.Rows)
                    adapterList[row.ConvertField<int>("ID")] = row.Field<string>("Name");

                return adapterList;
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Пример #30
0
        /// <summary>
        /// Deletes specified <see cref="Adapter"/> record from database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType">Type of adapter to determine from which table record to be deleted.</param>
        /// <param name="adapterID">ID of the record to be deleted.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string Delete(AdoDataConnection database, AdapterType adapterType, int adapterID)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                // Setup current user context for any delete triggers
                CommonFunctions.SetCurrentUserContext(database);

                string tableName;

                if (adapterType == AdapterType.Action)
                    tableName = "CustomActionAdapter";
                else if (adapterType == AdapterType.Input)
                    tableName = "CustomInputAdapter";
                else
                    tableName = "CustomOutputAdapter";

                string query = database.ParameterizedQueryString("DELETE FROM " + tableName + " WHERE ID = {0}", "adapterID");
                database.Connection.ExecuteNonQuery(query, DefaultTimeout, adapterID);

                TimeSeriesFramework.UI.CommonFunctions.SendCommandToService("ReloadConfig");

                return "Adapter deleted successfully";
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Пример #31
0
        public static List<Adapter> GetAdapterList(DataConnection connection, bool enabledOnly, AdapterType adapterType, string nodeID)
        {
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }
                List<Adapter> adapterList = new List<Adapter>();
                string viewName;
                if (adapterType == AdapterType.Action)
                    viewName = "CustomActionAdapterDetail";
                else if (adapterType == AdapterType.Input)
                    viewName = "CustomInputAdapterDetail";
                else
                    viewName = "CustomOutputAdapterDetail";

                IDbCommand command = connection.Connection.CreateCommand();
                command.CommandType = CommandType.Text;
                if (string.IsNullOrEmpty(nodeID) || MasterNode(connection, nodeID))
                    command.CommandText = "Select * From " + viewName + " Order By LoadOrder";
                else
                {
                    command.CommandText = "Select * From " + viewName + " Where NodeID = @nodeID Order By LoadOrder";
                    //command.Parameters.Add(AddWithValue(command, "@nodeID", nodeID));
                    if (command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB"))
                        command.Parameters.Add(AddWithValue(command, "@nodeID", "{" + nodeID + "}"));
                    else
                        command.Parameters.Add(AddWithValue(command, "@nodeID", nodeID));
                }

                DataTable resultTable = new DataTable();
                resultTable.Load(command.ExecuteReader());
                adapterList = (from item in resultTable.AsEnumerable()
                               select new Adapter()
                               {
                                   NodeID = item.Field<object>("NodeID").ToString(),
                                   ID = Convert.ToInt32(item.Field<object>("ID")),
                                   AdapterName = item.Field<string>("AdapterName"),
                                   AssemblyName = item.Field<string>("AssemblyName"),
                                   TypeName = item.Field<string>("TypeName"),
                                   ConnectionString = item.Field<string>("ConnectionString"),
                                   LoadOrder = Convert.ToInt32(item.Field<object>("LoadOrder")),
                                   Enabled = Convert.ToBoolean(item.Field<object>("Enabled")),
                                   NodeName = item.Field<string>("NodeName"),
                                   adapterType = adapterType
                               }).ToList();

                return adapterList;
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }
Пример #32
0
        /// <summary>
        /// Detects the CAN adapter type
        /// </summary>
        /// <param name="bluetoothSocket">Bluetooth socket for communication</param>
        /// <returns>Adapter type</returns>
        private AdapterType AdapterTypeDetection(BluetoothSocket bluetoothSocket)
        {
            const int versionRespLen = 9;

            byte[]      customData  = { 0x82, 0xF1, 0xF1, 0xFD, 0xFD, 0x5E };
            AdapterType adapterType = AdapterType.Unknown;

            try
            {
                Stream bluetoothInStream  = bluetoothSocket.InputStream;
                Stream bluetoothOutStream = bluetoothSocket.OutputStream;

                {
                    // custom adapter
                    bluetoothInStream.Flush();
                    while (bluetoothInStream.IsDataAvailable())
                    {
                        bluetoothInStream.ReadByte();
                    }
                    LogData(customData, 0, customData.Length, "Send");
                    bluetoothOutStream.Write(customData, 0, customData.Length);

                    LogData(null, 0, 0, "Resp");
                    List <byte> responseList = new List <byte>();
                    long        startTime    = Stopwatch.GetTimestamp();
                    for (; ;)
                    {
                        while (bluetoothInStream.IsDataAvailable())
                        {
                            int data = bluetoothInStream.ReadByte();
                            if (data >= 0)
                            {
                                LogByte((byte)data);
                                responseList.Add((byte)data);
                                startTime = Stopwatch.GetTimestamp();
                            }
                        }
                        if (responseList.Count >= customData.Length + versionRespLen)
                        {
                            LogString("Custom adapter length");
                            bool validEcho = !customData.Where((t, i) => responseList[i] != t).Any();
                            if (!validEcho)
                            {
                                LogString("*** Echo incorrect");
                                break;
                            }
                            byte checkSum = 0x00;
                            for (int i = 0; i < versionRespLen - 1; i++)
                            {
                                checkSum += responseList[i + customData.Length];
                            }
                            if (checkSum != responseList[customData.Length + versionRespLen - 1])
                            {
                                LogString("*** Checksum incorrect");
                                break;
                            }
                            int adapterTypeId   = responseList[customData.Length + 5] + (responseList[customData.Length + 4] << 8);
                            int fwVersion       = responseList[customData.Length + 7] + (responseList[customData.Length + 6] << 8);
                            int fwUpdateVersion = PicBootloader.GetFirmwareVersion((uint)adapterTypeId);
                            if (fwUpdateVersion >= 0 && fwUpdateVersion > fwVersion)
                            {
                                LogString("Custom adapter with old firmware detected");
                                return(AdapterType.CustomUpdate);
                            }
                            LogString("Custom adapter detected");
                            return(AdapterType.Custom);
                        }
                        if (Stopwatch.GetTimestamp() - startTime > ResponseTimeout * TickResolMs)
                        {
                            if (responseList.Count >= customData.Length)
                            {
                                bool validEcho = !customData.Where((t, i) => responseList[i] != t).Any();
                                if (validEcho)
                                {
                                    LogString("Valid echo detected");
                                    adapterType = AdapterType.EchoOnly;
                                }
                            }
                            break;
                        }
                    }
                }

                // ELM327
                bool elmReports21 = false;
                for (int i = 0; i < 2; i++)
                {
                    bluetoothInStream.Flush();
                    while (bluetoothInStream.IsDataAvailable())
                    {
                        bluetoothInStream.ReadByte();
                    }
                    byte[] sendData = Encoding.UTF8.GetBytes("ATI\r");
                    LogData(sendData, 0, sendData.Length, "Send");
                    bluetoothOutStream.Write(sendData, 0, sendData.Length);

                    string response = GetElm327Reponse(bluetoothInStream);
                    if (response != null)
                    {
                        if (response.Contains("ELM327"))
                        {
                            LogString("ELM327 detected");
                            if (response.Contains("ELM327 v2.1"))
                            {
                                LogString("Version 2.1 detected");
                                elmReports21 = true;
                            }
                            adapterType = AdapterType.Elm327;
                            break;
                        }
                    }
                }
                if (adapterType == AdapterType.Elm327)
                {
                    foreach (string command in EdBluetoothInterface.Elm327InitCommands)
                    {
                        bluetoothInStream.Flush();
                        while (bluetoothInStream.IsDataAvailable())
                        {
                            bluetoothInStream.ReadByte();
                        }
                        byte[] sendData = Encoding.UTF8.GetBytes(command + "\r");
                        LogData(sendData, 0, sendData.Length, "Send");
                        bluetoothOutStream.Write(sendData, 0, sendData.Length);

                        string response = GetElm327Reponse(bluetoothInStream);
                        if (response == null)
                        {
                            LogString("*** No ELM response");
                            adapterType = AdapterType.Elm327Invalid;
                            break;
                        }
                        if (!response.Contains("OK\r"))
                        {
                            LogString("*** No ELM OK found");
                            adapterType = AdapterType.Elm327Invalid;
                            break;
                        }
                    }
                    if (adapterType == AdapterType.Elm327Invalid && elmReports21)
                    {
                        adapterType = AdapterType.Elm327Fake21;
                    }
                }
            }
            catch (Exception)
            {
                return(AdapterType.Unknown);
            }
            return(adapterType);
        }
Пример #33
0
 public void SetAdapterType(AdapterType adpType)
 {
     m_adapterType = adpType;
 }
Пример #34
0
 public static void DoSomething(this AdapterType obj)
 {
 }
Пример #35
0
 private void Win32_NetworkAdapter_Init()
 {
     this._adapterType = GetPropStr(_mo, "AdapterType");
     this._adapterTypeID = (AdapterType)GetPropShort(_mo, "AdapterTypeID");
     this._caption = GetPropStr(_mo, "Captioin");
     this._description = GetPropStr(_mo, "Description");
     this._deviceID = GetPropStr(_mo, "DeviceID");
     this._index = GetPropInt(_mo, "Index");
     this._installed = GetPropBool(_mo, "Installed");
     this._mACAddress = GetPropStr(_mo, "MACAddress");
     this._manufacturer = GetPropStr(_mo, "Manufacturer");
     this._name = GetPropStr(_mo, "Name");
     this._netConnectionID = GetPropStr(_mo, "NetConnectionID");
     this._netConnectionStatus = (NetConnectionStatusType)GetPropShort(_mo, "NetConnectionStatus");
     this._networkAddresses = GetPropStrs(_mo, "NetworkAddresses");
     this._permanentAddress = GetPropStr(_mo, "PermanentAddress");
     this._pNPDeviceID = GetPropStr(_mo, "PNPDeviceID");
     this._productName = GetPropStr(_mo, "ProductName");
     this._serviceName = GetPropStr(_mo, "ServiceName");
     this._speed = GetPropInt64(_mo, "Speed");
     this._status = GetPropStr(_mo, "Status");
 }
Пример #36
0
        // Static Methods      

        /// <summary>
        /// Loads <see cref="Adapter"/> IDs as an <see cref="IList{T}"/>.
        /// </summary>        
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="adapterType"><see cref="AdapterType"/> collection to be returned.</param>      
        /// <param name="sortMember">The field to sort by.</param>
        /// <param name="sortDirection"><c>ASC</c> or <c>DESC</c> for ascending or descending respectively.</param>  
        /// <returns>Collection of <see cref="Int32"/>.</returns>
        public static IList<int> LoadIDs(AdoDataConnection database, AdapterType adapterType, string sortMember, string sortDirection)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string viewName;

                if (adapterType == AdapterType.Action)
                    viewName = "CustomActionAdapterDetail";
                else if (adapterType == AdapterType.Input)
                    viewName = "CustomInputAdapterDetail";
                else
                    viewName = "CustomOutputAdapterDetail";

                IList<int> adapterList = new List<int>();
                string sortClause = string.Empty;
                DataTable adapterTable;
                string query;

                if (!string.IsNullOrEmpty(sortMember) || !string.IsNullOrEmpty(sortDirection))
                    sortClause = string.Format("ORDER BY {0} {1}", sortMember, sortDirection);

                query = database.ParameterizedQueryString(string.Format("SELECT ID FROM {0} WHERE NodeID = {{0}} {1}", viewName, sortClause), "nodeID");

                adapterTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, database.CurrentNodeID());

                foreach (DataRow row in adapterTable.Rows)
                {
                    adapterList.Add(row.ConvertField<int>("ID"));
                }

                return adapterList;
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Пример #37
0
 public AdapterEventArgs(bool present, AdapterType type)
 {
     this._present = present;
     this._type = type;
 }
 public static IAdapter GetAdapter(AdapterType claimType, int tid)
 {
 }
Пример #39
0
 public void SetAdapterType(AdapterType adpType)
 {
     TypeOfAdapter = adpType;
 }
Пример #40
0
        public void LoadRegistrySettings()
        {
            // Fetch adapter types from TrionicCANLib.API
            cbxAdapterType.Items.Clear();

            foreach (var AdapterType in Enum.GetValues(typeof(CANBusAdapter)))
            {
                try
                {
                    cbxAdapterType.Items.Add(((DescriptionAttribute)AdapterType.GetType().GetField(AdapterType.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false)[0]).Description.ToString());
                }

                catch (Exception ex)
                {
                    logger.Debug(ex.Message);
                }
            }

            RegistryKey SoftwareKey     = Registry.CurrentUser.CreateSubKey("Software");
            RegistryKey ManufacturerKey = SoftwareKey.CreateSubKey("MattiasC");

            using (RegistryKey Settings = ManufacturerKey.CreateSubKey("TrionicCANFlasher"))
            {
                if (Settings != null)
                {
                    string[] vals = Settings.GetValueNames();
                    foreach (string a in vals)
                    {
                        try
                        {
                            if (a == "AdapterType")
                            {
                                AdapterType.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "Adapter")
                            {
                                Adapter.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "ComSpeed")
                            {
                                Baudrate.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "ECU")
                            {
                                SelectedECU.Name = Settings.GetValue(a).ToString();
                            }

                            else if (a == "EnableLogging")
                            {
                                m_enablelog = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "OnboardFlasher")
                            {
                                m_onbflash = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "OnlyPBus")
                            {
                                m_onlypbus = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "UseLegionBootloader")
                            {
                                m_uselegion = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "PowerUser")
                            {
                                m_poweruser = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "FormatSystemPartitions")
                            {
                                m_unlocksys = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "FormatBootPartition")
                            {
                                m_unlckboot = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "AutoChecksum")
                            {
                                m_autocsum = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "SuperUser")
                            {
                                m_enablesufeatures = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "UseLastAddressPointer")
                            {
                                m_uselastpointer = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "ViewRemember")
                            {
                                m_remember = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewWidth")
                            {
                                m_width = Convert.ToInt32(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewHeight")
                            {
                                m_height = Convert.ToInt32(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewFullscreen")
                            {
                                m_fullscreen = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewCollapsed")
                            {
                                m_collapsed = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                        }

                        catch (Exception ex)
                        {
                            logger.Debug(ex.Message);
                        }
                    }
                }
            }

            try
            {
                if (AdapterType.Name != null)
                {
                    cbxAdapterType.SelectedItem = AdapterType.Name;
                    AdapterType.Index           = cbxAdapterType.SelectedIndex;
                }

                if (Adapter.Name != null)
                {
                    cbxAdapterItem.SelectedItem = Adapter.Name;
                    Adapter.Index = cbxAdapterItem.SelectedIndex;
                }

                if (Baudrate.Name != null)
                {
                    cbxComSpeed.SelectedItem = Baudrate.Name;
                    Baudrate.Index           = cbxComSpeed.SelectedIndex;
                }
            }

            catch (Exception ex)
            {
                logger.Debug(ex.Message);
            }

            /////////////////////////////////////////////
            // Recover from strange settings in registry

            // Make sure settings are returned to safe values in case power user is not enabled
            if (!m_poweruser)
            {
                m_unlocksys = false;
                m_unlckboot = false;
                m_autocsum  = false;

                m_enablesufeatures = false;
            }

            // We have to plan this section..
            if (!m_enablesufeatures)
            {
                m_verifychecksum      = true;
                m_uselastpointer      = true;
                m_faster              = false;
                InterframeDelay.Index = 9;
            }

            // Maybe we should have different unlock sys for ME9 and T8?
            if (!m_unlocksys)
            {
                m_unlckboot = false;
            }

            if ((m_fullscreen && m_collapsed) || !m_remember)
            {
                m_collapsed  = false;
                m_fullscreen = false;
            }
        }
Пример #41
0
 public AdapterEventArgs(bool present, AdapterType type)
 {
     this._present = present;
     this._type    = type;
 }