예제 #1
0
파일: Program.cs 프로젝트: qwert11/mojo
        public static void Main(string[] args)
        {
            //var l = Data.GoogleSheetProvider<Data.MyData>.Get<Data.MyData>("1kE61PAN5zG_Ygx98PmaRxKZp0L1_NxSelEfOFC2owJs", "Class Data!A1:B");
            Data.GoogleSheetProvider <Data.MyData> .Set("1kE61PAN5zG_Ygx98PmaRxKZp0L1_NxSelEfOFC2owJs", "Class Data!A1:B");

            while (true)
            {
                IConnectionStringBuilder conn = new Connection("https://www.olx.ua");
                ICPath path1 = new CPath("/elektronika/kompyutery-i-komplektuyuschie/komplektuyuschie-i-aksesuary/protsessory/dnepr/q-5450/" +
                                         "?search%5Bfilter_float_price%3Afrom%5D=500&search%5Bfilter_float_price%3Ato%5D=1000"
                                         );
                ICPath path2 = new CPath("/elektronika/kompyutery-i-komplektuyuschie/komplektuyuschie-i-aksesuary/protsessory/dnepr/q-5460/" +
                                         "?search%5Bfilter_float_price%3Afrom%5D=500&search%5Bfilter_float_price%3Ato%5D=1000");
                ICPath path3 = new CPath("/elektronika/kompyutery-i-komplektuyuschie/komplektuyuschie-i-aksesuary/videokarty/dnepr/" +
                                         "?search%5Bfilter_float_price%3Afrom%5D=500&search%5Bfilter_float_price%3Ato%5D=2000");
                Parce(conn, path1);
                Thread.Sleep(2000);
                Parce(conn, path2);
                Thread.Sleep(3600);
//				Parce(conn, path3);
                Thread.Sleep(3600000);
//				Parce(new CPath("/elektronika/kompyutery-i-komplektuyuschie/komplektuyuschie-i-aksesuary/videokarty/dnepr/q-450/?search%5Bfilter_float_price%3Afrom%5D=1500&search%5Bfilter_float_price%3Ato%5D=1500"));
//				Thread.Sleep(3000);
            }
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
예제 #2
0
파일: CWeb.cs 프로젝트: doctorgu/MadeIn9
        public static bool IsCallerInSameServer(out string ErrMsgIs)
        {
            ErrMsgIs = "";

            string RemoteAddr = CWeb.GetRemoteIpAddress(HttpContext.Current);

            RemoteAddr = CPath.GetServerUrl(RemoteAddr).ToLower();

            string Server = HttpContext.Current.Request.ServerVariables.Get("LOCAL_ADDR");

            Server = CPath.GetServerUrl(Server).ToLower();

            if (RemoteAddr == Server)
            {
                return(true);
            }

            Server = HttpContext.Current.Request.ServerVariables.Get("HTTP_HOST");
            Server = CPath.GetServerUrl(Server).ToLower();

            if (RemoteAddr == Server)
            {
                return(true);
            }

            ErrMsgIs = "서버명이 다음과 같이 일치하지 않습니다.\r\n클라이언트: " + RemoteAddr + ", 서버: " + Server;
            return(false);
        }
예제 #3
0
파일: CWeb.cs 프로젝트: doctorgu/MadeIn9
        public static string ConvertRelativeToAbsoluteImgSrc(string UrlDirectory, string Html)
        {
            StringBuilder sb = new StringBuilder();

            Regex r = new Regex(CRegex.Pattern.ExtractUrlFromImgTag, RegexOptions.IgnoreCase);
            int   PosStart = 0, PosEnd = 0;

            for (Match m = r.Match(Html); m.Success; m = m.NextMatch())
            {
                PosEnd = (m.Index - 1);
                sb.Append(Html.Substring(PosStart, (PosEnd - PosStart + 1)));
                PosStart = (m.Index + m.Length);

                string Url    = m.Groups["Url"].Value;
                string UrlNew = CPath.ConvertRelativeToAbsolute(UrlDirectory, Url);
                sb.Append(m.Value.Replace(Url, UrlNew));
            }

            if ((PosStart + 1) <= Html.Length)
            {
                sb.Append(Html.Substring(PosStart));
            }

            return(sb.ToString());
        }
예제 #4
0
    //游戏初始化
    public void Init()
    {
        CPath.Init();

        fixedModules = new List <CModule>(3);
        fixedModules.Add(new Server());
        fixedModules[0].Init();

        updateModules = new List <CModule>(20);
        modules       = new List <CModule>(10);
        AddModule("Network", new CNetwork());
        AddModule("NetworkSrv", new CNetwork_Server());
        AddModule("AssetManager", new CAssetsManager());
        AddModule("DataBase", new CDatabase());
        AddModule("ScriptManager", new CScriptManager());

        AddModule("DataModel", new CDataModel());
        AddModule("UIManager", new CUIManager());
        AddModule("SceneManager", new CSceneManager());


        fixedUpdateNum = fixedModules.Count;
        updateNum      = updateModules.Count;

        // .ServerRunning = true;

        //fixedModules.Add();
        //CDataModel.Player.CsAccountLogin();
    }
예제 #5
0
        public static void Delete(string PathHasPattern, bool Recursive)
        {
            string LastPath = CPath.GetLastFolder(PathHasPattern);

            if ((LastPath.IndexOf('*') != -1) ||
                (LastPath.IndexOf('?') != -1))
            {
                string ParentPath = CPath.GetParentPath(PathHasPattern);
                if (!Directory.Exists(ParentPath))
                {
                    throw new FileNotFoundException(ParentPath + " Not exists", ParentPath);
                }

                DirectoryInfo di = new DirectoryInfo(ParentPath);

                foreach (DirectoryInfo dSub in di.GetDirectories(LastPath, SearchOption.TopDirectoryOnly))
                {
                    dSub.Delete(Recursive);
                }
            }
            else
            {
                Directory.Delete(PathHasPattern, Recursive);
            }
        }
예제 #6
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버의 파일을 삭제함.
        /// </summary>
        /// <param name="RemoteFullPath">서버에 있는 삭제할 파일의 전체 경로</param>
        public void DeleteFile(string RemoteFullPath)
        {
            string Folder = CPath.GetFolderName(RemoteFullPath, '/');
            string File   = CPath.GetFileName(RemoteFullPath, '/');

            DeleteFile(Folder, File);
        }
예제 #7
0
        static void Main(string[] args)
        {

            CStage _myStage = new CStage();
            StageControl myStageControl = new StageControl();

            myStageControl.Initialize();
            _myStage = myStageControl.Stage;
            CmillCmdCtrl myMillCtrl = new CmillCmdCtrl();

 //           double x, y, z;
 //           _myStage.GetPos(out x, out y, out z);
            CPath _myPath = new CPath();
            _myPath.SetPathParams(60,   //path frequency = 30 Hz
                                  75,       //Store a minimum of 45 points in the path point buffer
                                  15000.0,  //X scale - 20000.0 counts per inch
                                  15000.0,  //Y scale - 20000.0 counts per inch
                                  15000.0,      //Z scale - 1.0 counts per inch - not used
                                  0.175);

            _myPath.SetOrigin(0.0, 0.0, 0.0);
            _myPath.SetFeedrate(0.175);
            _myPath.SetTangentTolerance((float)10.0);

            myMillCtrl.ProcessGCode("C:\\Program Files (x86)\\Mill1A\\input\\CircleAtOrigin.nc");
            myMillCtrl.RunGCode();
        }
예제 #8
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버의 특정 폴더를 만듦.
        /// </summary>
        /// <param name="FolderName">만들 폴더 위치</param>
        public void CreateDirectory(string FolderName)
        {
            string[] aPath    = CPath.GetAllPathInArray(FolderName, '/', StringSplitOptions.RemoveEmptyEntries);
            string   PathList = "";

            for (int i = 0, i2 = aPath.Length; i < i2; i++)
            {
                PathList += aPath[i] + "/";
                if (!this.DirectoryExists(PathList))
                {
                    Uri RemoteUri = GetRemoteUri(PathList);

                    FtpWebRequest FtpReq = (FtpWebRequest)WebRequest.Create(RemoteUri);
                    if (!string.IsNullOrEmpty(this._Info.UserId))
                    {
                        FtpReq.Credentials = new NetworkCredential(this._Info.UserId, this._Info.Password);
                    }
                    FtpReq.UsePassive = this._Info.UsePassive;

                    FtpReq.Method = WebRequestMethods.Ftp.MakeDirectory;
                    FtpWebResponse FtpResp = (FtpWebResponse)FtpReq.GetResponse();
                    FtpResp.Close();
                }
            }
        }
예제 #9
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 클라이언트 컴퓨터의 파일을 업로드함.
        /// </summary>
        /// <param name="LocalFullPath">클라이언트 컴퓨터의 파일 전체 경로</param>
        /// <param name="RemoteFullPath">서버의 파일 전체 경로</param>
        public void UploadFile(string LocalFullPath, string RemoteFullUrl)
        {
            string Folder = CPath.GetFolderName(RemoteFullUrl, '/');
            string File   = CPath.GetFileName(RemoteFullUrl, '/');

            this.UploadFile(LocalFullPath, Folder, File);
        }
예제 #10
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 메모리 상에 있는 Stream을 업로드함.
        /// </summary>
        /// <param name="str">Stream 개체</param>
        /// <param name="RemoteFullPath">서버에 있는 파일의 전체 경로</param>
        public void UploadStream(Stream str, string RemoteFullPath)
        {
            string Folder = CPath.GetFolderName(RemoteFullPath, '/');
            string File   = CPath.GetFileName(RemoteFullPath, '/');

            UploadStream(str, Folder, File);
        }
예제 #11
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 있는 텍스트 파일의 내용을 리턴함.
        /// </summary>
        /// <param name="RemoteFullPath">서버에 있는 텍스트 파일의 전체 경로</param>
        /// <returns>텍스트 파일의 내용</returns>
        public string GetText(string RemoteFullPath)
        {
            string Folder = CPath.GetFolderName(RemoteFullPath, '/');
            string File   = CPath.GetFileName(RemoteFullPath, '/');

            return(GetText(Folder, File));
        }
예제 #12
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 있는 파일을 클라이언트 컴퓨터로 다운로드함.
        /// </summary>
        /// <param name="LocalFullPath">다운로드할 파일의 클라이언트 전체 경로</param>
        /// <param name="RemoteFullPath">서버에 있는 파일의 전체 경로</param>
        public void DownloadFile(string LocalFullPath, string RemoteFullPath)
        {
            string Folder = CPath.GetFolderName(RemoteFullPath, '/');
            string File   = CPath.GetFileName(RemoteFullPath, '/');

            DownloadFile(LocalFullPath, Folder, File);
        }
예제 #13
0
파일: CTts.cs 프로젝트: doctorgu/MadeIn9
        public void SaveAsMp3(string Ssml, bool UseThread, string FullPathMp3, string LameFullPath, WaveToMp3Preset Preset)
        {
            string FullPathWave = CPath.GetNumberedFullPath(Path.Combine(Path.GetDirectoryName(FullPathMp3), Path.GetFileNameWithoutExtension(FullPathMp3) + ".wav"));

            if (UseThread)
            {
                Thread t = new Thread(() =>
                {
                    using (SpeechSynthesizer ss = new SpeechSynthesizer())
                    {
                        ss.SetOutputToWaveFile(FullPathWave);
                        ss.SpeakSsml(Ssml);
                    }
                });
                t.Start();
                t.Join();
            }
            else
            {
                using (SpeechSynthesizer ss = new SpeechSynthesizer())
                {
                    ss.SetOutputToWaveFile(FullPathWave);
                    ss.SpeakSsml(Ssml);
                }
            }

            CAudio.ConvertWaveToMp3(FullPathWave, FullPathMp3, LameFullPath, Preset);
            File.Delete(FullPathWave);
        }
예제 #14
0
 public void OnPahFound(Vector3[] waypoints, bool pathSuccessful)
 {
     if (pathSuccessful)
     {
         path = new CPath(waypoints, transform.position, turnDist, stoppingDistance);
         StopCoroutine("FollowPath");
         StartCoroutine("FollowPath");
     }
 }
예제 #15
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// <paramref name="RemoteFullPath"/> 파일이 존재하는 지 여부를 리턴함.
        /// </summary>
        /// <param name="RemoteFullPath">폴더</param>
        /// <returns><paramref name="RemoteFullPath"/> 파일이 존재하는 지 여부</returns>
        public bool FileExists(string RemoteFullPath)
        {
            string[] aFile = this.GetFileNames(RemoteFullPath);
            if ((aFile.Length == 1) && (aFile[0] == CPath.GetFileName(RemoteFullPath, '/')))
            {
                return(true);
            }

            return(false);
        }
예제 #16
0
        /// <summary>
        /// 단축아이콘의 아이콘을 실행파일의 아이콘으로 변경함.
        /// </summary>
        /// <param name="ExePath"></param>
        /// <param name="ExeFile"></param>
        public static void ChangeShortcutIconWithExeIcon(string ExePath, string ExeFile)
        {
            string ExeFileNoExt = CPath.GetFileNameWithoutExtension(ExeFile);

            string[] aPathFile =
                new String[]
            {
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Internet Explorer\Quick Launch",
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                Environment.GetFolderPath(Environment.SpecialFolder.Programs),
                Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
            };

            Type   typWsh  = Type.GetTypeFromProgID("WScript.Shell");
            object instWsh = Activator.CreateInstance(typWsh);

            for (int i = 0, i2 = aPathFile.Length; i < i2; i++)
            {
                FileInfo fi = CFile.FindFirstFile(aPathFile[i], ExeFileNoExt + ".lnk", true);
                if (fi != null)
                {
                    string PathFile = (string)fi.FullName;

                    object Shortcut = typWsh.InvokeMember(
                        "CreateShortcut",
                        BindingFlags.InvokeMethod | BindingFlags.Public,
                        null,
                        instWsh,
                        new object[1] {
                        PathFile
                    });

                    Type typShortcut = Shortcut.GetType();
                    typShortcut.InvokeMember(
                        "IconLocation",
                        BindingFlags.SetProperty | BindingFlags.Public,
                        null,
                        Shortcut,
                        new object[1] {
                        ExePath + "\\" + ExeFile
                    });

                    typShortcut.InvokeMember(
                        "Save",
                        BindingFlags.InvokeMethod | BindingFlags.Public,
                        null,
                        Shortcut,
                        null);
                }
            }
        }
예제 #17
0
        public static void UnregisterNet(FrameworkVersion Ver, string FullPath)
        {
            string RegasmFullPath = Path.Combine(CPath.GetFrameworkFolder(Ver), "regasm.exe");

            Process p = new Process();

            ProcessStartInfo si = new ProcessStartInfo(RegasmFullPath);

            si.Arguments   = "\"" + FullPath + "\"" + " /unregister";
            si.WindowStyle = ProcessWindowStyle.Hidden;
            p.StartInfo    = si;

            p.Start();
            p.WaitForExit(3000);
        }
예제 #18
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// <paramref name="RemoteFolder"/> 폴더가 존재하는 지 여부를 리턴함.
        /// </summary>
        /// <param name="RemoteFolder">폴더</param>
        /// <returns><paramref name="RemoteFolder"/> 폴더가 존재하는 지 여부</returns>
        public bool DirectoryExists(string RemoteFolder)
        {
            string[] aFile = this.GetFileNames(RemoteFolder);
            if (aFile == null)
            {
                return(false);
            }

            if ((aFile.Length == 1) && (aFile[0] == CPath.GetFileName(RemoteFolder, '/')))
            {
                return(false);
            }

            return(true);
        }
예제 #19
0
        public static void RegisterNet(FrameworkVersion Ver, string FullPath)
        {
            string RegasmFullPath = Path.Combine(CPath.GetFrameworkFolder(Ver), "regasm.exe");

            Process p = new Process();

            ProcessStartInfo si      = new ProcessStartInfo(RegasmFullPath);
            string           TlbName = Path.GetFileNameWithoutExtension(FullPath) + ".tlb";

            si.Arguments   = "\"" + FullPath + "\"" + " /codebase /tlb:" + TlbName;
            si.WindowStyle = ProcessWindowStyle.Hidden;
            p.StartInfo    = si;

            p.Start();
            p.WaitForExit(3000);
            //C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm D:\My\MadeIn9\C#\ComhwalChecker\bin\Release\ComhwalChecker.dll /codebase /tlb:ComhwalChecker.tlb
        }
예제 #20
0
        private void containerBtn_Click()
        {
            var dialog = new FolderBrowserDialog();

            dialog.ShowDialog();
            CPath = dialog.SelectedPath;

            if (!string.IsNullOrWhiteSpace(CPath))
            {
                ContainerBtnText = CPath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last();
            }
            else
            {
                ContainerBtnText = null;
            }

            CheckStartBtnEnabled();
            CheckStartBtnWPDEnabled();
            CPath += "\\log report\\" + DateTime.Now.ToString("dd.MM.yyyy");
        }
예제 #21
0
    //设置目的地指示环
    public void                 SetMouseTargetProjTex(float x, float z)
    {
        if (m_pMouseTarget == null)
        {
            //创建
            m_pMouseTarget = (CObject_ProjTex_MouseTarget)CObjectManager.Instance.NewProjTexMouseTarget(-1);
            m_pMouseTarget.Initial(null);
        }
        //判断目标是否不可走
        bool bUnReachAble = CPath.IsPointInUnreachRegion(x, z);

        m_pMouseTarget.SetReachAble(!bUnReachAble);
        if (bUnReachAble)
        {
//          STRING strWarn = COLORMSGFUNC("UNREACHABLE");
//          ADDTALKMSG(strWarn);
        }
        //设置位置
        m_pMouseTarget.SetMapPosition(x, z);
    }
예제 #22
0
        /// <summary>

        public static CFullPathFullUrl GetNumberedFullPathFullUrl(HttpContext ctx, string FullUrl)
        {
            CFullPathFullUrl PathUrl = new CFullPathFullUrl();

            string FileName  = CUrl.GetFileName(FullUrl);
            string UrlFolder = CUrl.GetParentDirectory(FullUrl);
            string FullPath  = ctx.Server.MapPath(FullUrl);

            string FullPathNew = CPath.GetNumberedFullPath(FullPath);

            if (FullPath != FullPathNew)
            {
                FileName = Path.GetFileName(FullPathNew);
                FullUrl  = Combine(UrlFolder, FileName);
                FullPath = FullPathNew;
            }

            PathUrl.FullUrl  = FullUrl;
            PathUrl.FullPath = FullPath;
            return(PathUrl);
        }
예제 #23
0
        //!!!
        //현재는 쓰이지 않으나 쓰게 되면 CopyAll의 것으로 수정하고 Copy, CopyAll을 공통으로 쓰게 해야 함.
        private void Copy(FileInfo fiSrc)
        {
            bool IsFile = !CFile.GetIsFolder(fiSrc);

            if (_DestType == DestTypes.FileSystem)
            {
                for (int i = 0, i2 = this._aRootFolderDest.Length; i < i2; i++)
                {
                    string FullPathDest = this._aRootFolderDest[i] + fiSrc.FullName.Substring(this._RootFolderSrc.Length);

                    if (IsFile)
                    {
                        _File.CopyFile(fiSrc.FullName, FullPathDest);
                    }
                    else
                    {
                        _File.CopyDirectory(fiSrc.FullName, FullPathDest);
                    }
                }
            }
            else if (_DestType == DestTypes.Ftp)
            {
                for (int i = 0, i2 = this._aFtpInfoDest.Length; i < i2; i++)
                {
                    CFtpInfoSync InfoSync = (CFtpInfoSync)_aFtp[i].Info;

                    if (IsFile)
                    {
                        string FullPathSrc  = fiSrc.FullName;
                        string FullPathDest = CPath.GetFullPathDest(fiSrc.DirectoryName, InfoSync.Folder, FullPathSrc, '/');
                        //FullPathDest의 폴더가 없다면 에러 나나 속도 때문에 무시함.
                        _aFtp[i].UploadFile(FullPathSrc, FullPathDest);
                    }
                    else
                    {
                        _aFtp[i].UploadDirectory(fiSrc.DirectoryName, InfoSync.Folder);
                    }
                }
            }
        }
예제 #24
0
        public static bool Exists(string PathHasPattern)
        {
            string LastPath = CPath.GetLastFolder(PathHasPattern);

            if ((LastPath.IndexOf('*') != -1) ||
                (LastPath.IndexOf('?') != -1))
            {
                string ParentPath = CPath.GetParentPath(PathHasPattern);
                if (!Directory.Exists(ParentPath))
                {
                    return(false);
                }

                DirectoryInfo di = new DirectoryInfo(ParentPath);

                DirectoryInfo[] adi = di.GetDirectories(LastPath, SearchOption.TopDirectoryOnly);
                return(adi.Length > 0);
            }
            else
            {
                return(Directory.Exists(PathHasPattern));
            }
        }
예제 #25
0
        /// <summary>
        /// 주의: 현재 시점에서는 참조하는 파일이 없을 수 있으므로 이곳에서는 참조하는 외부 파일을 이용하면 안됨.
        /// </summary>
        /// <param name="htRefs"></param>
        public static void SaveResourcesToFiles(Hashtable htRefs)
        {
            string          ResName = "AutoUpdate." + Application.ProductName;
            ResourceManager rm      = new ResourceManager(ResName, CAssembly.GetEntryOrExecuting());

            foreach (DictionaryEntry d in htRefs)
            {
                string Name     = (string)d.Key;
                string PathFile = (string)d.Value;

                string NewPathFile = Path.GetDirectoryName(Application.ExecutablePath)
                                     + "\\" + CPath.GetFileName(PathFile);

                if (System.IO.File.Exists(NewPathFile))
                {
                    continue;
                }

                byte[]     byt = (byte[])rm.GetObject(Name);
                FileStream fs  = new FileStream(NewPathFile, FileMode.Create, FileAccess.Write, FileShare.Write);
                fs.Write(byt, 0, byt.Length);
                fs.Close();

                //DoctorGu.dll이 없을 수도 있으므로
                //CFile.WaitForFileCreation(NewPathFile)을 사용하지 않음.
                for (int i = 0; i < 10; i++)
                {
                    if (System.IO.File.Exists(NewPathFile))
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
예제 #26
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        private Uri GetRemoteUri(string FolderName, string FileName)
        {
            string Url = this.Url;

            if (!string.IsNullOrEmpty(FolderName))
            {
                Url = CPath.CombineUrl(Url, FolderName.Trim('/'));
                if (!Url.EndsWith("/"))
                {
                    Url = Url + "/";
                }
            }
            if (!string.IsNullOrEmpty(FileName))
            {
                Url = CPath.CombineUrl(Url, FileName);
            }

            //C# 폴더가 C 폴더로 만들어지는 것을 방지
            Url = CWeb.EncodeUrlForWebRequest(Url);

            Uri RemoteUri = new Uri(Url);

            return(RemoteUri);
        }
예제 #27
0
        private List <Tuple <string, string, CFtpInfoSync> > GetFullPathReferencingDest(string[] aFullPathReferencing)
        {
            List <Tuple <string, string, CFtpInfoSync> > tpFullPathDest = new List <Tuple <string, string, CFtpInfoSync> >();

            foreach (string FullPath in aFullPathReferencing)
            {
                for (int i = 0; i < this._aRootFolderDest.Length; i++)
                {
                    if (_DestType == DestTypes.FileSystem)
                    {
                        tpFullPathDest.Add(new Tuple <string, string, CFtpInfoSync>(FullPath, CPath.GetFullPathDest(this._RootFolderSrc, this._aRootFolderDest[i], FullPath), null));
                    }
                    else
                    {
                        tpFullPathDest.Add(new Tuple <string, string, CFtpInfoSync>(FullPath, CUrl.GetFullUrlDest(this._RootFolderSrc, this._aRootFolderDest[i], FullPath), this._aFtpInfoDest[i]));
                    }
                }
            }

            return(tpFullPathDest);
        }
예제 #28
0
        private bool IsValidForSync(FileInfo fiSrc, FileInfo fiDest, bool IsFtp, out string FullPathSrcNewIs)
        {
            FullPathSrcNewIs = "";

            bool IsFile = !CFile.GetIsFolder(fiSrc);

            bool IsValid = true;

            if (IsFile)
            {
                if (IsValid)
                {
                    IsValid = IsValidExtension(fiSrc);
                }

                if (IsFtp)
                {
                    if (_SyncType == SyncTypes.CompareTimeBetweenSrcAndDest)
                    {
                        throw new Exception(string.Format("SyncType:{0} disallowed in Ftp.", _SyncType));
                    }

                    //숨김 속성인 경우 new FileStream 사용할 때 읽지 못함.
                    if (IsValid)
                    {
                        IsValid = ((fiSrc.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden);
                    }

                    if (IsValid)
                    {
                        IsValid = (fiSrc.LastWriteTime > _DateTimeAfter);
                    }
                }
                else
                {
                    if (_SyncType == SyncTypes.CompareTimeBetweenSrcAndDest)
                    {
                        if (fiDest != null)
                        {
                            DateTime DateSrc  = fiSrc.LastWriteTime;
                            DateTime DateDest = fiDest.LastWriteTime;

                            long SizeSrc  = fiSrc.Length;
                            long SizeDest = fiDest.Length;

                            if (IsValid)
                            {
                                IsValid = ((DateSrc != DateDest) || (SizeSrc != SizeDest));
                            }
                        }
                    }
                    else
                    {
                        if (IsValid)
                        {
                            IsValid = (fiSrc.LastWriteTime > _DateTimeAfter);
                        }
                    }
                }
            }
            else
            {
                if (IsValid)
                {
                    IsValid = IsValidFolder(fiSrc);
                }
            }

            if (IsValid)
            {
                if (this._MinifyJs && (string.Compare(fiSrc.Extension, ".js", true) == 0))
                {
#if !DotNet35
                    string JsSource = CFile.GetTextInFile(fiSrc.FullName);

                    Minifier mf = new Minifier();
                    string   JsSourceMinified = mf.MinifyJavaScript(JsSource);

                    FullPathSrcNewIs = CFile.GetTempFileName(fiSrc.Extension);
                    CFile.WriteTextToFile(FullPathSrcNewIs, JsSourceMinified);
#else
                    throw new Exception(".Net 3.5 does not support Minifier.");
#endif
                }

                if ((this._aJsFullPathRefered != null) && (this._aJsFullPathRefered.Length > 0))
                {
                    if (CArray.IndexOf(this._aJsFullPathRefered, fiSrc.FullName, true) != -1)
                    {
                        List <Tuple <string, string, CFtpInfoSync> > tpPathAndHtml = GetPathAndHtmlAndFtpInfoDest(this._aFullPathReferencingJs, fiSrc);

                        foreach (Tuple <string, string, CFtpInfoSync> tp in tpPathAndHtml)
                        {
                            string       FullPathDest = tp.Item1;
                            string       Html         = tp.Item2;
                            CFtpInfoSync FtpInfo      = tp.Item3;

                            if (_DestType == DestTypes.FileSystem)
                            {
                                CFile.WriteTextToFile(FullPathDest, Html);
                            }
                            else
                            {
                                string TmpFullPath = CFile.GetTempFileName();
                                CFile.WriteTextToFile(TmpFullPath, Html);

                                CFtp2 Ftp = new CFtp2(FtpInfo);
                                Ftp.UploadFile(TmpFullPath, FullPathDest);
                            }
                        }
                    }
                    else if (CArray.IndexOf(this._aFullPathReferencingJs, fiSrc.FullName, true) != -1)
                    {
                        for (int i = 0; i < this._aRootFolderDest.Length; i++)
                        {
                            string HtmlSrc = CFile.GetTextInFile(fiSrc.FullName);

                            string HtmlDest = "";

                            string FullPathDest = "";
                            string FullUrlDest  = "";
                            if (_DestType == DestTypes.FileSystem)
                            {
                                FullPathDest = CPath.GetFullPathDest(this._RootFolderSrc, this._aRootFolderDest[i], fiSrc.FullName);
                                HtmlDest     = CFile.GetTextInFile(FullPathDest);
                            }
                            else
                            {
                                CFtp2 Ftp = new CFtp2(this._aFtpInfoDest[i]);
                                FullUrlDest = CUrl.GetFullUrlDest(this._RootFolderSrc, this._aRootFolderDest[i], fiSrc.FullName);
                                HtmlDest    = Ftp.GetText(FullUrlDest);
                            }

                            string HtmlSrcNew = GetHtmlVersionReplaced(HtmlSrc, HtmlDest);
                            if (string.IsNullOrEmpty(HtmlSrcNew))
                            {
                                continue;
                            }


                            FullPathSrcNewIs = CFile.GetTempFileName(fiSrc.Extension);
                            CFile.WriteTextToFile(FullPathSrcNewIs, HtmlSrcNew);
                        }
                    }
                }
            }

            return(IsValid);
        }
예제 #29
0
        /// <summary>
        /// 설정된 조건에 따라 원본 폴더의 모든 파일을 대상 폴더에 복사함.
        /// </summary>
        public void CopyAll()
        {
            string FolderSrc = this._RootFolderSrc;

            if (_DestType == DestTypes.FileSystem)
            {
                List <string> aDirectoryChecked = new List <string>();

                for (int i = 0, i2 = this._aRootFolderDest.Length; i < i2; i++)
                {
                    if (this._aFullPathSrc != null)
                    {
                        for (int j = 0; j < this._aFullPathSrc.Length; j++)
                        {
                            string FullPathSrc  = this._aFullPathSrc[j];
                            string FullPathDest = CPath.GetFullPathDest(FolderSrc, this._aRootFolderDest[i], FullPathSrc);

                            string FolderDest = CPath.GetFolderName(FullPathDest);
                            if (aDirectoryChecked.IndexOf(FolderDest) == -1)
                            {
                                if (!Directory.Exists(FolderDest))
                                {
                                    Directory.CreateDirectory(FolderDest);
                                }

                                aDirectoryChecked.Add(FolderDest);
                            }

                            _File.CopyFile(FullPathSrc, FullPathDest);
                        }
                    }
                    else
                    {
                        _File.CopyDirectory(FolderSrc, this._aRootFolderDest[i]);
                    }
                }
            }
            else if (_DestType == DestTypes.Ftp)
            {
                for (int i = 0, i2 = this._aFtpInfoDest.Length; i < i2; i++)
                {
                    CFtp2        FtpCur   = _aFtp[i];
                    CFtpInfoSync InfoSync = (CFtpInfoSync)FtpCur.Info;

                    List <string> aDirectoryChecked = new List <string>();

                    if (this._aFullPathSrc != null)
                    {
                        for (int j = 0; j < this._aFullPathSrc.Length; j++)
                        {
                            string FullPathSrc  = this._aFullPathSrc[j];
                            string FullPathDest = CUrl.GetFullUrlDest(FolderSrc, InfoSync.Folder, FullPathSrc);

                            string FolderDest = CUrl.GetDirectoryName(FullPathDest);
                            if (aDirectoryChecked.IndexOf(FolderDest) == -1)
                            {
                                if (!FtpCur.DirectoryExists(FolderDest))
                                {
                                    FtpCur.CreateDirectory(FolderDest);
                                }

                                aDirectoryChecked.Add(FolderDest);
                            }

                            FtpCur.UploadFile(FullPathSrc, FullPathDest);
                        }
                    }
                    else
                    {
                        FtpCur.UploadDirectory(FolderSrc, InfoSync.Folder);
                    }
                }
            }
        }
예제 #30
0
파일: CFtp2.cs 프로젝트: doctorgu/MadeIn9
        /// <summary>
        /// FTP 서버에 클라이언트 컴퓨터의 파일을 업로드함.
        /// </summary>
        /// <param name="LocalFullPath">클라이언트 컴퓨터의 파일 전체 경로</param>
        /// <param name="RemoteFolder">서버의 폴더 위치</param>
        /// <param name="RemoteFile">서버의 파일 이름</param>
        public void UploadFile(string LocalFullPath, string RemoteFolder, string RemoteFile)
        {
            string LocalFullPathNew = "";

            if (this.BeforeFileUpload != null)
            {
                CBeforeFileUploadEventArgs e = new CBeforeFileUploadEventArgs()
                {
                    LocalFullPath = LocalFullPath
                };
                this.BeforeFileUpload(this, e);

                if (e.Cancel)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(e.LocalFullPathNew))
                {
                    LocalFullPathNew = e.LocalFullPathNew;
                }
            }

            try
            {
                Uri RemoteUri = GetRemoteUri(RemoteFolder, RemoteFile);

                FtpWebRequest FtpReq = (FtpWebRequest)WebRequest.Create(RemoteUri);
                if (!string.IsNullOrEmpty(this._Info.UserId))
                {
                    FtpReq.Credentials = new NetworkCredential(this._Info.UserId, this._Info.Password);
                }
                FtpReq.UsePassive = this._Info.UsePassive;

                FtpReq.Method = WebRequestMethods.Ftp.UploadFile;

                using (FileStream readStream = new FileStream((!string.IsNullOrEmpty(LocalFullPathNew) ? LocalFullPathNew : LocalFullPath), FileMode.Open, FileAccess.Read))
                {
                    using (Stream writeStream = FtpReq.GetRequestStream())
                    {
                        int    Length    = 256;
                        Byte[] buffer    = new Byte[Length];
                        int    bytesRead = readStream.Read(buffer, 0, Length);

                        while (bytesRead > 0)
                        {
                            writeStream.Write(buffer, 0, bytesRead);
                            bytesRead = readStream.Read(buffer, 0, Length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (this.FileUploadFailed != null)
                {
                    CFileUploadFailedEventArgs e = new CFileUploadFailedEventArgs()
                    {
                        LocalFullPath    = LocalFullPath,
                        LocalFullPathNew = LocalFullPathNew,
                        RemoteFullUrl    = CPath.CombineUrl(RemoteFolder, RemoteFile),
                        ex = ex
                    };
                    this.FileUploadFailed(this, e);
                    return;
                }
                else
                {
                    throw new Exception(ex.Message, ex);
                }
            }

            if (this.AfterFileUpload != null)
            {
                CAfterFileUploadEventArgs e = new CAfterFileUploadEventArgs()
                {
                    LocalFullPath    = LocalFullPath,
                    LocalFullPathNew = LocalFullPathNew,
                    RemoteFullUrl    = CPath.CombineUrl(RemoteFolder, RemoteFile)
                };
                this.AfterFileUpload(this, e);
            }
        }