C#编写的可供PHP调用的com dll(Visual studio 2017)

新增类库项目

依次选择“文件”》“新建”》“项目”,然后选择“类库(.net framework)”

添加引用

在“解决方案资源管理器”的“引用”点击鼠标右键,才程序集中搜索“InteropServices”,勾选“System.Runtime.InteropServices”

com可见

在“解决方案资源管理器”的项目名称上点击鼠标右键,选择“属性”,然后在“应用程序”面板选择“程序集信息”,勾选“使程序集COM可见”

签名

在“解决方案资源管理器”的项目名称上点击鼠标右键,选择“属性”,然后在“签名”面板勾选“为程序集签名”,然后在下拉菜单选择“新建”,输入“签名文件名称”,取消“使用密码保护密钥文件”勾选,点击确认

创建程序

using System.Runtime.InteropServices;

namespace HelloWorld
{ 
    [ComVisible(true)]
    public class Say
    {
        public string Hello()
        {
            return "Hello World";
        }
    }
}

发布dll

点击主菜单“生成”》“生成解决方案”(或者按F6)

注册com

按键盘上的win键,打开开始菜单,输入”vs”搜索,鼠标右键点击”VS 2017开发人员命令提示符”,选择用管理员身份打开;

进入生成的dll目录(通常在项目的bin/release目录下)

cd d:/helloworld/bin/release
regasm HelloWord.dll
gacutil /i HelloWord.dll

PHP调用com

<?php  
$r=new Com("HelloWorld.Say");  
$s=$r->Hello();  
echo $s;

调用出现Uncaught com_exception: Failed to create COM object

http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php

backgroundWorker in c# console application

A sample console program with backgroundworkwr.

class Program
{
    private static BackgroundWorker worker = new BackgroundWorker();
    private event EventHandler BackgroundWorkFinished;

    static void Main(string[] args)
    {
        worker.DoWork += worker_DoWork;
        worker.RunWorkerCompleted += worker_RunWorkerCompleted;
        worker.ProgressChanged += worker_ProgressChanged;
        worker.WorkerReportsProgress = true;
        worker.WorkerSupportsCancellation = true;

        Console.WriteLine("Starting Application...");

        worker.RunWorkerAsync();
        Console.ReadKey();
    }

    static void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        Console.WriteLine(e.ProgressPercentage.ToString());
    }

    static void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        Console.WriteLine("Starting to do some work now...");
        int i;
        for (i = 1; i < 10; i++)
        {
            Thread.Sleep(1000);
            worker.ReportProgress(Convert.ToInt32((100.0 * i) / 10));
        }

        e.Result = i;
    }

    static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        Console.WriteLine("Value Of i = " + e.Result.ToString());
        Console.WriteLine("Done now...");
    }
}

office在线预览隐藏发布窗口

C# Excel Interop – Suppress ‘Publishing’ dialog when invoking Worksheet.ExportAsFixedFormat

方法一:采用BackgroundWorker

var worker = new BackgroundWorker();
worker.DoWork += (o, args) =>
{
    var path = @"D:\sample.xlsx";
    var application = new Microsoft.Office.Interop.Excel.Application();
    application.Workbooks.Open(path,
        Type.Missing, true);
    application.Worksheets[1].ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, path);
};
worker.RunWorkerAsync();

方法二:采用pedamorf

A PDF conversion server for Windows that supports documents, text, images, html and urls.

office文档在线预览方案比较(免费、付费、效果和价格)

免费方案

目前技术上主要存在两种方案:1,通过openoffice转pdf,2,通过ms提供的接口进行转换(。

相关文章:

付费方案

百度API(介绍 效果展示)

支持平台 无要求

支持源格式 doc、docx、ppt、pptx、xls、xlsx、vsd、pot、pps、rtf、wps、et、dps、pdf、txt、epub

元信息提取 是

缩略图生成 是

多端支持 是

内置防复制 否

内置防分享 否

内置CDN加速 百度云

开发成本(转码以及多端在线预览) 一周内

价格成本 调用成功:0~1500次 0.15元/次,3001~30000次 0.1元每次,30001次以上 0.08元一次;外网下行流量 0.5元/GB

成功案例 百度文库

永中 (介绍 效果展示

支持平台 windows,linux

支持源格式 不支持wps

元信息提取 不支持

缩略图生成 否

多端支持 是

内置防复制 是

内置防分享 否

内置CDN加速 否

开发成本(转码以及多端在线预览) 2周左右

价格成本 联系后初次报价:5000一年 50000次; 普及版(只支持office)终生授权49800元 完整版终生授权79800元

成功案例 QQ邮箱、网易126/163邮箱、移动139邮箱、189邮箱

officeweb365 (介绍 效果展示)

支持平台 无要求,部署版需要Windows Server

支持源格式 Word、Excel、PowerPoint、PDF、WPS

元信息提取 是

缩略图生成 是

多端支持 是

内置防复制 是

内置防分享 是

内置CDN加速 否

开发成本(转码以及多端在线预览) 一周内

价格成本 1, 最大5M免费500次每天有广告 2, 最大20M10000次每天无广告可防复制分享 1800 元/年 3,无限制,2800 元/年、300元/月 4,部署版 日预览次数十万次以内的,一次性六千。不限制日预览次数的,一次性八千 免费升级5年 重大升级,终身免费,比如office2018新版本出来了,免费更新

成功案例 联通邮箱,腾讯游戏开发者平台

idocv

因为测试结果明显不达标准,放弃

使用国内镜像快速安装composer以及yii2(附安装脚本)

通过中国镜像安装composer

参考文章 如何安装 Composer

下载安装文件

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

安装

php composer-setup.php

删除安装文件

php -r "unlink('composer-setup.php');"

设置全局路径(windows请按参考文档设置)

sudo mv composer.phar /usr/local/bin/composer

配置使用国内镜像

composer config -g repo.packagist composer https://packagist.phpcomposer.com

安装Yii2

参考文章 Install via Composer

首先安装 Composer Asset Plugin

composer global require "fxp/composer-asset-plugin:^1.2.0"

安装基础模板

php composer.phar create-project yiisoft/yii2-app-basic yiitest

安装高级模板

php composer.phar create-project yiisoft/yii2-app-advanced yiitest

安装过程中如果提示“please create a GitHub OAuth token to go over the API rate limit”,登录github,在https://github.com/settings/tokens生成一个token,权限只需要勾选repo即可

进入项目目录

cd yiitest

测试安装环境

php requirements.php

初始化项目

 ./init

运行项目

./yii serve/index -h
./yii serve/index -t="@frontend/web"
./yii serve/index -t="@backend/web"

centos 7 + php 7 + nginx + wordpress之yum最简单安装办法

安装eple库

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

安装webtatic库

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

更新yum源

yum update

安装php7以及扩展

yum install php71w-gd php71w-pdo php71w-opcache php71w-fpm php71w-pecl-redis php71w-mysql php71w-mcrypt php71w-mbstring php71w-intl php71w-cli

安装nginx

yum install nginx1w -y

系统启动时自动启动nginx以及php-fpm

systemctl enable nginx php-fpm
systemctl start nginx php-fpm

修改php程序目录权限

chown -R apache:apache /data/web/www.c4ys.com/

修改ngingx配置(以为wordpress例)

vim /etc/nginx/conf.d/www.c4ys.com.conf

server {
    server_name  www.c4ys.com c4ys.com;
    root   /data/phpproject/www.c4ys.com;
    location / {
        index  index.html index.php;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

golang 自动编译(live reload, auto reload, auto refresh, auto compile)比较

fresh – Build and (re)start go web apps after saving/creating/deleting source files.

Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file.

If the web framework you are using supports the Fresh runner, it will show build errors on your browser.

It currently works with Traffic, Martini and gocraft/web.

gin – Live reload utility for Go web servers

gin is a simple command line utility for live-reloading Go web applications. Just run gin in your app directory and your web app will be served with gin as a proxy. gin will automatically recompile your code when it detects a change. Your app will be restarted the next time it receives an HTTP request.

gin adheres to the “silence is golden” principle, so it will only complain if there was a compiler error or if you succesfully compile after an error.

realize – Go build system with file watcher, live reload and output streams. Run, build and watch file changes with custom paths

A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths

Features

  • Highly customizable
  • Config your project Step by Step
  • Build, Install, Test, Fmt, Generate and Run at the same time
  • Live reload on file changes (re-build, re-install…)
  • Watch custom paths and specific file extensions
  • Watch by FsNotify or by polling
  • Support for multiple projects
  • Output streams and error logs (support for save on a file)
  • Web Panel (projects list, config settings, logs)

CompileDaemon – Very simple compile daemon for Go

Watches your .go files in a directory and invokes go build if a file changed. Nothing more.