zoukankan      html  css  js  c++  java
  • MyCodeBar我的代码片段管理工具

    好久没有写blogs 了, 感觉这样好像失去了blogs的意义了,所以决定以后要常来。。今天天气阴,中午又吃的牛肉面,天天吃一样的东西马上就要崩溃了,没有办法,附近只有这样一家快餐...继续坚持吧.


    最近发现在写代码的时候,总会有突然一个方法,以前做过,但是就想不起来如何实现的了.唉~~没有办法,那我自己来写一个代码片段管理的程序吧,当我使用的时候,就可以直接找到对应的code了.虽然有很多类似的工具,并且可以加载到vs.net中,但是感觉那个功能太麻烦,我就是要记录一下,所以自己来写吧。

    该界面的主界面如下:

    toolbar停留在任务栏中.

    大概介绍一下这个工具的功能.

    1. 可以调用google code search 功能,查找相关的代码.

    2.可以对现有code的片段进行保存.编辑,删除等操作.

    3.可以备份所有的code片段到设定的Mail中备份.

    4. 恢复备份...(这段一直没有时间来写,慢慢在补上吧)

    主要开发思路...这个其实很简单,使用xml文件,记录标题和保存的code片段的文件的路径,这样当点击使用复制功能时,自动到对应的path下获取code ,然后复制到剪贴板上。


    主要功能就是将保存的code以菜单的方式显示,当点击的时候,保存到剪贴版上.如下图:

    该程序主要实现方法

    google code search 这个功能很简单啦...就是调用Process 的类,调用Code Search的URl,代入参数就好了。

    bar的功能主要使用bho 技术,可以到codeProject上去查 BandObject ,就能找到对应的一些实力。

    但是要设定bar的类的属性不要在IE中显示,只要在任务栏显示就好。

    [BandObject("MyCodeBar" ,BandObjectStyle.Horizontal |BandObjectStyle.TaskbarToolBar, HelpText = "My Code bar")]

    这样就OK 。


    备份方式,主要使用将文件均压缩到zip中,然后通过Mail保存起来。


    发mail的code:


    string smtpserver = "smtp.126.com";
    string username = "XXXXXX@126.com";
    string userpwd = "XXXX";
    string emailfrom = "XXXX@126.com";

    SmtpClient client = new SmtpClient(smtpserver);
    client.Credentials = new NetworkCredential(username,userpwd);

    client.DeliveryMethod = SmtpDeliveryMethod.Network;

    MailMessage email = new System.Net.Mail.MailMessage();
    email.From = new MailAddress(emailfrom);
    email.To.Add("XXXXX@126.com");
    email.Body = "MyCodeBar 备份文件 ,见附件";
    email.BodyEncoding = System.Text.Encoding.UTF8;
    email.Subject = "MyCodeBar 备份文件";
    email.SubjectEncoding = System.Text.Encoding.UTF8;
    email.IsBodyHtml = true;
    Attachment a = new Attachment(tempname);
    email.Attachments.Add(a);

    client.Send(email);


    压缩文件的code:


    try
    {
    SaveFileDialog sfd = new SaveFileDialog();
    sfd.Title = "BackUp File";
    sfd.Filter = "ZIP|*.zip|All|*.*";
    if (sfd.ShowDialog() == DialogResult.OK)
    {

    string tempname = sfd.FileName;

    FileStream outs = File.Create(tempname);

    ICSharpCode.SharpZipLib.Zip.ZipOutputStream tos = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(outs);
    FileStream ins = null;

    string[] FileNames = Directory.GetFiles(Common.fileDir);
    foreach (string file in FileNames)
    {
    ins = File.OpenRead(file);

    byte[] buffer = new byte[ins.Length];

    ins.Read(buffer, 0, buffer.Length);
    ins.Close();
    string tempfile = file.Substring(3, file.Length - 3);
    ICSharpCode.SharpZipLib.Zip.ZipEntry tarEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(tempfile);
    tarEntry.Size = buffer.Length;

    tos.PutNextEntry(tarEntry);

    tos.Write(buffer, 0, buffer.Length);
    tos.CloseEntry();
    }

    ins = File.OpenRead(Common.configfilePath);

    byte[] buffer2 = new byte[ins.Length];

    ins.Read(buffer2, 0, buffer2.Length);
    ins.Close();
    string tempfile2 = Common.configfilePath.Substring(3, Common.configfilePath.Length - 3);
    ICSharpCode.SharpZipLib.Zip.ZipEntry tarEntry2 = new ICSharpCode.SharpZipLib.Zip.ZipEntry(tempfile2);
    tarEntry2.Size = buffer2.Length;

    tos.PutNextEntry(tarEntry2);

    tos.Write(buffer2, 0, buffer2.Length);
    tos.CloseEntry();


    tos.Close();
    MessageBox.Show("OK");
    }
    }
    catch (System.Exception exp)
    {
    Common.MessageBoxError(exp.Message);
    }


    没什么了,剩下的就是管理逻辑了。

    目前的问题,在使用BandObject后,虽然可以加载到任务栏中,但是重起电脑后,不会自动加载MyCodeBar 而是加载 快速启动...这个问题没有查到为什么,可能是我的GUID有问题..以后再查吧。有谁遇到过这样的问题麻烦也告诉我哦。:-)




    文件下载

  • 相关阅读:
    【Spring源码这样读】-再次走近容器Spring IOC 一
    【Spring源码这样读】-下载安装一份Spring源码
    【Spring源码这样读】-认识Spring的基本功能
    【Spring源码这样读】-怎么阅读源码
    RabbitMQ没有延时队列?学会这一招玩转延时队列
    【HDU 3746 Cyclic Nacklace】
    10要点解决IE6兼容性问题
    《遍地风流》- 阿城
    PyCharm2021使用教程 --- 1、PyCharm的下载与安装
    爬虫系列 | 6、详解爬虫中BeautifulSoup4的用法
  • 原文地址:https://www.cnblogs.com/zhucl1006/p/892979.html
Copyright © 2011-2022 走看看