Beispiel #1
0
        public void FileCopyTo(string LocalSourceFileName, string RemoteDestinationFileName)
        {
            string     cmd    = "";
            string     answer = "";
            string     resp   = "";
            string     desc   = "";
            KeyValPair kvp    = new KeyValPair(';', ':');


            FileInfo fi = new FileInfo(LocalSourceFileName);

            if (fi.Exists == false)
            {
                throw new Exception("Local source file not found!");
            }

            //byte checksum = 0;


            string destination_dir_path = Globals.GetDirectoryOfFile(RemoteDestinationFileName);

            cmd    = string.Format("req:dir_exists; path:{0};", destination_dir_path);
            answer = RequestCommand(cmd, 2000);
            //MessageBox.Show(answer);
            HandleDeviceEvent(answer);
            kvp.Clear();
            kvp.Fill(answer);
            resp = kvp.GetVal("resp");
            desc = kvp.GetVal("desc");
            // add a log here with 'desc' field
            if (resp == "0")
            {
                cmd  = string.Format("req:dir_create; path:{0};", destination_dir_path);
                resp = RequestCommand(cmd, 2000);
                if (resp == "0")
                {
                    throw new Exception("Unable to locate destination folder");
                }
            }

            cmd    = string.Format("req:file_create; file_name:{0}; file_length:{1}", RemoteDestinationFileName, fi.Length);
            answer = RequestCommand(cmd, 2000);
            //MessageBox.Show(answer);
            HandleDeviceEvent(answer);
            kvp.Clear();
            kvp.Fill(answer);
            resp = kvp.GetVal("resp");
            desc = kvp.GetVal("desc");
            // add a log here with 'desc' field
            if (resp == "1")    // The other side is ready to receive the content of the file.
            {
                long total_bytes_sent = SendOutData(LocalSourceFileName);
            }
        }
Beispiel #2
0
        public string FetchFile(string RemoteFullFileName, string LocalDirPath)
        {
            string     cmd    = string.Format("req:file_get_preper_to_send_file; full_file_name:{0};", RemoteFullFileName);
            string     answer = RequestCommand(cmd, 10000);
            KeyValPair kvp    = new KeyValPair(';', ':');

            kvp.Fill(answer);

            string resp = kvp.GetVal("resp");

            if (resp == "1")
            {
                long file_length = 0;
                long.TryParse(kvp.GetVal("file_length"), out file_length);

                cmd    = string.Format("req:file_sned_file; full_file_name:{0};", RemoteFullFileName);
                answer = RequestCommand(cmd, 10000);
                kvp.Clear();
                kvp.Fill(answer);
                if (kvp.GetVal("resp") == "1")
                {
                    string remote_root           = kvp.GetVal("root");
                    string remote_full_file_name = kvp.GetVal("full_file_name");
                    string remote_rel_file_name  = remote_full_file_name.Replace(remote_root, "");


                    string local_full_file_name = LocalDirPath + remote_rel_file_name;

                    local_full_file_name    = local_full_file_name.Replace("/", "\\");
                    this.IncomingFileLength = file_length;
                    this.IncomingFileName   = local_full_file_name;
                    string local_path = Globals.GetDirOfFile(local_full_file_name);
                    try
                    {
                        if (Directory.Exists(local_path) == false)
                        {
                            Directory.CreateDirectory(local_path);
                        }
                        this.IncomingStream        = new BinaryWriter(new FileStream(IncomingFileName, FileMode.Create));
                        this.IncomingFileAvailable = true;
                    }
                    catch
                    {
                        //
                    }
                }
            }
            return(answer);
        }
Beispiel #3
0
        public string[] GetListOfCards(string Group)
        {
            List <string> res    = new List <string>();
            string        cmd    = string.Format("req:card_get_cards; group:{0}", Group);
            string        answer = RequestCommand(cmd, 10000);

            KeyValPair kvp = new KeyValPair(';', ':');

            kvp.Fill(answer);
            if (kvp.GetVal("resp") != "1")
            {
                return(res.ToArray());
            }

            try
            {
                int group_count = int.Parse(kvp.GetVal("card_count"));
                for (int i = 0; i < group_count; i++)
                {
                    res.Add(kvp.GetVal(string.Format("c_{0}", i + 1)));
                }
            }
            catch (Exception ex)
            {
                return(res.ToArray());
            }
            return(res.ToArray());
        }
Beispiel #4
0
        internal string[] GetListOfDirs(string RemotePath)
        {
            List <string> res    = new List <string>();
            string        cmd    = string.Format("req:dir_get_dirs; path:{0};", RemotePath);
            string        answer = RequestCommand(cmd, 10000);

            KeyValPair kvp = new KeyValPair(';', ':');

            kvp.Fill(answer);
            if (kvp.GetVal("resp") != "1")
            {
                return(res.ToArray());
            }

            try
            {
                int dir_count = int.Parse(kvp.GetVal("dir_count"));
                for (int i = 0; i < dir_count; i++)
                {
                    res.Add(kvp.GetVal(string.Format("d_{0}", i + 1)));
                }
            }
            catch (Exception ex)
            {
                return(res.ToArray());
            }

            return(res.ToArray());
        }
Beispiel #5
0
        private void HandleDeviceEvent(string EventString)
        {
            if (this.OnLog == null)
            {
                return;
            }
            if (this.Owner == null)
            {
                return;
            }
            if (EventString == null || EventString == "")
            {
                return;
            }
            if (this.Owner.InvokeRequired)
            {
                try
                {
                    this.Owner.Invoke(new DelegateLog(HandleDeviceEvent), new object[] { EventString });
                }
                catch (Exception ex)
                {
                    //
                }
            }
            else
            {
                KeyValPair kvp = new KeyValPair(';', ':');
                kvp.Fill(EventString);
                string event_name = kvp.GetVal("event");

                if (event_name == "file_received")
                {
                    string file_name   = kvp.GetVal("file_name");
                    long   file_length = 0;
                    long.TryParse(kvp.GetVal("file_length"), out file_length);
                    if (this.OnFileSentCompeleted != null)
                    {
                        OnFileSentCompeleted(file_name, file_length);
                        this.OnLog(string.Format("File '{0}' Copied.", file_name));
                    }
                }
                else if (event_name == "file_transmition_finished")
                {
                    string file_name   = kvp.GetVal("file_name");
                    long   file_length = 0;
                    long.TryParse(kvp.GetVal("file_length"), out file_length);

                    if (this.OnFileReceivedCompeleted != null)
                    {
                        OnFileReceivedCompeleted(file_name, file_length);
                        this.OnLog(string.Format("File '{0}' Fetched.", file_name));
                    }
                }
            }
        }
Beispiel #6
0
        public string EchoBack(string Text)
        {
            string     cmd    = string.Format("req:echo_back; text:{0};", Text);
            string     answer = RequestCommand(cmd, 2000);
            KeyValPair kvp    = new KeyValPair(';', ':');

            kvp.Fill(answer);
            string resp = kvp.GetVal("resp");
            string desc = kvp.GetVal("desc");

            return(desc);
        }
Beispiel #7
0
        internal bool RemoveCard(string CardPath)
        {
            List <string> res    = new List <string>();
            string        cmd    = string.Format("req:card_remove; card_path:{0}", CardPath);
            string        answer = RequestCommand(cmd, 10000);

            KeyValPair kvp = new KeyValPair(';', ':');

            kvp.Fill(answer);
            if (kvp.GetVal("resp") != "1")
            {
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        public bool DirCreate(string RemoteDirPathRel)
        {
            string     cmd    = string.Format("req:dir_create; path:{0};", RemoteDirPathRel);
            string     answer = RequestCommand(cmd, 10000);
            KeyValPair kvp    = new KeyValPair(';', ':');

            kvp.Fill(answer);
            if (kvp.GetVal("resp") != "1")
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #9
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            dgvCards.Rows.Clear();
            string[] Phone_cards = com.GetListOfCards(cmbPhoneCardGroup.SelectedItem.ToString());
            string[] Pc_cards =null;
            int row = 0;

            foreach (string phone_side_card in Phone_cards)
            {
                int indx = dgvCards.Rows.Add(1);
                dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCard.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = Globals.GetLastPartOfDir(phone_side_card);
                dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = phone_side_card;
                dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

            }


            if (cmbPcCardGroup.SelectedIndex == 0)
            {
                List<string> all_cards = new List<string>();
                string[] groups = Globals.GetPathOfEachGroup();
                foreach (string group in groups)
                {
                    string[] cards = Globals.GetPathOfEachCard(group);
                    foreach (string card in cards)
                    {
                        all_cards.Add(card);
                    }
                }
                Pc_cards = all_cards.ToArray();
            }
            else
            {
                string group = group = Globals.GetCardsPath() + "\\" + cmbPcCardGroup.SelectedItem.ToString();
                Pc_cards = Globals.GetPathOfEachCard(group);
            }

            if (Phone_cards != null)
            {

                if (Pc_cards!=null) foreach (string card_dir_path in Pc_cards)
                {
                    string card_name = Globals.GetLastPartOfDir(card_dir_path);
                    int idx = Lookup(card_name, dgvCards);
                    if (idx == -1)
                    {
                        int indx = dgvCards.Rows.Add(1);
                        dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                        dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                        dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

                    }
                    else
                    {
                        dgvCards.Rows[idx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[idx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                    }
                }
            }


            // Extract manifest data
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                
                // Extract manifest data of phone-side cards
                string card_path_phone = (string)dgvCards.Rows[i].Cells[clmnCardPathPhone.Index].Value;
                string manifest_phone = "";
                if (card_path_phone != "")
                {
                    manifest_phone = com.GetManifestData(card_path_phone);
                    dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value = manifest_phone;
                }
                

                // Extract manifest data of pc-side cards
                string card_path_pc = (string)dgvCards.Rows[i].Cells[clmnCardPathPc.Index].Value;
                string manifest_pc = "";
                if (card_path_pc != "")
                {
                    manifest_pc = File.ReadAllText(card_path_pc+"/manifest.man");
                    KeyValPair kvp = new KeyValPair('\n','=');
                    kvp.Fill(manifest_pc);
                    manifest_pc = kvp.GetString(';',':');
                    dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value = manifest_pc;
                }
            }


            // Define proper action for transfering cards to/from pc from/to phone.
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                string manifest_phone = (string)dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value;
                string manifest_pc = (string)dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value;

                if (manifest_phone == "" && manifest_pc == "") continue;
                else if (manifest_phone == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                else if (manifest_pc == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                else
                {
                    KeyValPair kvp_phone = new KeyValPair(';', ':');
                    kvp_phone.Fill(manifest_phone);

                    KeyValPair kvp_pc = new KeyValPair(';', ':');
                    kvp_pc.Fill(manifest_pc);


                    double ph_last_modified = 0; 
                    double pc_last_modified = 0;
                    try
                    {
                       ph_last_modified = Double.Parse(kvp_phone.GetVal("last_modified"));
                       pc_last_modified = Double.Parse(kvp_pc.GetVal("last_modified"));
                    }
                    catch
                    {
                        dgvCards.Rows[i].Cells[clmnAction.Index].Value = "!";
                        continue;
                    }

                    if (pc_last_modified == ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<--->";
                    else if (pc_last_modified > ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                    else dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                }

            }

            if (chbxShowDiffs.Checked) ShowOnlyDiffs();
        }