コード例 #1
0
        public override string ReadLine()
        {
            string line = Readline.ReadLine(currentPrompt);

            if (++lineCount > 0)
            {
                currentPrompt = emptyPrompt;
            }

            return(line);
        }
コード例 #2
0
 private static void Main(string[] args)
 {
     while (true)
     {
         var line = Readline.ReadLine("REPL> ");
         if (line == null)
         {
             break;
         }
         Console.WriteLine(Rep(line));
     }
 }
コード例 #3
0
ファイル: Step2Eval.cs プロジェクト: TimofonicJunkRoom/mal
 // ReSharper disable once UnusedParameter.Local
 private static void Main(string[] args)
 {
     while (true)
     {
         var line = Readline.ReadLine("REPL> ");
         if (line == null)
         {
             break;
         }
         try
         {
             Console.WriteLine(Rep(line));
         }
         catch (Exception e)
         {
             Console.WriteLine("ERROR: " + e.Message);
         }
     }
 }
コード例 #4
0
        static void Main(string[] args)
        {
            try
            {
                if (args == null || args.Length <= 0)
                {
                    ILog log = new FileLog();
                    log.Log("The agrument is null");
                }
                else
                {
                    string fileName = string.Empty;

                    IGetFileName getFileName = new FileName();
                    fileName = getFileName.GetFileName(args[0]);

                    List <Name> nameList = new List <Name>();
                    IReadLine   readline = new Readline();
                    nameList = readline.ReadLine(fileName);

                    List <Name> sortedNameList = new List <Name>();
                    ISortName   sortName       = new SortName();
                    sortedNameList = sortName.Sort(nameList);

                    IPrintName printName = new PrintName();
                    printName.PrintNameToScreen(sortedNameList);

                    IWriteNameToFile writeNameToFile = new WriteNameToFile();
                    writeNameToFile.WriteName(sortedNameList);

                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(ex.Message);
                ILog log = new FileLog();
                log.Log("The file could not be read:" + ex);
            }
        }
コード例 #5
0
        private static void PlayWithStrings()  // examples on using strings also for the first lab on padding columns
		{
			 string hoursString = "10";

             From String -------------------------------------------------------------------------------------------------------------------------
             int hours = Int32.Parse(hoursString);                     //takes the string and gives the int equivalent (Parse)
             int hours;
             bool result = Int32.TryParse(hoursString, out hours);    // safer version to use. It returns if it failed. Returns a boolean value
              it is required for (out) to before the word hours in C# using TryParse
             bool result = Int32.TryParse(hoursString, out int hours);  // int is a local declartion


              To String-------------------------------------------------------------------------------------------------------------------------------
             hoursString = hours.ToString();                 // work on any expression
             4.75.ToString(); converts double to a string
             475.ToString(); converts double to a string                   // converts anything these to a string
             Console.Readline.ToString(); converts double to a string

             string message = "Hello\tworld";
             string filePath = "C:\\Temp\\Test";

             Verbatim strings   eliminates the need for the extra Slash like the above statements when calling a file
             string filePath = @ "C:\Temp\Test";

              Concat adds two string together
             string firstName = "Bob";
             string lastName = "Smith";
             string name = firstName + " " + lastName;

              string can not be changed once they are set

             String are immutable - this produces a new string
             name = "Hello" + name;
             Console.WriteLine("Hello " + name);                         // approach 1
             Console.WriteLine("Hello {0} {1}", firstName, lastName);    // apporach 2 the zero is a replacement just like an array. Called string formatting
             string str = String.Format("Hello {0}", name);              // apporach 3
             Console.WriteLine(str);

              Approach 4
             Console.WriteLine($"Hello {firstName} {lastName}");         // $ is crital its an interpeted string   string fullName = $"{firstName} {lastName}"
                                                                          going forward use this type of string(Interpeted string) *****************************************

              Null vs Empty-------------------------------------------------------------------------------
             string missing = null;      // c++ and c# nulls are not the same.... Null in C# means i have a value                                    
             string empty = "";
             string empty2 = String.Empty;       // predefinded value which its string is empty---- used for langues that dont use strings

             every expression has a to string

              checking for empty strings---------------------------------------------------------
              if (firstName.Length == 0)            
             if (missing != null && firstName != "")            // returns a boolean result

             if (!String.IsNullOrEmpty(firstName))       // this is the perfered waay ************************************************************
                 Console.WriteLine(firstName);

              if (firstName.Lenght == 0)
              if (firstName == " ")
              if (firstName ==  string.Empty)

              Other Stuff -------------------------------------------------------------------
             string upperName = firstName.ToUpper();         // changes to uppercase letters    
             string lowerName = firstName.ToLower();         // changes to lowercase letters

              Comparison---------------------------------------------------------------------
             bool areEqual = firstName == lastName;
             areEqual = firstName.ToLower() == lastName.ToLower();       // not the best solution. it will not always work
             areEqual = String.Compare(firstName, lastName, true) == 0;    // still case sensitive -- perfered way ******************************************************************

              fins a letter in a string-------------------------------------------------------------
             bool startsWithA = firstName.StartsWith("A");           // they are case sensitive
             bool endsWithA = firstName.EndsWith("A");
             bool hasA = firstName.IndexOf("A") >= 0;                // finds if there is an "A" somewhere in the string
             string subset = firstName.Substring(4);                 // returns everthing after the 4 character

              Clean up-------------------------------------------------------------------------
             string cleanMe = firstName.Trim();                  // removes all white space left and right of string----- also TrimStart, TrimEnd  will clean just the left or right
             string makeLonger = firstName.PadLeft(20); //PadRight         // adds white space to align columns of text----- building table or reciptes***********************
             

		}
コード例 #6
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated)
            {
                Error.WriteLine("a context is already opened: try to disconnect first");
                Error.WriteLine();
                return(CommandResultCode.ExecutionFailed);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            if (args.Current != "to")
            {
                return(CommandResultCode.SyntaxError);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string          address = args.Current;
            IServiceAddress serviceAddress;

            try {
                serviceAddress = ServiceAddresses.ParseString(address);
            } catch (Exception) {
                Error.WriteLine("Invalid service address specified: {0}", address);
                return(CommandResultCode.ExecutionFailed);
            }

            NetworkConfigSource configSource = new NetworkConfigSource();

            try {
                configSource.AddNetworkNode(serviceAddress);
            } catch (Exception e) {
                Error.WriteLine("The address '" + address + "' is invalid: " + e.Message);
                return(CommandResultCode.ExecutionFailed);
            }

            string protocol    = "tcp";
            string credentials = String.Empty;
            string format      = "binary";

            if (args.MoveNext())
            {
                if (args.Current == "identified")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (args.Current != "by")
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    credentials = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "on")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        protocol = args.Current;

                        if (args.MoveNext())
                        {
                            if (args.Current != "with")
                            {
                                return(CommandResultCode.SyntaxError);
                            }

                            format = args.Current;
                        }
                    }
                }
                else if (args.Current == "on")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    protocol = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "with")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        format = args.Current;
                    }
                }
                else if (args.Current == "with")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    format = args.Current;
                }
                else
                {
                    return(CommandResultCode.SyntaxError);
                }
            }

            IServiceConnector connector;

            if (protocol == "tcp")
            {
                if (String.IsNullOrEmpty(credentials))
                {
                    while (String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }
                    Out.WriteLine();
                }
                connector = new TcpServiceConnector(credentials);
            }
            else if (protocol == "http")
            {
                string userName = credentials;
                string password = null;
                int    index    = credentials.IndexOf(':');
                if (index != -1)
                {
                    password = credentials.Substring(index + 1);
                    userName = credentials.Substring(0, index);
                }

                if (String.IsNullOrEmpty(password))
                {
                    while (String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }

                    Out.WriteLine();
                }

                // TODO: connector = new HttpServiceConnector(userName, password);
                Out.WriteLine("Not supported yet.");
                return(CommandResultCode.ExecutionFailed);
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            IMessageSerializer serializer;

            if (format == "binary")
            {
                serializer = new BinaryRpcMessageSerializer();
            }
            else if (format == "xml")
            {
                //TODO: serializer = new XmlRpcMessageSerializer();
                return(CommandResultCode.ExecutionFailed);
            }
            else if (format == "json")
            {
                if (JsonRpcMessageSerializer == null)
                {
                    Error.WriteLine("JSON serializer was not installed.");
                    Error.WriteLine();
                    return(CommandResultCode.ExecutionFailed);
                }
                serializer = JsonRpcMessageSerializer;
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            connector.MessageSerializer = serializer;

            NetworkProfile networkProfile = new NetworkProfile(connector);

            networkProfile.Configuration = configSource;

            //TODO: test the connection is correct ...

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));

            Out.WriteLine("connected successfully to {0}", address);
            Out.WriteLine();

            return(CommandResultCode.Success);
        }