Пример #1
0
        /// <summary>
        /// 29/01/2015
        /// 1) Create update files list
        /// 2) Create queue upload list. Iterating file list foreach connection ( i can have multiple cloud storage )
        /// 3) Start async upload.
        /// </summary>
        internal void BeginUpdatedFiles(int mode)
        {
            // ? -> Set IsEnabled = false on GUI to prevent change during upload ?

            var releasesPath = SquirrelOutputPath;

            if (!Directory.Exists(releasesPath))
            {
                throw new Exception("Releases directory " + releasesPath + "not finded !");
            }

            if (SelectedConnection == null)
            {
                throw new Exception("No selected upload location !");
            }

            /* I tried picking file to update, by their  LastWriteTime , but it doesn't works good. I don't know why.
             *
             * So i just pick these file by their name
             *
             */

            var fileToUpdate = new List <string>()
            {
                "RELEASES",
                string.Format("{0}-{1}-delta.nupkg", AppId, Version),
            };

            if (mode == 0)
            {
                fileToUpdate.Add(string.Format("Setup.exe"));
                //     fileToUpdate.Add(string.Format("{0}-{1}-full.nupkg", AppId, Version));
            }



            var updatedFiles = new List <FileInfo>();

            foreach (var fp in fileToUpdate)
            {
                var ffp = releasesPath + fp;
                if (!File.Exists(ffp))
                {
                    continue;
                }

                updatedFiles.Add(new FileInfo(ffp));
            }

            if (UploadQueue == null)
            {
                UploadQueue = new ObservableCollection <SingleFileUpload>();
            }

            UploadQueue.Clear();

            var WebConnections = new List <WebConnectionBase>()
            {
                SelectedConnection
            };

            foreach (var connection in WebConnections)
            {
                foreach (var file in updatedFiles)
                {
                    UploadQueue.Add(new SingleFileUpload()
                    {
                        Filename       = Path.GetFileName(file.FullName),
                        ConnectionName = connection.ConnectionName,
                        FileSize       = BytesToString(file.Length),
                        Connection     = connection,
                        FullPath       = file.FullName,
                    });
                }
            }

            if (!CheckInternetConnection.IsConnectedToInternet())
            {
                throw new Exception("Internet Connection not available");
            }

            ProcessNextUploadFile();
        }