public _DeploymentController()
        {
            AllowThreadedAssignment = true;
            PollError = "";
            PreprocessPerformsDiscovery = false;

            InstructionSetTemplate            = "MyTemplate";
            OverrideInstructionSetProcessName = "";

            SandboxAppConfigXml = new List <string>();

            TemplateKVP        = new STEM.Sys.Serialization.Dictionary <string, string>();
            PostMortemMetaData = new Sys.Serialization.Dictionary <string, string>();

            TemplateKVP["[MANAGERS]"] = "Reserved";
            TemplateKVP["[BRANCHES]"] = "Reserved";
            TemplateKVP["[NOSOURCE]"] = "Reserved";

            TemplateKVP["[ControllerVersionNumber]"] = "Reserved";
            TemplateKVP["[BranchIP]"]   = "Reserved";
            TemplateKVP["[BranchName]"] = "Reserved";
            TemplateKVP["[ISetID]"]     = "Reserved";
            TemplateKVP["[NewGuid]"]    = "Reserved";
            TemplateKVP["[DeploymentControllerName]"]  = "Reserved";
            TemplateKVP["[DeploymentControllerID]"]    = "Reserved";
            TemplateKVP["[SwitchboardRowID]"]          = "Reserved";
            TemplateKVP["[DeploymentManagerIP]"]       = "Reserved";
            TemplateKVP["[InitiationSource]"]          = "Reserved";
            TemplateKVP["[InstructionSetProcessName]"] = "Reserved";
            TemplateKVP["[PollerSourceString]"]        = "Reserved";
            TemplateKVP["[PollerFileFilter]"]          = "Reserved";
            TemplateKVP["[PollerDirectoryFilter]"]     = "Reserved";
            TemplateKVP["[UtcNow]"] = "yyyy-MM-dd HH.mm.ss.fff";
        }
Ejemplo n.º 2
0
        protected override bool _Run()
        {
            try
            {
                STEM.Sys.Serialization.Dictionary <string, string> map = WindowsReplacementMap;

                if (!STEM.Sys.Control.IsWindows)
                {
                    map = LinuxReplacementMap;
                }

                for (int x = OrdinalPosition + 1; x < InstructionSet.Instructions.Count; x++)
                {
                    string xml = InstructionSet.Instructions[x].Serialize();

                    foreach (string s in map.Keys)
                    {
                        xml = xml.Replace(s, map[s]);
                    }

                    InstructionSet.Instructions[x] = Instruction.Deserialize(xml) as Instruction;

                    if (ReplaceInInstructions == ReplaceIn.Next)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.Message);
                Exceptions.Add(ex);
            }

            return(Exceptions.Count == 0);
        }
Ejemplo n.º 3
0
        protected override bool _Run()
        {
            try
            {
                STEM.Sys.Serialization.Dictionary <string, DateTime> dict = null;

                string key = TargetPath + ":" + FileFilter + ":" + DirectoryFilter + ".fisher";

                if (!STEM.Sys.Global.Cache.ContainsKey(key))
                {
                    STEM.Sys.Global.Cache[key] = new STEM.Sys.Serialization.Dictionary <string, DateTime>();
                }

                dict = STEM.Sys.Global.Cache[key] as STEM.Sys.Serialization.Dictionary <string, DateTime>;

                if (dict == null)
                {
                    STEM.Sys.Global.Cache[key] = new STEM.Sys.Serialization.Dictionary <string, DateTime>();
                    dict = STEM.Sys.Global.Cache[key] as STEM.Sys.Serialization.Dictionary <string, DateTime>;
                }

                if (dict == null)
                {
                    throw new Exception("There is an issue with the fisher cache for " + key + ". Fisher will not run.");
                }

                TargetPath = STEM.Sys.IO.Path.AdjustPath(TargetPath);
                ErrorPath  = STEM.Sys.IO.Path.AdjustPath(ErrorPath);

                bool modified = false;

                DateTime epoch = DateTime.UtcNow;

                List <string> files = STEM.Sys.IO.Directory.STEM_GetFiles(TargetPath, FileFilter, DirectoryFilter, Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly, true);

                lock (dict)
                {
                    files = files.Except(dict.Keys).ToList();

                    foreach (string file in dict.Keys.ToList())
                    {
                        try
                        {
                            if (!File.Exists(file))
                            {
                                dict.Remove(file);
                                modified = true;
                                continue;
                            }

                            if ((epoch - dict[file]).TotalMinutes > FilePresenceMinutes)
                            {
                                string errDir = ErrorPath;

                                if (Recurse)
                                {
                                    errDir = Path.Combine(ErrorPath, Path.GetDirectoryName(file.Replace(STEM.Sys.IO.Path.FirstTokenOfPath(file), STEM.Sys.IO.Path.FirstTokenOfPath(TargetPath))).Substring(TargetPath.Length).Trim(Path.DirectorySeparatorChar));
                                }

                                if (!Directory.Exists(errDir))
                                {
                                    Directory.CreateDirectory(errDir);
                                }

                                string dfn = "";
                                if (errDir.ToLower().Contains(STEM.Sys.IO.Path.AdjustPath("/dev/null")))
                                {
                                    File.Delete(file);
                                }
                                else
                                {
                                    STEM.Sys.IO.File.STEM_Move(file, Path.Combine(errDir, Path.GetFileName(file)), Sys.IO.FileExistsAction.MakeUnique, out dfn, 0, 0, false);
                                }

                                dict.Remove(file);
                                modified = true;
                            }
                        }
                        catch { }
                    }

                    if (files.Count() > 0)
                    {
                        foreach (string file in files)
                        {
                            dict[file] = epoch;
                        }

                        modified = true;
                    }

                    if (modified)
                    {
                        STEM.Sys.Global.Cache[key] = dict;
                    }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.ToString());
                Exceptions.Add(ex);
            }

            return(Exceptions.Count == 0);
        }
Ejemplo n.º 4
0
 public TokenReplace() : base()
 {
     ReplaceInInstructions = ReplaceIn.All;
     WindowsReplacementMap = new Sys.Serialization.Dictionary <string, string>();
     LinuxReplacementMap   = new Sys.Serialization.Dictionary <string, string>();
 }
Ejemplo n.º 5
0
        protected override bool _Run()
        {
            try
            {
                STEM.Sys.Serialization.Dictionary <string, DateTime> dict = null;

                string key = TargetPath + ":" + FileFilter + ":" + DirectoryFilter + ".fisher";

                if (!STEM.Sys.Global.Cache.ContainsKey(key))
                {
                    STEM.Sys.Global.Cache[key] = new STEM.Sys.Serialization.Dictionary <string, DateTime>();
                }

                dict = STEM.Sys.Global.Cache[key] as STEM.Sys.Serialization.Dictionary <string, DateTime>;

                if (dict == null)
                {
                    STEM.Sys.Global.Cache[key] = new STEM.Sys.Serialization.Dictionary <string, DateTime>();
                    dict = STEM.Sys.Global.Cache[key] as STEM.Sys.Serialization.Dictionary <string, DateTime>;
                }

                if (dict == null)
                {
                    throw new Exception("There is an issue with the fisher cache for " + key + ". Fisher will not run.");
                }

                TargetPath = STEM.Sys.IO.Path.AdjustPath(TargetPath);
                ErrorPath  = STEM.Sys.IO.Path.AdjustPath(ErrorPath);

                bool modified = false;

                DateTime epoch = DateTime.UtcNow;

                List <SftpFile> files = Authentication.ListDirectory(ServerAddress, Int32.Parse(Port), TargetPath, SSHListType.File, Recurse, DirectoryFilter, FileFilter);

                lock (dict)
                {
                    foreach (string file in dict.Keys)
                    {
                        SftpFile f = files.FirstOrDefault(i => i.FullName == file);

                        if (f != null)
                        {
                            files.Remove(f);
                        }
                    }

                    foreach (string file in dict.Keys.ToList())
                    {
                        try
                        {
                            if (!Authentication.FileExists(ServerAddress, Int32.Parse(Port), file))
                            {
                                dict.Remove(file);
                                modified = true;
                                continue;
                            }

                            if ((epoch - dict[file]).TotalMinutes > FilePresenceMinutes)
                            {
                                string errDir = ErrorPath;

                                if (Recurse)
                                {
                                    errDir = Path.Combine(ErrorPath, Path.GetDirectoryName(file.Replace(STEM.Sys.IO.Path.FirstTokenOfPath(file), STEM.Sys.IO.Path.FirstTokenOfPath(TargetPath))).Substring(TargetPath.Length).Trim(Path.DirectorySeparatorChar));
                                }

                                if (!Directory.Exists(errDir))
                                {
                                    Directory.CreateDirectory(errDir);
                                }

                                if (errDir.ToLower().Contains(STEM.Sys.IO.Path.AdjustPath("/dev/null")))
                                {
                                    Authentication.DeleteFile(ServerAddress, Int32.Parse(Port), Authentication.AdjustPath(ServerAddress, file));
                                }
                                else
                                {
                                    SftpClient client = null;

                                    try
                                    {
                                        client = Authentication.OpenSftpClient(ServerAddress, Int32.Parse(Port));

                                        if (client != null)
                                        {
                                            try
                                            {
                                                string errFile = STEM.Sys.IO.Path.AdjustPath(Path.Combine(errDir, Path.GetFileName(file)));

                                                try
                                                {
                                                    using (System.IO.Stream dStream = System.IO.File.Open(errFile, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
                                                    {
                                                        client.DownloadFile(Authentication.AdjustPath(ServerAddress, file), dStream);
                                                    }
                                                }
                                                catch
                                                {
                                                    try
                                                    {
                                                        if (File.Exists(errFile))
                                                        {
                                                            File.Delete(errFile);
                                                        }
                                                    }
                                                    catch { }

                                                    throw;
                                                }

                                                Authentication.DeleteFile(ServerAddress, Int32.Parse(Port), Authentication.AdjustPath(ServerAddress, file));
                                            }
                                            finally
                                            {
                                                Authentication.RecycleClient(client);
                                                client = null;
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        try
                                        {
                                            client.Disconnect();
                                        }
                                        catch { }
                                        try
                                        {
                                            client.Dispose();
                                        }
                                        catch { }

                                        throw;
                                    }
                                }

                                dict.Remove(file);
                                modified = true;
                            }
                        }
                        catch { }
                    }

                    if (files.Count() > 0)
                    {
                        foreach (Renci.SshNet.Sftp.SftpFile file in files)
                        {
                            dict[file.FullName] = epoch;
                        }

                        modified = true;
                    }

                    if (modified)
                    {
                        STEM.Sys.Global.Cache[key] = dict;
                    }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.ToString());
                Exceptions.Add(ex);
            }

            return(Exceptions.Count == 0);
        }
Ejemplo n.º 6
0
 public PollResult()
 {
     Listing   = new Sys.Serialization.Dictionary <string, List <string> >();
     PollError = "";
 }