WordPress安装自定义字体

0x00.下载所需字体 ,确保FTP服务器可用


0x01.将字体文件上传至FTP服务器


0x02.在主题目录下新建fonts文件夹

mkdir fonts

0x03.复制字体文件至fonts文件夹

cp xxx.ttf /www/wwwroot/async.website/wp-content/themes/xxx/fonts

0x04.修改fonts文件夹权限

chmod -R 777 fonts

0x05.在主题的style.css中添加@font-face

@font-face {
  font-family: xxx; 
  src: url(https://xxxx.xxx/wp-content/themes/xxx/fonts/xxx.ttf); /*修改url为自己的字体路径*/
  font-weight: normal; 
}

0x06.在所需地方引用,如需要修改style.css中site-description的字体

.site-description {
  display: inline-block;
  margin-top: 15px;
  margin-bottom: 0;
  font-size: 50px;
  font-family:Debby;
  line-height: 1.1;
}

 

 

 

UWP 使用BackgroundTransfer下载图片

 0x00.添加引用

using System;
using System.Threading.Tasks;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;

0x01.下载

Uri uri = new Uri(imageUri);//需要下载图片的Uri,exp:http*****.jpg
BackgroundDownloader backgroundDownload = new BackgroundDownloader();
StorageFolder folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Acafe", CreationCollisionOption.OpenIfExists);//此处为下载路径,可是要Openfolder改为自定义路径
StorageFile newFile = await folder.CreateFileAsync(imageName, CreationCollisionOption.OpenIfExists);//创建文件,需要定义文件名
DownloadOperation download = backgroundDownload.CreateDownload(uri, newFile);//创建下载器
await download.StartAsync();//启动

 

UWP 自定义Popup控件的自适应

0x00.前提

自定义了一个查看图片细节的控件,本质是一个Image控件,但是应为采用了左侧为NavigationView右侧为Frame的导航模式,为了使该控件能覆盖到左侧的NavigationView之上,只能采用Popup。

这也导致该控件的容器不能是Frame/Page中的Grid,从而不能直接随窗体一起拉伸,可以采用SizeChanged事件和INotifyPropertyChanged接口来实现,也可使使用MeasurePopupSize()


0x01.实现

public Image_Detail()
{
    this.InitializeComponent();
    _popup = new Popup();
    ApplicationView.GetForCurrentView().VisibleBoundsChanged += (s, e) =>
    {
        MeasurePopupSize();
    };
    MeasurePopupSize();
    _popup.Child = this;
}

private void MeasurePopupSize()
{
    this.Width = ApplicationView.GetForCurrentView().VisibleBounds.Width;
    this.Height = ApplicationView.GetForCurrentView().VisibleBounds.Height;
}

C# Json反序列化

0x00.使用工具将Json格式化

Json作为一种数据交换格式,具有简洁和清晰的结构。
在线Json格式化校验工具:http://tool.chinaz.com/tools/jsonformat.aspx

在线转换C#类工具:http://json2csharp.chahuo.com/

Json数据
{
    "code": "00",
    "count": 1,
    "followersList": [
        {
            "followerDate": "2017-11-29 11:11:10",
            "follower_id": "WEP2DU",
            "userIconPath": "http://www.sonystyle.com.cn/mysony/acafe/myspace/images/space/default.gif"
        }
    ],
    "programId": 1,
    "userId": "YIOMOOOO"
}
使用C#类工具转换后新建一个”JsonFollower”类
class JsonFollower
{
    public class FollowersList
    {
        public string followerDate { get; set; }
        public string follower_id { get; set; }
        public string userIconPath { get; set; }
    }

    public class RootObject
    {
        public string code { get; set; }
        public string count { get; set; }
        public List<followerslist> followersList { get; set; }
        public List<followering> following { get; set; }
        public string programId { get; set; }
        public string userId { get; set; }
    }
}

0x01.添加引用

using System.Collections.Generic;
using System.Net.Http;
using Newtonsoft.Json;//在Nuget中下载对应类库

0x02.模拟发送请求获取Json

HttpClient request = new HttpClient();
HttpResponseMessage MyFolResponse = request.GetAsync("http://www.sonystyle.com.cn/mysony/campaign/api/program.do?methodName=getMyFollowersList&programId=1" + "&userId=YIOMOOOO").Result;
string a = MyFolResponse.Content.ReadAsStringAsync().Result;
JsonFollower.RootObject rb1 = JsonConvert.DeserializeObject<JsonFollower.RootObject>(a);

0x03.遍历RootObject并转化为对象

List<FollowerInfo> FolInfo = new List<FollowerInfo >();
List<string> followerDate = new List<string>();
List<string> follower_id = new List<string>();

foreach (JsonFollower.FollowersList fl in rb1.followersList)
{
    followerDate.Add(fl.followerDate);
    follower_id.Add(fl.follower_id);
}

for (int i = 0; i < follower_id.Count; i++)
{
    FollowerInfo FI = new FollowerInfo();
    FI.followerDate = followerDate[i];
    FI.follower_id = follower_id[i];
    FolInfo.Add(FI);
}
return FolInfo;

UWP 设定图片为桌面/锁屏

0x00.添加引用

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.Storage;
using System;
using Windows.System.UserProfile;
using Windows.ApplicationModel;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Media;

0x01.选择图片

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");

var file = await openPicker.PickSingleFileAsync();

0x02.复制所选图片并设定

if (!UserProfilePersonalizationSettings.IsSupported())
{
    MessageDialog md = new MessageDialog("Not Support");
    md.ShowAsync();
}
else
{
    StorageFolder base_folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");//选择App安装目录下Assets文件夹作为复制目录
    await file.CopyAsync(base_folder,file.Name, NameCollisionOption.ReplaceExisting);//将选择的图片复制到base_folder
    StorageFile copy_file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/" + file.Name));

    UserProfilePersonalizationSettings setting = UserProfilePersonalizationSettings.Current;
    await setting.TrySetWallpaperImageAsync(copy_file);//设置为壁纸,返回true成功,false失败
    await setting.TrySetLockScreenImageAsync(copy_file);//设置为锁屏,返回true成功,false失败
}

PS.如不将所选文件复制至App目录下会出现权限问题

Jumony.Core爬虫学习 [1]

 0x00.Nuget 中下载 Jumony.Core 安装至当前项目

0x01.获取http://www.sonystyle.com.cn/mysony/acafe/index.htm 首页滚动图片URL

foreach (var img in new JumonyParser().LoadDocument("http://www.sonystyle.com.cn/mysony/acafe/index.htm/",Encoding.GetEncoding(65001)).Find("[target=_blank]>img[src*=\"index\"]"))<br> textBox.Text = textBox .Text + "http://www.sonystyle.com.cn/mysony/acafe/" + img.Attribute("src").Value() +" \n";

 

PS. 注意head 中页面的编码信息注意转码

CSS选择器 http://www.w3school.com.cn/cssref/css_selectors.asp

WPF C# 获取机器信息

 0x00.添加引用

using System; using System.Collections.Specialized; 
using System.IO; 
using System.Management; 
using System.Net; 
using System.Net.Sockets; 
using System.Windows; 
using System.Windows.Input; 
using System.Windows.Media;

0x01.获取机器名称

string machineName = Environment.MachineName;

0x02.获取MAC地址

string result;
try
{using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
{
using (ManagementObjectCollection moc = mc.GetInstances())
{
string macAddress = "";
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
macAddress = mo["MacAddress"].ToString();
break;
}
}
result = macAddress;
}
}
}
catch
{
result = "unknown";
}
finally
{
}

0x03.判断32/64位系统

string result;
bool is64OS = Environment.Is64BitOperatingSystem;
if (is64OS == true)
result = "64 bits OS";//64位
else
result = "32 bits OS";//32位

0x04.获取硬盘信息

string HDSN = "";
string HDID = "";

ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject.GetInstances();
foreach (ManagementObject mo in moc1)
{
HDSN = (string)mo.Properties["Model"].Value;
}
ManagementClass mc1 = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc2 = mc1.GetInstances();

foreach (ManagementObject mo in moc2)
{
HDID = mo.Properties["SerialNumber"].Value.ToString().Trim();
}

0x05.IPV4

string[] GetLocalIpv4()
string Ipv4;
{
IPAddress[] localIPs;
localIPs = Dns.GetHostAddresses(Dns.GetHostName());
StringCollection IpCollection = new StringCollection();
foreach (IPAddress ip in localIPs)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
IpCollection.Add(ip.ToString());
}
string[] IpArray = new string[IpCollection.Count];
IpCollection.CopyTo(IpArray, 0);
return IpArray;
}

void ShowIP()
{
foreach (string ip in GetLocalIpv4())
{
Ipv4 = ip.ToString();
}
return;
}

ShowIP();

0x06.IPV6

string ip =  "";
IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
for (int i = 0; i < addressList.Length; i++)
{
    ip = addressList[i].ToString();
}

0x07.获取厂商和机器型号(manufacturer)(model)

string manufacturer;
string model;
ManagementClass mc2 = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc3 = mc2.GetInstances();

if (moc3.Count != 0)
{
    foreach (ManagementObject mo in mc2.GetInstances())
    {
        manufacturer =mo["Manufacturer"].ToString();///////////制造厂商
    }
}

foreach (ManagementObject m in moc3)
{
    model = m["model"].ToString ();////机器型号
}

 

C# 获取必应每日一图

 0x00.添加引用

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;
using System.Xml;

0x01.模仿请求

public static Task< bool> GetBingPics()
{
    return Task.Run(async () =>
     {
         string temp = "http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1";
         string downtemp = "http://cn.bing.com";
         string baseurlexp = "//images/image/url";
         string copyrightexp = "//images/image/copyright";
         string dateexp = "//images/image/enddate";

         HttpClient request = new HttpClient();
         {
             request.DefaultRequestHeaders.Add("Accept", "application/json, text/javascript, */*; q=0.01");
             request.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
             request.DefaultRequestHeaders.Add("Accept-Encoding", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
             request.DefaultRequestHeaders.Add("Accept-Language", "gzip, deflate");
         }//填写请求头

         try
         {
             HttpResponseMessage response = request.GetAsync(temp).Result;
             string xmlstr = response.Content.ReadAsStringAsync().Result;
             XmlDocument doc = new XmlDocument();
             doc.LoadXml(xmlstr);

             XmlElement root = null;
             root = doc.DocumentElement;

             XmlNode xmlNode = root.SelectSingleNode(baseurlexp);
             XmlNode xmlNode1 = root.SelectSingleNode(copyrightexp);
             XmlNode xmlNode2 = root.SelectSingleNode(dateexp);
             string baseurl = xmlNode.InnerText;
             string copyrighturl = xmlNode1.InnerText;
             string date = xmlNode2.InnerText;
             string plus = "." + baseurl.Split('.')[1];

             BackgroundDownloader backgroundDownload = new BackgroundDownloader();

             StorageFolder folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("BingPics", CreationCollisionOption.OpenIfExists);
             StorageFile newFile = await folder.CreateFileAsync(date + plus, CreationCollisionOption.OpenIfExists);

             Uri uri = new Uri(downtemp + baseurl);
             DownloadOperation download = backgroundDownload.CreateDownload(uri, newFile);

             await download.StartAsync();
             return true;
         }
         catch
         {
             return false;
         }
     });
}

 

UWP 判断程序是否为第一次运行

 0x00.添加引用

using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Storage;

0x01.通过判断本地设置文件中是否存在对应项来判断是否为第一次运行

public static bool IsFirstlyRun()
{
    ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
    if (localSettings.Values["BackgroundSource"] == null)
        return true;
    else
        return false;
}

 

C# Gzip解压

0x00.添加引用

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

0x01.解压

    public static string GZipDecompress(Stream stream)
    {
        byte[] buffer = new byte[100];
        int length = 0;

        GZipStream gzs = new GZipStream(stream, CompressionMode.Decompress);
        MemoryStream ms = new MemoryStream();

        while ((length = gzs.Read(buffer, 0, buffer.Length)) != 0)
        {
            ms.Write(buffer, 0, length);
        }
        return Encoding.UTF8.GetString(ms.ToArray());
    }
}