示例#1
0
文件: TSFile.cs 项目: mteletin/NXtel
 public static bool Save(TSFile File, out string Err, bool ResetOwnerIfNotFound = true)
 {
     Err = "";
     try
     {
         using (var ConX = new MySqlConnection(DBOps.GetConnectionString(File.Environment)))
         {
             ConX.Open();
             if (!string.IsNullOrWhiteSpace(File.Environment))
             {
                 File.GetIDFromDescription(ConX, true, ResetOwnerIfNotFound);
             }
             if (File.TeleSoftwareID <= 0)
             {
                 return(File.Create(out Err, ConX));
             }
             else
             {
                 return(File.Update(out Err, ConX));
             }
         }
     }
     catch (Exception ex)
     {
         Err = ex.Message;
         return(false);
     }
 }
示例#2
0
文件: Page.cs 项目: mteletin/NXtel
        public bool CopySave(out string Err, MySqlConnection ConX)
        {
            Err = "";
            bool success = true;

            try
            {
                var zones = this.ZoneIDs;
                foreach (var zone in Zones ?? new Zones())
                {
                    zone.Environment = Environment;
                    zone.GetIDFromDescription(ConX);
                    success = success & zone.Save(out Err);
                    if (!success)
                    {
                        return(false);
                    }
                }
                if (TeleSoftwareID != null && TeleSoftwareID > 0)
                {
                    var file = TSFile.Load((int)TeleSoftwareID);
                    file.Environment = Environment;
                    success          = success & TSFile.Save(file, out Err, false);
                    if (!success)
                    {
                        return(false);
                    }
                    TeleSoftwareID = file.TeleSoftwareID;
                }
                foreach (var template in Templates ?? new Templates())
                {
                    template.Environment = Environment;
                    success = success & template.CopySave(out Err, ConX);
                    if (!success)
                    {
                        return(false);
                    }
                }
                GetIDFromDescription(ConX);
                if (PageID <= 0)
                {
                    return(Create(-1, out Err, ConX));
                }
                else
                {
                    return(Update(-1, out Err, ConX));
                }
            }
            catch (Exception ex)
            {
                Err = ex.Message;
                return(false);
            }
        }
示例#3
0
文件: TSFile.cs 项目: mteletin/NXtel
        public static TSFile Load(int TelesoftwareID)
        {
            var item = new TSFile();

            using (var con = new MySqlConnection(DBOps.ConnectionString))
            {
                con.Open();
                string sql = "SELECT * FROM telesoftware WHERE TelesoftwareID=" + TelesoftwareID;
                var    cmd = new MySqlCommand(sql, con);
                using (var rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        item.Read(rdr);
                        break;
                    }
                }
            }
            return(item);
        }
示例#4
0
 public bool Can(TSFile File)
 {
     if (File == null)
     {
         return(false);
     }
     if (Options.DisablePermissions || IsAdmin || File.TeleSoftwareID == -1)
     {
         return(true);
     }
     if (!IsPageEditor)
     {
         return(false);
     }
     if (File.OwnerID == this.User.UserNo)
     {
         return(true);
     }
     if (FileIDs.Any(f => f == File.TeleSoftwareID))
     {
         return(true);
     }
     return(false);
 }
示例#5
0
        public void Encode(ref Page Page)
        {
            if (Page == null || Page.TeleSoftwareID == null || Page.TeleSoftwareID <= 0)
            {
                return;
            }
            var file = TSFile.Load((int)Page.TeleSoftwareID);

            if (file.FileSizeBytes <= 0)
            {
                return;
            }
            //using (var debug = new DebugLogger("NXtel.TSEncode"))
            DebugLogger debug = null;
            {
                CurrentSeq             = -1;
                Pages                  = new List <Page>();
                Page.PageType          = PageTypes.TeleSoftware;
                Page.PageRangeSequence = CurrentSeq++;
                CurrentPageNo          = Page.PageNo;
                CurrentFrameNo         = Page.FrameNo;
                CurrentEscape          = TelesoftEscapes.E0;
                CurrentPage            = Page;
                Pages.Add(Page);
                CreateNewPage(); // Add header page for later
                string fn = (file.FileName ?? "").Trim();
                if (string.IsNullOrWhiteSpace(fn))
                {
                    fn = "Telesoftware";
                }
                fn = fn.Replace("|", "|E"); // Escape escape sequence if present in filename
                string contents = "";
                CreateNewPage();
                contents        = new string(' ', 40);                       // Blank line for NXtel header
                contents       += "|A";                                      // Start of telesoftware block
                CurrentChecksum = 0;
                contents       += Checksum("|G" + CurrentPage.Frame + "|I"); // Frame letter of telesoftware block, terminated
                                                                             //contents += Checksum("|L"); // EOL, completing header
                int address = 0;
                foreach (byte b in file.Contents)
                {
                    string newChar = EscapeChar(b);
                    if (contents.Length + newChar.Length > PAGE_LEN)
                    {
                        contents += "|Z" + CurrentChecksum.ToString("D3");
                        CurrentPage.ConvertContentsFromString(contents);
                        debug.LogWithoutTimestamp("");
                        CreateNewPage();
                        //newChar = EscapeChar(b); // Recalculate from TelesoftEscapes.E0
                        contents        = new string(' ', 40);                       // Blank line for NXtel header
                        contents       += "|A";                                      // Start of telesoftware block
                        CurrentChecksum = 0;
                        contents       += Checksum("|G" + CurrentPage.Frame + "|I"); // Frame letter of telesoftware block, terminated
                                                                                     //contents += Checksum("|L"); // EOL, completing header
                        contents += Checksum(newChar);
                    }
                    else
                    {
                        contents += Checksum(newChar);
                    }
                    debug.Log(address.ToString("X8"), b.ToString("X2") + "  " + b.ToString().PadLeft(3)
                              + "  " + newChar.PadRight(6) + CurrentEscape.ToString());
                    address++;
                }
                contents += Checksum("|F");
                contents += "|Z" + CurrentChecksum.ToString("D3"); // end of frame plus checksum
                CurrentPage.ConvertContentsFromString(contents);
                // Calculate header contents
                contents        = new string(' ', 40);                        // Blank line for NXtel header
                contents       += "|A";                                       // Start of telesoftware block
                CurrentChecksum = 0;
                contents       += Checksum("|G" + Pages[1].Frame);            // Frame letter of telesoftware block
                contents       += Checksum("|I" + fn + "|L");                 // Telesoftware filename
                contents       += Checksum((Pages.Count - 2).ToString("D3")); // header frame count
                contents       += "|Z";                                       // end of telesoftware block
                contents       += CurrentChecksum.ToString("D3");             // header checksum
                Pages[1].ConvertContentsFromString(contents);
                Page.PageRange = new NXtelData.Pages();
                Page.PageRange.AddRange(Pages);
                var lastPage = Pages[Pages.Count - 1];
                Pages[0].ToPageNo  = lastPage.PageNo;
                Pages[0].ToFrameNo = lastPage.FrameNo;
                Pages[0].Routing.AddOrUpdate((byte)RouteKeys.Enter, Pages[0].NextPageNo, Pages[0].NextFrameNo);
                foreach (var page in Pages)
                {
                    page.PageRangeCount = Pages.Count;
                }
                PageCache.Add(Pages[0]);
            }
        }