Ejemplo n.º 1
0
        /// <summary>
        /// Save the data in the input datagram and the output datagram.  Currently this saves them both to disk.
        /// </summary>
        /// <param name="datagram">Input POCO</param>
        /// <param name="output">Result POCO</param>
        private static void saveData(ManifestRequest datagram, ManifestResponse output)
        {
            string fileNameBase = string.Format("{0}@{1}", datagram.ContractorID, datagram.ShipmentID);
            var    drives       = DriveInfo.GetDrives();
            //DriveInfo drive = null;
            ////Get the last drive on the machine
            //for (int lcv = 0; lcv < drives.Length; lcv++)
            //{
            //    if (drives[lcv].IsReady && drives[lcv].DriveType == DriveType.Fixed)
            //    {
            //        drive = drives[lcv];
            //    }
            //}
            //string path = drive.RootDirectory.FullName + "data";
            string path = System.Configuration.ConfigurationManager.AppSettings["dataFolder"];

            createDirectory(path);
            createDirectory(path + @"\datagrams");
            createDirectory(path + @"\results");

            string inputFile  = string.Format("{0}\\datagrams\\{1}.datagram.json", path, fileNameBase);
            string outputFile = string.Format("{0}\\results\\{1}.result.json", path, fileNameBase);

            File.WriteAllText(inputFile, JsonConvert.SerializeObject(datagram));
            File.WriteAllText(outputFile, JsonConvert.SerializeObject(output));
        }
Ejemplo n.º 2
0
    public static ManifestRequest Initialize()
    {
        //改成不依赖MonoBehavior
        //var instance = FindObjectOfType<Assets>();
        //if(instance == null)
        //{
        //    instance = new GameObject("Assets").AddComponent<Assets>();
        //    DontDestroyOnLoad(instance.gameObject);
        //}

        if (string.IsNullOrEmpty(basePath))
        {
            basePath = Application.streamingAssetsPath + Path.DirectorySeparatorChar;
        }

        if (string.IsNullOrEmpty(updatePath))
        {
            updatePath = Application.persistentDataPath + Path.DirectorySeparatorChar;
        }

        Clear();

        GameLog.Log(string.Format(
                        "Initialize with: runtimeMode={0}\nbasePath:{1}\nupdatePath={2}",
                        runtimeMode, basePath, updatePath));

        var request = new ManifestRequest {
            name = ManifestAsset
        };

        AddAssetRequest(request);
        return(request);
    }
Ejemplo n.º 3
0
        public ManifestRequest LoadManifest()
        {
            Log.Debug("Initialize with: runtimeMode={0}\nbasePath:{1}\nupdatePath={2}",
                      GameUtility.Assets.runtimeMode, GameUtility.Assets.basePath, GameUtility.Assets.dataPath);
            var request = new ManifestRequest {
                url = GameUtility.Assets.manifestFilePath
            };

            AddAssetRequest(request);
            return(request);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Accept and process a Manifest request.  Use the Distance calculation engine to compute the distance.
        /// </summary>
        /// <param name="datagram">Input request</param>
        /// <returns>Manifest Response - simple POCO with results</returns>
        public static ManifestResponse ProcessMessage(ManifestRequest datagram)
        {
            //TASK: Use the distance calculation engine here
            var distance = -1;
            var output   = new ManifestResponse()
            {
                ServerAddress = System.Environment.MachineName, ClientAddress = datagram.ClientAddress, Distance = distance, Status = distance < 1000 ? ManifestStatus.Accepted : ManifestStatus.Pending
            };

            saveData(datagram, output);
            return(output);
        }
Ejemplo n.º 5
0
        public ResponseBase <ManifestResponse> FindData(ManifestRequest request)
        {
            ManifestValidator validator;
            ValidationResult  results;
            ResponseBase <ManifestResponse> response;
            ManifestResponse manifestResponse;

            try
            {
                //throw new Exception("webeo");
                validator        = new ManifestValidator();
                results          = validator.Validate(request);
                manifestResponse = new ManifestResponse();

                if (results.IsValid)
                {
                    var queryResult = _context.TBL_MAN_MANIFEST.Where(x =>
                                                                      (x.VCH_DIRECTMASTERGUIDE == request.VCH_DIRECTMASTERGUIDE || request.VCH_DIRECTMASTERGUIDE == null) &&
                                                                      (x.DAT_DEPARTUREDATE >= request.DAT_STARTDATE || request.DAT_STARTDATE == null) && (x.DAT_DEPARTUREDATE <= request.DAT_ENDDATE || request.DAT_ENDDATE == null) &&
                                                                      (x.VCH_CONSIGNEE.Contains(request.VCH_CONSIGNEE) || request.VCH_CONSIGNEE == null) && (x.VCH_SHIPPER.Contains(request.VCH_SHIPPER) || request.VCH_SHIPPER == null) &&
                                                                      (x.VCH_DESCRIPTION.Contains(request.VCH_DESCRIPTION) || request.VCH_DESCRIPTION == null) && (x.VCH_AIRLINE.Contains(request.VCH_AIRLINE) || request.VCH_AIRLINE == null) &&
                                                                      (x.VCH_DESTINATION == request.VCH_DESTINATION || request.VCH_DESTINATION == null) &&
                                                                      ((x.DAT_DEPARTUREDATE.Value.Year == request.INT_YEAR && x.INT_WEEK >= request.INT_STARTWEEK && x.INT_WEEK <= request.INT_ENDWEEK) ||
                                                                       (request.INT_YEAR == null || request.INT_STARTWEEK == null || request.INT_ENDWEEK == null))).OrderByDescending(x => x.DAT_DEPARTUREDATE);

                    int pageCount     = queryResult.Count();
                    var listManifests = queryResult.Skip((request.INT_CURRENTPAGE - 1) * request.INT_LIMITPAGES).Take(request.INT_LIMITPAGES == 1000 ? pageCount : request.INT_LIMITPAGES).ToList();
                    manifestResponse.INT_TOTALREGISTERS = pageCount;
                    manifestResponse.INT_CURRENTPAGE    = request.INT_CURRENTPAGE;
                    manifestResponse.Manifests          = listManifests;

                    response = new UtilityResponse <ManifestResponse>().SetResponseBaseForObj(manifestResponse);
                }
                else
                {
                    response = new UtilityResponse <ManifestResponse>().SetResponseBaseFunctionalErrors(results);
                }
                return(response);
            }
            catch (Exception ex)
            {
                response = new UtilityResponse <ManifestResponse>().SetResponseBaseForException(ex);
                return(response);
            }
            finally
            {
                response  = null;
                validator = null;
                results   = null;
                _context.Database.Connection.Close();
            }
        }
Ejemplo n.º 6
0
    private ManifestRequest AsbMfLoader_OnComplete(ManifestRequest request)
    {
        AssetRequest asRq = new AssetRequest();

        asRq.LoadName = request.LoadName.ToLower();

        string[] line = request.LoadRequest.downloadHandler.text.Split(new string[] { "\n" }, StringSplitOptions.None);

        if (ParseAssetManifest(line, ref asRq))
        {
            mMainfestDict[request.LoadName] = asRq;
        }

        return(request);
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Accept and process a Manifest request.  The algorythm is based on a StackOverflow post:
        /// http://stackoverflow.com/questions/365826/calculate-distance-between-2-gps-coordinates
        /// I did some basic testing and it seems pretty legitimate.
        /// </summary>
        /// <param name="datagram">Input request</param>
        /// <returns>Manifest Response - simple POCO with results</returns>
        public static ManifestResponse ProcessMessage(ManifestRequest datagram)
        {
            var earthRadiusKm = 6371;

            var dLat = degreesToRadians(datagram.End.Latitude - datagram.Start.Latitude);
            var dLon = degreesToRadians(datagram.End.Longitude - datagram.Start.Longitude);

            var lat1 = degreesToRadians(datagram.End.Latitude);
            var lat2 = degreesToRadians(datagram.Start.Latitude);

            var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                    Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
            var c        = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            var distance = earthRadiusKm * c;
            var output   = new ManifestResponse()
            {
                ServerAddress = System.Environment.MachineName, ClientAddress = datagram.ClientAddress, Distance = distance, Status = distance < 1000 ? ManifestStatus.Accepted : ManifestStatus.Pending
            };

            saveData(datagram, output);
            return(output);
        }
        // POST: api/Manifest
        public ManifestResponse Post(ManifestRequest datagram)
        {
            var request = Request;

            //Append the captured client IP to the datagram.
            if (request.Properties.ContainsKey("MS_HttpContext"))
            {
                datagram.ClientAddress = ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
            }
            else if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
            {
                RemoteEndpointMessageProperty prop = (RemoteEndpointMessageProperty)this.Request.Properties[RemoteEndpointMessageProperty.Name];
                datagram.ClientAddress = prop.Address;
            }
            else if (HttpContext.Current != null)
            {
                datagram.ClientAddress = HttpContext.Current.Request.UserHostAddress;
            }
            else
            {
                datagram.ClientAddress = null;
            }
            return(ManifestModel.ProcessMessage(datagram));
        }
Ejemplo n.º 9
0
    public IEnumerator LoadManifest()
    {
#if USE_DROPBOX
        mDropboxDict["background"] = "https://www.dropbox.com/s/yhqzu2tqhmhbex4/";
        mDropboxDict["finalani_1"] = "https://www.dropbox.com/s/b431yjype0u4d6i/";
        mDropboxDict["avatar_ch1"] = "https://www.dropbox.com/s/e4xgv0n2xorkhv7/";
        mDropboxDict["avatar_ch2"] = "https://www.dropbox.com/s/joqklmteepjs5wm/";
#endif

        string manifestURL = string.Empty;

#if USE_LOCAL
#if UNITY_ANDROID
        mPlatform = "Android";
#else
        mPlatform = "StandaloneWindows";
#endif
        string basePath = string.Format("file://{0}/AssetBundles/{1}/", Application.dataPath, mPlatform);
        manifestURL = string.Format("{0}{1}.manifest", basePath, mPlatform);
#endif

#if USE_DROPBOX
        manifestURL = "https://www.dropbox.com/s/e8wxi1zrgn44yfl/AssetBundleList.txt?dl=1";
#endif

        UrlAppendTimeStamp(ref manifestURL);

        ManifestLoader  mfLoader = new ManifestLoader();
        ManifestRequest mr       = new ManifestRequest();
        mr.LoadPath = manifestURL;
        mr.LoadName = "Android";

        yield return(LoadAssetHandler.Instance.StartCoroutine(mfLoader.DownloadProcess(mr, () => { return null; })));

        #region parse json.txt to get asset list
        Dictionary <string, object> assetDict = (Dictionary <string, object>)MiniJSON.Json.Deserialize(mr.LoadRequest.downloadHandler.text);

        foreach (KeyValuePair <string, object> kv in assetDict)
        {
            AssetRequest asRq   = new AssetRequest();
            var          key    = kv.Key.ToString().ToLower();
            var          values = (List <object>)kv.Value;

            asRq.LoadName = key;
            asRq.H128     = Hash128.Parse(values[0].ToString());
            asRq.CRC      = uint.Parse(values[1].ToString());

            mMainfestDict[asRq.LoadName] = asRq;
        }

        yield break;
        #endregion

        #region parse manifest to get asset list
        string[] lines = mr.LoadRequest.downloadHandler.text.Split(new string[] { "\n" }, StringSplitOptions.None);

        mAssetList = new List <string>();
        foreach (var s in lines)
        {
            if (s.Contains("CRC: "))
            {
                int  startCatchIndex = s.IndexOf("CRC: ") + 5;
                uint latestCRC       = uint.Parse(s.Substring(startCatchIndex, s.Length - startCatchIndex));
            }

            if (s.Contains("Name: "))
            {
                int    startCatchIndex = s.LastIndexOf("Name: ") + 6;
                string asName          = s.Substring(startCatchIndex, s.Length - startCatchIndex);

                if (!mAssetList.Contains(asName))
                {
                    mAssetList.Add(asName);
                }
            }
        }

        int requestCount = 0;
        if (mAssetList.Count > 0)
        {
            int assetCount = mAssetList.Count;
            List <ManifestLoader> mfLoadQueue = new List <ManifestLoader>();
            foreach (var ms in mAssetList)
            {
                if (!mDropboxDict.ContainsKey(ms.ToLower()))
                {
                    continue;
                }

                string asbManifestURL = string.Empty;
#if USE_LOCAL
                asbManifestURL = string.Format("{0}{1}.manifest", basePath, ms);
                UrlAppendTimeStamp(ref asbManifestURL);
#endif

#if USE_DROPBOX
                asbManifestURL = string.Format("{0}{1}.manifest?dl=1", mDropboxDict[ms.ToLower()], ms.ToLower());
#endif

                ManifestLoader  asbMfLoader = new ManifestLoader();
                ManifestRequest mmr         = new ManifestRequest();
                mmr.LoadPath = asbManifestURL;
                mmr.LoadName = ms;

                LoadAssetHandler.Instance.StartCoroutine(asbMfLoader.DownloadProcess(mmr, () => { return(AsbMfLoader_OnComplete(mmr)); }));

                requestCount++;
            }
        }

        while (mMainfestDict.Count < requestCount)
        {
            yield return(null);
        }
        #endregion
    }