コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: JMCNAM/StarWarsChallenge
        public void Main_Returns_List_Of_Starships()
        {
            var p   = new ProcessClass();
            var res = p.ComputeStarshipResupply(0);

            Assert.AreEqual(res.GetType(), new Dictionary <Starship, string>().GetType());
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: r2d2m/NIOS
 public void InitializeSession(Session session)
 {
     this.session = session;
     Console      = new ConsoleClass(session);
     Environment  = new EnvironmentClass(session);
     Path         = new PathClass(session);
     File         = new FileClass(session);
     Directory    = new DirectoryClass(session);
     Thread       = new ThreadClass(session);
     Process      = new ProcessClass(session);
 }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: JMCNAM/StarWarsChallenge
        public void Main_Assigns_Distance_To_Ships()
        {
            var p = new ProcessClass();

            var res  = p.ComputeStarshipResupply(1000000);
            var val1 = res.Where(x => x.Key.name == "Y-wing").ToList();
            var val2 = res.Where(x => x.Key.name == "Millennium Falcon").ToList();
            var val3 = res.Where(x => x.Key.name == "Rebel transport").ToList();

            Assert.AreEqual(val1[0].Value, "74");
            Assert.AreEqual(val2[0].Value, "9");
            Assert.AreEqual(val3[0].Value, "11");
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var processClass = new ProcessClass();

            processClass.MessageDelayed += ProcessClass_MessageDelayed1;

            string line            = string.Empty;
            var    outputStringDic = new Dictionary <int, string>();

Input:
            line = Console.ReadLine();

            if (line != string.Empty)
            {
                if (!line.Contains(':'))
                {
                    Console.WriteLine("Invalid entry... Your entry should be in the following format string:number");
                }
                else
                {
                    var splitArray = line.Split(':');
                    if (splitArray.Length == 2)
                    {
                        if (!string.IsNullOrEmpty(splitArray[1]))
                        {
                            var iTemp = 0;

                            if (int.TryParse(splitArray[1].Trim(), out iTemp))
                            {
                                outputStringDic.Add(iTemp, splitArray[0].Trim());
                            }
                            else
                            {
                                Console.WriteLine("Invalid entry : " + splitArray[1].Trim());
                            }
                        }
                    }
                    goto Input;
                }
            }
            else
            {
                foreach (var delayMessage in outputStringDic)
                {
                    Task.Run(() => processClass.EchoDelayed(delayMessage.Value, delayMessage.Key));
                }
            }

            Console.ReadKey();
        }
コード例 #5
0
        public void GetData()
        {
            List <Process> listProcesses = Process.GetProcesses(".").ToList();

            foreach (var item in listProcesses)
            {
                ProcessClass pc = new ProcessClass();
                pc.id          = item.Id;
                pc.name        = item.ProcessName;
                pc.threadcount = item.Threads.Count;
                pc.memory      = item.WorkingSet64;
                processClasses.Add(pc);
            }

            ListViewTaskManager.ItemsSource = processClasses;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: JMCNAM/StarWarsChallenge
        public static void Main(string[] args)
        {
            ProcessClass p = new ProcessClass();

            Console.WriteLine("| - StarWars Code Challenge - |\n" +
                              "\nEnter a integer distance in Mega-Lightyears: ");
            var distance = Convert.ToInt32(Console.ReadLine());
            var res      = p.ComputeStarshipResupply(distance);

            if (res != null)
            {
                Console.WriteLine("\n| {0, -30} | {1, 14} |", "Ship Name", "Num Resupplies");
                foreach (var ship in res)
                {
                    Console.WriteLine("| {0, -30} | {1, 14} |", ship.Key.name, ship.Value);
                }
            }
            else
            {
                Console.WriteLine("ERROR : Result was null.");
            }
            Console.ReadKey();
        }
コード例 #7
0
 internal void Navigate(ViewType viewType, ProcessClass selectedProcess)
 {
     _navigationModel.Navigate(viewType, selectedProcess);
 }
コード例 #8
0
        private static void CommandPAS(int props, Image bmp, string url, Process currentProcess)
        {
            string ProccesName = currentProcess.ProcessName;
            string WindowTitle = currentProcess.MainWindowTitle;
            string MachineName = Environment.MachineName;
            string UserName    = Environment.UserName;
            string idFile;
            string selfFile;


            switch (props)
            {
            case 1:
                using (var hc = new HttpClient())
                {
                    ProcessClass pas = new ProcessClass();
                    Type         tl  = new Type();
                    tl.href = "http://localhost/rest/type/node/process_and_screen";
                    Links l = new Links();
                    l.type     = tl;
                    pas._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "process_and_screen"
                    });
                    pas.type = t2;
                    List <Title> title = new List <Title>();
                    title.Add(new Title()
                    {
                        value = currentProcess.ProcessName
                    });
                    pas.title = title;
                    List <FieldType> type = new List <FieldType>();
                    type.Add(new FieldType()
                    {
                        value = "url"
                    });
                    pas.field_type = type;
                    List <FieldActiveWindow> activeWindows = new List <FieldActiveWindow>();
                    activeWindows.Add(new FieldActiveWindow()
                    {
                        value = currentProcess.MainWindowTitle
                    });
                    pas.field_active_window = activeWindows;
                    List <FieldMachine> fieldMachines = new List <FieldMachine>();
                    fieldMachines.Add(new FieldMachine()
                    {
                        value = machineId
                    });
                    pas.field_machine = fieldMachines;
                    List <FieldUrl> fieldUrl = new List <FieldUrl>();
                    fieldUrl.Add(new FieldUrl()
                    {
                        value = url
                    });
                    pas.field_url = fieldUrl;
                    var pasJson   = JsonConvert.SerializeObject(pas);
                    var data      = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var response = hc.PostAsync(path + "/node?_format=json", data).Result.Content.ReadAsStringAsync().Result;
                }
                break;

            case 2:
                using (var hc = new HttpClient())
                {
                    ProcessClass pas = new ProcessClass();
                    Type         tl  = new Type();
                    tl.href = "http://localhost/rest/type/node/process_and_screen";
                    Links l = new Links();
                    l.type     = tl;
                    pas._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "process_and_screen"
                    });
                    pas.type = t2;
                    List <Title> title = new List <Title>();
                    title.Add(new Title()
                    {
                        value = currentProcess.ProcessName
                    });
                    pas.title = title;
                    List <FieldType> type = new List <FieldType>();
                    type.Add(new FieldType()
                    {
                        value = "process"
                    });
                    pas.field_type = type;
                    List <FieldActiveWindow> activeWindows = new List <FieldActiveWindow>();
                    activeWindows.Add(new FieldActiveWindow()
                    {
                        value = currentProcess.MainWindowTitle
                    });
                    pas.field_active_window = activeWindows;
                    List <FieldMachine> fieldMachines = new List <FieldMachine>();
                    fieldMachines.Add(new FieldMachine()
                    {
                        value = machineId
                    });
                    pas.field_machine = fieldMachines;
                    var pasJson   = JsonConvert.SerializeObject(pas);
                    var data      = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var response = hc.PostAsync(path + "/node?_format=hal_json", data).Result.Content.ReadAsStringAsync().Result;
                }
                break;

            case 3:
                using (var hc = new HttpClient())
                {
                    FileClass file = new FileClass();
                    Type      tl   = new Type();
                    tl.href = "http://localhost/rest/type/file/image";
                    Links l = new Links();
                    l.type      = tl;
                    file._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "file"
                    });
                    file.type = t2;
                    List <Filename> filename = new List <Filename>();
                    filename.Add(new Filename()
                    {
                        value = currentProcess.ProcessName + "-" + machineId + ".png"
                    });
                    file.filename = filename;
                    List <Filemime> filemime = new List <Filemime>();
                    filemime.Add(new Filemime()
                    {
                        value = @"image/png"
                    });
                    file.filemime = filemime;
                    List <Data> data = new List <Data>();
                    data.Add(new Data()
                    {
                        value = Convert.ToBase64String(ImageToByte(bmp))
                    });
                    file.data = data;
                    List <Uri> uri = new List <Uri>();
                    uri.Add(new Uri()
                    {
                        value = "public://image.png"
                    });
                    file.uri = uri;
                    var pasJson   = JsonConvert.SerializeObject(file);
                    var datam     = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var          response = hc.PostAsync(path + "/entity/file?_format=hal_json", datam).Result.Content.ReadAsStringAsync().Result;
                    ResFileClass ResJson  = JsonConvert.DeserializeObject <ResFileClass>(response);
                    selfFile = ResJson._links.self.href;
                    idFile   = ResJson.uuid[0].value;
                }
                using (var hc = new HttpClient())
                {
                    ScreenClass pas = new ScreenClass();
                    Type        tl  = new Type();
                    tl.href = "http://localhost/rest/type/node/process_and_screen";
                    Links l = new Links();
                    l.type = tl;
                    List <FieldImageUrl> urlFile = new List <FieldImageUrl>();
                    urlFile.Add(new FieldImageUrl()
                    {
                        href = selfFile
                    });
                    l.url      = urlFile;
                    pas._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "process_and_screen"
                    });
                    pas.type = t2;
                    List <Title> title = new List <Title>();
                    title.Add(new Title()
                    {
                        value = currentProcess.ProcessName
                    });
                    pas.title = title;
                    List <FieldType> type = new List <FieldType>();
                    type.Add(new FieldType()
                    {
                        value = "screenshot"
                    });
                    pas.field_type = type;
                    List <FieldActiveWindow> activeWindows = new List <FieldActiveWindow>();
                    activeWindows.Add(new FieldActiveWindow()
                    {
                        value = currentProcess.MainWindowTitle
                    });
                    pas.field_active_window = activeWindows;
                    List <FieldMachine> fieldMachines = new List <FieldMachine>();
                    fieldMachines.Add(new FieldMachine()
                    {
                        value = machineId
                    });
                    pas.field_machine = fieldMachines;
                    List <FieldUrl> fieldUrl = new List <FieldUrl>();
                    fieldUrl.Add(new FieldUrl()
                    {
                        value = url
                    });
                    pas.field_url = fieldUrl;
                    Self3 s3 = new Self3();
                    s3.href = selfFile;
                    Type3 t3 = new Type3();
                    t3.href = "http://localhost/rest/type/file/image";
                    Links3 l3 = new Links3();
                    l3.self = s3;
                    l3.type = t3;
                    List <Uuid3> uuid = new List <Uuid3>();
                    uuid.Add(new Uuid3()
                    {
                        value = idFile
                    });
                    List <NodeFileImage> nfi = new List <NodeFileImage>();
                    nfi.Add(new NodeFileImage()
                    {
                        _links = l3, uuid = uuid, display = "1", description = "", alt = "", title = ""
                    });
                    Embedded e = new Embedded();
                    e.url         = nfi;
                    pas._embedded = e;
                    var pasJson   = JsonConvert.SerializeObject(pas);
                    var data      = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var response = hc.PostAsync(path + "/node?_format=hal_json", data).Result.Content.ReadAsStringAsync().Result;
                }
                break;

            case 4:
                using (var hc = new HttpClient())
                {
                    FileClass file = new FileClass();
                    Type      tl   = new Type();
                    tl.href = "http://localhost/rest/type/file/image";
                    Links l = new Links();
                    l.type      = tl;
                    file._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "file"
                    });
                    file.type = t2;
                    List <Filename> filename = new List <Filename>();
                    filename.Add(new Filename()
                    {
                        value = currentProcess.ProcessName + "-" + machineId + ".png"
                    });
                    file.filename = filename;
                    List <Filemime> filemime = new List <Filemime>();
                    filemime.Add(new Filemime()
                    {
                        value = @"image/png"
                    });
                    file.filemime = filemime;
                    List <Data> data = new List <Data>();
                    data.Add(new Data()
                    {
                        value = Convert.ToBase64String(ImageToByte(bmp))
                    });
                    file.data = data;
                    List <Uri> uri = new List <Uri>();
                    uri.Add(new Uri()
                    {
                        value = "public://image.png"
                    });
                    file.uri = uri;
                    var pasJson   = JsonConvert.SerializeObject(file);
                    var datam     = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var          response = hc.PostAsync(path + "/entity/file?_format=hal_json", datam).Result.Content.ReadAsStringAsync().Result;
                    ResFileClass ResJson  = JsonConvert.DeserializeObject <ResFileClass>(response);
                    selfFile = ResJson._links.self.href;
                    idFile   = ResJson.uuid[0].value;
                }
                using (var hc = new HttpClient())
                {
                    ScreenClass pas = new ScreenClass();
                    Type        tl  = new Type();
                    tl.href = "http://localhost/rest/type/node/process_and_screen";
                    Links l = new Links();
                    l.type = tl;
                    List <FieldImageUrl> urlFile = new List <FieldImageUrl>();
                    urlFile.Add(new FieldImageUrl()
                    {
                        href = selfFile
                    });
                    l.url      = urlFile;
                    pas._links = l;
                    List <Type2> t2 = new List <Type2>();
                    t2.Add(new Type2()
                    {
                        target_id = "process_and_screen"
                    });
                    pas.type = t2;
                    List <Title> title = new List <Title>();
                    title.Add(new Title()
                    {
                        value = currentProcess.ProcessName
                    });
                    pas.title = title;
                    List <FieldType> type = new List <FieldType>();
                    type.Add(new FieldType()
                    {
                        value = "screenshot"
                    });
                    pas.field_type = type;
                    List <FieldActiveWindow> activeWindows = new List <FieldActiveWindow>();
                    activeWindows.Add(new FieldActiveWindow()
                    {
                        value = currentProcess.MainWindowTitle
                    });
                    pas.field_active_window = activeWindows;
                    List <FieldMachine> fieldMachines = new List <FieldMachine>();
                    fieldMachines.Add(new FieldMachine()
                    {
                        value = machineId
                    });
                    pas.field_machine = fieldMachines;
                    Self3 s3 = new Self3();
                    s3.href = selfFile;
                    Type3 t3 = new Type3();
                    t3.href = "http://localhost/rest/type/file/image";
                    Links3 l3 = new Links3();
                    l3.self = s3;
                    l3.type = t3;
                    List <Uuid3> uuid = new List <Uuid3>();
                    uuid.Add(new Uuid3()
                    {
                        value = idFile
                    });
                    List <NodeFileImage> nfi = new List <NodeFileImage>();
                    nfi.Add(new NodeFileImage()
                    {
                        _links = l3, uuid = uuid, display = "1", description = "", alt = "", title = ""
                    });
                    Embedded e = new Embedded();
                    e.url         = nfi;
                    pas._embedded = e;
                    var pasJson   = JsonConvert.SerializeObject(pas);
                    var data      = new StringContent(pasJson, Encoding.UTF8, "application/hal+json");
                    var authToken = Encoding.ASCII.GetBytes($"{name}:{pass}");
                    hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                           Convert.ToBase64String(authToken));
                    var response = hc.PostAsync(path + "/node?_format=hal_json", data).Result.Content.ReadAsStringAsync().Result;
                }
                break;
            }
        }