Ejemplo n.º 1
0
        public override void execute(Options options, INIManager iniManager)
        {
            string AppKey = iniManager.IniReadValue("APP", "AppKey");
            string AppSecret = iniManager.IniReadValue("APP", "AppSecret");
            string TaobaoAsistantPath = iniManager.IniReadValue("淘宝助理", "安装目录");

            string nick = options.Nick;
            string SessionKey = iniManager.IniReadValue(nick, "SessionKey");

            string userId = iniManager.IniReadValue(nick, "UserId");
            if (userId == null || userId.Trim().Equals(""))
            {
                userId = "1696293148";
            }

            StreamWriter MovePicLogWriter;

            FileStream MovePicLog = new FileStream(Environment.CurrentDirectory + "\\" + "MovePic.log", FileMode.Append);
            MovePicLogWriter = new StreamWriter(MovePicLog, Encoding.Default);
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
            cs.Database = Path.Combine(TaobaoAsistantPath, "users\\" + nick + "\\APPITEM.DAT");
            cs.Charset = "UTF8";
            cs.UserID = "SYSDBA";
            cs.Password = "******";
            cs.ServerType = FbServerType.Embedded;
            FbConnection fbCon = new FbConnection(cs.ToString());
            fbCon.Open();

            FbCommand ItemsCommand = null;
            ItemsCommand = new FbCommand("SELECT * FROM ITEM WHERE OUTER_ID = @SearchString OR TITLE = @SearchString", fbCon);
            FbParameter SearchString = new FbParameter("@SearchString", FbDbType.VarChar);
            SearchString.Value = options.Item;
            ItemsCommand.Parameters.Add(SearchString);

            FbDataReader ItemsReader = ItemsCommand.ExecuteReader();
            while (ItemsReader.Read())
            {
                MovePicLogWriter.WriteLine("--------------------------------------------------------------------------------");
                Console.WriteLine("--------------------------------------------------------------------------------");
                string ClientID = ItemsReader["CLIENT_ID"].ToString();
                string Title = ItemsReader["TITLE"].ToString();
                Console.WriteLine("ClientID=" + ClientID);
                MovePicLogWriter.WriteLine("ClientID=" + ClientID);
                Console.WriteLine("TITLE=" + Title);

                MovePicLogWriter.WriteLine("TITLE=" + Title);
                FbTransaction myTransaction = fbCon.BeginTransaction();
                FbCommand DeleteCommand = new FbCommand("UPDATE ITEM SET CLIENT_IS_DELETE = 1 WHERE CLIENT_ID = @ClientID", fbCon);
                FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                ParamID.Value = ClientID;
                DeleteCommand.Parameters.Add(ParamID);
                DeleteCommand.Transaction = myTransaction;
                DeleteCommand.ExecuteNonQuery();
                myTransaction.Commit();
            }
            fbCon.Close();
            MovePicLogWriter.Close();
            MovePicLog.Close();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Jobs jobs = new Jobs();
            jobs.addJob(new Upload("Upload", "上传图片"));
            jobs.addJob(new ReUpload("ReUpload", "重新上传图片"));
            jobs.addJob(new DeleteItem("DeleteItem", "删除宝贝"));

            Options options = new Options();
            CommandLine.Parser.Default.ParseArguments(args, options);

            INIManager iniManager = new INIManager(System.AppDomain.CurrentDomain.BaseDirectory + "MovePic.ini");

            Job job = jobs.getJob(options.Action);
            if (job != null)
            {
                job.execute(options, iniManager);
            }
        }
Ejemplo n.º 3
0
        public override void execute(Options options, INIManager iniManager)
        {
            string AppKey = iniManager.IniReadValue("APP", "AppKey");
            string AppSecret = iniManager.IniReadValue("APP", "AppSecret");
            string TaobaoAsistantPath = iniManager.IniReadValue("淘宝助理", "安装目录");

            string nick = options.Nick;
            string SessionKey = iniManager.IniReadValue(nick, "SessionKey");

            string userId = iniManager.IniReadValue(nick, "UserId");
            if (userId == null || userId.Trim().Equals(""))
            {
                userId = "1696293148";
            }

            StreamWriter MovePicLogWriter;

            FileStream MovePicLog = new FileStream(Environment.CurrentDirectory + "\\" + "MovePic.log", FileMode.Append);
            MovePicLogWriter = new StreamWriter(MovePicLog, Encoding.Default);
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
            cs.Database = Path.Combine(TaobaoAsistantPath, "users\\" + nick + "\\APPITEM.DAT");
            cs.Charset = "UTF8";
            cs.UserID = "SYSDBA";
            cs.Password = "******";
            cs.ServerType = FbServerType.Embedded;
            FbConnection fbCon = new FbConnection(cs.ToString());
            fbCon.Open();

            FbCommand ItemsCommand = null;
            if ("all".Equals(options.Item))
            {
                ItemsCommand = new FbCommand("SELECT * FROM ITEM WHERE NUM_IID IS NULL AND CLIENT_NAVIGATION_TYPE = 1 OR SYNC_STATUS <> 1", fbCon);
            }
            else
            {
                ItemsCommand = new FbCommand("SELECT * FROM ITEM WHERE OUTER_ID = @SearchString OR TITLE = @SearchString", fbCon);
                FbParameter SearchString = new FbParameter("@SearchString", FbDbType.VarChar);
                SearchString.Value = options.Item;
                ItemsCommand.Parameters.Add(SearchString);
            }

            FbDataReader ItemsReader = ItemsCommand.ExecuteReader();
            while (ItemsReader.Read())
            {
                Boolean mainallpass = true;
                Boolean descallpass = true;
                MovePicLogWriter.WriteLine("--------------------------------------------------------------------------------");
                Console.WriteLine("--------------------------------------------------------------------------------");
                string ClientID = ItemsReader["CLIENT_ID"].ToString();
                string Title = ItemsReader["TITLE"].ToString();
                Console.WriteLine("ClientID=" + ClientID);
                MovePicLogWriter.WriteLine("ClientID=" + ClientID);
                Console.WriteLine("TITLE=" + Title);
                MovePicLogWriter.WriteLine("TITLE=" + Title);

                if ("main".Equals(options.Scope) || "all".Equals(options.Scope))
                {
                    FbCommand PicturesCommand = new FbCommand("SELECT * FROM PICTURE WHERE CLIENT_ITEMID = @ClientItemID", fbCon);
                    FbParameter ParamClientID = new FbParameter("@ClientItemID", FbDbType.VarChar);
                    ParamClientID.Value = ClientID;
                    PicturesCommand.Parameters.Add(ParamClientID);
                    FbDataReader PicturesReader = PicturesCommand.ExecuteReader();
                    while (PicturesReader.Read())
                    {
                        MovePicLogWriter.WriteLine("----------");
                        Console.WriteLine("----------");
                        string PicClientID = PicturesReader["CLIENT_ID"].ToString();
                        string Url = PicturesReader["URL"].ToString();
                        string ClientName = PicturesReader["CLIENT_NAME"].ToString();
                        Console.WriteLine("URL=" + Url);
                        MovePicLogWriter.WriteLine("URL=" + Url);
                        Console.WriteLine("图片本地ID=" + PicClientID);
                        MovePicLogWriter.WriteLine("图片本地ID=" + PicClientID);
                        Console.WriteLine("CLIENT_NAME=" + ClientName);
                        MovePicLogWriter.WriteLine("CLIENT_NAME=" + ClientName);

                        if ("reupload".Equals(options.Action))
                        {
                            if (Url != null && !Url.Equals(""))
                            {
                                List<Picture> pictures = ImagesUtil.getPictures(Url, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                                if (pictures != null && pictures.Count > 0)
                                {
                                    foreach (Picture picture in pictures)
                                    {
                                        Console.WriteLine(picture.PicturePath);
                                        MovePicLogWriter.WriteLine(picture.PicturePath);
                                        if (!picture.Status.Equals("pass"))
                                        {
                                            mainallpass = false;
                                            Console.WriteLine("审核中");
                                            MovePicLogWriter.WriteLine("审核中");
                                            DateTime dt = Convert.ToDateTime(picture.Modified);
                                            if (dt < DateTime.Now.AddDays(-3))
                                            {
                                                Console.WriteLine("过了3天重新上传");
                                                MovePicLogWriter.WriteLine("过了3天重新上传");
                                                ImagesUtil.reUploadImage(picture, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                                            }
                                            else
                                            {
                                                Console.WriteLine("没有到3天再等一等");
                                                MovePicLogWriter.WriteLine("没有到3天再等一等");
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("排查通过");
                                            MovePicLogWriter.WriteLine("排查通过");
                                        }
                                    }
                                }
                                else
                                {
                                    mainallpass = false;
                                    Console.WriteLine("图片不在图片空间 " + Url);
                                    MovePicLogWriter.WriteLine("图片不在图片空间 " + Url);
                                    string PicPath = ImagesUtil.uploadImage(Url, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                                    if (!PicPath.Equals(""))
                                    {
                                        FbTransaction myTransaction = fbCon.BeginTransaction();
                                        Console.WriteLine("PicPath=" + PicPath);
                                        MovePicLogWriter.WriteLine("PicPath=" + PicPath);
                                        FbCommand UpdateUrlCommand = new FbCommand("UPDATE PICTURE SET URL = @Url WHERE CLIENT_ID = @ClientID", fbCon);
                                        FbParameter ParamUrl = new FbParameter("@Url", FbDbType.VarChar);
                                        ParamUrl.Value = PicPath;
                                        FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                                        ParamID.Value = PicClientID;
                                        UpdateUrlCommand.Parameters.Add(ParamUrl);
                                        UpdateUrlCommand.Parameters.Add(ParamID);
                                        UpdateUrlCommand.Transaction = myTransaction;
                                        UpdateUrlCommand.ExecuteNonQuery();
                                        myTransaction.Commit();
                                        MovePicLogWriter.WriteLine(Url + " 被替换为\n" + PicPath);
                                        Console.WriteLine(Url + " 被替换为\n" + PicPath);
                                        Console.WriteLine("上传完成");
                                        MovePicLogWriter.WriteLine("上传完成");
                                    }
                                }

                            }
                        }
                    }
                }
                if ("desc".Equals(options.Scope) || "all".Equals(options.Scope))
                {
                    ArrayList images = new ArrayList();
                    string Desc = ItemsReader["DESCRIPTION"].ToString();
                    string imgpattern = "http://[^\\s]*?((\\.jpg)|(\\.png)|(\\.gif)|(\\.bmp))";
                    Regex r = new Regex(imgpattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    Match m = r.Match(Desc);
                    while (m.Success)
                    {
                        System.Text.RegularExpressions.Group imageGroup = m.Groups[0];
                        images.Add(imageGroup.Value);
                        m = m.NextMatch();
                    }
                    foreach (string image in images)
                    {
                        MovePicLogWriter.WriteLine("----------");
                        Console.WriteLine("----------");
                        Console.WriteLine(image);
                        MovePicLogWriter.WriteLine(image);
                        if ("reupload".Equals(options.Action))
                        {
                            Console.WriteLine("检查图片状态");
                            MovePicLogWriter.WriteLine("检查图片状态");
                            List<Picture> pictures = ImagesUtil.getPictures(image, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                            if (pictures != null && pictures.Count > 0)
                            {
                                foreach (Picture picture in pictures)
                                {
                                    Console.WriteLine(picture.PicturePath);
                                    MovePicLogWriter.WriteLine(picture.PicturePath);
                                    if (!picture.Status.Equals("pass"))
                                    {
                                        descallpass = false;
                                        Console.WriteLine("审核中");
                                        MovePicLogWriter.WriteLine("审核中");
                                        DateTime dt = Convert.ToDateTime(picture.Modified);
                                        if (dt < DateTime.Now.AddDays(-3))
                                        {
                                            Console.WriteLine("过了3天重新上传");
                                            MovePicLogWriter.WriteLine("过了3天重新上传");
                                            bool done = ImagesUtil.reUploadImage(picture, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                                            if (!done)
                                            {
                                                if (options.Prune)
                                                {
                                                    Desc = Desc.Replace(picture.PicturePath, "");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("没有到3天再等一等");
                                            MovePicLogWriter.WriteLine("没有到3天再等一等");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("排查通过");
                                        MovePicLogWriter.WriteLine("排查通过");
                                    }
                                }

                            }
                            else
                            {
                                descallpass = false;
                                Console.WriteLine("图片不在图片空间");
                                MovePicLogWriter.WriteLine("图片不在图片空间");
                                string PicPath = ImagesUtil.uploadImage(image, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                                if (PicPath.Equals(""))
                                {
                                    if (options.Prune)
                                    {
                                        Desc = Desc.Replace(image, PicPath);
                                    }
                                }
                                else
                                {
                                    Desc = Desc.Replace(image, PicPath);
                                }
                            }
                        }
                    }

                    ArrayList localImages = new ArrayList();
                    string localImgPattern = @"[a-zA-Z]{1}\:[\\/][^\s]*?((\.jpg)|(\.png)|(\.gif)|(\.bmp))";
                    Regex r2 = new Regex(localImgPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    Match m2 = r2.Match(Desc);
                    while (m2.Success)
                    {
                        System.Text.RegularExpressions.Group imageGroup = m2.Groups[0];
                        localImages.Add(imageGroup.Value);
                        m2 = m2.NextMatch();
                    }
                    foreach (string localImage in localImages)
                    {
                        MovePicLogWriter.WriteLine("----------");
                        Console.WriteLine("----------");
                        string PicPath = "";
                        if (System.IO.File.Exists(localImage))
                        {
                            PicPath = ImagesUtil.uploadLocalImage(localImage, AppKey, AppSecret, SessionKey, MovePicLogWriter);
                        }
                        else
                        {
                            MovePicLogWriter.WriteLine(localImage + " 不存在。");
                            Console.WriteLine(localImage + " 不存在。");
                        }
                        if (PicPath.Equals(""))
                        {
                            if (options.Prune)
                            {
                                Desc = Desc.Replace(localImage, PicPath);
                            }
                        }
                        else
                        {
                            Desc = Desc.Replace(localImage, PicPath);
                        }

                    }

                    FbTransaction myTransaction = fbCon.BeginTransaction();
                    FbCommand UpdateDescCommand = new FbCommand("UPDATE ITEM SET DESCRIPTION = @Desc WHERE CLIENT_ID = @ClientID", fbCon);
                    FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                    ParamID.Value = ClientID;
                    FbParameter ParamDesc = new FbParameter("@Desc", FbDbType.Text);
                    ParamDesc.Value = Desc;
                    UpdateDescCommand.Parameters.Add(ParamID);
                    UpdateDescCommand.Parameters.Add(ParamDesc);
                    UpdateDescCommand.Transaction = myTransaction;
                    UpdateDescCommand.ExecuteNonQuery();
                    myTransaction.Commit();
                }
                if (mainallpass && descallpass)
                {
                    FbTransaction myTransaction = fbCon.BeginTransaction();
                    FbCommand UpdateSyncStatusCommand = new FbCommand("UPDATE ITEM SET SYNC_STATUS = 2, UPLOAD_FAIL_MSG ='所有图片审核通过,可以上传了。' WHERE CLIENT_ID = @ClientID", fbCon);
                    FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                    ParamID.Value = ClientID;
                    UpdateSyncStatusCommand.Parameters.Add(ParamID);
                    UpdateSyncStatusCommand.Transaction = myTransaction;
                    UpdateSyncStatusCommand.ExecuteNonQuery();
                    myTransaction.Commit();
                    Console.WriteLine("所有图片审核通过");
                    MovePicLogWriter.WriteLine("所有图片审核通过");
                }
                else
                {
                    FbTransaction myTransaction = fbCon.BeginTransaction();
                    FbCommand UpdateSyncStatusCommand = new FbCommand("UPDATE ITEM SET SYNC_STATUS = 4, UPLOAD_FAIL_MSG ='有图片等待审核。' WHERE CLIENT_ID = @ClientID", fbCon);
                    FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                    ParamID.Value = ClientID;
                    UpdateSyncStatusCommand.Parameters.Add(ParamID);
                    UpdateSyncStatusCommand.Transaction = myTransaction;
                    UpdateSyncStatusCommand.ExecuteNonQuery();
                    myTransaction.Commit();
                    Console.WriteLine("==========>图片审核中");
                    MovePicLogWriter.WriteLine("==========>图片审核中");
                }
                Console.WriteLine("");
                MovePicLogWriter.WriteLine("");
            }

            fbCon.Close();
            MovePicLogWriter.Close();
            MovePicLog.Close();
        }
Ejemplo n.º 4
0
 public abstract void execute(Options options, INIManager iniManager);