#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using HeuristicLab.Common;
using HeuristicLab.Core;
namespace HeuristicLab.Clients.Hive.CloudManager.Model {
public class HostedService : Item {
public string ServiceName { get; set; }
public string Url { get; set; }
public Subscription Subscription { get; set; }
public HostedServiceProperties HostedServiceProperties { get; set; }
public List Deployments { get; set; }
public HostedService() {
}
public HostedService(HostedService original, Cloner cloner) {
this.ServiceName = original.ServiceName;
this.Url = original.Url;
this.Subscription = cloner.Clone(original.Subscription);
this.HostedServiceProperties = cloner.Clone(original.HostedServiceProperties);
this.Deployments = new List(original.Deployments);
}
public override bool Equals(object obj) {
if (obj == null)
return false;
HostedService sub = obj as HostedService;
if ((this.ServiceName == sub.ServiceName))
return true;
else
return false;
}
public override string ToString() {
return string.Format("HostedService: Name={0}, Url={1}", ServiceName, Url);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new HostedService(this, cloner);
}
public void Merge(HostedService hostedService) {
if (!this.Equals(hostedService)) {
throw new ArgumentException("Objects must be equal to be merged.", "subscription");
}
this.ServiceName = hostedService.ServiceName;
this.Url = hostedService.Url;
this.Subscription = hostedService.Subscription;
this.HostedServiceProperties = hostedService.HostedServiceProperties;
foreach (Deployment dep in hostedService.Deployments) {
int idx = this.Deployments.IndexOf(dep);
if (idx != -1) {
this.Deployments[idx].Merge(dep);
} else {
this.Deployments.Add(dep);
}
}
List listToDelete = new List();
foreach (Deployment dep in this.Deployments) {
int idx = hostedService.Deployments.IndexOf(dep);
if (idx == -1) {
//this.Deployments.Remove(dep);
listToDelete.Add(dep);
}
}
foreach (Deployment d in listToDelete) {
this.Deployments.Remove(d);
}
}
}
}