Exemplo n.º 1
0
    static Helper()
    {
        Tags.Add(TagName.Room, "Room");
        Tags.Add(TagName.MovementCurvy, "MoveCurvy");
        Tags.Add(TagName.Difficulty, "Difficulty");

        Resource.Add(TagName.RightTarget, "Sprites/RightTarget");
        Resource.Add(TagName.WrongTarget, "Sprites/WrongTarget");
        Resource.Add(TagName.NeutralTarget, "Sprites/NeutralTarget");
        Resource.Add(TagName.DeadTarget, "Sprites/DeadTarget/among-dead");
        Resource.Add(TagName.TargetPrefab, "Assets/Client/Prefabs/Target.prefab");

        Difficulty.Add(TagName.Easy, "Easy");
        Difficulty.Add(TagName.Medium, "Medium");
        Difficulty.Add(TagName.Hard, "Hard");

        Scenes.Add(TagName.DefaultShootingGallery, "DefaultShootingGallery");
        Scenes.Add(TagName.MainMenu, "Menu");

        SaveFiles.Add(TagName.PlayerSave, "/SaveFiles.save");

        Audio.Add(TagName.AmongDeathSound, "among-death");
        Audio.Add(TagName.GunShotSound, "gun-shot");
        Audio.Add(TagName.RicochetSound, "ricochet");
        Audio.Add(TagName.MistakeShotSound, "mistake-shot");
    }
Exemplo n.º 2
0
    public float UpdateProgress()
    {
        currTime += Time.deltaTime;

        timeUntilSFX -= Time.deltaTime;
        if (timeUntilSFX <= 0.0f)
        {
            soundPlayer.PlaySound(SoundType.ResourceCollecting);
            Instantiate(gatherParticle, GetComponentInParent <Transform>().position, GetComponentInParent <Transform>().rotation);
            timeUntilSFX = timeBetweenSFX;
        }

        if (currTime > timeToCollect)
        {
            resource.Add(amountPerTier);        //Collect some
            soundPlayer.PlaySound(SoundType.ResourceCollected);
            currTime = 0f;
            if (OnCollected != null)
            {
                OnCollected(this);
            }
            currTier--;
            if (currTier <= 0)                  //Nothing left to collect
            {
                Completed();
            }
        }
        return(currTime / timeToCollect);        //Returns the current progress
    }
Exemplo n.º 3
0
 /// <summary>
 /// Load assembly references and add them to resource object
 /// </summary>
 public void ApplySettings()
 {
     foreach (AssemblyElement e in this.Assemblies)
     {
         Resource.Add(e.Assembly);
     }
 }
Exemplo n.º 4
0
        private void SetLootedResources(IBarbarianTribe barbarianTribe, IBattleManager battle, ITroopObject troopObject, ICombatGroup combatGroup)
        {
            if (!battle.BattleStarted)
            {
                return;
            }

            // Calculate bonus
            Resource resource = battleFormula.GetBonusResources(troopObject,
                                                                originalUnitCount,
                                                                troopObject.Stub.TotalCount);

            // Add barbarian tribe bonus
            resource.Add(formula.BarbarianTribeBonus(barbarianTribe.Lvl, battle, combatGroup, barbarianTribe));

            // Copy looted resources since we'll be modifying the troop's loot variable
            var looted = new Resource(troopObject.Stats.Loot);

            // Add bonus to troop object
            Resource returning;
            Resource actual;
            Resource cap = new Resource(troopObject.Stub.Carry / 1,
                                        troopObject.Stub.Carry / 2,
                                        troopObject.Stub.Carry / Config.battle_loot_resource_iron_ratio,
                                        troopObject.Stub.Carry / 1,
                                        troopObject.Stub.Carry / Config.battle_loot_resource_labor_ratio);

            troopObject.Stats.Loot.Add(resource, cap, out actual, out returning);

            // Update battle report view with actual received bonus
            battle.BattleReport.SetLootedResources(combatGroup.Owner, combatGroup.Id, battle.BattleId, looted, actual);
        }
Exemplo n.º 5
0
        public virtual Resource BarbarianTribeBonus(byte level, IBattleManager battle, ICombatGroup combatGroup, IBarbarianTribe barbarianTribe)
        {
            var bonusAmt = new[] { 15, 34, 75, 141, 232, 349, 493, 665, 865, 1094 };

            // Get nothing if they didnt defeat the camp
            if (battle.Defenders.UpkeepExcludingWaitingToJoinBattle > 0)
            {
                return(new Resource());
            }

            decimal total =
                battle.Attackers.AllCombatObjects()
                .Sum(combatObj => combatObj.Upkeep * combatObj.RoundsParticipated * combatObj.RoundsParticipated);

            decimal myTotal = combatGroup.Sum(combatObj => combatObj.Upkeep * combatObj.RoundsParticipated * combatObj.RoundsParticipated);

            if (total == 0 || myTotal == 0)
            {
                return(new Resource());
            }

            var myPercentage = myTotal / total;

            var bonus = new Resource(wood: bonusAmt[level - 1], crop: bonusAmt[level - 1]) * (double)myPercentage;

            // Add remaining barb resources as well
            bonus.Add(barbarianTribe.Resource * (double)myPercentage);

            return(bonus);
        }
Exemplo n.º 6
0
    private IEnumerator ReplenishMana()
    {
        yield return(new WaitForSeconds(1));

        mana.Add(2);
        StartCoroutine(ReplenishMana());
    }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdFiAuthorizationContext"/> class using the principal, resource, action and Ed-Fi authorization context data.
        /// </summary>
        /// <param name="apiKeyContext">Direct information about the current API client, typically presented as claims.</param>
        /// <param name="principal">The <see cref="ClaimsPrincipal" /> containing the claims.</param>
        /// <param name="resourceClaimUris">The URI representations of the resource claims being authorized.</param>
        /// <param name="action">The action being taken on the resource.</param>
        /// <param name="data">An object containing the data available for authorization which implements one of the
        /// model interfaces (e.g. IStudent).</param>
        public EdFiAuthorizationContext(
            ApiKeyContext apiKeyContext,
            ClaimsPrincipal principal,
            string[] resourceClaimUris,
            string action,
            object data)
        {
            Preconditions.ThrowIfNull(apiKeyContext, nameof(apiKeyContext));
            Preconditions.ThrowIfNull(resourceClaimUris, nameof(resourceClaimUris));
            Preconditions.ThrowIfNull(action, nameof(action));

            ApiKeyContext = apiKeyContext;
            Principal     = principal;
            Data          = data;

            resourceClaimUris.ForEach(
                resourceClaimUri =>
                Resource.Add(new Claim(ClaimsName, resourceClaimUri)));

            Action.Add(new Claim(ClaimsName, action));

            if (data != null)
            {
                Type = data.GetType();
            }
        }
Exemplo n.º 8
0
        public void TestAddCrop()
        {
            var resource1 = new Resource(1, 2, 3, 4, 5);

            resource1.Add(new Resource(10, 0, 0, 0, 0));

            Assert.True(resource1.CompareTo(new Resource(11, 2, 3, 4, 5)) == 0);
        }
Exemplo n.º 9
0
        public void TestAddLabor()
        {
            var resource1 = new Resource(1, 2, 3, 4, 5);

            resource1.Add(new Resource(0, 0, 0, 0, 10));

            Assert.True(resource1.CompareTo(new Resource(1, 2, 3, 4, 15)) == 0);
        }
Exemplo n.º 10
0
        public override void ReceiveReward(int attackPoints, Resource resource)
        {
            loot.Add(resource);

            troopObject.BeginUpdate();
            troopObject.Stats.AttackPoint += attackPoints;
            troopObject.Stats.Loot.Add(resource);
            troopObject.EndUpdate();
        }
Exemplo n.º 11
0
    protected virtual void Update()
    {
        _time += Time.deltaTime;

        if (_time > IncomeCooldown / GameSettings.IncomeSpeedModifier)
        {
            BioMass.Add(_baseIncomeBiomass);
            _time = 0;
        }
    }
Exemplo n.º 12
0
        /// <summary>
        ///     Gets amount of resources that are hidden
        /// </summary>
        /// <param name="city"></param>
        /// <param name="checkAlignmentPointBonus"></param>
        /// <returns></returns>
        public virtual Resource HiddenResource(ICity city, bool checkAlignmentPointBonus = false)
        {
            int[] rateCrop = { 0, 100, 150, 220, 330, 500, 740, 1100, 1100, 1100, 1100 };
            int[] rateWood = { 0, 100, 150, 220, 330, 500, 740, 1100, 1100, 1100, 1100 };
            int[] rateGold = { 0, 0, 0, 0, 0, 100, 150, 220, 330, 500, 740 };
            int[] rateIron = { 0, 0, 0, 0, 0, 0, 0, 0, 200, 360, 660 };

            var resource = new Resource();

            foreach (var structure in city.Where(x => ObjectTypeFactory.IsStructureType("Basement", x)))
            {
                resource.Add(rateCrop[structure.Lvl],
                             rateGold[structure.Lvl],
                             rateIron[structure.Lvl],
                             rateWood[structure.Lvl],
                             0);
            }

            int[] tempRateCrop = { 0, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700 };
            int[] tempRateWood = { 0, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700 };
            int[] tempRateGold = { 0, 0, 0, 0, 0, 500, 600, 700, 800, 900, 1000 };
            int[] tempRateIron = { 0, 0, 0, 0, 0, 0, 0, 0, 500, 750, 1000 };
            foreach (var structure in city.Where(x => ObjectTypeFactory.IsStructureType("TempBasement", x)))
            {
                resource.Add(tempRateCrop[structure.Lvl],
                             tempRateGold[structure.Lvl],
                             tempRateIron[structure.Lvl],
                             tempRateWood[structure.Lvl],
                             0);
            }

            if (checkAlignmentPointBonus && city.AlignmentPoint >= 75m)
            {
                const double pct = .75;
                return(new Resource((int)Math.Max(city.Resource.Crop.Limit * pct, resource.Crop),
                                    (int)Math.Max(city.Resource.Gold.Limit * pct, resource.Gold),
                                    (int)Math.Max(city.Resource.Iron.Limit * pct, resource.Iron),
                                    (int)Math.Max(city.Resource.Wood.Limit * pct, resource.Wood),
                                    0));
            }
            return(resource);
        }
Exemplo n.º 13
0
 public void AddResource(string name, byte[] value)
 {
     if (Resource.Contains(name))
     {
         Resource[name] = value;
     }
     else
     {
         Resource.Add(name, value);
     }
 }
Exemplo n.º 14
0
 public void NextRound()
 {
     resources.Gold     += 1;
     resources.Iron     += 1;
     resources.Water    += 1;
     resources.ManPower += 1;
     foreach (Building building in buildings)
     {
         resources.Add(building.GetIncome());
     }
 }
Exemplo n.º 15
0
        public void TestMethod1()
        {
            m = new GameModel();
            Resource r = new Resource();

            r = m.GetResource();
            Assert.AreEqual(r, m.GetResource());
            m.NextRound();
            r.Add(new Resource(1, 1, 1, 1));
            Assert.AreEqual(r, m.GetResource());
        }
Exemplo n.º 16
0
        public void Setup()
        {
            Log.LogManager.Level = Log.LogLevel.Fatal;
            _root = new Resource(String.Empty);
            Resource sensors = new Resource("sensors");
            Resource temp    = new Resource("temp");
            Resource light   = new Resource("light");

            _root.Add(sensors);
            sensors.Add(light);
            sensors.Add(temp);

            sensors.Attributes.Title = "Sensor Index";
            temp.Attributes.AddResourceType("temperature-c");
            temp.Attributes.AddInterfaceDescription("sensor");
            temp.Attributes.Add("foo");
            temp.Attributes.Add("bar", "one");
            temp.Attributes.Add("bar", "two");
            light.Attributes.AddResourceType("light-lux");
            light.Attributes.AddInterfaceDescription("sensor");
        }
Exemplo n.º 17
0
        public void TestAddWithCapAndInitialIsHigher()
        {
            var      resource1 = new Resource(0, 20, 30, 40, 50);
            Resource returning;
            Resource actual;

            resource1.Add(new Resource(1, 20, 30, 40, 50), new Resource(5), out actual, out returning);

            Assert.True(resource1.CompareTo(new Resource(1, 5, 5, 5, 5)) == 0);
            Assert.True(returning.CompareTo(new Resource(0, 35, 55, 75, 95)) == 0);
            Assert.True(actual.CompareTo(new Resource(1, 0, 0, 0, 0)) == 0);
        }
Exemplo n.º 18
0
        public void TestAddWithCapAndCapIsHigher()
        {
            var      resource1 = new Resource(1, 2, 3, 4, 5);
            Resource returning;
            Resource actual;

            resource1.Add(new Resource(1, 2, 3, 4, 5), new Resource(10), out actual, out returning);

            Assert.True(resource1.CompareTo(new Resource(2, 4, 6, 8, 10)) == 0);
            Assert.True(returning.CompareTo(new Resource(0, 0, 0, 0, 0)) == 0);
            Assert.True(actual.CompareTo(new Resource(1, 2, 3, 4, 5)) == 0);
        }
Exemplo n.º 19
0
        public void TestAddWithCapAndCapIsLowerThanBase()
        {
            var      resource1 = new Resource(1, 2, 3, 4, 5);
            Resource returning;
            Resource actual;

            resource1.Add(new Resource(1, 2, 3, 4, 5), new Resource(5), out actual, out returning);

            Assert.True(resource1.CompareTo(new Resource(2, 4, 5, 5, 5)) == 0);
            Assert.True(returning.CompareTo(new Resource(0, 0, 1, 3, 5)) == 0);
            Assert.True(actual.CompareTo(new Resource(1, 2, 2, 1, 0)) == 0);
        }
Exemplo n.º 20
0
    public IEnumerator ResourceAlert(Resource r, int num)
    {
        float time_start     = 0.2F;
        float time_adding    = 0.8F;
        float time_end_pause = 0.3F;
        float time_end       = 0.2F;
        float time_total     = time_start + time_adding + time_end;
        float time_curr      = 0.0F;

        UIObj   res   = ResUI.Child[(int)r.Index];
        UIAlert alert = Instantiate(UIResObj);

        alert.Init(-1, WorldObjects, time_total);
        WorldObjects.AddChild(alert);

        alert.ResetRect();
        alert.transform.position = res.Txt[0].transform.position -
                                   res.Txt[0].transform.up * 0.5F;

        Tweens.Bounce(alert.transform);

        int init = r.Current;

        alert.Txt[0].text  = "+" + num;
        alert.Svg[0].color = r.Col;

        yield return(new WaitForSeconds(time_start));

        Tweens.Bounce(res.transform);

        /*float amt_soft = num / (time_adding/Time.deltaTime);
         * while((time_curr += Time.deltaTime) <= time_adding)
         * {
         *      init += (int) amt_soft;
         *
         *      res.Txt[0].text = r.ToString();
         *
         *      yield return null;
         * }*/
        r.Add(num);
        res.Txt[0].text = r.ToString();

        yield return(new WaitForSeconds(time_end_pause));

        if (alert != null)
        {
            alert.PoolDestroy();
        }
        yield return(new WaitForSeconds(time_end));

        yield return(null);
    }
Exemplo n.º 21
0
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _resource = new TestResource(NAME_1, PAYLOAD);
            _server   = new CoapServer();
            _server
            .Add(new Resource(RES_A)
                 .Add(new Resource(RES_AA)
                      .Add(_resource
                           .Add(new TestResource(CHILD, CHILD_PAYLOAD)))));

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Constructs a server with the specified configuration that
        /// listens to the given ports.
        /// </summary>
        /// <param name="config">the configuration, or <code>null</code> for default</param>
        /// <param name="ports">the ports to bind to</param>
        public CoapServer(ICoapConfig config, params Int32[] ports)
        {
            _config    = config ?? CoapConfig.Default;
            _root      = new RootResource(this);
            _deliverer = new ServerMessageDeliverer(_config, _root);

            Resource wellKnown = new Resource(".well-known", false);

            wellKnown.Add(new DiscoveryResource(_root));
            _root.Add(wellKnown);

            foreach (Int32 port in ports)
            {
                Bind(port);
            }
        }
Exemplo n.º 23
0
        public CoapServer(ICoapConfig config, IResource rootResource, System.Net.EndPoint endPoint, params int[] ports)
        {
            Config     = config ?? CoapConfig.Default;
            _root      = rootResource ?? new RootResource(this);
            _deliverer = new ServerMessageDeliverer(Config, _root);

            Resource wellKnown = new Resource(".well-known", false);

            wellKnown.Add(new DiscoveryResource(_root));
            _root.Add(wellKnown);

            _endPointSupplied = endPoint;
            foreach (int port in ports)
            {
                Bind(port);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EdFiAuthorizationContext"/> class using the principal, resource, action and Ed-Fi entity type.
        /// </summary>
        /// <param name="principal">The <see cref="ClaimsPrincipal" /> containing the claims.</param>
        /// <param name="resourceClaimUris">The URI representations of the resource claims being authorized.</param>
        /// <param name="action">The action being taken on the resource.</param>
        /// <param name="type">The entity type which implements one of the model interfaces (e.g. IStudent) which is the subject of a multiple-item request.</param>
        public EdFiAuthorizationContext(
            ClaimsPrincipal principal,
            string[] resourceClaimUris,
            string action,
            Type type)
        {
            Preconditions.ThrowIfNull(resourceClaimUris, nameof(resourceClaimUris));
            Preconditions.ThrowIfNull(action, nameof(action));
            Preconditions.ThrowIfNull(type, nameof(type));

            Principal = principal;
            Type      = type;

            resourceClaimUris.ForEach(
                resourceClaimUri =>
                Resource.Add(new Claim(ClaimsName, resourceClaimUri)));

            Action.Add(new Claim(ClaimsName, action));
        }
Exemplo n.º 25
0
        private void BattleActionAttacked(IBattleManager battle,
                                          BattleManager.BattleSide attackingSide,
                                          ICombatGroup attackerGroup,
                                          ICombatObject attacker,
                                          ICombatGroup targetGroup,
                                          ICombatObject target,
                                          decimal damage,
                                          int attackerCount,
                                          int targetCount)
        {
            ICity        city;
            ITroopObject troopObject;

            if (!gameObjectLocator.TryGetObjects(cityId, troopObjectId, out city, out troopObject))
            {
                throw new ArgumentException();
            }

            if (attackerGroup.Id == groupId && target.ClassType == BattleClass.Structure && target is ICombatStructure &&
                target.IsDead)
            {
                // if our troop knocked down a building, we get the bonus.
                bonus.Add(structureCsvFactory.GetCost(target.Type, target.Lvl) / 2);

                IStructure structure = ((ICombatStructure)target).Structure;
                object     value;
                if (structure.Properties.TryGet("Crop", out value))
                {
                    if (value is int)
                    {
                        bonus.Crop += (int)value;
                    }
                }
                if (structure.Properties.TryGet("Gold", out value))
                {
                    if (value is int)
                    {
                        bonus.Gold += (int)value;
                    }
                }
                if (structure.Properties.TryGet("Iron", out value))
                {
                    if (value is int)
                    {
                        bonus.Iron += (int)value;
                    }
                }
                if (structure.Properties.TryGet("Wood", out value))
                {
                    if (value is int)
                    {
                        bonus.Wood += (int)value;
                    }
                }
                if (structure.Properties.TryGet("Labor", out value))
                {
                    if (value is int)
                    {
                        bonus.Labor += (int)value;
                    }
                }

                dbManager.Save(this);
            }
        }
Exemplo n.º 26
0
    public void UpdateResources()
    {
        Resource delta = new Resource();

        production = new Resource();
        cost       = new Resource();
        buildingDeltas.Clear();
        for (var i = 0; i < buildingTypes.Count; i++)
        {
            buildingDeltas.Add(new Resource());
        }
        foreach (BuildingSpot building in GM.I.city.buildings)
        {
            Resource currentBuildingDelta = new Resource();
            if (building.currentBuilding != null)
            {
                if (building.Built)
                {
                    if (building.currentProject != null)
                    {
                        currentBuildingDelta.Add(building.currentProject.monthlyCost);
                        cost.Add(building.currentProject.monthlyCost);
                    }
                    else
                    {
                        if (building.currentBuilding.productor)
                        {
                            currentBuildingDelta.Add(building.Production);
                            production.Add(building.Production);
                        }
                        currentBuildingDelta.Add(building.Cost);
                        cost.Add(building.Cost);
                        if (building.increaseStorage && !building.currentBuilding.storageIncreaseMonthlyCost.Limited(GM.I.resource.resources))
                        {
                            currentBuildingDelta.Add(building.currentBuilding.storageIncreaseMonthlyCost);
                            cost.Add(building.currentBuilding.storageIncreaseMonthlyCost);
                        }
                    }
                }
                else if (!building.constructionHalted)
                {
                    currentBuildingDelta.Add(building.currentBuilding.constructionMonthlyCost);
                    cost.Add(building.currentBuilding.constructionMonthlyCost);
                }
            }
            delta.Add(currentBuildingDelta);
            for (var i = 0; i < buildingTypes.Count; i++)
            {
                if (building.currentBuilding == buildingTypes[i])
                {
                    buildingDeltas[i].Add(currentBuildingDelta);
                }
            }
        }

        resources.r[0] = Mathf.Clamp(resources.r[0] + delta.r[0], 0, resourcesLimit.r[0]);
        resources.r[1] = Mathf.Clamp(resources.r[1] + delta.r[1], 0, resourcesLimit.r[1]);
        resources.r[2] = Mathf.Clamp(resources.r[2] + delta.r[2], 0, resourcesLimit.r[2]);

        GM.I.ui.resourceMeters.UpdateResources();
    }
Exemplo n.º 27
0
 public void Cancel()
 {
     m_resource.Add();
     Destroy(gameObject);
 }
Exemplo n.º 28
0
        private string newUploadImage()
        {
            //HttpPostedFile objFile = Request.Files["Filedata"];
            HttpPostedFile objFile = this.fuImage.PostedFile;

            if (objFile != null)
            {
                string filename = objFile.FileName;
                string fileType = Path.GetExtension(filename).ToLower();
                if (fileType.IndexOf(".") == -1)
                {
                    fileType = "." + fileType;
                }
                //string resourceType = new Resource().GetResourceTypeByFileExtention(fileType);
                string resourceType = ResourceTypeFactory.getResourceType(fileType.Substring(1)).ResourceType;

                if (resourceType.Equals("image"))
                {
                    string strClientFileName = filename;
                    string strServerFileName = SaveImage();

                    if (string.IsNullOrEmpty(strServerFileName))
                    {
                        ShowMessage("发生错误");
                        return(string.Empty);
                    }

                    /** start **/
                    Resource       objResource = new Resource();
                    ResourceEntity model       = new ResourceEntity();

                    //管理员上传直接审核通过
                    if (IsSuperAdmin)
                    {
                        model.Status = (int)ResourceEntity.ResourceStatus.IsPass;
                    }
                    else
                    {
                        model.Status = (int)ResourceEntity.ResourceStatus.NewUpload;
                    }

                    if (this.txtTitle.Text.Trim().Length > 0)
                    {
                        model.Caption = this.txtTitle.Text.Trim();
                    }
                    else
                    {
                        model.Caption = Path.GetFileNameWithoutExtension(strClientFileName);
                    }

                    model.Description = this.txtRemark.Text.Trim();
                    model.EndDate     = DateTime.Now.AddYears(10);
                    model.FileName    = strClientFileName;
                    model.FolderName  = CurrentUser.UserLoginName;

                    model.ServerFileName = strServerFileName;

                    model.GroupId       = CurrentUser.UserGroupId;
                    model.ItemId        = Guid.NewGuid();
                    model.ItemSerialNum = Path.GetFileNameWithoutExtension(strServerFileName);
                    //model.Keyword = this.keyWord.Value;
                    model.Keyword = this.txtTitle.Text.Trim();
                    //model.shotDate = Convert.ToDateTime(this.shotDate1.Text);
                    model.StartDate  = Convert.ToDateTime("1900-01-01");
                    model.uploadDate = DateTime.Now;
                    model.userId     = CurrentUser.UserId;
                    model.updateDate = DateTime.Now;
                    model.Author     = "";

                    //取得文件的扩展名,不包括.号
                    string fileExtName = string.Empty;
                    fileExtName = Path.GetExtension(filename);
                    if (fileExtName.IndexOf(".") > -1)
                    {
                        fileExtName = fileExtName.Substring(1);
                    }

                    model.ResourceType = ResourceTypeFactory.getResourceType(fileExtName).ResourceType;
                    model.FileSize     = Resource.GetResourceFileSize(strServerFileName, model.FolderName, fileExtName, "");
                    model.HasCopyright = 0;

                    model.shotDate = DateTime.Now;


                    objResource.Add(model);
                    //objResource.CreateRelationshipResourceAndCatalog(model.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid)));


                    //return strServerFileName;
                    return(model.ItemId.ToString());
                }
            }
            return(string.Empty);
        }
Exemplo n.º 29
0
        protected void btnUpload_ServerClick(object sender, EventArgs e)
        {
            //是否有版权的资源
            int hasCopyRight = 0;

            try
            {
                hasCopyRight = Convert.ToInt32(this.rblCopyright.SelectedValue);
            }
            catch (Exception ex)
            { }


            #region 验证日期部分
            //if (this.shotDate1.Text.Trim() == string.Empty)
            //{
            //    this.ShowMessage(this, "请选择时间");
            //    return;
            //}
            //else
            //{
            //    if (Convert.ToDateTime(this.shotDate1.Text) > DateTime.Now)
            //    {
            //        this.ShowMessage(this, "拍摄时间应比现在早");
            //        return;
            //    }
            //}
            //验证日期
            DateTime sDate = new DateTime();
            DateTime eDate = new DateTime();
            if (this.startDate.Text != "")
            {
                //有效开始日期就不做验证了,只要结束日期比现在晚就可以了。

                sDate = Convert.ToDateTime(this.startDate.Text);
                //if (sDate <= DateTime.Now)
                //{
                //    this.ShowMessage(this, "有效开始日期应比现在日期晚");
                //    return;
                //}
            }
            else
            {
                sDate = Convert.ToDateTime("1900-01-01");
            }
            if (this.endDate.Text != "")
            {
                eDate = Convert.ToDateTime(this.endDate.Text);

                if (sDate == Convert.ToDateTime("1900-01-01") && eDate < DateTime.Now)
                {
                    this.ShowMessage(this, "有效结束日期应至少比现在日期晚");
                    return;
                }
                else if (eDate < sDate)
                {
                    this.ShowMessage(this, "有效结束日期应比有效开始日期晚");
                    return;
                }
            }
            else
            {
                eDate = Convert.ToDateTime("1900-01-01");
            }

            #endregion


            #region 验证是否选择目录节点
            ////根节点
            //TreeNode parentNode = catalogTree.RootNode;
            ////获取checked的节点List
            //ArrayList nodeList = new ArrayList();
            //this.catalogTree.ArrCheckbox(nodeList, parentNode);

            //ArrayList catalogIds = new ArrayList(nodeList.Count);
            //foreach (TreeNode node in nodeList)
            //{

            //    catalogIds.Add(new Guid(node.Value));
            //}

            //if (catalogIds.Count == 0)
            //{
            //    this.ShowMessage(this, "没有选择分类,上传失败!");
            //    return;
            //}


            string   catIds    = this.hidCatIds.Value.Trim().Trim(new char[] { ',' });
            string[] arrCatIds = catIds.Split(",".ToCharArray());
            if (arrCatIds.Length == 0)
            {
                this.ShowMessage(this, "没有选择分类,上传失败!");
                return;
            }
            ArrayList catalogIds = new ArrayList(arrCatIds.Length);
            foreach (string _s in arrCatIds)
            {
                catalogIds.Add(new Guid(_s));
            }
            #endregion


            string fileName = "";   //原始文件名
            if (!string.IsNullOrEmpty(Request["selectedFile"]))
            {
                fileName = Request["selectedFile"].ToString().ToLower();
            }
            else
            {
                return;
            }

            string uploadFileName = ""; //上传以后重新分配的文件名 prefix+yymmdd+00001.extention
            if (!string.IsNullOrEmpty(Request["uploadFileName"]))
            {
                uploadFileName = Request["uploadFileName"].ToString();
            }
            else
            {
                return;
            }

            string[] arrFiles = uploadFileName.Split(',');


            foreach (string singleFiles in arrFiles)
            {
                if (!singleFiles.Contains(":"))
                {
                    continue;
                }

                string[] _arr = singleFiles.Split(':');
                string   strClientFileName = _arr[1];
                string   strServerFileName = _arr[0];



                fileName       = strClientFileName;
                uploadFileName = strServerFileName;

                /** start **/
                Resource       objResource = new Resource();
                ResourceEntity model       = new ResourceEntity();

                //管理员上传直接审核通过
                if (IsSuperAdmin)
                {
                    model.Status = (int)ResourceEntity.ResourceStatus.IsPass;
                }
                else
                {
                    model.Status = (int)ResourceEntity.ResourceStatus.NewUpload;
                }

                //改成所有人上传的都可以直接通过 , 到时直接注释下面一句话就可以
                model.Status = (int)ResourceEntity.ResourceStatus.IsPass;
                model.Status = 0;

                if (this.txt_Caption.Value.Trim().Length > 0)
                {
                    model.Caption = this.txt_Caption.Value;
                }
                else
                {
                    model.Caption = Path.GetFileNameWithoutExtension(strClientFileName);
                }

                model.Description = this.description.Value;
                model.EndDate     = eDate;
                model.FileName    = fileName;
                model.FolderName  = CurrentUser.UserLoginName;
                if (uploadFileName.ToLower().IndexOf(".cr2") != -1 || uploadFileName.ToLower().IndexOf(".nef") != -1 || uploadFileName.ToLower().IndexOf(".psd") != -1)
                {
                    model.ServerFileName = uploadFileName.Replace("cr2", "jpg").Replace("nef", "jpg").Replace("psd", "jpg");
                }
                else
                {
                    model.ServerFileName = uploadFileName;
                }
                model.GroupId       = CurrentUser.UserGroupId;
                model.ItemId        = Guid.NewGuid();
                model.ItemSerialNum = Path.GetFileNameWithoutExtension(uploadFileName);
                //model.Keyword = this.keyWord.Value;
                model.Keyword = this.txtKeyWords.Text.Trim().Trim(",".ToCharArray());
                //model.shotDate = Convert.ToDateTime(this.shotDate1.Text);
                model.StartDate  = sDate;
                model.uploadDate = DateTime.Now;
                model.userId     = CurrentUser.UserId;
                model.updateDate = DateTime.Now;
                model.Author     = this.txt_Author.Value.Trim();

                //取得文件的扩展名,不包括.号
                string fileExtName = string.Empty;
                fileExtName = Path.GetExtension(fileName);
                if (fileExtName.IndexOf(".") > -1)
                {
                    fileExtName = fileExtName.Substring(1);
                }

                model.ResourceType = ResourceTypeFactory.getResourceType(fileExtName).ResourceType;
                model.FileSize     = Resource.GetResourceFileSize(uploadFileName, model.FolderName, fileExtName, "");
                model.HasCopyright = hasCopyRight;

                model.shotDate = DateTime.Now;
                DateTime shotDateTime = Resource.GetResourceShotDateTime(uploadFileName, model.FolderName, model.ResourceType, "");
                if (shotDateTime != DateTime.MinValue)
                {
                    model.shotDate = shotDateTime;
                }

                objResource.Add(model);
                objResource.CreateRelationshipResourceAndCatalog(model.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid)));

                //同时更新索引
                string[] SNs = new string[] { model.ItemSerialNum };
                ResourceIndex.updateIndex(SNs);
            }
            /** end  **/



            #region 注释部分

            //VideoStorageClass vsc = new VideoStorageClass();
            //VideoStorage v = new VideoStorage();
            //v.Caption = this.txt_Caption.Value;
            //v.Description = this.description.Value;
            //v.EndDate = eDate;
            //v.FileName = fileName;
            //v.FolderName = CurrentUser.UserLoginName;
            //v.ServerFileName = uploadFileName;
            //v.GroupId = CurrentUser.UserGroupId;
            //v.ItemId = Guid.NewGuid();
            //v.ItemSerialNum = Path.GetFileNameWithoutExtension(uploadFileName);
            //v.Keyword = this.keyWord.Value;
            //v.shotDate = Convert.ToDateTime(this.shotDate.Value);
            //v.StartDate = sDate;
            //v.uploadDate = DateTime.Now;
            //v.userId = CurrentUser.UserId;
            //v.updateDate = DateTime.Now;

            ////存储数据库记录
            //// img.ItemSerialNum = ImageStorageClass.AddImageStorage(img);

            //if (!vsc.Add(v))
            //{
            //    this.ShowMessage(this, "上传失败");
            //    return;
            //}

            //vsc.CreateRelationshipVideoAndCatalog(v.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid)));
            #endregion


            //this.shotDate1.Text = "";
            this.keyWord.Value     = "";
            this.description.Value = "";
            this.txt_Caption.Value = "";
            this.startDate.Text    = "";
            this.endDate.Text      = "";
            initCalendar();

            //this.ShowMessage(this, "上传成功");
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>myUploadSuccess2()</script>");
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>myUploadSuccess2()</script>");
        }
Exemplo n.º 30
0
 private void AddResources()
 {
     brick.Add(Resource(brickPerSecond));
     paper.Add(Resource(paperPerSecond));
     ink.Add(Resource(inkPerSecond));
 }