Exemple #1
0
        static void InitXmlConfig()
        {
            csDBToExcel e2o = new csDBToExcel();

            e2o.Sheets  = new List <Sheet>();
            e2o.ConnStr = "connection string";
            e2o.DBType  = "oracle";

            Sheet sm = new Sheet();

            sm.SheetName = "sheetname";
            sm.Sql       = "sql sentence";

            sm.Fileds = new List <Filed>();

            Filed fm = new Filed();

            fm.FldName = "fieldname";
            fm.RowName = "rowname";

            sm.Fileds.Add(fm);
            e2o.Sheets.Add(sm);

            e2o.toXmlFile();
        }
 public override AjaxResultModel <T> IsValid <T>(object value)
 {
     if (!value.IsStringEmpty())
     {
         return(AjaxResult.Success <T>(1000, "验证成功"));
     }
     return(AjaxResult.Error <T>(Filed.IsStringEmpty() ? _errMsg : Filed + "不能为空"));
 }
Exemple #3
0
        /// <summary>
        /// Function that uploads file to a Joined based on Relative path and IP:Port that it has to upload to.
        /// </summary>
        /// <param name="IpPost">IP:Port that it has to upload to.</param>
        /// <param name="rel"> Relative path of uploading file.</param>
        public void UploadFile(string IpPost, string rel)
        {
            string loc = Filed.GetLocalFromRelative(rel);

            using (FileStream fs = new FileStream(loc, FileMode.Open))
            {
                servH.Send(IpPost, fs.Length, fs);
            }
            UIHandler.WriteLog($"Uploaded {rel}", Color.Green);
        }
Exemple #4
0
        /// <summary>
        /// Function that uploads file to a Joined based on Relative path and IP:Port that it has to upload to.
        /// </summary>
        /// <param name="IpPost">IP:Port that it has to upload to.</param>
        /// <param name="rel"> Relative path of uploading file.</param>
        public void UploadFile(string rel)
        {
            string loc = Filed.GetLocalFromRelative(rel);

            SyncResponse sr = SendMessage("!catchFile " + rel);

            using (FileStream fs = new FileStream(loc, FileMode.Open))
            {
                clientH.Send(fs.Length, fs);
            }

            UIHandler.WriteLog($"Uploaded {rel}", Color.Green);
        }
Exemple #5
0
        private static SyntaxObjectNode ParseNodeFromObject(Type ObjType, object Obj)
        {
            var Node   = new SyntaxObjectNode();
            var Fileds = ObjType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var Filed in Fileds)
            {
                var FiledValue = Filed.GetValue(Obj);
                var FiledNode  = ParseNodeFromValue(Filed.FieldType, FiledValue);
                Node.AddChild(Filed.Name, FiledNode);
            }

            return(Node);
        }
Exemple #6
0
 public override AjaxResultModel <T> IsValid <T>(object value)
 {
     if (value != null)
     {
         if (value.IsStringEmpty())
         {
             return(AjaxResult.Error <T>(Filed.IsStringEmpty() ? _errMsg : Filed + "不能为空"));
         }
         var res = Regex.IsMatch(value.ToString(), @"^[1][3,4,5,6,7,8,9]\d{9}$");
         if (res)
         {
             return(AjaxResult.Success <T>(1000, "验证成功"));
         }
     }
     return(AjaxResult.Error <T>(Filed.IsStringEmpty() ? _errMsg : Filed + "不正确"));
 }
Exemple #7
0
        private List <object> GetSubcolumns(Filed column)
        {
            var           subColumnIDs       = column.subColumns.Where(x => x.subColumns != null).Select(y => y.pidURI).AsEnumerable();
            var           subColumnDocuments = _elasticSearchRepository.GetSchemaUIResource(subColumnIDs, UpdateIndex.Published).ToList <object>();
            List <object> filledColumns      = new List <object>();

            foreach (var item in subColumnDocuments)
            {
                var subColumnObject = column.subColumns.Where(x => x.pidURI == GetPidUrl((JObject)item)).FirstOrDefault();
                if (subColumnObject.subColumns.Count > 0)
                {
                    JObject jsonColumnDocument = JObject.Parse(item.ToString());
                    jsonColumnDocument.Add(new JProperty("hasSubColumns", GetSubcolumns(subColumnObject)));
                    filledColumns.Add(jsonColumnDocument);
                }
                else
                {
                    filledColumns.Add(item);
                }
            }
            return(filledColumns);
        }
Exemple #8
0
        /// <summary>
        /// Event handler for receiving stream from Joined. Currently made for downloading files.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void StreamReceived(object sender, StreamReceivedFromClientEventArgs args)
        {
            UIHandler.WriteLog($"Downloading {DownloadFileTo.Replace(Filed.RootPath, "")}...", Color.Green);
            UIHandler.ResetProgressBarValue();

            gettingFile = true;
            long bytesRemaining = args.ContentLength;
            int  bytesRead      = 0;

            byte[] buffer = new byte[bufferSize];

            UIHandler.SetProgressBarMaxValue((int)bytesRemaining);

            Directory.CreateDirectory(Path.GetDirectoryName(DownloadFileTo));

            using (FileStream fs = new FileStream(DownloadFileTo, FileMode.CreateNew))
            {
                while (bytesRemaining > 0)
                {
                    bytesRead = args.DataStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead > 0)
                    {
                        fs.Write(buffer, 0, bytesRead);
                        UIHandler.IncrementProgressBar(bytesRead);
                        bytesRemaining -= bytesRead;
                    }
                }
            }

            Filed.FilesData.Add(new FileData(Filed.RootPath, DownloadFileTo));
            Filed.ChangeFileModifiedStatusByRelativePath(DownloadFileTo.Replace(Filed.RootPath, ""), FileModifiedStatus.Changed);
            UIHandler.WriteLog($"Downloaded {DownloadFileTo.Replace(Filed.RootPath, "")}", Color.Green);

            DownloadFileTo = "";
            servH.Events.StreamReceived -= StreamReceived;
            gettingFile = false;
        }
Exemple #9
0
        /// <summary>
        /// Event handler for SyncRequest being received by Host.
        /// </summary>
        /// <param name="arg">The SyncRequest that recieved.</param>
        /// <returns></returns>
        //======Joined requests======
        //!qq = Exit
        //!getFile *relative path to file* = upload file to Joined
        //!catchFile *relative path to file* = get file from Joined
        //!exists *relative path to file* = check if file exists on servers side and then answer for Joined
        //!getFileDataList = get all relative pathes and hashes to it and send it to Joined
        //!sessiondone = updates servers Filer and Hasher
        //!rm *relative path to file* = remove file on Host side
        //!getFileInfo *relative path to file* = get file info from Host

        //======Host Respones======
        //!dd = ready for next operation
        //!Yes = answer for file existance if it does exist
        //!No = answer for file existance if it does not exist
        private SyncResponse SyncSolver(SyncRequest arg)
        {
            servH.Events.StreamReceived -= StreamReceived;
            string       cmd = GetStringFromBytes(arg.Data);
            SyncResponse sr  = new SyncResponse(arg, GetBytesFromString("NotRecognized"));

            if (cmd.Contains("!qq"))
            {
                servH.DisconnectClients();
                servH.Stop();
                servH.Dispose();
            }
            else if (cmd.Contains("!getFile "))
            {
                cmd = cmd.Replace("!getFile ", "");
                UploadFile(arg.IpPort, cmd);
                sr = new SyncResponse(arg, GetBytesFromString("!dd"));
            }
            else if (cmd.Contains("!catchFile "))
            {
                while (gettingFile)
                {
                }

                DownloadFileTo = Filed.RootPath + cmd.Replace("!catchFile ", "");
                sr             = new SyncResponse(arg, GetBytesFromString("!dd"));
                servH.Events.StreamReceived += StreamReceived;
            }
            else if (cmd.Contains("!exists "))
            {
                cmd = cmd.Replace("!exists ", "");
                if (Filed.CheckFileExistanceFromRelative(cmd))
                {
                    sr = new SyncResponse(arg, GetBytesFromString("!Yes"));
                }
                else
                {
                    sr = new SyncResponse(arg, GetBytesFromString("!No"));
                }
            }
            else if (cmd.Contains("!getFileDataList"))
            {
                cmd = cmd.Replace("!getFileDataList", "");
                sr  = new SyncResponse(arg, GetBytesFromString(GetFileList()));
            }
            else if (cmd.Contains("!sessiondone"))
            {
                cmd = cmd.Replace("!sessiondone", "");
                Filed.RecomputeHashesBasedOnModifiedStatus();
                FilerHashesIO.WriteHashesToFile(ts.hashDictionaryName, Filed);
                sr = new SyncResponse(arg, GetBytesFromString("!dd"));
                UIHandler.WriteLog("Session done!", Color.Green);
            }
            else if (cmd.Contains("!rm "))
            {
                cmd = cmd.Replace("!rm ", "");
                if (Filed.GetLocalFromRelative(cmd) != "?FileNotFound?")
                {
                    File.Delete(Filed.GetLocalFromRelative(cmd));
                    Filed.ChangeFileModifiedStatusByRelativePath(cmd, FileModifiedStatus.Deleted);
                }
                sr = new SyncResponse(arg, GetBytesFromString("!dd"));
            }
            else if (cmd.Contains("!getFileInfo "))
            {
                cmd = cmd.Replace("!getFileInfo ", "");
                FileInfo fi = Filed.GetLocalFileInfoFromRelative(cmd);
                sr = new SyncResponse(arg, GetBytesFromString($"{fi.Length}\n{fi.LastAccessTime.ToString()}"));
            }
            return(sr);
        }
Exemple #10
0
        internal static bool SaveDataTableChanges(DataTable CSVDataTable, string FileFullPath, char DataSaperator)
        {
            try
            {
                List <string>  AddedLinesList = new List <string>();
                List <DataRow> result;


                if (!File.Exists(FileFullPath) || string.IsNullOrWhiteSpace(File.ReadAllText(FileFullPath)))
                {
                    string Header = "";

                    int Index = 0;
                    foreach (DataColumn Col in CSVDataTable.Columns)
                    {
                        if (Index == 0)
                        {
                            Header += Col.Caption;
                        }
                        else
                        {
                            Header += DataSaperator + Col.Caption;
                        }

                        Index++;
                    }

                    AddedLinesList.Add(Header);
                    result = CSVDataTable.AsEnumerable().ToList();
                }
                else
                {
                    result = CSVDataTable.AsEnumerable().Where(dr => dr.RowState == DataRowState.Added).ToList();
                }


                foreach (var AddedRow in result)
                {
                    string Line = "";

                    int Index = 0;
                    foreach (object Filed in AddedRow.ItemArray)
                    {
                        if (Index == 0)
                        {
                            Line += Filed.ToString();
                        }
                        else
                        {
                            Line += DataSaperator + Filed.ToString();
                        }

                        Index++;
                    }
                    AddedLinesList.Add(Line);
                }

                File.AppendAllLines(FileFullPath, AddedLinesList);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #11
0
        /// <summary>
        /// The main syncronization procedure.
        /// </summary>
        public void Syncronize()
        {
            UIHandler.PlayColorfulBarAnimation(true);
            GetHostFileDataList();
            UIHandler.WriteLog($"Recieved Host FileData list!", Color.Green);
            Syncronizer sync = new Syncronizer(Filed.FilesData, FDGotFromServer);

            var fddList = sync.fdd.ToList();

            for (int i = 0; i < sync.saList.Count; i++)
            {
                // Switch that makes stuff specified on what was chosen.
                switch (sync.saList[i])
                {
                case SyncAction.GetFromHost:
                    if (File.Exists(Filed.MakeLocalPathFromRelative(fddList[i].FileRelativePath)))
                    {
                        File.Delete(Filed.MakeLocalPathFromRelative(fddList[i].FileRelativePath));
                    }
                    DownloadFile(fddList[i].FileRelativePath);
                    Filed.ChangeFileModifiedStatusByRelativePath(fddList[i].FileRelativePath, FileModifiedStatus.Changed);
                    break;

                case SyncAction.GetFromJoined:
                    DeleteOnHost(fddList[i].FileRelativePath);
                    UploadFile(fddList[i].FileRelativePath);
                    break;

                case SyncAction.Skip:
                    break;

                case SyncAction.GetNewClone:
                    string tempFileName             = Filed.RootPath + fddList[i].FileRelativePath;
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(tempFileName);
                    string extenstion = Path.GetExtension(tempFileName);
                    int    cntr       = 1;
                    while (File.Exists(Filed.RootPath + fileNameWithoutExtension + $"(Cloned {cntr})" + extenstion))
                    {
                        cntr++;
                    }
                    DownloadFile(fddList[i].FileRelativePath, fileNameWithoutExtension + $"(Cloned {cntr})" + extenstion);
                    Filed.FilesData.Add(new FileData(Filed.RootPath, Filed.MakeLocalPathFromRelative(fileNameWithoutExtension + $"(Cloned {cntr})" + extenstion)));
                    Filed.ChangeFileModifiedStatusByRelativePath(fileNameWithoutExtension + $"(Cloned {cntr})" + extenstion, FileModifiedStatus.Changed);
                    break;

                case SyncAction.Delete:
                    if (File.Exists(Filed.MakeLocalPathFromRelative(fddList[i].FileRelativePath)))
                    {
                        File.Delete(Filed.MakeLocalPathFromRelative(fddList[i].FileRelativePath));
                    }
                    DeleteOnHost(fddList[i].FileRelativePath);
                    Filed.ChangeFileModifiedStatusByRelativePath(fddList[i].FileRelativePath, FileModifiedStatus.Deleted);
                    break;

                case SyncAction.NotChosen:
                    break;

                default:
                    break;
                }
            }

            SyncResponse sr = SendMessage("!sessiondone");

            Filed.RecomputeHashesBasedOnModifiedStatus();
            FilerHashesIO.WriteHashesToFile(ts.hashDictionaryName, Filed);
            UIHandler.WriteLog("Session done!");
            UIHandler.ToggleProgressBarVisibility(false);
            UIHandler.StopColorfulBarAnimation();
        }