private static void Load(string path) { var xmlGrid = XDocument.Load(path); for (var I = 0; I < 12; I++) { for (var j = 0; j < 12; j++) { var xElms = (from el in xmlGrid.Elements("GridProduct").Elements("_" + I + "x" + j).Elements("rec") select el).ToList(); //var e = new Elm[xElms.Count]; foreach (var x in xElms) { var f = new Elm { X = byte.Parse(x.GetXElementValue("X")), Y = byte.Parse(x.GetXElementValue("Y")), Description = x.GetXElementValue("Description") }; try { var rgbtF = x.GetXElementValue("font").Split(','); f.Font = rgbtF.Length == 3 ? new SolidColorBrush(Color.FromRgb(byte.Parse(rgbtF[0]), byte.Parse(rgbtF[1]), byte.Parse(rgbtF[2]))) : new SolidColorBrush(Color.FromRgb(0, 0, 0)); } catch { f.Font = new SolidColorBrush(Color.FromRgb(0, 0, 0)); } try { var rgbt = x.GetXElementValue("background").Split(','); f.Background = rgbt.Length == 3 ? new SolidColorBrush(Color.FromRgb(byte.Parse(rgbt[0]), byte.Parse(rgbt[1]), byte.Parse(rgbt[2]))) : new SolidColorBrush(Color.FromRgb(0, 255, 255)); } catch { f.Background = new SolidColorBrush(Color.FromRgb(0, 255, 255)); } f.CustomerId = x.Element("customerId") != null ? Guid.Parse(x.GetXElementValue("customerId")) : Guid.Empty; if (f.CustomerId == Guid.Empty) { LogService.Log(TraceLevel.Warning, 3, "Ошибка сетки проверьте продукт = " + f.Description + "."); } Grid[I, j, f.X, f.Y] = f; } } } }
public static Elm[,] GridCurrencyPathGetPath(TypePay tp) { Initialize(); var r = new Elm[12, 12]; foreach (var elm in GridCurrencyPath) { if ((elm[0, 0] != null) && (elm[0, 0].Path == AppDomain.CurrentDomain.BaseDirectory + @"\Data\" + tp.Id + ".xml")) { r = elm; } } return(r); }
protected void Page_Load(object sender, EventArgs e) { string Apikey = "4a5075dbb713f58f60e3acf8f924fa41c9555287"; //"e9370cd124274b2dcd0cc7735ad912eb6be52f79"; string ApiUrl = "http://i.earthinfralanddevelopers.co.in/admin/nlp.ashx?apikey=" + Apikey + "&page=http://news.nationalgeographic.com/2017/04/jungle-dogs-peru-amazon-rare"; var ApiRequest = (HttpWebRequest)WebRequest.Create(ApiUrl); ApiRequest.Method = "GET"; ApiRequest.ContentType = "application/xml"; var webResponse = (HttpWebResponse)ApiRequest.GetResponse(); string KeyWordsAsString = string.Empty; using (StreamReader KayReader = new StreamReader(webResponse.GetResponseStream())) { KeyWordsAsString = KayReader.ReadToEnd(); KayReader.Close(); } System.Xml.Linq.XDocument KeyWordsAsXml; KeyWordsAsXml = System.Xml.Linq.XDocument.Parse(KeyWordsAsString); string keyList = string.Empty; foreach (XElement Elm in KeyWordsAsXml.Root.Elements()) { if (Elm.Name == "keywords") { foreach (XElement keys in Elm.Elements()) { try { keyList += keyList == string.Empty ? keys.Value.ToString() : "," + keys.Value.ToString(); } catch { continue; } } } } form1.InnerHtml = keyList; }
private double getPrice(Elm elm, DPar.DPar csDP, string priceStr) { double price = Lib.ToDouble(priceStr); foreach (var sec in csDP.dpar) { if (!sec.Key.ToString().Contains("UNIT_")) continue; switch (sec.Key) { case SType.UNIT_Weight: // kg -> tonn if (elm.weight == 0) return elm.volume * 7850; return elm.weight / 1000 * price; case SType.UNIT_Vol: // mm3 -> m3 return elm.volume / 1000 / 1000 / 1000 * price; case SType.UNIT_Length: return elm.length * price; case SType.UNIT_Qty: return price; } } return 0; }
private static void Load(string path) { var xmlGrid = XDocument.Load(path); for (var i = 0; i < 12; i++) { for (var j = 0; j < 12; j++) { var xElms = (from el in xmlGrid.Elements("GridStatistique_Region_et_Pays").Elements("_" + i + "x" + j).Elements("rec") select el).ToList(); foreach (var x in xElms) { var f = new Elm { X = byte.Parse(x.GetXElementValue("X")), Y = byte.Parse(x.GetXElementValue("Y")), NameCountry = x.GetXElementValue("NameCountry") }; var rgbt = x.GetXElementValue("background").Split(','); try { f.Background = new SolidColorBrush(Color.FromRgb(byte.Parse(rgbt[0]), byte.Parse(rgbt[1]), byte.Parse(rgbt[2]))); } catch { f.Background = new SolidColorBrush(Color.FromRgb(0, 255, 255)); } f.Font = x.GetXElementValue("font"); f.CustomerId = x.Element("customerId") != null?Guid.Parse(x.GetXElementValue("customerId")) : Guid.Empty; Grid[i, j, f.X, f.Y] = f; } } } }
/*fredrikhaglund/ChromeLauncher.cs * https://gist.github.com/fredrikhaglund/43aea7522f9e844d3e7b * * private const string ChromeAppKey = * @"\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"; * * private static string ChromeAppFileName * { * get * { * return (string)(Registry.GetValue("HKEY_LOCAL_MACHINE" + * ChromeAppKey, "", null) ?? * Registry.GetValue("HKEY_CURRENT_USER" + ChromeAppKey, * "", null)); * } * } * * public void OpenLinkChrome(string url) * { * string chromeAppFileName = ChromeAppFileName; * if (string.IsNullOrEmpty(chromeAppFileName)) * { * throw new Exception("Could not find chrome.exe!"); * } * Process.Start(chromeAppFileName, urlRegx(url)); * } */ #endregion string getUrl(ControlType controlType) { string urls = ""; try { //Process[] procsChrome = Process.GetProcessesByName("chrome"); Process[] procsBrowser = Process.GetProcessesByName(browsername); if (procsBrowser.Length <= 0) { // MessageBox.Show("Chrome is not running"); MessageBox.Show(browsername + " " + "is not the source running browser" + "\n" + "來源流覽器"); } else { foreach (Process proc in procsBrowser) { // the chrome process must have a window if (proc.MainWindowHandle == IntPtr.Zero) { continue; } // find the automation element AutomationElement elm = AutomationElement.FromHandle (proc.MainWindowHandle); //AutomationElement elmUrlBar = // elm.FindFirst(TreeScope.Descendants, // new PropertyCondition(AutomationElement.NameProperty, // "Address and search bar")); AutomationElementCollection elmUrlBar = elm.FindAll(TreeScope.Subtree, new PropertyCondition( AutomationElement.ControlTypeProperty, controlType));//https://social.msdn.microsoft.com/Forums/en-US/f9cb8d8a-ab6e-4551-8590-bda2c38a2994/retrieve-chrome-url-using-automation-element-in-c-application?forum=csharpgeneral /*要用Edit屬性才抓得到網址列,Text也不行 */ // if it can be found, get the value from the URL bar if (elmUrlBar != null) { int i = 0; int cnt = elmUrlBar.Count; nx : foreach (AutomationElement Elm in elmUrlBar) { try { i++; if (i > cnt) { break; } string vp = ((ValuePattern)Elm. GetCurrentPattern(ValuePattern.Pattern)). Current.Value as string; if (urls.IndexOf(vp) == -1) { urls += (vp + " "); } } catch (Exception) { goto nx; //throw; } } } } } } catch (Exception ex) { //textBox2.Text = ex.ToString(); MessageBox.Show(ex.ToString()); } return(urls); }
public DataSet MatchedCampaigns(string pageUrl, string bannerType, string country, string osType, int noOfAds, int maxConversions, string todaysConversions, string matchOrder, string targettingFilter, string LimitConversionsInQuery) { try { //bool combinationFlag = CheckCombination(bannerType, country, osType, todaysConversions, maxConversions, matchOrder, targettingFilter, LimitConversionsInQuery); //combinationFlag = false; //if (combinationFlag == true) //{ #region Get keywords from web page #region Setting page Url // pageUrl = "http://news.nationalgeographic.com/2017/04/jungle-dogs-peru-amazon-rare"; // pageUrl = "http://camp.earthinfralanddevelopers.co.in/test/test.html"; #endregion string Apikey = "4a5075dbb713f58f60e3acf8f924fa41c9555287"; //"e9370cd124274b2dcd0cc7735ad912eb6be52f79"; //string ApiUrl = "https://gateway-a.watsonplatform.net/calls/url/URLGetRankedKeywords?apikey=" + Apikey + "&url=" + pageUrl; // ibm api string ApiUrl = "http://i.earthinfralanddevelopers.co.in/admin/nlp.ashx?apikey=" + Apikey + "&page=" + pageUrl; var ApiRequest = (HttpWebRequest)WebRequest.Create(ApiUrl); ApiRequest.Method = "GET"; ApiRequest.ContentType = "application/xml"; var webResponse = (HttpWebResponse)ApiRequest.GetResponse(); string KeyWordsAsString = string.Empty; using (StreamReader KayReader = new StreamReader(webResponse.GetResponseStream())) { KeyWordsAsString = KayReader.ReadToEnd(); KayReader.Close(); } System.Xml.Linq.XDocument KeyWordsAsXml; KeyWordsAsXml = System.Xml.Linq.XDocument.Parse(KeyWordsAsString); string keyList = string.Empty; foreach (XElement Elm in KeyWordsAsXml.Root.Elements()) { if (Elm.Name == "keywords") { foreach (XElement keys in Elm.Elements()) { try { keyList += keyList == string.Empty ? keys.Value.ToString() : "," + keys.Value.ToString(); //if (keyList == string.Empty) // keyList = keys.Element("text").Value.ToString(); //else // keyList = keyList + "," + keys.Element("text").Value.ToString(); } catch { continue; } } } } DataSet dsReturnCampaigns = GetMatchedCampaigns(keyList, bannerType, country, osType, noOfAds, todaysConversions, matchOrder, targettingFilter, LimitConversionsInQuery); #endregion Get keywords from web page return(dsReturnCampaigns); //} //else //{ // if (noOfAds != 0) // { // #region Get Possible Combinations // string Query = "SELECT top(" + noOfAds + ") [campaign_id],[campaigin_name],[title],[discription],[url],[call_to_action],[action],[device_and_action],[stars],[cost],[sponsers_adv],[country_targeted],[Add_style_formate],[date],[icon_img],[vedio_url] FROM [dbo].[campaigns] where Add_style_formate='" + bannerType + "' and " + targettingFilter + " and (select status from dbo.campain_details where campain_id=campaigns.campaign_id)='Running' AND " + todaysConversions + " <= " + maxConversions + " ORDER BY NEWID() "; // SqlConnection con = new SqlConnection(strcon); // con.Open(); // SqlDataAdapter adp = new SqlDataAdapter(Query, con); // DataSet dsGetData = new System.Data.DataSet(); // adp.Fill(dsGetData); // con.Close(); // #endregion // if (bannerType == "Banner 1" || bannerType == "Banner 4") // { return null; } // else // { // if (dsGetData.Tables[0].Rows.Count > 0) // return dsGetData; // else // return null; // } // } else // { // return null; // } //} } catch (Exception sqe) { return(null); } }
public static Elm[,] Load(XmlDocEnum type, int payId = -1) { var g = new Elm[12, 12]; var xmlGrid = RepositoryXmlFile.Load(type, payId); var xId = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("id") select el).ToList(); var xX = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("X") select el).ToList(); var xY = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Y") select el).ToList(); var xCaption = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Caption") select el).ToList(); var xColor = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Color") select el).ToList(); var xImg = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Img") select el).ToList(); var xFunc = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Fun") select el).ToList(); var xForeground = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("foreground") select el).ToList(); for (var i = 0; i < xId.Count; i++) { var f = new Elm(RepositoryXmlFile.GetPathByType(type, payId), xX[i].Value.ToByte(), xY[i].Value.ToByte(), xCaption[i].Value, xFunc[i].Value); var argbtColor = xColor[i].Value.Split(','); var argbtForeground = xForeground.Count != xId.Count ? new[] { "255", "255", "255", "255" } : xForeground[i].Value.Split(','); if (argbtColor.Length == 0) { f.Background = null; } if (argbtColor.Length == 4) { f.Background = new SolidColorBrush(Color.FromArgb(byte.Parse(argbtColor[0]), byte.Parse(argbtColor[1]), byte.Parse(argbtColor[2]), byte.Parse(argbtColor[3]))); } if (argbtColor.Length == 3) { f.Background = new SolidColorBrush(Color.FromRgb(byte.Parse(argbtColor[0]), byte.Parse(argbtColor[1]), byte.Parse(argbtColor[2]))); } if (argbtForeground.Length == 0) { f.Foreground = null; } if (argbtForeground.Length == 4) { f.Foreground = new SolidColorBrush(Color.FromArgb(byte.Parse(argbtForeground[0]), byte.Parse(argbtForeground[1]), byte.Parse(argbtForeground[2]), byte.Parse(argbtForeground[3]))); } if (argbtForeground.Length == 3) { f.Foreground = new SolidColorBrush(Color.FromRgb(byte.Parse(argbtForeground[0]), byte.Parse(argbtForeground[1]), byte.Parse(argbtForeground[2]))); } var myImage3 = new Image(); var bi3 = new BitmapImage(); bi3.BeginInit(); bi3.UriSource = new Uri(xImg[i].Value, UriKind.Relative); bi3.EndInit(); myImage3.Stretch = Stretch.Fill; myImage3.Source = bi3; f.Img = myImage3; g[f.X, f.Y] = f; } return(g); }
public void Save(Elm el, int x, int y) { Grid[x, y, Convert.ToInt16(el.X), Convert.ToInt16(el.Y)] = el; var solid = (el.Background as SolidColorBrush); var colorText = solid != null ? solid.Color.R + "," + solid.Color.G + "," + solid.Color.B : "255,0,0"; var doc = XDocument.Load(Path); XElement target; try { target = doc.Elements("GridStatistique_Region_et_Pays").Elements("_" + x + "x" + y).Elements("rec").Single( e => (e.GetXElementValue("X") == el.X.ToString()) & (e.GetXElementValue("Y") == el.Y.ToString())); } catch { target = null; } if (target != null) { var d = target.Nodes().ToArray(); var dateUpd = (d[1] as XElement); var nameCountry = (d[4] as XElement); var background = (d[5] as XElement); var font = (d[7] as XElement); if (d.Length > 8) { var customerId = (d[8] as XElement); customerId.Value = el.CustomerId.ToString(); } else { target.Add(new XElement("customerId", el.CustomerId)); } dateUpd.Value = DateTime.Now.ToString(Config.DateFormat); nameCountry.Value = el.NameCountry; background.Value = colorText; font.Value = el.Font; } else { var e = doc.GetXElement("GridStatistique_Region_et_Pays", "_" + x + "x" + y); if (e != null) { e.Add( new XElement("rec", new XElement("id", (el.X * el.Y).ToString()), new XElement("Date_upd", DateTime.Now.ToString(Config.DateFormat)), new XElement("X", el.X), new XElement("Y", el.Y), new XElement("NameCountry", el.NameCountry), new XElement("background", colorText), new XElement("img", el.Img), new XElement("font", el.Font), new XElement("customerId", el.CustomerId))); } else { doc.GetXElement("GridStatistique_Region_et_Pays").Add( new XElement("_" + x + "x" + y, new XElement("rec", new XElement("id", (el.X * el.Y).ToString()), new XElement("Date_upd", DateTime.Now.ToString(Config.DateFormat)), new XElement("X", el.X), new XElement("Y", el.Y), new XElement("NameCountry", el.NameCountry), new XElement("background", colorText), new XElement("img", el.Img), new XElement("font", el.Font), new XElement("customerId", el.CustomerId)))); } } doc.Save(Path); }
public void Save(Elm el, int x, int y) { Grid[x, y, Convert.ToInt16(el.X), Convert.ToInt16(el.Y)] = el; var solid = (el.Background as SolidColorBrush); var solid2 = (el.Font as SolidColorBrush); var colorText = solid != null ? solid.Color.R + "," + solid.Color.G + "," + solid.Color.B : "255,0,0"; var colorFontText = solid2 != null ? solid2.Color.R + "," + solid2.Color.G + "," + solid2.Color.B : "255,0,0"; var doc = XDocument.Load(Path); XElement target; try { target = doc.Elements("GridProduct") .Elements("_" + x + "x" + y) .Elements("rec") .SingleOrDefault(e => (e.GetXElementValue("X") == el.X.ToString()) & (e.GetXElementValue("Y") == el.Y.ToString())); } catch { target = null; } if (target != null) { var d = target.Nodes().ToArray(); var dateUpd = (d[1] as XElement); var description = (d[4] as XElement); var background = (d[5] as XElement); var font = (d[7] as XElement); if (d.Length > 8) { var customerId = d[8] as XElement; customerId.Value = el.CustomerId.ToString(); } else { target.Add(new XElement("customerId", el.CustomerId)); } dateUpd.Value = DateTime.Now.ToString(Config.DateFormat); description.Value = el.Description; background.Value = colorText; font.Value = colorFontText; } else { var e = doc.Element("GridProduct").Element("_" + x + "x" + y); if (e != null) { e.Add(new XElement("rec", new XElement("id", (el.X * el.Y).ToString()), new XElement("Date_upd", DateTime.Now.ToString(Config.DateFormat)), new XElement("X", el.X), new XElement("Y", el.Y), new XElement("Description", el.Description), new XElement("background", colorText), new XElement("img", el.Img), new XElement("font", el.Font), new XElement("customerId", el.CustomerId))); } else { doc.GetXElement("GridProduct").Add(new XElement("_" + x + "x" + y, new XElement("rec", new XElement("id", (el.X * el.Y).ToString()), new XElement("Date_upd", DateTime.Now.ToString(Config.DateFormat)), new XElement("X", el.X), new XElement("Y", el.Y), new XElement("Description", el.Description), new XElement("background", colorText), new XElement("img", el.Img), new XElement("font", el.Font), new XElement("customerId", el.CustomerId) ) ) ); } } doc.Save(Path); RepositoryXmlFile.SaveToDb(Path, doc); }