Esempio n. 1
0
        public Lumbermill(Map map, IntVector pos)
        {
            Type     = BuildingType.Lumbermill;
            Width    = 2;
            Height   = 2;
            Consumer = new ResourceInput(map, this, (-2, -2), 6, Item.Wood);
            var producer = new DirectProducer(5, 1, Item.Wood);

            Producer       = producer;
            Output         = producer;
            ProcessingTime = 1;
            Entrance       = new BuildingEntrance(this, (0, 1), (0, 2), PathType.Driveway);
        }
Esempio n. 2
0
        public Mine(Map map, IntVector pos)
        {
            var item = map.GetNearestResource(pos + (Width / 2, Height / 2), 2, Item.Stone, Item.IronOre, Item.CopperOre);

            Type     = BuildingType.Mine;
            Consumer = new ResourceInput(map, this, (-1, -1), 4, item);
            var output = new DirectProducer(5, 1, item);

            Output         = output;
            Producer       = output;
            ProcessingTime = 2;
            Width          = 2;
            Height         = 2;
            Entrance       = new BuildingEntrance(this, (0, 1), (0, 2), PathType.Driveway);
        }
Esempio n. 3
0
    public void OnMachineInput(ITransportable transportable)
    {
        Resource resource = transportable.OnPeek();

        if (ResourceInput == null)
        {
            ResourceInput        = Instantiate(resource);
            ResourceInput.amount = 0;
        }

        //Is this resource not wood?
        if (!resource.title.Equals("Wood"))
        {
            transportable.OnRejected();
            return;
        }
        //Is the input amount full
        if (ResourceInput.IsFull)
        {
            transportable.OnRejected();
            return;
        }

        //Callback for picking up the transport
        transportable.OnPickup();

        ResourceInput.Add(ref resource);

        OnInput();
    }
        public ResourceOutput ProvisionOrUpdateResource(string subscriptionId, string cloudServiceName, string resourceType, string resourceName, ResourceInput resource)
        {
            if (String.IsNullOrEmpty(cloudServiceName) || String.IsNullOrEmpty(resourceType) || String.IsNullOrEmpty(resourceName) || (resource == null))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return DataModel.ProvisionOrUpdateResource(subscriptionId, cloudServiceName, resourceType, resourceName, resource);
        }
Esempio n. 5
0
        private void ClearBoxOnFocus(object sender, RoutedEventArgs e)
        {
            if (ResourceInput.IsFocused)
            {
                ResourceInput.Clear();
            }
            else
            {
                if (string.IsNullOrEmpty(ResourceInput.Text))
                {
                    ResourceInput.Text = "Resourse";
                }
            }

            if (LoginInput.IsFocused)
            {
                LoginInput.Clear();
            }
            else
            {
                if (string.IsNullOrEmpty(LoginInput.Text))
                {
                    LoginInput.Text = "Login name";
                }
            }

            if (PasswordInput.IsFocused)
            {
                PasswordInput.Clear();
            }
            else
            {
                if (string.IsNullOrEmpty(PasswordInput.Text))
                {
                    PasswordInput.Text = "Password";
                }
            }
        }
        public ResourceOutput CreateOrUpdateResource(string subscriptionId, string cloudServiceName, string resourceType, string resourceName)
        {
            if (!AzureStoreAuthorization.AuthorizeRequest(this.Request.GetClientCertificate()))
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            ResourceInput resourceInput = null;

            try
            {
                resourceInput = Request.Content.ReadAsAsync <ResourceInput>().Result;

                using (var provider = AccountDataProvider.Instance)
                {
                    if (String.IsNullOrEmpty(cloudServiceName) || String.IsNullOrEmpty(resourceType) || String.IsNullOrEmpty(resourceName) || (resourceInput == null))
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }

                    var eTag          = resourceInput.ETag;
                    var region        = resourceInput.CloudServiceSettings.GeoRegion;
                    var plan          = resourceInput.Plan;
                    var promotionCode = resourceInput.PromotionCode;

                    var resource = provider.GetAzureStoreResource(
                        subscriptionId: subscriptionId,
                        cloudServiceName: cloudServiceName,
                        resourceType: resourceType,
                        resourceName: resourceName
                        );

                    if (resource == null)
                    {
                        var subscription = provider.GetAzureStoreSubscriptionBySubscriptionId(subscriptionId);
                        if (subscription == null)
                        {
                            Logger.ErrorFormat("CreateOrUpdateResource: Unable to find Azure Store resource {1} for subscription {0}. Raw data:\n{2}\n", subscriptionId, resourceName, resourceInput.AsJson());
                            throw new HttpResponseException(HttpStatusCode.BadRequest);
                        }

                        resource = new AzureStoreResource
                        {
                            id_TenantId          = subscription.id_TenantId,
                            nvc_SubscriptionId   = subscriptionId,
                            nvc_CloudServiceName = cloudServiceName,
                            nvc_ResourceType     = resourceType,
                            nvc_ResourceName     = resourceName,
                        };
                    }

                    if (!eTag.Equals(resource.nvc_ETag, StringComparison.OrdinalIgnoreCase))
                    {
                        resource.nvc_ETag          = eTag;
                        resource.nvc_Region        = region ?? resource.nvc_Region;
                        resource.nvc_Plan          = plan ?? resource.nvc_Plan;
                        resource.nvc_PromotionCode = promotionCode ?? resource.nvc_PromotionCode;
                        resource.nvc_RawData       = resourceInput.AsJson();

                        provider.CreateOrUpdateAzureStoreResource(resource);
                    }

                    Logger.InfoFormat("CreateOrUpdateResource: Azure Store resource {1} for subscription {0} create or updated. Raw data:\n{2}\n", subscriptionId, resourceName, resourceInput.AsJson());
                    return(this.MapAzureStoreResourceToResourceOutput(resource, expandOutputItems: true));
                }
            }
            catch (Exception ex)
            {
                if (Utils.IsFatalException(ex) || ex is HttpResponseException)
                {
                    throw;
                }

                Logger.Error(
                    message: String.Format(
                        "CreateOrUpdateResource: Unable to provision or update resource {1} for subscription {0}. Raw data:\n{2}\n",
                        subscriptionId,
                        resourceName,
                        resourceInput != null ? resourceInput.AsJson() : "<null>"
                        ),
                    exception: ex
                    );

                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
        public static ResourceOutput ProvisionOrUpdateResource(string subscriptionId, string cloudServiceName, string resourceType, string resourceName, ResourceInput resource)
        {
            ResourceOutput output;

            lock (theMassiveLock)
            {
                Subscription subscription;
                if (!allSubscriptions.TryGetValue(subscriptionId, out subscription))
                {
                    subscription = new Subscription() { Id = subscriptionId };
                    allSubscriptions[subscriptionId] = subscription;
                }

                CloudService theMatchingCloudService = subscription.CloudServices.SingleOrDefault<CloudService>(cs => String.CompareOrdinal(cs.Name, cloudServiceName) == 0);

                if (theMatchingCloudService == null)
                {
                    theMatchingCloudService = new CloudService() { Name = cloudServiceName };
                    subscription.CloudServices.Add(theMatchingCloudService);
                }

                ResourceOutput theMatchingResource = theMatchingCloudService.Resources.FirstOrDefault(r => String.Compare(r.Name, resourceName) == 0);

                if (theMatchingResource != null)
                {
                    // We can be called to provision / update a resource several time - Ignore the request if we have a record of the resource with the same incarnation id
                    if (theMatchingResource.ETag != resource.ETag)
                    {
                        theMatchingResource.CloudServiceSettings = resource.CloudServiceSettings;
                        theMatchingResource.ETag = resource.ETag;
                        theMatchingResource.IntrinsicSettings = resource.IntrinsicSettings;
                        theMatchingResource.Name = resourceName;
                        theMatchingResource.OperationStatus = new OperationStatus()
                        {
                            Error = new ErrorData() { HttpCode = 200, Message="OK" },
                            Result = OperationResult.Succeeded
                        };
                        theMatchingResource.Plan = resource.Plan;
                        theMatchingResource.SchemaVersion = resource.SchemaVersion;
                        theMatchingResource.State = ResourceState.Started.ToString();
                        theMatchingResource.SubState = "";
                        theMatchingResource.Type = resource.Type;
                    }

                    output = theMatchingResource;
                }
                else
                {
                    output = new ResourceOutput()
                    {
                        CloudServiceSettings = resource.CloudServiceSettings,
                        ETag = resource.ETag,
                        IntrinsicSettings = resource.IntrinsicSettings,
                        Name = resourceName,
                        OperationStatus = new OperationStatus()
                        {
                            Error = new ErrorData() { HttpCode = 200, Message="OK" },
                            Result = OperationResult.Succeeded
                        },
                        OutputItems = GenerateOutputItems(),
                        Plan = resource.Plan,
                        SchemaVersion = resource.SchemaVersion,
                        State = ResourceState.Started.ToString(),
                        SubState = "",
                        Type = resource.Type
                    };

                    theMatchingCloudService.Resources.Add(output);
                }
            }

            return output;
        }