Пример #1
0
        public bool AddOrChangeTagInfo(string tagId, string holderName, bool isEnabled)
        {
            bool changesMade = false;

            // Find tagId if present
            for (int i = 0; i < numValidTags; i++)
            {
                TagInfo ti = validTagInfos[i];
                if (tagId.Trim() == ti.mTagId)
                {
                    if (ti.mHolderName != holderName)
                    {
                        ti.mHolderName = holderName.Trim();
                        changesMade = true;
                    }
                    if (ti.mIsEnabled != isEnabled)
                    {
                        ti.mIsEnabled = isEnabled;
                        changesMade = true;
                    }
                    return changesMade;
                }
            }

            // Not found so add tag to db
            TagInfo tagInfo = new TagInfo(tagId.Trim(), holderName, isEnabled);
            validTagInfos[numValidTags] = tagInfo;
            numValidTags++;
            changesMade = true;

            return changesMade;
        }
Пример #2
0
        private void ReadValidTags()
        {
            // Set to zero tags
            numValidTags = 0;

            // Open tags file
            try
            {
                using (StreamReader sr = new StreamReader(mDbFullPath))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length < 0)
                            continue;

                        // Store tag data
                        string[] lineSplit = line.Split(new char [] {'\t'});
                        if (lineSplit.Length == 0)
                            continue;

                        string tagId = lineSplit[0].Trim();
                        string holderName = "";
                        bool isEnabled = true;
                        if (lineSplit.Length > 1)
                            holderName = lineSplit[1].Trim();
                        if (lineSplit.Length > 2)
                            isEnabled = (lineSplit[2][0] == 'E');
                        TagInfo tagInfo = new TagInfo(tagId, holderName, isEnabled);
                        validTagInfos[numValidTags] = tagInfo;

                        // Next tag
                        numValidTags++;
                        if (numValidTags >= MAX_TAGS)
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Print("Opening: " + mDbFullPath + " Exception: " + e.ToString());
            }
               // validTagIds[numValidTags++] = "42F770DA000000";
        }
Пример #3
0
        /// <summary>
        /// Handles the CommandReceived event.
        /// </summary>
        private static void server_CommandReceived(object source, WebCommandEventArgs e)
        {
            try
            {
                timeOfLastWebCommandRx = DateTime.Now;

                if (e.Command.CommandString != "status")
                    Debug.Print("Command received:" + e.Command.CommandString);

                // Check for home page
                bool bReturnStatus = false;
                if (e.Command.CommandString == "")
                {
                    e.ReturnString = Resources.GetString(Resources.StringResources.index);
                }
                else if ((e.Command.CommandString == "setup") || (e.Command.CommandString == "setup.html"))
                {
                    e.ReturnString = Resources.GetString(Resources.StringResources.setup);
                }
                else if (e.Command.CommandString == "status")
                {
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "addtag")
                {
                    TagInfo tagInfo = new TagInfo();
                    tagInfo.FromWebSerialized(e.Command.Arguments[0].ToString());
                    rfidTagDb.AddTagToDb(tagInfo.mTagId, tagInfo.mHolderName, tagInfo.mIsEnabled);
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "testtag")
                {
                    TagInfo tagInfo = new TagInfo();
                    tagInfo.FromWebSerialized(e.Command.Arguments[0].ToString());
                    testTagId = tagInfo.mTagId;
                    testTimer = DateTime.Now;
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "main-unlock")
                {
                    mainDoorStrike.Unlock(settingsDb.mainManualTimeout);
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "main-lock")
                {
                    mainDoorStrike.Lock();
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "inner-unlock")
                {
                    innerDoorStrike.Unlock(settingsDb.innerManualTimeout);
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "inner-lock")
                {
                    innerDoorStrike.Lock();
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "submit-settings")
                {
                    settingsDb.FromWebSerialized(e.Command.Arguments[0].ToString());
                    settingsDb.WriteValuesToFile();
                    Debug.Print("Submit settings " + e.Command.Arguments[0].ToString());
                    bReturnStatus = true;
                }
                else if (e.Command.CommandString == "get-settings")
                {
                    e.ReturnString = settingsDb.ToWebSerialized();
                }
                else if (e.Command.CommandString == "get-tags")
                {
                    e.ReturnString = rfidTagDb.ToWebHTML();
                }
                else if (e.Command.CommandString == "get-events")
                {
                    e.ReturnString = eventLogger.ToWebHTML(20, true);
                }
                else if (e.Command.CommandString == "get-debug")
                {
                    e.ReturnString = eventLogger.ToWebHTML(20, false);
                }

                if (e.ReturnString == null)
                    e.ReturnString = "";

                // Handle commands that require status to be returned
                if (bReturnStatus)
                {
                    e.ReturnString += GetStatusString();
                }

                if (e.ReturnString == "")
                {
                    e.ReturnString = "<html><body></body></html>";
                }

            }
            catch (Exception excp)
            {
                Debug.Print("Exception in server_CommandReceived " + excp.Message);
            }
        }