public ActionResult Edit(ResourceClass resourceClass, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                using (SqlConnection con = new SqlConnection(Helper.connectionString))
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand("spUpdateRes", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@re_id", resourceClass.ResId);

                    if (file != null && file.ContentLength > 0)
                    {
                        var filename = Path.GetFileName(file.FileName);
                        var imgpath  = Path.Combine(Server.MapPath("~/Temp/"), filename);
                        file.SaveAs(imgpath);
                    }
                    cmd.Parameters.AddWithValue("@images", "~/Temp/" + file.FileName);
                    cmd.Parameters.AddWithValue("@title", resourceClass.Title);
                    cmd.Parameters.AddWithValue("@author", resourceClass.Author);
                    cmd.Parameters.AddWithValue("@subjects", resourceClass.Subject);
                    cmd.Parameters.AddWithValue("@years", resourceClass.Years);
                    cmd.Parameters.AddWithValue("@descriptions", resourceClass.Files);
                    cmd.ExecuteNonQuery();
                }
                return(RedirectToAction("UpdateStatus"));
            }
            return(View(resourceClass));
        }
        public dynamic AddResourceClass(Guid tool_id, Guid executor_id, ResourceClassCreateM model)
        {
            try
            {
                EnsureExecutorExisted(tool_id, executor_id);

                ResourceClass resource_class = _resourceClass.Add(new ResourceClass
                {
                    ExecutorId = executor_id,
                    Name       = model.Name
                });
                SaveChanges();

                return(new
                {
                    resource_class.Id,
                    resource_class.Name
                });
            }
            catch (Exception e)
            {
                throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred!",
                                                                         e, DateTime.Now, "Server", "Service-Configuration-AddResourceClass");
            }
        }
        public static ResourceClass GetResourceType(this Resource resource, ISpecIfMetadataReader dataProvider)
        {
            ResourceClass result = null;

            result = dataProvider.GetResourceClassByKey(resource.Class);

            return(result);
        }
예제 #4
0
        public MaterialDefinitionWindowView(ResourceClass mclass)
        {
            InitializeComponent();

            _class    = mclass;
            _material = CreateMaterialDefinition();

            dataForm.CurrentItem = _material;
        }
예제 #5
0
    public void AddResource(ResourceId _id, float _amount)
    {
        if (usedCapacity >= maxCapacity)
        {
            return;
        }
        float _requiredCapacity;

        foreach (ResourceClass _valuable in resources)
        {
            if (_valuable.Id == _id)
            {
                _requiredCapacity = _valuable.EvaluateAmount(_amount);
                Debug.Log("Required Capacity Old: " + _requiredCapacity);
                if (usedCapacity + _requiredCapacity <= maxCapacity)
                {
                    usedCapacity -= _valuable.Weight;
                    _valuable.AddAmount(_amount);
                    usedCapacity += _valuable.Weight;
                }
                else if (usedCapacity + _requiredCapacity > maxCapacity)
                {
                    float overCapacity = (usedCapacity + _requiredCapacity) - maxCapacity;
                    float newAmount    = _amount - (overCapacity / _valuable.WeightPerUnit);
                    Debug.Log("Over Capacity " + overCapacity + ". Adding " + newAmount + " Resources Instead.");
                    usedCapacity -= _valuable.Weight;
                    _valuable.AddAmount(newAmount);

                    if (_valuable.EvaluateAmount(_valuable.Quantity) > maxCapacity)
                    {
                        Debug.LogError("ERROR: Too High Weight");
                    }

                    usedCapacity += _valuable.Weight;
                }
                return;
            }
        }//If it completes the loop, it doesn't contain the resource
        ResourceClass newResource = new ResourceClass(_id);

        _requiredCapacity = newResource.EvaluateAmount(_amount);
        Debug.Log("Required Capacity: " + _requiredCapacity);
        if (usedCapacity + _requiredCapacity <= maxCapacity)
        {
            newResource.AddAmount(_amount);
        }
        else
        {
            float overCapacity = (usedCapacity + _requiredCapacity) - maxCapacity;
            float newAmount    = _amount - (overCapacity / newResource.WeightPerUnit);
            Debug.Log("Over Capacity " + overCapacity + ". Adding " + newAmount + " New Resources Instead.");
            newResource.AddAmount(newAmount);
        }

        resources.Add(newResource);
        usedCapacity += newResource.Weight;
    }
예제 #6
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variable" <see
        /// cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnVariableSelected</b> updates all dialog controls to reflect the selected item in
        /// the "Variable" list view.</remarks>

        private void OnVariableSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;

            // clear data display
            VariableInfo.Clear();
            MinimumInfo.Clear();
            MaximumInfo.Clear();
            StepSizeInfo.Clear();

            // disable resource display
            ResourceGroup.IsEnabled = false;
            DefeatInfo.Text         = "—"; // em dash
            VictoryInfo.Text        = "—"; // em dash
            ResetToggle.IsChecked   = false;
            LimitToggle.IsChecked   = false;

            // retrieve selected item, if any
            VariableClass variable = VariableList.SelectedItem as VariableClass;

            if (variable == null)
            {
                return;
            }

            // show target range and step size
            MinimumInfo.Text  = variable.Format(variable.Minimum, false);
            MaximumInfo.Text  = variable.Format(variable.Maximum, false);
            StepSizeInfo.Text = variable.Format(1, false);

            // show additional data for resources
            ResourceClass resource = variable as ResourceClass;

            if (resource != null)
            {
                ResourceGroup.IsEnabled = true;

                ResetToggle.IsChecked = resource.IsResetting;
                LimitToggle.IsChecked = resource.IsLimited;

                if (resource.Defeat != Int32.MinValue)
                {
                    DefeatInfo.Text = resource.Format(resource.Defeat, false);
                }

                if (resource.Victory != Int32.MaxValue)
                {
                    VictoryInfo.Text = resource.Format(resource.Victory, false);
                }
            }

            // show associated informational text
            VariableInfo.Text = String.Join(Environment.NewLine, variable.Paragraphs);
        }
예제 #7
0
        public ResourseRecord(string name, ResourceType type, ResourceClass resClass, uint ttl, ushort dataLength,
                              IData data)
        {
            Name       = name;
            Type       = type;
            Class      = resClass;
            Ttl        = ttl;
            DataLength = dataLength;
            var now = DateTime.Now;

            AbsoluteExpitationDate = now.AddSeconds(ttl);
            Data = data;
        }
        private UIElement CreatePartPath(ResourceClass mc)
        {
            TextBlock tb = new TextBlock()
            {
                Text = mc.Name, Tag = mc, Cursor = Cursors.Hand
            };

            tb.MouseLeftButtonDown += new MouseButtonEventHandler(tbRoot_MouseLeftButtonDown);
            tb.MouseEnter          += new MouseEventHandler(tbRoot_MouseEnter);
            tb.MouseLeave          += new MouseEventHandler(tbRoot_MouseLeave);

            return(tb);
        }
예제 #9
0
        public override ResourceClass GetResourceClassByKey(Key key)
        {
            ResourceClass result = null;

            List <ResourceClass> resourceClassesWithSameID = _metaData?.ResourceClasses.FindAll(res => res.ID == key.ID);

            if (resourceClassesWithSameID.Count != 0)
            {
                result = resourceClassesWithSameID.Find(r => r.Revision == key.Revision);
            }

            return(result);
        }
 public void DeleteResourceClass(Guid tool_id, Guid executor_id, Guid resouce_classes_id)
 {
     try
     {
         ResourceClass resource_class = EnsureResourceClassExisted(tool_id, executor_id, resouce_classes_id);
         _resourceClass.Remove(resource_class);
         SaveChanges();
     }
     catch (Exception e)
     {
         throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred!",
                                                                  e, DateTime.Now, "Server", "Service-Configuration-DeleteResourceClass");
     }
 }
        private void SetPath()
        {
            spContent.Children.Clear();
            spContent.Children.Add(tbRoot);

            ResourceClass rc = CurrentResourceClass;

            while (rc != null)
            {
                spContent.Children.Insert(1, CreatePartPath(rc));
                spContent.Children.Insert(1, new TextBlock()
                {
                    Text = Separator
                });
                rc = rc.ParentClass;
            }
        }
 public ResourceClass EnsureResourceClassExisted(Guid tool_id, Guid executor_id, Guid resouce_classes_id)
 {
     try
     {
         ResourceClass resource_class = _resourceClass.GetOne(rc => rc.Executor.ToolId.Equals(tool_id) && rc.ExecutorId.Equals(executor_id) && rc.Id.Equals(resouce_classes_id));
         if (resource_class == null)
         {
             throw NotFound();
         }
         return(resource_class);
     }
     catch (Exception e)
     {
         throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred!",
                                                                  e, DateTime.Now, "Server", "Service-Configuration-EnsureResourceClassExisted");
     }
 }
 public dynamic UpdateResourceClass(Guid tool_id, Guid executor_id, Guid resouce_classes_id, ResourceClassUpdateM model)
 {
     try
     {
         ResourceClass resource_class = EnsureResourceClassExisted(tool_id, executor_id, resouce_classes_id);
         resource_class.Name = model.Name;
         SaveChanges();
         return(new
         {
             resource_class.Id,
             resource_class.Name
         });
     }
     catch (Exception e)
     {
         throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred!",
                                                                  e, DateTime.Now, "Server", "Service-Configuration-UpdateResourceClass");
     }
 }
        public bool TryGetHostEntry(string hostName, ResourceClass resClass, ResourceType resType, out IPHostEntry entry)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (hostName.Length > 126)
            {
                throw new ArgumentOutOfRangeException("hostName");
            }

            entry = null;

            Interlocked.Increment(ref this._queries);

            // fail fasts
            if (!this.IsZoneLoaded())
            {
                return(false);
            }
            if (!hostName.EndsWith(this._zone.Suffix))
            {
                return(false);
            }

            // lookup locally
            string            key = GenerateKey(hostName, resClass, resType);
            IAddressDispenser dispenser;

            if (_zoneMap.TryGetValue(key, out dispenser))
            {
                Interlocked.Increment(ref this._hits);
                entry = new IPHostEntry {
                    AddressList = dispenser.GetAddresses().ToArray(), Aliases = new string[] {}, HostName = hostName
                };
                return(true);
            }

            Interlocked.Increment(ref this._misses);
            return(false);
        }
        public static string GetTypeName(this Resource resource, ISpecIfMetadataReader dataProvider)
        {
            string result = "";

            try
            {
                ResourceClass resourceType = dataProvider.GetResourceClassByKey(resource.Class);

                if (resourceType != null)
                {
                    if (resourceType.Title is string)
                    {
                        result = resourceType.Title.ToString();
                    }
                    //result = resourceType.Title.LanguageValues[0];
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error with getTypeName() " + exception);
            }
            return(result);
        }
        public static void SetPropertyValue(this Resource resource,
                                            string propertyTitle,
                                            string stringValue,
                                            ISpecIfMetadataReader metadataProvider,
                                            string format = "plain")
        {
            ResourceClass resourceClass = metadataProvider.GetResourceClassByKey(resource.Class);

            Value value = new Value();

            foreach (Key propertyClassKey in resourceClass.PropertyClasses)
            {
                PropertyClass propertyClass = metadataProvider.GetPropertyClassByKey(propertyClassKey);

                if (propertyClass.Title == propertyTitle)
                {
                    DataType dataType = metadataProvider.GetDataTypeByKey(propertyClass.DataType);

                    if (dataType.Type == "xs:string")
                    {
                        MultilanguageText multilanguageText = new MultilanguageText
                        {
                            Text   = stringValue,
                            Format = format
                        };

                        value = new Value(multilanguageText);
                    }
                    else
                    {
                        value = new Value(stringValue);
                    }
                }
            }

            SetPropertyValue(resource, propertyTitle, value, metadataProvider);
        }
        public ActionResult AddTblResource(ResourceClass uc, HttpPostedFileBase file)
        {
            using (SqlConnection con = new SqlConnection(Helper.connectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("spresource", con);
                cmd.CommandType = CommandType.StoredProcedure;

                if (file != null && file.ContentLength > 0)
                {
                    string filename = Path.GetFileName(file.FileName);
                    string imgpath  = Path.Combine(Server.MapPath("~/Cover_page/"), filename);
                    file.SaveAs(imgpath);
                }
                cmd.Parameters.AddWithValue("@images", "~/Cover_page/" + file.FileName);
                cmd.Parameters.AddWithValue("@title", uc.Title);
                cmd.Parameters.AddWithValue("@author", uc.Author);
                cmd.Parameters.AddWithValue("@subjects", uc.Subject);
                cmd.Parameters.AddWithValue("@years", uc.Years);
                cmd.Parameters.AddWithValue("@descriptions", uc.Files);
                cmd.ExecuteNonQuery();
            }
            return(View("AddedStatus"));
        }
예제 #18
0
 public abstract void AddResourceClass(ResourceClass resourceClass);
 private string GenerateKey(string host, ResourceClass resClass, ResourceType resType)
 {
     return(string.Format("{0}|{1}|{2}", host, resClass, resType));
 }
        public static void SetPropertyValue(this Resource resource,
                                            string propertyTitle,
                                            Value value,
                                            ISpecIfMetadataReader metadataProvider)
        {
            bool propertyFound = false;

            foreach (Property property in resource.Properties)
            {
                PropertyClass propertyClass = metadataProvider.GetPropertyClassByKey(property.Class);

                if (propertyClass != null)
                {
                    if (propertyClass.Title == propertyTitle)
                    {
                        if (property.Values.Count == 0)
                        {
                            property.Values.Add(value);
                        }
                        else
                        {
                            property.Values[0] = value;
                        }
                        propertyFound = true;
                        break;
                    }
                }
            }

            if (!propertyFound)
            {
                ResourceClass resourceType = metadataProvider.GetResourceClassByKey(resource.Class);

                if (resourceType != null)
                {
                    PropertyClass matchingPropertyClass = null;
                    Key           matchingPropertyKey   = null;


                    foreach (Key propertyKey in resourceType.PropertyClasses)
                    {
                        PropertyClass propertyClass = metadataProvider.GetPropertyClassByKey(propertyKey);

                        if (propertyClass.Title == propertyTitle)
                        {
                            matchingPropertyClass = propertyClass;
                            matchingPropertyKey   = propertyKey;
                            break;
                        }
                    }

                    if (matchingPropertyClass != null)
                    {
                        Property property = new Property()
                        {
                            Class  = matchingPropertyKey,
                            Values = new List <Value> {
                                value
                            }
                        };

                        resource.Properties.Add(property);
                    }
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BuildListItem"/> class with the specified
        /// <see cref="Scenario.ResourceClass"/>.</summary>
        /// <param name="resource">
        /// The initial value for the <see cref="ResourceClass"/> property.</param>
        /// <remarks>
        /// The <see cref="EntityClass"/> property remains a null reference.</remarks>

        public BuildListItem(ResourceClass resource)
        {
            ResourceClass = resource;
        }
예제 #22
0
 public int Carry(ResourceClass resclass, int amount)
 {
     ResourcesCarried.Add(resclass, amount);
     return(amount);
 }
예제 #23
0
 public bool FullForResourceClass(ResourceClass rc) =>
 Math.Floor(MaxCarryWeight - ResourcesCarried.Weight) / rc.UnitWeight <= 0;
        public ActionResult Edit(int Id)
        {
            ResourceClass resource = UpdateClass.GetResourceList.Single(List => List.ResId == Id);

            return(View(resource));
        }
예제 #25
0
        /// <summary>
        /// Adds one <see cref="ConditionListItem"/> for each condition that applies to the selected
        /// <see cref="Faction"/> to the "Condition" <see cref="ListView"/> on the <see
        /// cref="ConditionsTab"/> page.</summary>
        /// <remarks>
        /// <b>CreateConditionRows</b> adds one row for each possible <see
        /// cref="ConditionParameter"/>, plus one row for each resource defined in the current <see
        /// cref="VariableSection"/> that appears in the <see cref="Faction.Resources"/> collection
        /// of the selected <see cref="Faction"/>, if any.</remarks>

        private void CreateConditionRows()
        {
            var defeatConditions  = this._faction.FactionClass.DefeatConditions;
            var victoryConditions = this._faction.FactionClass.VictoryConditions;

            // process all non-resource conditions
            foreach (ConditionParameter parameter in FactionClass.AllConditionParameters)
            {
                // get current value for this faction
                int    currentValue = this._faction.GetConditionValue(this._worldState, parameter);
                string current      = currentValue.ToString("N0", ApplicationInfo.Culture);

                // get individual defeat & victory thresholds
                string    defeat = "—", victory = "—";
                Condition condition;
                if (defeatConditions.TryGetValue(parameter, out condition))
                {
                    defeat = condition.Threshold.ToString("N0", ApplicationInfo.Culture);
                }
                if (victoryConditions.TryGetValue(parameter, out condition))
                {
                    victory = condition.Threshold.ToString("N0", ApplicationInfo.Culture);
                }

                var item = new ConditionListItem(parameter)
                {
                    Current = current, Defeat = defeat, Victory = victory
                };

                ConditionList.Items.Add(item);
            }

            ConditionList.Items.Add(new ConditionListItem());

            // process all resources defined by scenario
            foreach (var pair in MasterSection.Instance.Variables.Resources)
            {
                // skip resources not owned by faction
                if (!this._faction.Resources.Variables.ContainsKey(pair.Key))
                {
                    continue;
                }

                // get current value for this faction
                int    currentValue = this._faction.Resources.Variables[pair.Key].Value;
                string current      = currentValue.ToString("N0", ApplicationInfo.Culture);

                // get global defeat & victory thresholds
                ResourceClass resource = (ResourceClass)pair.Value;
                string        defeat = "—", victory = "—";
                if (resource.Defeat > Int32.MinValue)
                {
                    defeat = resource.Defeat.ToString("N0", ApplicationInfo.Culture);
                }
                if (resource.Victory < Int32.MaxValue)
                {
                    victory = resource.Victory.ToString("N0", ApplicationInfo.Culture);
                }

                var item = new ConditionListItem(pair.Value)
                {
                    Current = current, Defeat = defeat, Victory = victory
                };

                ConditionList.Items.Add(item);
            }
        }
예제 #26
0
 public abstract void UpdateResourceClass(ResourceClass resourceClass);
예제 #27
0
        /// <summary>
        /// Adds one <see cref="RankingListItem"/> for each <see cref="Faction"/> in the game to the
        /// "Faction" <see cref="ListView"/> on the <see cref="TablesTab"/> page.</summary>
        /// <param name="resource">
        /// The <see cref="ResourceClass"/> by which factions are ranked, or a null reference when
        /// ranking by another criterion.</param>
        /// <param name="id">
        /// The <see cref="VariableClass.Id"/> string of the specified <paramref name="resource"/>,
        /// if valid; or a string identifying the actual ranking criterion otherwise.</param>
        /// <remarks>
        /// <b>CreateFactionRows</b> adds one item for each faction in the associated <see
        /// cref="WorldState"/> to the "Faction" <see cref="ListView"/>.</remarks>

        private void CreateFactionRows(ResourceClass resource, string id)
        {
            var items = new List <RankingListItem>(this._worldState.Factions.Count);

            // determine faction values for current comparison criterion
            foreach (Faction faction in this._worldState.Factions)
            {
                var item = new RankingListItem(faction);

                if (resource != null)
                {
                    // show stockpile of specified resource
                    Variable variable = faction.Resources[id];
                    if (variable != null)
                    {
                        item.Value     = variable.Value;
                        item.ValueText = variable.ToString();
                    }
                }
                else
                {
                    switch (id)
                    {
                    case "sites":
                        // show number of owned sites
                        item.Value     = faction.Sites.Count;
                        item.ValueText = item.Value.ToString("N0", ApplicationInfo.Culture);
                        break;

                    case "site-values":
                        // show sum of normalized site values
                        foreach (Site site in faction.Sites)
                        {
                            item.Value += site.Valuation;
                        }
                        item.ValueText = item.Value.ToString("N2", ApplicationInfo.Culture);
                        break;

                    case "units":
                        // show number of owned units
                        item.Value     = faction.Units.Count;
                        item.ValueText = item.Value.ToString("N0", ApplicationInfo.Culture);
                        break;

                    case "unit-strength":
                        // show sum of current unit strength
                        item.Value     = faction.UnitStrength;
                        item.ValueText = item.Value.ToString("N0", ApplicationInfo.Culture);
                        break;

                    case "unit-values":
                        // show sum of normalized unit values
                        foreach (Entity unit in faction.Units)
                        {
                            item.Value += unit.Valuation;
                        }
                        item.ValueText = item.Value.ToString("N2", ApplicationInfo.Culture);
                        break;

                    default:
                        ThrowHelper.ThrowArgumentExceptionWithFormat(
                            "id", Tektosyne.Strings.ArgumentSpecifiesInvalid, "criterion");
                        break;
                    }
                }

                items.Add(item);
            }

            // sort faction items by value of comparison criterion
            items.ShellSort(new Comparison <RankingListItem>((x, y) => (int)(y.Value - x.Value)));

            // prepend rank to each entry
            int rank = 1;

            foreach (RankingListItem item in items)
            {
                item.Rank = rank++;
                FactionList.Items.Add(item);
            }
        }
예제 #28
0
 public Question(ResourceClass @class, string name, ResourceType type)
 {
     Class = @class;
     Name  = name;
     Type  = type;
 }