public MainWindow(string user, string pass, string broker, string project, LoginScreenViewModel ParentWindow)
        {
            viewModel = new HarvestUtilitiesViewModel(user, pass, broker, project, this);

            InitializeComponent();

            base.DataContext = viewModel;

            //Hide login window
            try
            {
                this.ParentWindow = ParentWindow;
                ParentWindow.thisScreen.Hide();
            }
            catch (Exception e) { Console.WriteLine(e.Message); }

            AllocConsole();
        }
Пример #2
0
        //Parse and asign values
        public void Allocate(HarvestUtilitiesViewModel HUObject)
        {
            if (File.Exists(filePath))
            {
                //Initialize objects. This also resets previously entered data.
                try
                {
                    HUObject.InitMembers();
                    

                    var doc = XDocument.Parse(System.IO.File.ReadAllText(filePath));
                    foreach (var child in doc.Element("HarvestXml").Elements())
                    {
                        switch (child.Name.ToString())
                        {
                            case "Dependencies":
                                foreach (var thisDependency in child.Elements())
                                    HUObject.DependencyList.Add(new ProjectDependencyModel() { PackageName = thisDependency.Value });
                                break;

                            case "SpecialInstructions":
                                foreach (var thisInstruction in child.Elements())
                                {
                                    switch (thisInstruction.Name.ToString())
                                    {
                                        case "Custom":
                                            HUObject.CustomInstructions = thisInstruction.Value;
                                            break;

                                        case "Forms": //ObjToRecompile
                                            foreach (var thisInstructionChild in thisInstruction.Elements())
                                                HUObject.RecompileList.Add( new SpInsRecompileModel(){
                                                    extensions = HUObject.RecompileValidExtensions,
                                                    ObjToRecompile = thisInstructionChild.Value
                                                } );
                                            break;

                                        case "DoNotRun":
                                            foreach (var thisInstructionChild in thisInstruction.Elements())
                                            {
                                                //DoNotRunSetVal
                                                string environment = thisInstructionChild.Name.ToString();
                                                string value = thisInstructionChild.Value;
                                                bool exists = false;
                                                for (int i = 0; i < HUObject.DoNotRunList.Count; i++)
                                                {
                                                    if (HUObject.DoNotRunList[i].Value == value && !exists)
                                                    {
                                                        exists = true;
                                                        HUObject.DoNotRunList[i] = DoNotRunSetVal(HUObject.DoNotRunList[i], environment);
                                                    }
                                                }

                                                if (!exists)
                                                {
                                                    SpInsDoNotRunModel obj = DoNotRunSetVal(new SpInsDoNotRunModel() { Value = value }, environment);
                                                    HUObject.DoNotRunList.Add(obj);
                                                }
                                            }
                                            break;

                                        case "RunOrdered":
                                            foreach (var thisInstructionChild in thisInstruction.Elements())
                                                HUObject.RunOrderedList.Add(new SpInsRunOrderedModel()
                                                {
                                                    Value = thisInstructionChild.Value,
                                                    Environment = thisInstructionChild.Name.ToString()
                                                });
                                            break;

                                        case "RunBefore":
                                        case "RunAfter":
                                            HUObject.RunBeforeOrAfterList.Add(new SpInsRunBoAModel()
                                            {
                                                Task = thisInstruction.Value,
                                                Order = thisInstruction.Name.ToString().Replace("Run", "")
                                            });
                                            break;
                                    }
                                }
                                break;

                            case "Files":
                                foreach (var thisAttachment in child.Elements())
                                {
                                    string type = thisAttachment.Element("Type").Value;
                                    string name = thisAttachment.Element("Name").Value;
                                    HUObject.AttachmentList.Add(new AttachmentModel()
                                    {
                                        Type = type,
                                        Name = name,
                                        Comments = thisAttachment.Element("Comments").Value,
                                        FilePath = Path.GetDirectoryName(filePath) + "\\" + type + "\\" + name
                                    });
                                }
                                break;

                            case "ProjectInformation":
                                foreach (var thisAttr in child.Elements())
                                {
                                    var property = HUObject.GetType().GetProperty(thisAttr.Name.ToString());
                                    DateTime DateVal;
                                    if (DateTime.TryParse(thisAttr.Value, out DateVal))
                                        property.SetValue(HUObject, DateVal, null);
                                    else
                                        property.SetValue(HUObject, thisAttr.Value, null);
                                }
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("XML format invalid: " + ex.Message);
                    log.Error("XML format invalid", ex);
                }
            }
            else
            {
                MessageBox.Show("Can't access XML file.", "Error loading", MessageBoxButton.OK, MessageBoxImage.Error);
                log.Warn("XML exists but won't load");
            }
        }