示例#1
0
        /// <summary>
        /// Self Populating Constructor
        /// </summary>
        /// <param name="args">args From the Program.cs</param>
        /// <param name="logger">Logger to Log things.</param>
        /// <param name="printComments">Should the comments from the settings.ini be printed?</param>
        public UXDevSettings(string[] args, Logger.Logger logger, bool printComments = false)
        {
            // read all the settings
            string[] settingsFile =
                File.ReadAllLines(args.Length != 0
                    ? args[0]
                // ReSharper disable once AssignNullToNotNullAttribute
                    : Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().FullName), "settings.ini"));

            // local dictionary
            Dictionary<string, string> settings = new Dictionary<string, string>();

            // print out the settings file
            foreach (string line in settingsFile)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    if (!line.StartsWith("#"))
                    {
                        string[] vals = line.Split('=');

                        logger.WriteLine(string.Format("\t- {0} => {1}", vals[0], vals[1]));
                        settings.Add(vals[0].ToLower(), vals[1]);
                    }
                    else
                    {
                        if( printComments )
                            logger.WriteLine(line);
                    }
                }
            }

            // create additional spacing
            logger.NewLine();

            // Populate properties from the settings.ini
            AuthType = (MFAuthType)Enum.Parse(typeof(MFAuthType), settings.TryGetValueEx("AuthType"));
            AutoExitApp = bool.Parse(settings.TryGetValueEx("AutoExitApp"));
            DirectoryToZip = settings.TryGetValueEx( "DirectoryToZip" );
            Domain = settings.TryGetValueEx( "Domain" );
            GenerateAutoInstallReg = bool.Parse( settings.TryGetValueEx( "GenerateAutoInstallReg" ));
            KillExplorerWindows = bool.Parse( settings.TryGetValueEx( "KillExplorerWindows" ));
            LocalComputerName = settings.TryGetValueEx( "LocalComputerName" );
            LocalVaultPath = settings.TryGetValueEx( "LocalVaultPath" );
            OpenVault = bool.Parse( settings.TryGetValueEx( "OpenVault" ));
            Outputname = settings.TryGetValueEx( "Outputname" );
            Password = settings.TryGetValueEx( "Password" );
            Port = settings.TryGetValueEx( "Port" );
            ProtocolSequence = settings.TryGetValueEx( "ProtocolSequence" );
            RestartVault = bool.Parse( settings.TryGetValueEx( "RestartVault" ));
            ServerAddress = settings.TryGetValueEx( "ServerAddress" );
            Username = settings.TryGetValueEx( "Username" );
            VaultGuid = settings.TryGetValueEx( "VaultGuid" );

            // Get the path to the appdef.xml
            AppDefPath = Directory.GetFiles(DirectoryToZip, "appdef.xml", SearchOption.AllDirectories).FirstOrDefault();
            // Deserialize the AppDef
            DeserializeAppDef(AppDefPath);
        }
示例#2
0
        /// <summary>
        /// Do everything necessary for actually running the scan.
        /// </summary>
        /// <param name="__scnmScan">The defenition of the scantype that will be used to tell the stage how to scan.</param>
        private void PrepnRunScan(Scanmode __scnmScan)
        {
            // Check if the stage is definitely ready.
            if (m_Stage.IsInitialized)
            {
                // Move the stage to the starting position.
                this.m_Stage.MoveAbs(System.Convert.ToDouble(this.txtbxSetInitX.Text), System.Convert.ToDouble(this.txtbxSetInitY.Text), 0.0);

                // Wait for the stage to settle.
                Thread.Sleep(2000);

                // Make sure the Stop button works.
                this.btnStop.Enabled = true;

                // Prepare the stage control task for writing as many samples as necessary to complete the scan.
                // Note that the second parameter is only there for compatibility with other hardware implementations,
                // IT IS NOT used for the PIDigitalStage!!!!
                // The first parameter defines the table rate of the DigitalStage.
                this.m_Stage.Configure(System.Convert.ToDouble(this.txtbxSetTimePPixel.Text), 1);

                // Debug Writing of coordinates to File.
                string _sLogFile = Logger.GetNewLogFilename("SIS Position Log");
                Logger m_logPositionLogger = new Logger(_sLogFile);
                m_logPositionLogger.WriteLine(LogType.Info, "New scan started\r\n----------------------");
                m_logPositionLogger.WriteLine(LogType.Info, "Axes: " + __scnmScan.ScanAxes.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "ImageWidthPx: " + __scnmScan.ImageWidthPx.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "ImageHeightPx: " + __scnmScan.ImageHeightPx.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "ImageDepthPx: " + __scnmScan.ImageDepthPx.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "XScanSizeNm: " + __scnmScan.XScanSizeNm.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "YScanSizeNm: " + __scnmScan.YScanSizeNm.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "ZScanSizeNm: " + __scnmScan.ZScanSizeNm.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "InitX: " + __scnmScan.InitialX.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "InitY: " + __scnmScan.InitialY.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "InitZ: " + __scnmScan.InitialZ.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "XAmp: " + __scnmScan.XAmplitude.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "YAmp: " + __scnmScan.YAmplitude.ToString());
                m_logPositionLogger.WriteLine(LogType.Info, "ZAmp: " + __scnmScan.ZAmplitude.ToString());

                // Run the actual measurement in a separate thread to the UI thread. This will prevent the UI from blocking and it will
                // enable continuous updates of the UI with scan data.
                bckgwrkPerformScan.RunWorkerAsync(__scnmScan);
            }

            // Update the UI.
            UpdateUI();
        }
示例#3
0
		/// <summary>
		/// Simple test of some ParseUtil methods.
		/// </summary>
		/// <returns>bool - true for all passed, false otherwise</returns>
		public static bool TestSelf()
		{
			Logger log = new Logger("ParseUtil: TestSelf");
			log.Info("Starting...");

			StreamTokenizer tokenizer = new StreamTokenizer();
			tokenizer.Verbosity = VerbosityLevel.Warn;

			// FindMatch
			ArrayList alist = new ArrayList();
			tokenizer.TokenizeString("{ [ ] '}' }", alist);
			foreach(Token t in alist) log.Debug("Token = {0}", t);

			Token[] tarray = (Token[])alist.ToArray(typeof(Token));
			int i = 0;
			if (!FindMatch(tarray, ref i, '{'))
			{
				log.Error("FindMatch failed to match { char");
				return(false);
			}

			if (i != 4)
			{
				log.Error("FindMatch got the wrong answer {0}", i);
				return(false);
			}
			else log.Info("FindMatch worked.");

			//
			// try BuildArray
			//
			ArrayList tokens = new ArrayList();
			tokenizer.TokenizeString("1 2 3 4 5", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			Int16[] shorts = (short[])ParseUtil.BuildArray(tokens, ref i, typeof(Int16), null,
				-1, log);
		
			if (shorts == null) 
			{
				log.Error("Unable to BuildArray of shorts.");
				return(false);
			}

			log.Info("Parsed shorts:");
			foreach(Int16 s in shorts)
			{
				log.Write("{0}, ", s);
			}
			log.WriteLine("");

			//
			// try BuildArray of floats, char terminated
			//
			tokens.Clear();
			tokenizer.TokenizeString("1 2 ; 3 4", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			Single[] floats = (float[])ParseUtil.BuildArray(tokens, ref i, typeof(Single), 
				new CharToken(';'), -1, log);
		
			if (floats == null) 
			{
				log.Error("Unable to BuildArray of floats.");
				return(false);
			}

			log.Info("Parsed floats:");
			foreach(float f in floats)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (i != 2)
			{
				log.Error("BuildArray left i = {0} which is incorrect");
				return(false);
			}

			//
			// try BuildArray on high-precision floats
			//
			tokens.Clear();
			float f1 = 1.23456f;
			float f2 = 2.34567f;
			tokenizer.TokenizeString(String.Format("{0:f6} {1:f6}", f1,f2), tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			floats = (float[])ParseUtil.BuildArray(tokens, ref i, typeof(Single), 
				null, -1, log);
		
			if (floats == null) 
			{
				log.Error("Unable to BuildArray of floats.");
				return(false);
			}

			log.Info("Parsed floats:");
			foreach(float f in floats)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (floats[0] != f1)
			{
				log.Error("BuildArray produced float {0:f6} instead of {1:f6}",
					floats[0], f1);
				return(false);
			}

			//
			// try BuildArray of chars, maxLength terminated
			//
			log.Info("Chars, terminated by maxLength");
			tokens.Clear();
			tokenizer.TokenizeString("12 2 ; 3 4", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			char[] chars = (char[])ParseUtil.BuildArray(tokens, ref i, typeof(Char), 
				null, 3, log);
		
			if (chars == null) 
			{
				log.Error("Unable to BuildArray of chars.");
				return(false);
			}

			log.Info("Parsed chars:");
			foreach(char f in chars)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (i != 4)
			{
				log.Error("BuildArray left i = {0} which is incorrect", i);
				return(false);
			}

			//
			// try BuildArray of hex numbers
			//
			log.Info("Hex numbers");
			tokens.Clear();
			tokenizer.Settings.ParseHexNumbers = true;
			tokenizer.TokenizeString("0xfff, 0xffe", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			ushort[] ushorts = (ushort[])ParseUtil.BuildArray(tokens, ref i, typeof(ushort), 
				null, 3, log);
		
			if (ushorts == null) 
			{
				log.Error("Unable to BuildArray of ushorts.");
				return(false);
			}

			log.Info("Parsed ushorts:");
			foreach(ushort us in ushorts)
			{
				log.Write("{0}, ", us);
			}
			log.WriteLine("");

//			if (i != 4)
//			{
//				log.Error("BuildArray left i = {0} which is incorrect", i);
//				return(false);
//			}

			log.Info("All PASSED");
			return(true);
		}
        public void WriteLineSucceeds()
        {
            // Arrange
            var message = "{0}{1}";
            var arg0 = "42";
            var arg1 = "arbitrary-string";

            var loggerImpl = Mock.Create<LoggerImpl>();
            Mock.Arrange(() => loggerImpl.WriteLine(Arg.Is<string>(message), Arg.Is<string>(arg0), Arg.Is<string>(arg1)))
                .IgnoreInstance()
                .OccursOnce();

            // Act
            var sut = new Logger();
            sut.WriteLine(message, arg0, arg1);

            // Assert
            Mock.Assert(loggerImpl);
        }
        public void WriteLineWithEmptyStringThrowsContractException()
        {
            // Arrange
            var message = string.Empty;
            var arg0 = default(object);
            var arg1 = default(object);

            // Act
            var sut = new Logger();
            sut.WriteLine(message, arg0, arg1);

            // Assert
            // N/A
        }
示例#6
0
文件: Flow.cs 项目: kyuhojeong/brunet
		public Flow(ref byte[] header, ref byte[] msg, Logger logger) {
		   ofp_version = header[0];
		   type = (ofp_type) header[1];
		   length = byte_reorder16(header, 2);
		   xid = byte_reorder32(header, 4);

		   wildcards = 0;
		   logger.WriteLine("-----------------------------------------------FLOW--------------------------------------------------------");
		   logger.WriteLine("FLOW ofp_header version:{0} type:{1} length:{2} xid:{3}", ofp_version, type, length, xid);

		   switch(type) {
		      case ofp_type.OFPT_HELLO:
		         logger.WriteLine("-----------------------------------------------------------------------------------------------------------");
		         return;
		      case ofp_type.OFPT_ERROR:
		         ofp_error_t = (ofp_error_type) byte_reorder16(msg, 0);
		         ofp_error_code = byte_reorder16(msg, 2);
		         logger.WriteLine("FLOW OFPT_ERROR | type:{0} code:{1} ", ofp_error_t, ofp_error_code);
		         logger.WriteLine("-----------------------------------------------------------------------------------------------------------");
		         return;
		      case ofp_type.OFPT_ECHO_REQUEST:
		         logger.WriteLine("-----------------------------------------------------------------------------------------------------------");
		         return;
				case ofp_type.OFPT_PACKET_IN:
		         buffer_id = byte_reorder32(msg, 0);
		         total_len = byte_reorder16(msg, 4);
		         in_port = (ofp_port) byte_reorder16(msg, 6);
		         reason = (ofp_packet_in_reason) msg[8];
		         logger.WriteLine("buffer_id:{0:x} total_len:{1} in_port:{2} reason:{3}", buffer_id, total_len, in_port, reason);
		         logger.WriteLine("");

		         // Link Layer
		         l2_offset = 10;
		         Array.Copy(msg, l2_offset, dl_dst, 0, OFP_ETH_ALEN);
		         Array.Copy(msg, l2_offset+OFP_ETH_ALEN, dl_src, 0, OFP_ETH_ALEN);

		         //802.11Q and VLAN tag is not yet implemented 
		         if (byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN) == (uint16_t) Eth_type.ETH_TYPE_VLAN ) {
		            dl_vlan = (uint16_t) (BitConverter.ToUInt16(msg, l2_offset+2*OFP_ETH_ALEN+2) & 0x0fff);
		            dl_vlan_pcp = (uint8_t) (BitConverter.ToUInt16(msg, l2_offset+2*OFP_ETH_ALEN+2) >> 13);
		            eth_type = (Eth_type) byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN+4);
		            l3_offset = l2_offset+2*OFP_ETH_ALEN+6;
		         } else {
		            eth_type = (Eth_type) byte_reorder16(msg, l2_offset+2*OFP_ETH_ALEN);
		            l3_offset = l2_offset+2*OFP_ETH_ALEN+2;
		         }
		         logger.WriteLine("dl_src:{0:X} dl_dst:{1:X}", BitConverter.ToString(dl_src), BitConverter.ToString(dl_dst));
		         logger.WriteLine("eth_type:{0}", eth_type);
		         switch (eth_type) {
		            case Eth_type.ETH_TYPE_RARP:
		               break;
		            case Eth_type.ETH_TYPE_ARP:
		               this.wildcards = ofp_flow_wildcards.OFPFW_TP_SRC | ofp_flow_wildcards.OFPFW_TP_DST | ofp_flow_wildcards.OFPFW_DL_VLAN | ofp_flow_wildcards.OFPFW_DL_VLAN_PCP;
		               if ( byte_reorder16(msg, l3_offset) == 1 && 
									byte_reorder16(msg, l3_offset+2)  == (uint16_t) Eth_type.ETH_TYPE_IP && 
									msg[l3_offset+4] == OFP_ETH_ALEN && 
									msg[l3_offset+5] == 4 && 
									byte_reorder16(msg, l3_offset+6) <= 0xff) { //referred to flow.c flow_extract
		                  nw_proto = byte_reorder16(msg, l3_offset+6);
		                  //nw_src = new IPAddress(byte_reorder32(msg, l3_offset+14));
		                  //nw_dst = new IPAddress(byte_reorder32(msg, l3_offset+24));
		                  //nw_src = new IPAddress(msg.Skip(l3_offset+14).Take(4).ToArray());
		                  //nw_dst = new IPAddress(msg.Skip(l3_offset+24).Take(4).ToArray());
								nw_src = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+14));
								nw_dst = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+24));

		                  Array.Copy(msg, l3_offset+8, arp_sha, 0, OFP_ETH_ALEN);
		                  Array.Copy(msg, l3_offset+18, arp_tha, 0, OFP_ETH_ALEN);
		               }
		               logger.WriteLine("nw_proto:{0:X} nw_src:{1:X} nw_dst:{2:X} arp_sha:{3:X} arp_tha", nw_proto, nw_src, nw_dst, arp_sha, arp_tha);
		               break;
						case Eth_type.ETH_TYPE_IP:
		               this.wildcards = ofp_flow_wildcards.OFPFW_DL_VLAN | ofp_flow_wildcards.OFPFW_DL_VLAN_PCP;

		               //Extract_IP_ETH_HEADER(ref msg);
		               ipv4_version = (byte) (msg[l3_offset] >> 4);
		               ihl = (byte) (msg[l3_offset] & 0x0f);
							nw_tos = (byte) (msg[l3_offset+1] >> 2); 
		               total_length = byte_reorder16(msg, l3_offset+2);
		               nw_proto = msg[l3_offset+9];

		               //TCP/UDP
		               //nw_src = new IPAddress(byte_reorder32(msg, l3_offset+12));
		               //nw_dst = new IPAddress(byte_reorder32(msg, l3_offset+16));
		               //nw_src = new IPAddress(msg.Skip(l3_offset+12).Take(4));
		               //nw_dst = new IPAddress(msg.Skip(l3_offset+16).Take(4));
		               nw_src = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+12));
		               nw_dst = new IPAddress(BitConverter.ToUInt32(msg, l3_offset+16));
					
		               logger.WriteLine("version:{0} ihl:{1}", ipv4_version, ihl);
		               logger.WriteLine("nw_tos(Type of Service):{0} total_length:{1} protocol:{2}", nw_tos, total_length, nw_proto);
		               if (ihl > 5) {
		                  l4_offset = l3_offset + 24;
		               } else {
		                  l4_offset = l3_offset + 20;
		               }
		               logger.WriteLine("l3_offset:{0}, l4_offset:{1}", l3_offset, l4_offset);
		               tp_src = byte_reorder16(msg, l4_offset);
		               tp_dst = byte_reorder16(msg, l4_offset+2);

		               logger.WriteLine("protocol:{0:X} ", nw_proto);
		               logger.WriteLine("nw_src:{0} nw_dst:{1} tp_src:{2} tp_dst:{3}", nw_src.ToString(), nw_dst.ToString(), tp_src, tp_dst);
		               break;
		            case Eth_type.ETH_TYPE_IPV6:
		               logger.WriteLine("Eth_type.ETH_TYPE_IPV6:");
		               break;
						case (Eth_type) 44:
		               logger.WriteLine("ethernet type 44 0x2c ipv6 framenet ");
							break;
						
		            default:
		               logger.WriteLine("FATAL: UNKNOWN ETHERNET HEADER TYPE");
		               Environment.Exit(1);
		               break;
		         }
		         break;
		      default:
		         logger.WriteLine("Unknown packet from switch");
		         Environment.Exit(1);
		         break;

		   }
		   logger.WriteLine("-----------------------------------------------------------------------------------------------------------");
		}