예제 #1
0
        private static void Main(string[] args)
        {
            var printer = new Printer.Printer();

            if (args.Length == 0)
            {
                printer.PrintLine("No input file path was specified.");
                Console.Read();
                return;
            }
            try
            {
                var filePath   = args[0].Trim();
                var reader     = new Reader.Reader();
                var cheeseList = reader.Load(filePath);

                printer.PrintLine("");
                printer.PrintLine(
                    "This application has been designed and implemented by Masoud ZehtabiOskuie as an assessment for Senior C# Developer role");
                var currentDate = Helper.GetDateTime('_', filePath, 1);

                var cheeseValidator = new CheeseValidator();
                var priceCalculationRulesContainer = new PriceCalculationRulesContainer();
                var priceResolversContainer        = new PriceResolversContainer();
                var priceCalculator = new PriceCalculator(cheeseValidator, priceCalculationRulesContainer,
                                                          priceResolversContainer);

                var daysManager  = new DaysManager(3000, currentDate);
                var storeManager = new StoreManager(priceCalculator, printer, daysManager)
                {
                    Cheeses = (List <ICheese>)cheeseList
                };
                storeManager.OpenStore();
            }
            catch (FileNotFoundException)
            {
                printer.PrintLine("File Does not exists. Please make sure that the path is correct.");
            }
            catch (XmlSchemaException)
            {
                printer.PrintLine("The XML files is not well format.");
            }
            catch (DateTimeFormatException dex)
            {
                printer.PrintLine(dex.Message);
            }
            Console.Read();
        }
예제 #2
0
        /// <summary>
        /// Returns Printer firmware version
        /// </summary>
        /// <param name="ipAddress">IP Address of the printer</param>
        /// <param name="productFamilies"><see cref=" ProductFamilies"/></param>
        /// <returns></returns>
        private string GetPrinterFirmwareVersion(IPAddress ipAddress, ProductFamilies productFamilies)
        {
            try
            {
                if (string.IsNullOrEmpty(_firmwareVersion))
                {
                    Printer.PrinterFamilies family  = (Printer.PrinterFamilies)Enum.Parse(typeof(Printer.PrinterFamilies), Enum <ProductFamilies> .Value(productFamilies));
                    Printer.Printer         printer = Printer.PrinterFactory.Create(family, ipAddress);

                    _firmwareVersion = printer.FirmwareVersion;
                }
            }
            catch (Exception ex)
            {
                _firmwareVersion = "Not Available";
                TraceFactory.Logger.Info("Unable to get Firmware version");
                TraceFactory.Logger.Debug("Exception details: {0}".FormatWith(ex.JoinAllErrorMessages()));
            }

            return(_firmwareVersion);
        }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            // create activity data
            IPConfigurationActivityData activityData = executionData.GetMetadata <IPConfigurationActivityData>();

            // Check if printer is accessible

            if (!(NetworkUtil.PingUntilTimeout(IPAddress.Parse(activityData.PrimaryWiredIPv4Address), TimeSpan.FromSeconds(20))) &&
                Utility.IsClientConfiguredWithServerIP(activityData.SecondDhcpServerIPAddress, activityData.LinuxServerIPAddress))
            {
                MessageBox.Show(string.Concat("Printer IP Address is not accessible or Client is not configured with Server IP Address.\n\n",
                                              "Make sure you have provided valid Printer IP Address and is accessible.\n",
                                              "Check if Client has acquired IPv4 Address from Secondary DHCP Server.\n",
                                              "Check if Client has acquired IPv4 Address from Linux Server."),
                                "IP Address Not Accessible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(new PluginExecutionResult(PluginResult.Failed, "Printer IP Address is not accessible or Client is not configured with Server IP Address."));
            }

            // Check if the required services are running on DHCP server
            if (!IsServicesRunning(activityData.PrimaryDhcpServerIPAddress, activityData.SecondDhcpServerIPAddress))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Services are not running on DHCP server."));
            }

            // create instance of ews adapter
            EwsWrapper.Instance().Create(activityData.ProductFamily, activityData.ProductName, activityData.PrimaryWiredIPv4Address, activityData.SitemapsVersion,
                                         BrowserModel.Firefox, EwsAdapterType.WebDriverAdapter);

            EwsWrapper.Instance().Start();


            EwsWrapper.Instance().WakeUpPrinter();
            EwsWrapper.Instance().SetAdvancedOptions();

            IPAddress secondaryAddress = null;

            if (IPAddress.TryParse(activityData.SecondaryWiredIPv4Address, out secondaryAddress))
            {
                EwsWrapper.Instance().ChangeDeviceAddress(secondaryAddress);
                EwsWrapper.Instance().SetAdvancedOptions();
            }

            if (IPAddress.TryParse(activityData.WirelessIPv4Address, out secondaryAddress))
            {
                EwsWrapper.Instance().ChangeDeviceAddress(secondaryAddress);
                EwsWrapper.Instance().SetAdvancedOptions();
            }

            EwsWrapper.Instance().ChangeDeviceAddress(activityData.PrimaryWiredIPv4Address);

            Printer.Printer printer = PrinterFactory.Create(activityData.ProductFamily, activityData.PrimaryWiredIPv4Address);

            try
            {
                activityData.PrimaryMacAddress = printer.MacAddress.Replace(":", string.Empty);
            }
            catch
            { }

            if (string.IsNullOrEmpty(activityData.PrimaryMacAddress))
            {
                TraceFactory.Logger.Info("Could not get the mac address for Secondary wired interface.");
                return(new PluginExecutionResult(PluginResult.Failed, "Could not get the mac address for Secondary wired interface."));
            }

            if (activityData.PrinterInterfaceType == CtcBase.Controls.InterfaceType.Single)
            {
                if (IPAddress.TryParse(activityData.SecondaryWiredIPv4Address, out secondaryAddress))
                {
                    try
                    {
                        printer = PrinterFactory.Create(activityData.ProductFamily, activityData.SecondaryWiredIPv4Address);
                        activityData.SecondaryMacAddress = printer.MacAddress;
                    }
                    catch { }

                    if (string.IsNullOrEmpty(activityData.SecondaryMacAddress))
                    {
                        TraceFactory.Logger.Info("Could not get the mac address for Secondary wired interface.");
                        return(new PluginExecutionResult(PluginResult.Failed, "Could not get the mac address for Secondary wired interface."));
                    }
                }

                if (IPAddress.TryParse(activityData.WirelessIPv4Address, out secondaryAddress))
                {
                    try
                    {
                        printer = PrinterFactory.Create(activityData.ProductFamily, activityData.WirelessIPv4Address);
                        activityData.WirelessMacAddress = printer.MacAddress;
                    }catch { }

                    if (string.IsNullOrEmpty(activityData.WirelessMacAddress))
                    {
                        TraceFactory.Logger.Info("Could not get the mac address for Secondary wired interface.");
                        return(new PluginExecutionResult(PluginResult.Failed, "Could not get the mac address for wireless interface."));
                    }
                }
            }

            DhcpApplicationServiceClient serviceFunction = DhcpApplicationServiceClient.Create(activityData.PrimaryDhcpServerIPAddress);

            activityData.DHCPScopeIPAddress        = serviceFunction.Channel.GetDhcpScopeIP(activityData.PrimaryDhcpServerIPAddress);
            activityData.ServerDNSPrimaryIPAddress = serviceFunction.Channel.GetPrimaryDnsServer(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);
            activityData.SecondaryDnsIPAddress     = serviceFunction.Channel.GetSecondaryDnsServer(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);
            activityData.ServerHostName            = serviceFunction.Channel.GetHostName(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);
            activityData.DomainName            = serviceFunction.Channel.GetDomainName(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);
            activityData.ServerRouterIPAddress = serviceFunction.Channel.GetRouterAddress(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);
            activityData.ServerDNSSuffix       = serviceFunction.Channel.GetDnsSuffix(activityData.PrimaryDhcpServerIPAddress, activityData.DHCPScopeIPAddress);

            string ipv6Scope = serviceFunction.Channel.GetIPv6Scope(activityData.PrimaryDhcpServerIPAddress);

            if (string.IsNullOrEmpty(ipv6Scope))
            {
                MessageBox.Show(string.Concat("Unable to fetch IPv6 Scope \n\n",
                                              "Check whether DHCP IPv6 Scope is configured on DHCP server."),
                                "IPv6 Scope Not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(new PluginExecutionResult(PluginResult.Failed, "Check whether DHCP IPv6 Scope is configured on DHCP server."));
            }

            activityData.DHCPScopeIPv6Address = serviceFunction.Channel.GetIPv6Scope(activityData.PrimaryDhcpServerIPAddress);

            // Fetch the VLAN details.
            GetVlanDetails(ref activityData);

            // Check if Switch VLAN details are fetched
            if (3 != activityData.VirtualLanDetails.Count)
            {
                MessageBox.Show(string.Concat("Unable to fetch Switch VLAN details\n\n",
                                              "Check whether Printer is connected to Network Switch.\n",
                                              "Switch should be configured with 3 network virtual LAN."),
                                "Network switch not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(new PluginExecutionResult(PluginResult.Failed, "Unable to fetch Switch VLAN details. Check whether Printer is connected to Network Switch. Switch should be configured with 3 network virtual LAN."));
            }

            // Router Details: Address, Id, IPv6 Addresses
            IRouter router = null;

            activityData.RouterAddress = ROUTER_IP_FORMAT.FormatWith(activityData.PrimaryWiredIPv4Address.Substring(0, activityData.PrimaryWiredIPv4Address.LastIndexOf(".", StringComparison.CurrentCultureIgnoreCase)));
            router = RouterFactory.Create(IPAddress.Parse(activityData.RouterAddress), ROUTER_USERNAME, ROUTER_PASSWORD);

            Dictionary <int, IPAddress> routerVlans = router.GetAvailableVirtualLans();

            activityData.RouterVlanId = routerVlans.Where(x => (null != x.Value) && (x.Value.IsInSameSubnet(IPAddress.Parse(activityData.RouterAddress)))).FirstOrDefault().Key;

            RouterVirtualLAN       routerVlan          = router.GetVirtualLanDetails(activityData.RouterVlanId);
            Collection <IPAddress> routerIPv6Addresses = router.GetIPv6Addresses(routerVlan.IPv6Details);

            activityData.RouterIPv6Addresses = new Collection <string>(routerIPv6Addresses.Select(x => x.ToString()).ToList());

            // Add source IP Address
            Utility.AddSourceIPAddress(activityData.PrimaryDhcpServerIPAddress, activityData.LinuxServerIPAddress);

            //create instance of SNMP wrapper
            SnmpWrapper.Instance().Create(activityData.PrimaryWiredIPv4Address);

            //create instance of Telnet wrapper
            TelnetWrapper.Instance().Create(activityData.PrimaryWiredIPv4Address);

            if (!ManageReservation(activityData))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Printer IP Address Reservation in DHCP Server for both DHCP and BOOTP: Failed"));
            }

            TraceFactory.Logger.Info("The Server Configured Value retrieved from the DHCP Server are as follows:");
            TraceFactory.Logger.Info("MacAddress:{0}, DNSPrimaryIP:{1}, HostName:{2}, RouterIP:{3}, DNSSuffix:{4}".FormatWith(activityData.PrimaryMacAddress, activityData.ServerDNSPrimaryIPAddress,
                                                                                                                              activityData.ServerHostName, activityData.ServerRouterIPAddress, activityData.ServerDNSSuffix));

            // assign the session id to activity id
            activityData.SessionId = executionData.SessionId;

            if (null == _ipConfigTests)
            {
                _ipConfigTests = new IPConfigurationTests(activityData);
            }

            foreach (int testNumber in activityData.SelectedTests)
            {
                try
                {
                    ApplicationFlowControl.Instance.CheckWait(LogPauseState, LogResumeState);
                    _ipConfigTests.RunTest(executionData, testNumber, activityData.PrimaryWiredIPv4Address, (ProductFamilies)Enum.Parse(typeof(ProductFamilies), activityData.ProductFamily));
                }
                catch (Exception generalException)
                {
                    TraceFactory.Logger.Info("Test {0} failed with error: {1}".FormatWith(testNumber, generalException.Message));
                }
            }

            EwsWrapper.Instance().Stop();

            return(new PluginExecutionResult(PluginResult.Passed));
        }