Changeset 8


Ignore:
Timestamp:
02/20/08 11:08:04 (13 years ago)
Author:
gkronber
Message:

removed silly assertion statements (ticket #12)

Location:
trunk/sources
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure.GUI/ManagerForm.cs

    r2 r8  
    111111
    112112    private void publishButton_Click(object sender, EventArgs args) {
    113       Trace.Assert(pluginTreeView.SelectedNode.Tag is PluginTag);
    114113
    115114      PluginInfo plugin = ((PluginTag)pluginTreeView.SelectedNode.Tag).Plugin;
     
    235234              return tag.PluginName == upgrade.Name;
    236235            });
    237             // only one plugin must be found
    238             Trace.Assert(oldPlugins.Count == 1);
    239236            PluginTag oldPlugin = oldPlugins[0];
    240 
    241             // the plugin must be installed already
    242             Trace.Assert(oldPlugin.State == PluginState.Installed);
    243             // the old plugin has to have an older version than the upgrade
    244             Trace.Assert(oldPlugin.PluginVersion < upgrade.Version);
    245237
    246238            // store the upgrade in the old plugin
     
    255247            });
    256248
    257             // only one plugin must be found
    258             Trace.Assert(currentPlugins.Count == 1);
    259249            PluginTag currentPlugin = currentPlugins[0];
    260 
    261             // the plugin must be available already
    262             Trace.Assert(currentPlugin.State == PluginState.Available);
    263             // the old plugin has to have an older version than the overriding plugin
    264             Trace.Assert(currentPlugin.PluginVersion < overridingPlugin.Version);
    265250
    266251            // replace the plugin description of the available plugin to point to the overriding plugin
     
    333318        });
    334319
    335         // either none or exactly one plugin to upgrade can be found
    336         Trace.Assert(oldPlugins.Count <= 1);
    337320        if(oldPlugins.Count == 1) {
    338321          if(oldPlugins[0].PluginVersion < availablePlugin.Version) {
     
    352335        });
    353336
    354         // either none or exactly one plugin to override can be found
    355         Trace.Assert(currentPlugins.Count <= 1);
    356337        if(currentPlugins.Count == 1) {
    357338          if(currentPlugins[0].PluginVersion < availablePlugin.Version) {
     
    374355          MarkRemove(action.Plugin);
    375356        } else
    376           Trace.Assert(false); // is not allowed to happen
     357          throw new InvalidOperationException();
    377358      }
    378359
     
    387368
    388369    private void MarkInstall(PluginTag actionTag) {
    389 
    390       Trace.Assert(actionTag.State == PluginState.Available);
    391 
    392370      if(!CheckInstallConflicts(actionTag)) {
    393371        CreateNewInstallAction(actionTag);
     
    398376
    399377    private void UnmarkInstall(PluginTag actionTag) {
    400       Trace.Assert(actionTag.State == PluginState.Available);
    401 
    402       Trace.Assert(GetOverlappingActions(actionTag, ManagerAction.Any).TrueForAll(delegate(PluginAction fixedPoint) {
    403         return fixedPoint.Action == ManagerAction.Install;
    404       }));
    405 
    406378      if(!CheckNoActionConflict(actionTag)) {
    407379        List<PluginAction> rootActions = GetActionsInvolving(actionTag);
    408         // if there is no conflict then there can only be one action connected to the pluginTag
    409         Trace.Assert(rootActions.Count == 1);
    410380        PluginAction rootAction = rootActions[0];
    411381        actions.Remove(rootAction.Plugin);
     
    418388    private void HandleNoActionConflict(PluginTag actionTag) {
    419389      List<PluginAction> conflictingActions = GetOverlappingActions(actionTag, ManagerAction.Any);
    420 
    421       Trace.Assert(conflictingActions.Count > 1);
    422390      PluginAction theAction = GetSmallestActionInvolving(actionTag, conflictingActions);
    423391      conflictingActions.Remove(theAction);
    424 
    425 
    426392      string action = theAction.GetInverseActionString();
    427 
    428393      DialogResult userResult = ShowGenericConflictDialog(action, theAction, conflictingActions);
    429 
    430394      if(userResult == DialogResult.OK) {
    431395        conflictingActions.ForEach(delegate(PluginAction conflictingAction) {
     
    445409
    446410    private void MarkRemove(PluginTag actionTag) {
    447 
    448       Trace.Assert((actionTag.State & (PluginState.Installed | PluginState.Upgradeable)) != 0);
    449 
    450411      if(!CheckRemoveConflicts(actionTag)) {
    451412        CreateNewRemoveAction(actionTag);
     
    456417
    457418    private void UnmarkRemove(PluginTag pluginTag) {
    458 
    459       Trace.Assert(pluginTag.State == PluginState.Installed);
    460 
    461       Trace.Assert(GetOverlappingActions(pluginTag, ManagerAction.Any).TrueForAll(delegate(PluginAction action) {
    462         return action.Action == ManagerAction.Remove;
    463       }));
    464 
    465419      if(!CheckNoActionConflict(pluginTag)) {
    466         Trace.Assert(GetOverlappingActions(pluginTag, ManagerAction.Remove).Count == 1);
    467420        List<PluginAction> rootActions = GetActionsInvolving(pluginTag);
    468421        // if there is no conflict then there can only be one action connected to the pluginTag
    469         Trace.Assert(rootActions.Count == 1);
    470422        PluginAction rootAction = rootActions[0];
    471 
    472423        // kill the root action
    473424        actions.Remove(rootAction.Plugin);
     
    547498
    548499    private DialogResult ShowGenericConflictDialog(string action, PluginAction theAction, List<PluginAction> conflictingActions) {
    549 
    550       Trace.Assert(conflictingActions.Count > 0);
    551 
    552500      string message = "The actions:\n\n";
    553501      conflictingActions.ForEach(delegate(PluginAction conflictingAction) {
     
    577525
    578526    private PluginAction GetSmallestActionInvolving(PluginTag actionTag, List<PluginAction> actions) {
    579       Trace.Assert(actions.Count > 0);
    580527      PluginAction smallestAction;
    581528      // if there is an action defined for which actionTag is the root then us it as root tag
     
    814761        string[] extractedFiles = Directory.GetFiles(tempDir, "*", SearchOption.AllDirectories);
    815762        foreach(string extractedFile in extractedFiles) {
    816           Trace.Assert(extractedFile.StartsWith(tempDir));
    817763          File.Copy(extractedFile, pluginDir + extractedFile.Remove(0, tempDir.Length));
    818764        }
     
    822768        string[] extractedFiles = Directory.GetFiles(tempDir, "*", SearchOption.AllDirectories);
    823769        foreach(string extractedFile in extractedFiles) {
    824           Trace.Assert(extractedFile.StartsWith(tempDir));
    825770          string filename = pluginDir + extractedFile.Remove(0, tempDir.Length);
    826771          if(File.Exists(filename)) {
     
    832777        string[] backupFiles = Directory.GetFiles(backupDir, "*", SearchOption.AllDirectories);
    833778        foreach(string backupFile in backupFiles) {
    834           Trace.Assert(backupFile.StartsWith(backupDir));
    835779          File.Copy(backupFile, pluginDir + backupFile.Remove(0, backupDir.Length));
    836780        }
     
    853797          if(tag.State == PluginState.Upgradeable || (involvingActions.Count > 0 && involvingActions[0].Action == ManagerAction.Remove)) {
    854798            tag.Plugin.Files.ForEach(delegate(string filename) {
    855               Trace.Assert(filename.StartsWith(pluginDir));
    856799              DialogResult result = MessageBox.Show("Deleting: " + filename, "Warning: deleting file", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
    857800              if(result == DialogResult.OK) {
     
    866809        string[] backupFiles = Directory.GetFiles(backupDir, "*", SearchOption.AllDirectories);
    867810        foreach(string backupFile in backupFiles) {
    868           Trace.Assert(backupFile.StartsWith(backupDir));
    869811          string oldFileName = pluginDir + backupFile.Remove(0, backupDir.Length);
    870812          if(!File.Exists(oldFileName)) {
     
    888830          if(tag.State == PluginState.Upgradeable || (actionsInvolving.Count > 0 && actionsInvolving[0].Action == ManagerAction.Remove)) {
    889831            tag.Plugin.Files.ForEach(delegate(string filename) {
    890               Trace.Assert(filename.StartsWith(pluginDir));
    891832              File.Copy(filename, backupDir + filename.Remove(0, pluginDir.Length));
    892833            });
     
    998939
    999940    private void removeButton_Clicked(object sender, EventArgs e) {
    1000       AssertAction();
    1001941      // get the tag of the selected treeNode
    1002942      PluginTag actionTag = (PluginTag)pluginTreeView.SelectedNode.Tag;
    1003943      List<PluginAction> rootActions = GetActionsInvolving(actionTag);
    1004944      if(rootActions.Count>0) {
    1005         Trace.Assert(rootActions.TrueForAll(delegate(PluginAction rootAction) {
    1006           return rootAction.Action == ManagerAction.Remove;
    1007         }));
    1008945        UnmarkRemove(actionTag);
    1009946      } else {
     
    1018955
    1019956    private void installButton_Clicked(object sender, EventArgs e) {
    1020       AssertAction();
    1021957      // get the tag of the selected treeNode
    1022958      PluginTag actionTag = (PluginTag)pluginTreeView.SelectedNode.Tag;
     
    1024960
    1025961      if(rootActions.Count > 0) {
    1026         Trace.Assert(rootActions.TrueForAll(delegate(PluginAction rootAction) {
    1027           return rootAction.Action == ManagerAction.Install;
    1028         }));
    1029962        UnmarkInstall(actionTag);
    1030963      } else {
     
    1036969      // update the plugin detail information of the selected plugin
    1037970      DisplayPluginInfo(actionTag.GetPluginDetails());
    1038     }
    1039 
    1040     private void AssertAction() {
    1041       Trace.Assert(pluginTreeView.SelectedNode != null);
    1042       Trace.Assert(pluginTreeView.SelectedNode.Tag is PluginTag);
    1043971    }
    1044972
     
    11011029          // check if none of the files exist
    11021030          foreach(string filename in Directory.GetFiles(cacheDir)) {
    1103             Trace.Assert(filename.StartsWith(cacheDir));
    11041031            if(File.Exists(pluginDir + filename.Remove(0, cacheDir.Length))) {
    11051032              ShowErrorDialog("Sorry can't install the plugin "+packageName+"\nThe file: "+filename.Remove(0, cacheDir.Length)+" already exist in "+pluginDir+"\nIt seems the plugin is already installed.");
  • trunk/sources/HeuristicLab.PluginInfrastructure.GUI/PluginAction.cs

    r2 r8  
    6464        default:
    6565          // this method is not defined for actions other than "Install" and "Remove"
    66           Trace.Assert(false);
     66          throw new InvalidOperationException();
    6767          return "";
    6868      }
  • trunk/sources/HeuristicLab.PluginInfrastructure.GUI/PluginNameTransform.cs

    r2 r8  
    4444
    4545    public string TransformFile(string name) {
    46       //Trace.Assert(name.StartsWith(pluginDir));
    4746      if(name.StartsWith(pluginDir)) {
    4847        return name.Remove(0, pluginDir.Length);
  • trunk/sources/HeuristicLab.PluginInfrastructure/BaseClasses/ApplicationBase.cs

    r2 r8  
    3939
    4040      // exactly one attribute of the type ClassInfoAttribute must be given
    41       Trace.Assert(pluginAttributes.Length == 1);
     41      if(pluginAttributes.Length != 1) {
     42        throw new InvalidPluginException();
     43      }
    4244
    4345      // after the assertion we are sure that the array access will not fail
  • trunk/sources/HeuristicLab.PluginInfrastructure/BaseClasses/PluginBase.cs

    r2 r8  
    4444
    4545      // exactly one attribute of the type ClassInfoAttribute must be given
    46       Trace.Assert(pluginAttributes.Length == 1);
     46      if(pluginAttributes.Length != 1) {
     47        throw new InvalidPluginException();
     48      }
    4749
    4850      // after the assertion we are sure that the array access will not fail
  • trunk/sources/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj

    r2 r8  
    5555    <Compile Include="Interfaces\IControl.cs" />
    5656    <Compile Include="Interfaces\IControlManager.cs" />
     57    <Compile Include="InvalidPluginException.cs" />
    5758    <Compile Include="PluginManager.cs" />
    5859    <Compile Include="PluginManagerActionEventArgs.cs" />
  • trunk/sources/HeuristicLab.PluginInfrastructure/Loader.cs

    r2 r8  
    217217        this.pluginAssemblies[pluginName] = pluginAssemblies;
    218218      } else {
    219         Trace.Assert(false);
     219        throw new InvalidPluginException();
    220220      }
    221221    }
  • trunk/sources/HeuristicLab/MainForm.cs

    r2 r8  
    7777
    7878    private void applicationsListView_ItemActivate(object sender, EventArgs e) {
    79       if(applicationsListView.SelectedItems.Count > 0) {
    80         Trace.Assert(applicationsListView.SelectedItems.Count == 1);
     79      if(applicationsListView.SelectedItems.Count > 0) {       
    8180        ListViewItem selected = applicationsListView.SelectedItems[0];
    8281        if(selected == pluginManagerListViewItem) {
Note: See TracChangeset for help on using the changeset viewer.