public HttpResponseMessage GetInfo(ClientBasicInfo clientBasicInfo)
        {
            var productName           = clientBasicInfo.ProductName;
            var revitVersion          = clientBasicInfo.RevitVersion;
            var currentProductVersion = clientBasicInfo.CurrentProductVersion;

            //ProductName_RevitVersion_OldProductVersion_NewProductVersion
            var latestFilePath = ServerFileUtils.GetLatestFilePath(productName, revitVersion, currentProductVersion);

            if (string.IsNullOrEmpty(latestFilePath) || !File.Exists(latestFilePath))
            {
                return(null);
            }

            var latestFile   = new FileInfo(latestFilePath);
            var downloadInfo = new DownloadFileInfo()
            {
                LatestProductVersion  = ServerFileUtils.GetLatestVersion(Path.GetFileNameWithoutExtension(latestFilePath)),
                DownloadFileMd5       = Md5Utils.GetFileMd5(latestFilePath),
                DownloadFileTotalSize = latestFile.Length
            };
            HttpResponseMessage response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(downloadInfo), Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(response);
        }
        //TestFile directory is used to Test socket
        //See Socket_APM-SAEA\TestFile
        static void Main(string[] args)
        {
            var mainFolder = AppDomain.CurrentDomain.BaseDirectory.Replace("bin", "TestFile");

            ClientBasicInfo basicInfo = new ClientBasicInfo()
            {
                ProductName           = "Airforce094",
                RevitVersion          = "Revit2016",
                CurrentProductVersion = "18.1.6"
            };

            var serverFilePath = Path.Combine(mainFolder, "Server\\Airforce094_Revit2016_18.1.6_18.1.7.zip");

            DownloadFileInfo dlInfo = new DownloadFileInfo()
            {
                LatestProductVersion  = "18.1.7",
                DownloadFileMd5       = Md5Utils.GetFileMd5(serverFilePath),
                DownloadFileTotalSize = new FileInfo(serverFilePath).Length
            };

            ClientLinkInfo clInfo = new ClientLinkInfo()
            {
                IpString = "127.0.0.1",
                Port     = 8885
            };

            var localSavePath = Path.Combine(mainFolder, "Local");
            var tempFilesDir  = Path.Combine(mainFolder, "TempFile");
            var cs            = new ClientSocket();
            var result        = cs.StartClient(basicInfo, dlInfo, clInfo, localSavePath, tempFilesDir);

            Console.WriteLine(result);
            Console.ReadKey();
        }
示例#3
0
        /// <summary>
        /// Get Download File Info
        /// </summary>
        /// <param name="basicInfo"></param>
        /// <param name="serverAddress"></param>
        /// <param name="controllerName"></param>
        /// <param name="actionName"></param>
        /// <param name="serverResult"></param>
        /// <returns></returns>
        public static bool RequestDownloadFileInfo(ClientBasicInfo basicInfo,
                                                   string serverAddress,
                                                   string controllerName,
                                                   string actionName,
                                                   ref DownloadFileInfo serverResult)
        {
            var packageInfo = JsonConvert.SerializeObject(basicInfo);

            try
            {
                HttpClient httpClient = new HttpClient
                {
                    BaseAddress = new Uri(serverAddress),
                    Timeout     = TimeSpan.FromMinutes(20)
                };

                if (ConnectionTest(serverAddress))
                {
                    StringContent strData           = new StringContent(packageInfo, Encoding.UTF8, "application/json");
                    string        postUrl           = httpClient.BaseAddress + $"api/{controllerName}/{actionName}";
                    Uri           address           = new Uri(postUrl);
                    Task <HttpResponseMessage> task = httpClient.PostAsync(address, strData);
                    try
                    {
                        task.Wait();
                    }
                    catch
                    {
                        return(false);
                    }
                    HttpResponseMessage response = task.Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        return(false);
                    }

                    try
                    {
                        string jsonResult = response.Content.ReadAsStringAsync().Result;
                        serverResult = JsonConvert.DeserializeObject <DownloadFileInfo>(jsonResult);
                        if (serverResult != null)
                        {
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        return(false);
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
示例#4
0
        public ClientDownLoadViewModel(ClientBasicInfo cb, DownloadFileInfo dl)
        {
            ClientInfo   = cb;
            DownloadInfo = dl;

            LinkInfos = new ObservableCollection <LinkInfo>();
            InitData();

            DownloadCmd = new DelegateCommand(StartDownload);
        }
示例#5
0
 public ActionResult RegisterClient(ClientBasicInfo cbi)
 {
     using (var db = new MainDbContext())
     {
         var client = db.clientBasicInfo.Create();
         client = cbi;
         db.clientBasicInfo.Add(client);
         db.SaveChanges();
     }
     return(RedirectToAction("RegisteredClients", "Admin"));
 }
        private void ConnectServer()
        {
            try
            {
                ClientBasicInfo cb = new ClientBasicInfo()
                {
                    ProductName           = RequestInfos.FirstOrDefault(x => string.Equals(x.RName, "ProductNameInEng", StringComparison.OrdinalIgnoreCase))?.RValue,
                    RevitVersion          = RequestInfos.FirstOrDefault(x => string.Equals(x.RName, "RevitVersion", StringComparison.OrdinalIgnoreCase))?.RValue,
                    CurrentProductVersion = RequestInfos.FirstOrDefault(x => string.Equals(x.RName, "ProductVersion", StringComparison.OrdinalIgnoreCase))?.RValue
                };
                ClientInfo = cb;
                DownloadFileInfo df = new DownloadFileInfo();

                var result = RequestInfoUtils.RequestDownloadFileInfo(cb, "http://localhost:55756/", "GetFileInfo", "GetInfo", ref df);
                DownloadInfo = df;
                if (result)
                {
                    ClientInfoModel r1 = new ClientInfoModel()
                    {
                        RName  = "LatestProductVersion",
                        RValue = df.LatestProductVersion
                    };
                    ClientInfoModel r2 = new ClientInfoModel()
                    {
                        RName  = "DownloadFileMd5",
                        RValue = df.DownloadFileMd5
                    };
                    ClientInfoModel r3 = new ClientInfoModel()
                    {
                        RName  = "DownloadFileTotalSize",
                        RValue = df.DownloadFileTotalSize.ToString()
                    };
                    ReceiveInfos.Add(r1);
                    ReceiveInfos.Add(r2);
                    ReceiveInfos.Add(r3);
                }
                else
                {
                    MessageBox.Show("Get DownLoad File Failed!");
                }
            }
            catch
            {
                MessageBox.Show("Get DownLoad File Failed!");
            }
        }
示例#7
0
        public ActionResult EditClient(ClientBasicInfo cbi_cl)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    //var _cbi_cl = db.clientBasicInfo.SingleOrDefault(c => c.clientId == cbi_cl.clientId);
                    //_cbi_cl = cbi_cl;
                    cbi_cl.clientId        = Convert.ToInt32(TempData.Get <string>("clientIdToEdit"));
                    db.Entry(cbi_cl).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            else
            {
                ModelState.AddModelError("", "Incorrect data has been entered");
            }

            //  in case editing and shit f***s up
            TempData.Put("currentPageNumberForServerSidePagination", "0");
            TempData.Put("currentPageNumber", "0");
            return(RedirectToAction("RegisteredClients"));
        }
示例#8
0
        public bool StartClient(ClientBasicInfo basicInfo, DownloadFileInfo dlInfo, ClientLinkInfo clInfo,
                                string localSaveFolderPath, string tempFilesDir)
        {
            if (basicInfo == null || dlInfo == null || clInfo == null ||
                string.IsNullOrEmpty(localSaveFolderPath) || string.IsNullOrEmpty(tempFilesDir))
            {
                return(false);
            }
            if (!Directory.Exists(localSaveFolderPath))
            {
                Directory.CreateDirectory(localSaveFolderPath);
            }
            if (!Directory.Exists(tempFilesDir))
            {
                Directory.CreateDirectory(tempFilesDir);
            }
            else
            {
                DirectoryInfo di = new DirectoryInfo(tempFilesDir);
                di.Delete(true);
                Directory.CreateDirectory(tempFilesDir);
            }


            var updateFileName = $"{basicInfo.ProductName}_{basicInfo.RevitVersion}_{basicInfo.CurrentProductVersion}_{dlInfo.LatestProductVersion}";

            _updateFileName = updateFileName;

            var localSavePath         = Path.Combine(localSaveFolderPath, $"{updateFileName}.zip");
            var downloadChannelsCount = DownloadSetting.DownloadChannelsCount;

            _downloadChannelsCount = downloadChannelsCount;

            try
            {
                IPAddress  ipAddress = IPAddress.Parse(clInfo.IpString);
                IPEndPoint remoteEp  = new IPEndPoint(ipAddress, clInfo.Port);

                int  packetCount = downloadChannelsCount;
                long packetSize  = dlInfo.DownloadFileTotalSize / packetCount;
                _packSize = packetSize;


                var tasks = new Task[packetCount];
                for (int index = 0; index < packetCount; index++)
                {
                    int packetNumber = index;
                    var task         = new Task(() =>
                    {
                        Socket client   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        ComObject state = new ComObject {
                            WorkSocket = client, PacketNumber = packetNumber
                        };
                        client.BeginConnect(remoteEp, ConnectCallback, state);
                    });
                    tasks[packetNumber] = task;
                    task.Start();
                }
                Task.WaitAll(tasks);
                ReceiveDone.WaitOne();


                _isPacketsComplete = CheckPackets(TempReceivePacketDict, _downloadChannelsCount);
                CloseSockets(TempReceivePacketDict);
                if (_isPacketsComplete)
                {
                    GenerateTempFiles(ResultPacketDict, downloadChannelsCount, tempFilesDir);
                    FileUtils.CombineTempFiles(localSavePath, tempFilesDir);
                    return(Md5Utils.IsMd5Equal(dlInfo.DownloadFileMd5, Md5Utils.GetFileMd5(localSavePath)));
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }