Example #1
0
        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (loaded)
            {
                return;
            }
            string url = "http://drugs.dxy.cn/api/v2/detail";

            switch (kind)
            {
            case "qa":

                break;

            case "disease":
                HttpRequestMessage    request  = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
                FormUrlEncodedContent postData = new FormUrlEncodedContent(
                    new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("id", id),
                    new KeyValuePair <string, string>("category", "4"),
                    new KeyValuePair <string, string>("u", ""),
                    new KeyValuePair <string, string>("mc", "0000000005e6b1d8ffffffff9c1fe4e0"),
                    new KeyValuePair <string, string>("page", "1"),
                    new KeyValuePair <string, string>("hardName", "ASUS_X002"),
                    new KeyValuePair <string, string>("ac", "d5424fa6-adff-4b0a-8917-4264daf4a348"),
                    new KeyValuePair <string, string>("bv", "2014"),
                    new KeyValuePair <string, string>("vc", "3.5"),
                    new KeyValuePair <string, string>("vs", "4.4.4")
                }
                    );
                request.Content = postData;
                HttpResponseMessage response = await c.SendAsync(request);

                string responseString = await response.Content.ReadAsStringAsync();

                com = JsonConvert.DeserializeObject <composite>(responseString);
                if (com.Success == "True")
                {
                    wb.NavigateToString(ConvertExtendedASCII(com.Data.Definition + com.Data.Therapy));
                    pwb.Header = com.Data.CnName;
                    com.Data.Components.ForEach(z =>
                    {
                        bindCom.Add(z);
                    });
                }
                else
                {
                }
                break;

            default:
                break;
            }
        }
Example #2
0
		/*
		public static bool ReadSecondary(string FileName, Circuit owner)
        {
			List<Circuit> CList;
			if(owner == null)
				CList = Program.Circuits;
			else
				CList = ((composite)owner).SubCircuits;
			
			
            StreamReader reader = new StreamReader(FileName); //reopen the file
            
            if (!StringReader.FindString("<secondary>", reader))
            {
                Console.WriteLine("INFO! No secondary channels were specified.");
                return true;
            }
			Console.WriteLine("\n   Reading secondary channels:");
			
            string line = "";
            string[] words, subwords;
            char[] delimiterChars = { ' ', '\t' };
            char[] subdel = { '.' };
            Channel ch; Circuit c;

            while ((line = reader.ReadLine()) != null) //parse to the end
            {
                line = line.Trim();
                if (line.StartsWith("<end>"))
                    break;
                if (line.StartsWith("#") || line.Length == 0)
                    continue;

                words = StringReader.TrimWords(line.Split(delimiterChars));

                if (words[0].StartsWith("#"))
                    continue;

                for (int i = 0; i < words.Length; i++)
                {
                    subwords = StringReader.TrimWords(words[i].Split(subdel));
                    if (subwords.Length != 2)
                    {
                        Console.WriteLine("FATAL! The format to describe secondary channel is: circuit1.channelA");
                        return false;
                    }

                    if (!Circuit.CheckCircuitChannel(subwords, ChannelType.Input, CList, out c, out ch))
                        return false;
                    ch.Priority = false;
                    Console.WriteLine("Channel {0} will not be needed to update circuit {1}.", words[i], subwords[1]);
                }

            }
			
			Console.WriteLine("---Secondary channels Read.");

            reader.Dispose();
            return true;
        }
		*/
		
		/*
        static bool ReadCustom(string TypeName, string CustomName)
        {
            //read a composite circuit descriptor

            StreamReader reader = new StreamReader(FileNameMain);
            Console.WriteLine("\n---CUSTOM CIRCUIT DESCRIPTION---");
			
            if (!StringReader.FindString("<customs>", reader)){
                Console.WriteLine("FATAL! Custom files block is missing.");
                return false;
            }
			
            string line = "";
            if (!StringReader.FindStringNoEnd(TypeName, reader, "<customs>", ref line, FileNameMain))
            {
                Console.WriteLine("FATAL! Input file for custom circuit type {0} is not specified.", TypeName);
                return false;
            }
            string[] words;
            char[] delimiterChars = { ' ', '\t' };

            words = StringReader.TrimWords(line.Split(delimiterChars)); //get the file where the description is stored
            if (words.Length < 2)
            {
                Console.WriteLine("FATAL! Input file for custom circuit {0} is not specified.", TypeName);
                return false;
            }

            if (!File.Exists(words[1])) // check if file exists
            {
                Console.WriteLine("FATAL! The input file for custom circuit ({0}) was not found.", words[1]);
                return false;
            }

            //create the custom
            SPICER.Network myCustom = new SPICER.Network(words[1], CustomName, mytimer.dt);
            Circuits.Add(myCustom);

            //call the input parser in the network
            if (!myCustom.Initialize())
                return false;


            Console.WriteLine("---------------DONE----------------\n");

            reader.Dispose();
            return true;
        }
*/
        //composites circuits reader

        public static bool ReadExternals(string FileName, composite myComp)
        {
            //read a composite circuit descriptor for externals ports

            StreamReader reader = new StreamReader(FileName);
            Console.WriteLine("\n   Reading external ports:");
            if (!StringReader.FindString("<externals>", reader))
            {
                Console.WriteLine("WARNING! Composite circuit does not have external connections?!.");
                return false;
            }
            string line = "";

            string[] words;
            char[] delimiterChars = { ' ', '\t' };
            int ip = 0, op = 0;

            while ((line = reader.ReadLine()) != null) //parse to the end
            {
                line = line.Trim();
				
				#region "check for comments/empty lines..."
                if (line.StartsWith("<end>"))
                    break;
                if (line.StartsWith("#") || line.Length == 0)
                    continue;

                words = StringReader.TrimWords(line.Split(delimiterChars));

                if (words[0].StartsWith("#"))
                    continue;
				#endregion
				
                if (words.Length < 2)
                {
                    Console.WriteLine("FATAL! External ports format is: input|output  name (true|false)");
                    return false;
                }

	
				if (words[0] == "input"){ //create an input port
                    Console.WriteLine("Input port named {0} was added", words[1]);
                    myComp.Input.Add(new Channel(words[1], null));
                    myComp.MetaInput.Add(new Channel(words[1], myComp)); //metainputs are owned by the container circuit: they are effectively outputs
					/*if (words.Length > 2){
						if (words[2] == "false"){
                            Console.WriteLine(" as secondary.");
                            myComp.Input[ip].Priority = false;
                            myComp.MetaInput[ip].Priority = false;
                        }
                    }
					else //if(words[2] == "true")
                        Console.WriteLine(" as primary.");
                    */

                    ip++;
                }
                if (words[0] == "output") //create an input port
                {
                    Console.WriteLine("Output port named {0} was added.", words[1]);
                    myComp.Output.Add(new Channel(words[1], myComp));
                    myComp.MetaOutput.Add(new Channel(words[1], myComp));
                    op++;
                }

            }
			Console.WriteLine("---External ports Read.");
            reader.Dispose();
            return true;
        }
Example #3
0
        public static bool ReadConnections(string FileName, composite myComp)
        {
            string[] words;
			string[] keys;
            string line;
            char[] delimiterChars = { ' ', '\t' };
			bool MetaIn, MetaOut;
			
            List<Circuit> CList = Program.Circuits;
            if (myComp != null)
                CList = myComp.SubCircuits;


            StreamReader reader = new StreamReader(FileName); //reopen the file
            Console.WriteLine("\n   Reading connection list:");
            if (!StringReader.FindString("<connections>", reader)){
                Console.WriteLine("FATAL! Connection list is missing.");
                return false;
            }

			//parse all the lines
            while ((line = reader.ReadLine()) != null)
            {
				line = line.Trim();
                words = StringReader.TrimWords(line.Split(delimiterChars)); //split with spaces and tabs
                
				#region "check for bad characters..."
                if (line.StartsWith("<end>"))
                    break;
                if (line.StartsWith("#") || line.Length == 0 || words.Length == 0)
                    continue;
                if (words[0].StartsWith("#"))
                    continue;
				
                if (words.Length < 2){
                    Console.WriteLine("FATAL! The format for connections is: circA.outX  circB.inY ...");
                    return false;
                }
				#endregion
				
                Circuit c1, c2;
                Channel v1, v2;
				
				#region "get the first circuit.channel"
				
				keys = StringReader.TrimWords(words[0].Split('.'));
				if (keys.Length != 2){
                    Console.WriteLine("FATAL! The format for connections is: circA.outX  circB.inY ...");
                    return false;
                }
				
                //SPECIAL CASE FOR COMPOSITE CIRCUIT CONNECTION TO EXTERNAL PORTS - INPUT
                if (keys[0] == "me" && myComp != null) {
					MetaIn = true;
                    if (!myComp.GetMetaChannel(keys[1], ChannelType.Input, out v1, true)){
                        Console.WriteLine("FATAL! Unable to find input port {0} in the composite circuit.", keys[1]);
                        return false;
                    }
					c1 = myComp;
					/*
                    v2.Signal = v1.Signal;
                    c2.Owner = myComp; //set the ownership so that this will be considered updatable according to this channel
                    Console.WriteLine("Input port {0} is connected to {1}.{2}.", words[1], words[2], words[3]);
                    continue;
                    */
                }
				else{ //get the first circuit.channel normally from the list
					MetaIn = false;
					if (!Circuit.CheckCircuitChannel(new string[] { keys[0], keys[1] },ChannelType.Output,CList, out c1, out v1))
						return false;
				}
				#endregion
				Console.WriteLine("Connecting {0}.{1} to: ",c1.Name,v1.Name);
				
				for(int i=1;i<words.Length;i++){ //parse the other words
					
					keys = StringReader.TrimWords(words[i].Split('.'));
					
					if (keys[0] == "me" && myComp != null){ //SPECIAL CASE FOR COMPOSITE CIRCUIT CONNECTION TO EXTERNAL PORTS - OUTPUT
						MetaOut = true;
						if (!myComp.GetMetaChannel(keys[1], ChannelType.Output, out v2, true)){
							Console.WriteLine("FATAL! Unable to find input port {0} in the composite circuit.", keys[1]);
							return false;
						}
						c2 = myComp;
					}
					else { //get the other circuit.channel normally from the list
						MetaOut = false;
					    if (!Circuit.CheckCircuitChannel(new string[] { keys[0], keys[1] },ChannelType.Input,CList, out c2, out v2))
							return false;
					}
					
					//perform the connection
					v2.Signal = v1.Signal; //put the signal of c1.v1 (the out) in the signal of c2.v2 (the input)
					if(MetaIn) //if the input was a metainput from composite, the receiver's channel becomes owned by the composite
						c2.Owner = myComp;
					Console.WriteLine("   {0}.{1}",c2.Name,v2.Name);
				}
				
				
				
				/*
				#region "SPECIAL CASES COMPOSITES - outputs"
                //SPECIAL CASE FOR COMPOSITE CIRCUIT CONNECTION TO EXTERNAL PORTS - OUTPUT
                if (words[2] == "me" && myComp != null)
                {
                    v2 = myComp.FindMetaOutput(words[3]);
                    if (v2 == null)
                    {
                        Console.WriteLine("FATAL! Unable to find output port {0} in the composite circuit.", words[3]);
                        return false;
                    }
                    if (!Circuit.CheckCircuitChannel(new string[] { words[0], words[1] }, ChannelType.Output, CList, out c1, out v1)) //find the first circuit
                        return false;

                    v2.Signal = v1.Signal; //take the subcircuit's channel.feed and give the ref to the metaoutput

                    Console.WriteLine("Output port {0} is connected to {1}.{2}.", words[3], words[0], words[1]);
                    continue;
                }
                #endregion

                if (!Circuit.CheckCircuitChannel(new string[] { words[0], words[1] }, ChannelType.Output, CList, out c1, out v1)) //find the first circuit
                    return false;
                if (!Circuit.CheckCircuitChannel(new string[] { words[2], words[3] }, ChannelType.Input, CList, out c2, out v2)) //find the second circuit
                    return false;


                if (!c2.Connect(v1, words[3]))
                {
                    Console.WriteLine("FATAL! Something went wrong during the connection: {0}", line);
                    return false;
                }
                */

            }

            Console.WriteLine("---Connections Read.");
            reader.Dispose();
            return true;
        }
Example #4
0
        protected override void AddTreeNode()
        {
            var lst = m_pgCnt.QryLectures();

            //build compsite struct
            var root = new composite();

            root.childs = new Dictionary <string, composite>();
            foreach (LectContent.LectRec rec in lst)
            {
                composite parent = root;
                composite child;
                var       path = new string[] { rec.auth, rec.target, rec.topic };
                //find topic node
                foreach (string name in path)
                {
                    if (parent.childs.ContainsKey(name))
                    {
                        child = parent.childs[name];
                    }
                    else
                    {
                        child = new composite()
                        {
                            name = name, childs = new Dictionary <string, composite>()
                        };
                        parent.childs.Add(name, child);
                    }
                    parent = child;
                }
                parent.childs.Add(rec.lect, new composite()
                {
                    key = rec.lect, name = rec.title
                });
            }

            //crt tree node
            var q = new Queue <object[]> ();

            q.Enqueue(new object[] { m_tree.Nodes, root });
            while (q.Count > 0)
            {
                var objs = q.Dequeue();
                TreeNodeCollection nodes  = (TreeNodeCollection)objs[0];
                composite          parent = (composite)objs[1];
                foreach (composite child in parent.childs.Values)
                {
                    var node = nodes.Add(child.name);
                    //node.Checked = false;
                    node.StateImageIndex = 0;
                    if (child.childs != null)
                    {
                        q.Enqueue(new object[] { node.Nodes, child });
                    }
                    else
                    {
                        //leaf
                        node.Tag = child.key;
                    }
                }
            }
        }